Cleanup on crate wrenching code, also made ore filtering optional
This commit is contained in:
parent
847c182571
commit
1212e27f54
2 changed files with 343 additions and 365 deletions
|
@ -17,18 +17,17 @@ import resonantinduction.core.Reference;
|
||||||
import universalelectricity.api.UniversalElectricity;
|
import universalelectricity.api.UniversalElectricity;
|
||||||
import calclavia.lib.prefab.block.BlockTile;
|
import calclavia.lib.prefab.block.BlockTile;
|
||||||
import calclavia.lib.utility.WrenchUtility;
|
import calclavia.lib.utility.WrenchUtility;
|
||||||
|
import calclavia.lib.utility.inventory.InventoryUtility;
|
||||||
import codechicken.multipart.ControlKeyModifer;
|
import codechicken.multipart.ControlKeyModifer;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
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.
|
* to go on Conveyor Belts.
|
||||||
*
|
*
|
||||||
* NOTE: Crates should be upgraded with an item.
|
* NOTE: Crates should be upgraded with an item.
|
||||||
*
|
*
|
||||||
* @author DarkGuardsman
|
* @author DarkGuardsman */
|
||||||
*/
|
|
||||||
public class BlockCrate extends BlockTile
|
public class BlockCrate extends BlockTile
|
||||||
{
|
{
|
||||||
Icon advanced, elite;
|
Icon advanced, elite;
|
||||||
|
@ -91,46 +90,27 @@ public class BlockCrate extends BlockTile
|
||||||
if (world.getBlockTileEntity(x, y, z) instanceof TileCrate)
|
if (world.getBlockTileEntity(x, y, z) instanceof TileCrate)
|
||||||
{
|
{
|
||||||
TileCrate tile = (TileCrate) world.getBlockTileEntity(x, y, z);
|
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())
|
if (player.isSneaking())
|
||||||
{
|
{
|
||||||
ItemStack containingStack = tile.getSampleStack();
|
if (sampleStack != null && sampleStack.stackSize > 0)
|
||||||
tile.buildSampleStack();
|
|
||||||
|
|
||||||
if (containingStack != null)
|
|
||||||
{
|
{
|
||||||
if (containingStack.stackSize > 0)
|
ItemStack dropStack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
|
||||||
{
|
ItemBlockCrate.setContainingItemStack(dropStack, sampleStack);
|
||||||
float area = 0.7F;
|
InventoryUtility.dropItemStack(world, x, y, z, dropStack, 10, 0);
|
||||||
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);
|
|
||||||
|
|
||||||
for (int i = 0; i < tile.getInventory().getSizeInventory(); i++)
|
for (int i = 0; i < tile.getInventory().getSizeInventory(); i++)
|
||||||
{
|
{
|
||||||
tile.getInventory().setInventorySlotContents(i, null);
|
tile.getInventory().setInventorySlotContents(i, null);
|
||||||
}
|
}
|
||||||
world.setBlock(x, y, z, 0, 0, 3);
|
world.setBlock(x, y, z, 0, 0, 3);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swap oredict nodes if the player is wrenching the crate.
|
|
||||||
*/
|
|
||||||
ItemStack sampleStack = tile.getSampleStack();
|
|
||||||
|
|
||||||
int oreID = OreDictionary.getOreID(sampleStack);
|
int oreID = OreDictionary.getOreID(sampleStack);
|
||||||
|
|
||||||
|
@ -154,6 +134,7 @@ public class BlockCrate extends BlockTile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make double clicking input all stacks. */
|
/** Make double clicking input all stacks. */
|
||||||
|
@ -186,10 +167,8 @@ public class BlockCrate extends BlockTile
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Try to inject it into the crate. Otherwise, look around for nearby crates and try to put them
|
||||||
* Try to inject it into the crate. Otherwise, look around for nearby crates and try to put them
|
* in. */
|
||||||
* in.
|
|
||||||
*/
|
|
||||||
public void tryInsert(TileCrate tileEntity, EntityPlayer player, boolean allMode, boolean doSearch)
|
public void tryInsert(TileCrate tileEntity, EntityPlayer player, boolean allMode, boolean doSearch)
|
||||||
{
|
{
|
||||||
boolean success;
|
boolean success;
|
||||||
|
@ -268,7 +247,7 @@ public class BlockCrate extends BlockTile
|
||||||
{
|
{
|
||||||
if (tileEntity.getSampleStack() != null)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -282,11 +261,9 @@ public class BlockCrate extends BlockTile
|
||||||
return false;
|
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)
|
public boolean insertAllItems(TileCrate tileEntity, EntityPlayer player)
|
||||||
{
|
{
|
||||||
ItemStack requestStack = null;
|
ItemStack requestStack = null;
|
||||||
|
@ -329,14 +306,12 @@ public class BlockCrate extends BlockTile
|
||||||
return false;
|
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 tileEntity
|
||||||
* @param player
|
* @param player
|
||||||
* @param requestSize - The maximum stack size to take out. Default should be 64.
|
* @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)
|
public boolean ejectItems(TileCrate tileEntity, EntityPlayer player, int requestSize)
|
||||||
{
|
{
|
||||||
World world = tileEntity.worldObj;
|
World world = tileEntity.worldObj;
|
||||||
|
@ -381,12 +356,10 @@ public class BlockCrate extends BlockTile
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Puts an itemStack into the crate.
|
||||||
* Puts an itemStack into the crate.
|
|
||||||
*
|
*
|
||||||
* @param tileEntity
|
* @param tileEntity
|
||||||
* @param itemStack
|
* @param itemStack */
|
||||||
*/
|
|
||||||
public static ItemStack addStackToCrate(TileCrate tileEntity, ItemStack itemStack)
|
public static ItemStack addStackToCrate(TileCrate tileEntity, ItemStack itemStack)
|
||||||
{
|
{
|
||||||
if (itemStack == null || itemStack.getItem().isDamageable() && itemStack.getItem().getDamage(itemStack) > 0)
|
if (itemStack == null || itemStack.getItem().isDamageable() && itemStack.getItem().getDamage(itemStack) > 0)
|
||||||
|
@ -396,7 +369,7 @@ public class BlockCrate extends BlockTile
|
||||||
|
|
||||||
ItemStack containingStack = tileEntity.getSampleStack();
|
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);
|
int room = Math.max((tileEntity.getInventory().getSizeInventory() * 64) - (containingStack != null ? containingStack.stackSize : 0), 0);
|
||||||
if (itemStack.stackSize <= room)
|
if (itemStack.stackSize <= room)
|
||||||
|
|
|
@ -23,13 +23,17 @@ import com.google.common.io.ByteArrayDataInput;
|
||||||
* @author DarkGuardsman */
|
* @author DarkGuardsman */
|
||||||
public class TileCrate extends TileExternalInventory implements IPacketReceiver, IExtendedStorage
|
public class TileCrate extends TileExternalInventory implements IPacketReceiver, IExtendedStorage
|
||||||
{
|
{
|
||||||
/** Collective total stack of all inv slots */
|
/** max meta size of the crate */
|
||||||
private ItemStack sampleStack;
|
public static final int maxSize = 2;
|
||||||
|
|
||||||
/** delay from last click */
|
/** delay from last click */
|
||||||
public long prevClickTime = -1000;
|
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
|
@Override
|
||||||
public InventoryCrate getInventory()
|
public InventoryCrate getInventory()
|
||||||
|
@ -112,7 +116,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
this.sampleStack = stack;
|
this.sampleStack = stack;
|
||||||
getInventory().buildInventory(getSampleStack());
|
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;
|
getSampleStack().stackSize += stack.stackSize;
|
||||||
getInventory().buildInventory(getSampleStack());
|
getInventory().buildInventory(getSampleStack());
|
||||||
|
@ -134,7 +138,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
@Override
|
@Override
|
||||||
public boolean canStore(ItemStack stack, int slot, ForgeDirection side)
|
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 */
|
/** Gets the current slot count for the crate */
|
||||||
|
@ -233,6 +237,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
this.sampleStack = stack;
|
this.sampleStack = stack;
|
||||||
this.getInventory().buildInventory(this.sampleStack);
|
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.setInteger("Count", stack.stackSize);
|
||||||
nbt.setCompoundTag("stack", stack.writeToNBT(new NBTTagCompound()));
|
nbt.setCompoundTag("stack", stack.writeToNBT(new NBTTagCompound()));
|
||||||
}
|
}
|
||||||
|
nbt.setBoolean("oreFilter", this.oreFilterEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue