From 8a54668e453aa254e953654d1ac5ef661cecfe9f Mon Sep 17 00:00:00 2001 From: DarkStarDS9 Date: Fri, 16 Jan 2015 10:21:17 +0100 Subject: [PATCH 1/2] Different Item-Place-Logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this fixes CrazyPants/EnderIO/#1648 the original way caused problems with items that relied on player.inventory.currentItem, like cables from AE2 - they would set the .currentItem-Stack to null when you placed the last cable, which in our case would kill the pick. Also, we’re now using the bult-in “can we place the item there?” logic and can therefore remove canPlaceBlockOnRightClick. It’s still not perfect though, because it doesn’t work with buckets… see the source-code-comments. A possible solution would be to implement a custom message that we send to ourself to switch back to the original item slot, but I’ll just go with “you’re holding the bucket wrong”. --- .../item/darksteel/ItemDarkSteelPickaxe.java | 63 ++++++++----------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/src/main/java/crazypants/enderio/item/darksteel/ItemDarkSteelPickaxe.java b/src/main/java/crazypants/enderio/item/darksteel/ItemDarkSteelPickaxe.java index 70d0391f..a59c4753 100644 --- a/src/main/java/crazypants/enderio/item/darksteel/ItemDarkSteelPickaxe.java +++ b/src/main/java/crazypants/enderio/item/darksteel/ItemDarkSteelPickaxe.java @@ -5,6 +5,7 @@ import java.util.Set; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -12,12 +13,10 @@ import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; -import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.util.ForgeDirection; import cofh.api.energy.IEnergyContainerItem; import com.google.common.collect.Sets; @@ -33,8 +32,6 @@ import crazypants.enderio.machine.power.PowerDisplayUtil; import crazypants.enderio.teleport.IItemOfTravel; import crazypants.enderio.teleport.TravelController; import crazypants.enderio.teleport.TravelSource; -import crazypants.render.BoundingBox; -import crazypants.util.BlockCoord; import crazypants.util.ItemUtil; import crazypants.util.Lang; @@ -125,39 +122,33 @@ public class ItemDarkSteelPickaxe extends ItemPickaxe implements IEnergyContaine } static boolean doRightClickItemPlace(EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) { - int current = player.inventory.currentItem; - int slot = current == 0 && Config.slotZeroPlacesEight ? 8 : current + 1; - if(slot < 9 && player.inventory.mainInventory[slot] != null && !(player.inventory.mainInventory[slot].getItem() instanceof IDarkSteelItem)) { - - if(!canPlaceBlockOnRightClick(player, world, x, y, z, side, slot)) { - return false; - } - boolean ret = player.inventory.mainInventory[slot].getItem().onItemUse(player.inventory.mainInventory[slot], player, world, x, y, z, side, par8, - par9, par10); - if(player.inventory.mainInventory[slot].stackSize <= 0) { - player.inventory.mainInventory[slot] = null; - } - return ret; + if (world.isRemote) { + int current = player.inventory.currentItem; + int slot = current == 0 && Config.slotZeroPlacesEight ? 8 + : current + 1; + if (slot < 9 + && player.inventory.mainInventory[slot] != null + && !(player.inventory.mainInventory[slot].getItem() instanceof IDarkSteelItem)) { + /* + * this will not work with buckets unless we don't switch back + * to the current item (the pick); there's probably some client + * <-> server event thing going on with buckets, so our + * item-switch within the same tick would be a problem. + */ + player.inventory.currentItem = slot; + Minecraft mc = Minecraft.getMinecraft(); + boolean result = mc.playerController.onPlayerRightClick( + mc.thePlayer, mc.theWorld, + player.inventory.mainInventory[slot], + mc.objectMouseOver.blockX, mc.objectMouseOver.blockY, + mc.objectMouseOver.blockZ, mc.objectMouseOver.sideHit, + mc.objectMouseOver.hitVec); + player.inventory.currentItem = current; + return (result); + } + } + return false; } - return false; - } - - static boolean canPlaceBlockOnRightClick(EntityPlayer player, World world, int x, int y, int z, int side, int slot) { - BlockCoord placeCoord = new BlockCoord(x, y, z).getLocation(ForgeDirection.getOrientation(side)); - ItemStack toUse = player.inventory.mainInventory[slot]; - AxisAlignedBB aabb; - Block blk = Block.getBlockFromItem(toUse.getItem()); - if(blk != null) { - aabb = blk.getCollisionBoundingBoxFromPool(world, placeCoord.x, placeCoord.y, placeCoord.z); - } else { - BoundingBox bb = new BoundingBox(placeCoord); - aabb = bb.getAxisAlignedBB(); - } - if(aabb != null && aabb.intersectsWith(player.boundingBox)) { - return false; - } - return true; - } private void applyDamage(EntityLivingBase entity, ItemStack stack, int damage) { From c3257e4d50886b55b9b024587496b5269ee76915 Mon Sep 17 00:00:00 2001 From: DarkStarDS9 Date: Sat, 17 Jan 2015 14:07:57 +0100 Subject: [PATCH 2/2] SMP Fix --- .../item/darksteel/ItemDarkSteelPickaxe.java | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/main/java/crazypants/enderio/item/darksteel/ItemDarkSteelPickaxe.java b/src/main/java/crazypants/enderio/item/darksteel/ItemDarkSteelPickaxe.java index a59c4753..4a270d7e 100644 --- a/src/main/java/crazypants/enderio/item/darksteel/ItemDarkSteelPickaxe.java +++ b/src/main/java/crazypants/enderio/item/darksteel/ItemDarkSteelPickaxe.java @@ -113,39 +113,40 @@ public class ItemDarkSteelPickaxe extends ItemPickaxe implements IEnergyContaine return true; } - @Override - public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) { - if(!isTravelUpgradeActive(player, item)) { - return doRightClickItemPlace(player, world, x, y, z, side, par8, par9, par10); + @Override + public boolean onItemUse(ItemStack item, EntityPlayer player, World world, + int x, int y, int z, int side, float par8, float par9, float par10) { + if (!isTravelUpgradeActive(player, item) && world.isRemote) { + return doRightClickItemPlace(player, world, x, y, z, side, par8, + par9, par10); + } + return false; } - return false; - } - static boolean doRightClickItemPlace(EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) { - if (world.isRemote) { - int current = player.inventory.currentItem; - int slot = current == 0 && Config.slotZeroPlacesEight ? 8 - : current + 1; - if (slot < 9 - && player.inventory.mainInventory[slot] != null - && !(player.inventory.mainInventory[slot].getItem() instanceof IDarkSteelItem)) { - /* - * this will not work with buckets unless we don't switch back - * to the current item (the pick); there's probably some client - * <-> server event thing going on with buckets, so our - * item-switch within the same tick would be a problem. - */ - player.inventory.currentItem = slot; - Minecraft mc = Minecraft.getMinecraft(); - boolean result = mc.playerController.onPlayerRightClick( - mc.thePlayer, mc.theWorld, - player.inventory.mainInventory[slot], - mc.objectMouseOver.blockX, mc.objectMouseOver.blockY, - mc.objectMouseOver.blockZ, mc.objectMouseOver.sideHit, - mc.objectMouseOver.hitVec); - player.inventory.currentItem = current; - return (result); - } + @SideOnly(Side.CLIENT) + static boolean doRightClickItemPlace(EntityPlayer player, World world, + int x, int y, int z, int side, float par8, float par9, float par10) { + int current = player.inventory.currentItem; + int slot = current == 0 && Config.slotZeroPlacesEight ? 8 : current + 1; + if (slot < 9 + && player.inventory.mainInventory[slot] != null + && !(player.inventory.mainInventory[slot].getItem() instanceof IDarkSteelItem)) { + /* + * this will not work with buckets unless we don't switch back to + * the current item (the pick); there's probably some client <-> + * server event thing going on with buckets, so our item-switch + * within the same tick would be a problem. + */ + player.inventory.currentItem = slot; + Minecraft mc = Minecraft.getMinecraft(); + boolean result = mc.playerController.onPlayerRightClick( + mc.thePlayer, mc.theWorld, + player.inventory.mainInventory[slot], + mc.objectMouseOver.blockX, mc.objectMouseOver.blockY, + mc.objectMouseOver.blockZ, mc.objectMouseOver.sideHit, + mc.objectMouseOver.hitVec); + player.inventory.currentItem = current; + return (result); } return false; }