Cleanup on crate wrenching code, also made ore filtering optional

This commit is contained in:
Robert S 2014-04-14 05:22:22 -04:00
parent 847c182571
commit 1212e27f54
2 changed files with 343 additions and 365 deletions

View file

@ -17,18 +17,17 @@ import resonantinduction.core.Reference;
import universalelectricity.api.UniversalElectricity;
import calclavia.lib.prefab.block.BlockTile;
import calclavia.lib.utility.WrenchUtility;
import calclavia.lib.utility.inventory.InventoryUtility;
import codechicken.multipart.ControlKeyModifer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* A block that allows the placement of mass amount of a specific item within it. It will be allowed
/** A block that allows the placement of mass amount of a specific item within it. It will be allowed
* to go on Conveyor Belts.
*
* NOTE: Crates should be upgraded with an item.
*
* @author DarkGuardsman
*/
* @author DarkGuardsman */
public class BlockCrate extends BlockTile
{
Icon advanced, elite;
@ -91,46 +90,27 @@ public class BlockCrate extends BlockTile
if (world.getBlockTileEntity(x, y, z) instanceof TileCrate)
{
TileCrate tile = (TileCrate) world.getBlockTileEntity(x, y, z);
tile.buildSampleStack();
ItemStack sampleStack = tile.getSampleStack();
if (player.getCurrentEquippedItem() != null && WrenchUtility.isWrench(player.getCurrentEquippedItem()))
if (WrenchUtility.isWrench(player.getCurrentEquippedItem()))
{
if (player.isSneaking())
{
ItemStack containingStack = tile.getSampleStack();
tile.buildSampleStack();
if (containingStack != null)
if (sampleStack != null && sampleStack.stackSize > 0)
{
if (containingStack.stackSize > 0)
{
float area = 0.7F;
double dropX = (world.rand.nextFloat() * area) + (1.0F - area) * 0.5D;
double dropY = (world.rand.nextFloat() * area) + (1.0F - area) * 0.5D;
double dropZ = (world.rand.nextFloat() * area) + (1.0F - area) * 0.5D;
ItemStack dropStack = new ItemStack(this, 1, tile.getBlockMetadata());
ItemBlockCrate.setContainingItemStack(dropStack, containingStack);
EntityItem var13 = new EntityItem(world, x + dropX, y + dropY, z + dropZ, dropStack);
var13.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(var13);
ItemStack dropStack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
ItemBlockCrate.setContainingItemStack(dropStack, sampleStack);
InventoryUtility.dropItemStack(world, x, y, z, dropStack, 10, 0);
for (int i = 0; i < tile.getInventory().getSizeInventory(); i++)
{
tile.getInventory().setInventorySlotContents(i, null);
}
world.setBlock(x, y, z, 0, 0, 3);
}
return true;
}
}
return false;
}
/**
* Swap oredict nodes if the player is wrenching the crate.
*/
ItemStack sampleStack = tile.getSampleStack();
int oreID = OreDictionary.getOreID(sampleStack);
@ -154,6 +134,7 @@ public class BlockCrate extends BlockTile
}
}
}
return true;
}
/** Make double clicking input all stacks. */
@ -186,10 +167,8 @@ public class BlockCrate extends BlockTile
return true;
}
/**
* Try to inject it into the crate. Otherwise, look around for nearby crates and try to put them
* in.
*/
/** Try to inject it into the crate. Otherwise, look around for nearby crates and try to put them
* in. */
public void tryInsert(TileCrate tileEntity, EntityPlayer player, boolean allMode, boolean doSearch)
{
boolean success;
@ -268,7 +247,7 @@ public class BlockCrate extends BlockTile
{
if (tileEntity.getSampleStack() != null)
{
if (!(tileEntity.getSampleStack().isItemEqual(currentStack) || (!OreDictionary.getOreName(OreDictionary.getOreID(tileEntity.getSampleStack())).equals("Unknown") && OreDictionary.getOreID(tileEntity.getSampleStack()) == OreDictionary.getOreID(currentStack))))
if (!(tileEntity.getSampleStack().isItemEqual(currentStack) || (tileEntity.oreFilterEnabled && !OreDictionary.getOreName(OreDictionary.getOreID(tileEntity.getSampleStack())).equals("Unknown") && OreDictionary.getOreID(tileEntity.getSampleStack()) == OreDictionary.getOreID(currentStack))))
{
return false;
}
@ -282,11 +261,9 @@ public class BlockCrate extends BlockTile
return false;
}
/**
* Inserts all items of the same type this player has into the crate.
/** Inserts all items of the same type this player has into the crate.
*
* @return True on success
*/
* @return True on success */
public boolean insertAllItems(TileCrate tileEntity, EntityPlayer player)
{
ItemStack requestStack = null;
@ -329,14 +306,12 @@ public class BlockCrate extends BlockTile
return false;
}
/**
* Ejects and item out of the crate and spawn it under the player entity.
/** Ejects and item out of the crate and spawn it under the player entity.
*
* @param tileEntity
* @param player
* @param requestSize - The maximum stack size to take out. Default should be 64.
* @return True on success
*/
* @return True on success */
public boolean ejectItems(TileCrate tileEntity, EntityPlayer player, int requestSize)
{
World world = tileEntity.worldObj;
@ -381,12 +356,10 @@ public class BlockCrate extends BlockTile
return false;
}
/**
* Puts an itemStack into the crate.
/** Puts an itemStack into the crate.
*
* @param tileEntity
* @param itemStack
*/
* @param itemStack */
public static ItemStack addStackToCrate(TileCrate tileEntity, ItemStack itemStack)
{
if (itemStack == null || itemStack.getItem().isDamageable() && itemStack.getItem().getDamage(itemStack) > 0)
@ -396,7 +369,7 @@ public class BlockCrate extends BlockTile
ItemStack containingStack = tileEntity.getSampleStack();
if (containingStack == null || (containingStack.isItemEqual(itemStack) || OreDictionary.getOreID(containingStack) == OreDictionary.getOreID(itemStack)))
if (containingStack == null || (containingStack.isItemEqual(itemStack) || (tileEntity.oreFilterEnabled && OreDictionary.getOreID(containingStack) == OreDictionary.getOreID(itemStack))))
{
int room = Math.max((tileEntity.getInventory().getSizeInventory() * 64) - (containingStack != null ? containingStack.stackSize : 0), 0);
if (itemStack.stackSize <= room)

View file

@ -23,13 +23,17 @@ import com.google.common.io.ByteArrayDataInput;
* @author DarkGuardsman */
public class TileCrate extends TileExternalInventory implements IPacketReceiver, IExtendedStorage
{
/** Collective total stack of all inv slots */
private ItemStack sampleStack;
/** max meta size of the crate */
public static final int maxSize = 2;
/** delay from last click */
public long prevClickTime = -1000;
/** max meta size of the crate */
public static final int maxSize = 2;
/** Check to see if oreName items can be force stacked */
public boolean oreFilterEnabled = false;
/** Collective total stack of all inv slots */
private ItemStack sampleStack;
@Override
public InventoryCrate getInventory()
@ -112,7 +116,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
this.sampleStack = stack;
getInventory().buildInventory(getSampleStack());
}
else if (this.getSampleStack().isItemEqual(stack) || OreDictionary.getOreID(getSampleStack()) == OreDictionary.getOreID(stack))
else if (this.getSampleStack().isItemEqual(stack) || (this.oreFilterEnabled && OreDictionary.getOreID(getSampleStack()) == OreDictionary.getOreID(stack)))
{
getSampleStack().stackSize += stack.stackSize;
getInventory().buildInventory(getSampleStack());
@ -134,7 +138,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
@Override
public boolean canStore(ItemStack stack, int slot, ForgeDirection side)
{
return getSampleStack() == null || stack != null && (stack.isItemEqual(getSampleStack()) || OreDictionary.getOreID(getSampleStack()) == OreDictionary.getOreID(stack));
return getSampleStack() == null || stack != null && (stack.isItemEqual(getSampleStack()) || (this.oreFilterEnabled && OreDictionary.getOreID(getSampleStack()) == OreDictionary.getOreID(stack)));
}
/** Gets the current slot count for the crate */
@ -233,6 +237,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
this.sampleStack = stack;
this.getInventory().buildInventory(this.sampleStack);
}
this.oreFilterEnabled = nbt.getBoolean("oreFilter");
}
@ -249,7 +254,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
nbt.setInteger("Count", stack.stackSize);
nbt.setCompoundTag("stack", stack.writeToNBT(new NBTTagCompound()));
}
nbt.setBoolean("oreFilter", this.oreFilterEnabled);
}
}