diff --git a/src/main/java/net/pufferlab/antiquities/Config.java b/src/main/java/net/pufferlab/antiquities/Config.java index 09ee955..479360f 100644 --- a/src/main/java/net/pufferlab/antiquities/Config.java +++ b/src/main/java/net/pufferlab/antiquities/Config.java @@ -41,6 +41,7 @@ public class Config { public static boolean enableIngotPileModification; public static String[] ingotPileMetals; + public static boolean ingotPileGiveDirectly; public static void synchronizeConfiguration(File configFile) { Configuration configuration = new Configuration(configFile); @@ -135,6 +136,13 @@ public static void synchronizeConfiguration(File configFile) { false, "Whether you want to enable modification of ingot pile metal types. By default it's off so metals are always synchronized to the default values."); + ingotPileGiveDirectly = configuration.getBoolean( + "ingotPileGiveDirectly", + CATEGORY_TECHNICAL, + false, + "If true, ingots taken from an ingot pile go directly into the player's inventory instead of dropping on the ground (falls back to dropping if the inventory is full)." + ); + if (enableIngotPileModification) { ingotPileMetals = configuration.getStringList( "ingotPileMetals", diff --git a/src/main/java/net/pufferlab/antiquities/blocks/BlockPile.java b/src/main/java/net/pufferlab/antiquities/blocks/BlockPile.java index f6b7f63..8ae4456 100644 --- a/src/main/java/net/pufferlab/antiquities/blocks/BlockPile.java +++ b/src/main/java/net/pufferlab/antiquities/blocks/BlockPile.java @@ -139,10 +139,10 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p } if (pile2 != null) { if (pile2.getNextSlot() != 1) { - dropItem(world, x, y + j, z, pile2.getPrevSlot()); + giveOrDropItem(world, x, y + j, z, pile2, pile2.getPrevSlot(), player); removeItemToPile(pile2); } else { - dropItem(world, x, y + j, z, 0); + giveOrDropItem(world, x, y + j, z, pile2, 0, player); pile2.setInventorySlotContentsUpdate(0); world.setBlockToAir(x, y + j, z); } @@ -298,6 +298,41 @@ private boolean dropItem(World world, int x, int y, int z, int index) { return false; } + private boolean giveOrDropItem(World world, int x, int y, int z, TileEntityPile pile, int index, + EntityPlayer player) { + if (pile == null) return false; + + ItemStack item = null; + if ((index < pile.getSizeInventory()) && (index >= 0)) { + item = pile.getInventoryStack(index); + } + if (item != null && item.stackSize > 0) { + EntityItem entityItem = new EntityItem( + world, + x + 0.5, + y + 0.25F + (0.125F * pile.getLayer()), + z + 0.5, + item.copy()); + entityItem.motionX = 0.0D; + entityItem.motionY = 0.0D; + entityItem.motionZ = 0.0D; + + // Allow instant pickup. + entityItem.delayBeforeCanPickup = 0; + + spawnEntity(world, entityItem); + + // Immediately collide with the player to attempt pickup, server-side only. + if (Config.ingotPileGiveDirectly && player != null && !world.isRemote) { + entityItem.onCollideWithPlayer(player); + } + + item.stackSize = 0; + return true; + } + return false; + } + private void dropItems(World world, int i, int j, int k) { TileEntity tileEntity = world.getTileEntity(i, j, k); if (!(tileEntity instanceof IInventory)) return;