From aa328792f7e237c811245ecd84d746c1bd7a1699 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Tue, 25 Nov 2014 21:42:41 +0100 Subject: [PATCH 1/4] Change AbilityHelper.spawnEntityAtPlayer to automatically put items into inventories by default (prevents lag-dupe) and also play sound if it got picked up. --- .../tconstruct/library/tools/AbilityHelper.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/tconstruct/library/tools/AbilityHelper.java b/src/main/java/tconstruct/library/tools/AbilityHelper.java index e0225cf8..b1c5ac11 100644 --- a/src/main/java/tconstruct/library/tools/AbilityHelper.java +++ b/src/main/java/tconstruct/library/tools/AbilityHelper.java @@ -21,6 +21,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.entity.player.UseHoeEvent; +import tconstruct.TConstruct; import tconstruct.library.*; import tconstruct.library.util.PiercingEntityDamage; @@ -568,10 +569,18 @@ public class AbilityHelper { if (!player.worldObj.isRemote) { - EntityItem entityitem = new EntityItem(player.worldObj, player.posX + 0.5D, player.posY + 0.5D, player.posZ + 0.5D, stack); - player.worldObj.spawnEntityInWorld(entityitem); - if (!(player instanceof FakePlayer)) - entityitem.onCollideWithPlayer(player); + // try to put it into the players inventory + if(player instanceof FakePlayer || !player.inventory.addItemStackToInventory(stack)) // note that the addItemStackToInventory is not called for fake players + { + // drop the rest as an entity + EntityItem entityitem = new EntityItem(player.worldObj, player.posX + 0.5D, player.posY + 0.5D, player.posZ + 0.5D, stack); + player.worldObj.spawnEntityInWorld(entityitem); + if (!(player instanceof FakePlayer)) + entityitem.onCollideWithPlayer(player); + } + // if it got picked up, we're playing the sound + else + player.worldObj.playSoundAtEntity(player, "random.pop", 0.2F, ((TConstruct.random.nextFloat() - TConstruct.random.nextFloat()) * 0.7F + 1.0F) * 2.0F); } } From 158ae52dd8bb1ee326dd32f6c0ba4d5390f5763c Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Tue, 25 Nov 2014 21:43:29 +0100 Subject: [PATCH 2/4] Fix OreBerry bushes not returning correct amount on leftclick --- .../tconstruct/world/blocks/OreberryBush.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main/java/tconstruct/world/blocks/OreberryBush.java b/src/main/java/tconstruct/world/blocks/OreberryBush.java index 0dc8a5cc..ce6cecfb 100644 --- a/src/main/java/tconstruct/world/blocks/OreberryBush.java +++ b/src/main/java/tconstruct/world/blocks/OreberryBush.java @@ -15,6 +15,7 @@ import net.minecraft.util.*; import net.minecraft.world.*; import net.minecraftforge.common.*; import net.minecraftforge.common.util.ForgeDirection; +import tconstruct.TConstruct; import tconstruct.library.TConstructRegistry; import tconstruct.library.tools.AbilityHelper; import tconstruct.world.TinkerWorld; @@ -175,24 +176,18 @@ public class OreberryBush extends BlockLeavesBase implements IPlantable @Override public void onBlockClicked (World world, int x, int y, int z, EntityPlayer player) { - if (!world.isRemote) - { - int meta = world.getBlockMetadata(x, y, z); - if (meta >= 12) - { - world.setBlock(x, y, z, this, meta - 4, 3); - AbilityHelper.spawnItemAtPlayer(player, new ItemStack(TinkerWorld.oreBerries, 1, meta % 4 + itemMeat)); - } - } + harvest(world, x,y,z, player); } /* Right-click harvests berries */ @Override public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { - /*if (world.isRemote) - return false;*/ + return harvest(world, x,y,z, player); + } + public boolean harvest(World world, int x, int y, int z, EntityPlayer player) + { int meta = world.getBlockMetadata(x, y, z); if (meta >= 12) { @@ -201,7 +196,6 @@ public class OreberryBush extends BlockLeavesBase implements IPlantable world.setBlock(x, y, z, this, meta - 4, 3); AbilityHelper.spawnItemAtPlayer(player, new ItemStack(TinkerWorld.oreBerries, random.nextInt(3) + 1, meta % 4 + itemMeat)); - return true; } return false; From 90e5d6af2591467479b8f3781924319801b702a0 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Tue, 25 Nov 2014 21:45:18 +0100 Subject: [PATCH 3/4] Remove special inventory-spawn-code in other blocks since it's handled by AbilityHelper now --- src/main/java/tconstruct/armor/blocks/DryingRack.java | 11 +---------- .../tconstruct/smeltery/logic/CastingBlockLogic.java | 9 +-------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/main/java/tconstruct/armor/blocks/DryingRack.java b/src/main/java/tconstruct/armor/blocks/DryingRack.java index 13a78885..318147db 100644 --- a/src/main/java/tconstruct/armor/blocks/DryingRack.java +++ b/src/main/java/tconstruct/armor/blocks/DryingRack.java @@ -98,7 +98,7 @@ public class DryingRack extends InventoryBlock { ItemStack decrStack = logic.decrStackSize(0, 1); if (decrStack != null) - addItemToInventory(player, world, x, y, z, decrStack); + AbilityHelper.spawnItemAtPlayer(player, decrStack); } world.markBlockForUpdate(x, y, z); @@ -106,15 +106,6 @@ public class DryingRack extends InventoryBlock return true; } - public void addItemToInventory (EntityPlayer player, World world, int x, int y, int z, ItemStack stack) - { - if(!player.inventory.addItemStackToInventory(stack)) - { - // drop the rest as an item - AbilityHelper.spawnItemAtPlayer(player, stack); - } - } - @Override public AxisAlignedBB getSelectedBoundingBoxFromPool (World world, int x, int y, int z) { diff --git a/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java b/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java index d971f348..1c7c7ea6 100644 --- a/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java @@ -317,14 +317,7 @@ public abstract class CastingBlockLogic extends InventoryLogic implements IFluid // try to transfer thes tack to the player inventory ItemStack output = event.item; - if(!player.inventory.addItemStackToInventory(output)) - { - // drop the rest as an item - AbilityHelper.spawnItemAtPlayer(player, output); - } - // added to inventory, update inventory - else - player.inventory.markDirty(); + AbilityHelper.spawnItemAtPlayer(player, output); // remove inventory contents, since we spilled the full contents of the slot inventory[slot] = null; From e1101fa41200cec7a61d79edc7f66f740235d6c0 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Tue, 25 Nov 2014 21:45:37 +0100 Subject: [PATCH 4/4] Fix inventory desync when activating drying rack/basin/oreberry --- src/main/java/tconstruct/library/tools/AbilityHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/tconstruct/library/tools/AbilityHelper.java b/src/main/java/tconstruct/library/tools/AbilityHelper.java index b1c5ac11..5004dbae 100644 --- a/src/main/java/tconstruct/library/tools/AbilityHelper.java +++ b/src/main/java/tconstruct/library/tools/AbilityHelper.java @@ -579,8 +579,10 @@ public class AbilityHelper entityitem.onCollideWithPlayer(player); } // if it got picked up, we're playing the sound - else + else { player.worldObj.playSoundAtEntity(player, "random.pop", 0.2F, ((TConstruct.random.nextFloat() - TConstruct.random.nextFloat()) * 0.7F + 1.0F) * 2.0F); + player.inventory.markDirty(); + } } }