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,33 +109,33 @@ 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){
player.setHeldItem(hand, toPlaceStack);
//tryPlaceItemIntoWorld could throw an Exception //tryPlaceItemIntoWorld could throw an Exception
try{ try{
//Places the Block into the World //Places the Block into the World
if(equip.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){ if(toPlaceStack.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){
if(!player.capabilities.isCreativeMode){ if(!player.capabilities.isCreativeMode){
player.inventory.setInventorySlotContents(slot, StackUtil.validateCopy(equip)); player.setHeldItem(hand, StackUtil.validateCopy(toPlaceStack));
} }
//Synchronizes the Client
player.inventoryContainer.detectAndSendChanges();
return EnumActionResult.SUCCESS;
} }
} }
//Notify the Player and log the Exception //Notify the Player and log the Exception
catch(Exception e){ 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!"); 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{ player.inventory.setInventorySlotContents(slot, player.getHeldItem(hand));
player.setHeldItem(hand, stack);
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }
} }
} }
}
return EnumActionResult.FAIL; return EnumActionResult.FAIL;
} }