Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/net/pufferlab/antiquities/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down
39 changes: 37 additions & 2 deletions src/main/java/net/pufferlab/antiquities/blocks/BlockPile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down