Fixed the drill replacing itself

Closes #394
This commit is contained in:
Ellpeck 2016-11-22 19:52:33 +01:00
parent 6f90197087
commit b5caedfeec

View file

@ -45,7 +45,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.*; import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
@ -110,30 +109,30 @@ public class ItemDrill extends ItemEnergy{
if(StackUtil.isValid(upgrade)){ if(StackUtil.isValid(upgrade)){
int slot = ItemDrillUpgrade.getSlotToPlaceFrom(upgrade); int slot = ItemDrillUpgrade.getSlotToPlaceFrom(upgrade);
if(slot >= 0 && slot < InventoryPlayer.getHotbarSize()){ if(slot >= 0 && slot < InventoryPlayer.getHotbarSize()){
ItemStack anEquip = player.inventory.getStackInSlot(slot); ItemStack equip = player.inventory.getStackInSlot(slot);
if(StackUtil.isValid(anEquip) && anEquip != stack){ if(StackUtil.isValid(equip) && equip != stack){
ItemStack equip = anEquip.copy(); ItemStack toPlaceStack = equip.copy();
if(!world.isRemote){
//tryPlaceItemIntoWorld could throw an Exception player.setHeldItem(hand, toPlaceStack);
try{
//Places the Block into the World //tryPlaceItemIntoWorld could throw an Exception
if(equip.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){ try{
if(!player.capabilities.isCreativeMode){ //Places the Block into the World
player.inventory.setInventorySlotContents(slot, StackUtil.validateCopy(equip)); if(toPlaceStack.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){
} if(!player.capabilities.isCreativeMode){
//Synchronizes the Client player.setHeldItem(hand, StackUtil.validateCopy(toPlaceStack));
player.inventoryContainer.detectAndSendChanges();
return EnumActionResult.SUCCESS;
} }
} }
//Notify the Player and log the Exception
catch(Exception e){
ModUtil.LOGGER.error("Player "+player.getName()+" who should place a Block using a Drill at "+player.posX+", "+player.posY+", "+player.posZ+" in World "+world.provider.getDimension()+" threw an Exception! Don't let that happen again!");
}
} }
else{ //Notify the Player and log the Exception
return EnumActionResult.SUCCESS; catch(Exception e){
ModUtil.LOGGER.error("Player "+player.getName()+" who should place a Block using a Drill at "+player.posX+", "+player.posY+", "+player.posZ+" in World "+world.provider.getDimension()+" threw an Exception! Don't let that happen again!");
} }
player.inventory.setInventorySlotContents(slot, player.getHeldItem(hand));
player.setHeldItem(hand, stack);
return EnumActionResult.SUCCESS;
} }
} }
} }