Some work done on crate
This commit is contained in:
parent
41b83362b2
commit
5a6e92ccd1
2 changed files with 309 additions and 239 deletions
|
@ -1,7 +1,11 @@
|
||||||
package resonantinduction.archaic.crate;
|
package resonantinduction.archaic.crate;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import calclavia.api.resonantinduction.IFilterable;
|
||||||
|
import calclavia.lib.network.IPacketReceiver;
|
||||||
|
import calclavia.lib.network.PacketHandler;
|
||||||
|
import calclavia.lib.prefab.tile.TileExternalInventory;
|
||||||
|
import calclavia.lib.utility.inventory.IExtendedStorage;
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -10,35 +14,54 @@ import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
import resonantinduction.core.ResonantInduction;
|
import resonantinduction.core.ResonantInduction;
|
||||||
import resonantinduction.core.prefab.imprint.ItemImprint;
|
|
||||||
import calclavia.api.resonantinduction.IFilterable;
|
|
||||||
import calclavia.lib.network.IPacketReceiver;
|
|
||||||
import calclavia.lib.network.PacketHandler;
|
|
||||||
import calclavia.lib.prefab.tile.TileExternalInventory;
|
|
||||||
import calclavia.lib.utility.inventory.IExtendedStorage;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
/**
|
||||||
|
* Basic single stack inventory.
|
||||||
/** Basic single stack inventory.
|
* <p/>
|
||||||
*
|
|
||||||
* TODO: Add filter-locking feature. Put filter in, locks the crate to only use that item.
|
* TODO: Add filter-locking feature. Put filter in, locks the crate to only use that item.
|
||||||
*
|
*
|
||||||
* @author DarkGuardsman */
|
* @author DarkGuardsman
|
||||||
public class TileCrate extends TileExternalInventory implements IPacketReceiver, IExtendedStorage, IFilterable
|
*/
|
||||||
|
public class TileCrate extends TileExternalInventory
|
||||||
|
implements IPacketReceiver, IExtendedStorage, IFilterable
|
||||||
{
|
{
|
||||||
/** max meta size of the crate */
|
/**
|
||||||
|
* max meta size of the crate
|
||||||
|
*/
|
||||||
public static final int maxSize = 2;
|
public static final int maxSize = 2;
|
||||||
|
|
||||||
/** delay from last click */
|
/**
|
||||||
|
* delay from last click
|
||||||
|
*/
|
||||||
public long prevClickTime = -1000;
|
public long prevClickTime = -1000;
|
||||||
|
|
||||||
/** Check to see if oreName items can be force stacked */
|
/**
|
||||||
|
* Check to see if oreName items can be force stacked
|
||||||
|
*/
|
||||||
public boolean oreFilterEnabled = false;
|
public boolean oreFilterEnabled = false;
|
||||||
|
|
||||||
/** Collective total stack of all inv slots */
|
/**
|
||||||
|
* Collective total stack of all inv slots
|
||||||
|
*/
|
||||||
private ItemStack sampleStack;
|
private ItemStack sampleStack;
|
||||||
private ItemStack filterStack;
|
private ItemStack filterStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the slot count for the crate meta
|
||||||
|
*/
|
||||||
|
public static int getSlotCount(int metadata)
|
||||||
|
{
|
||||||
|
if (metadata >= 2)
|
||||||
|
{
|
||||||
|
return 256;
|
||||||
|
}
|
||||||
|
else if (metadata >= 1)
|
||||||
|
{
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
return 32;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InventoryCrate getInventory()
|
public InventoryCrate getInventory()
|
||||||
{
|
{
|
||||||
|
@ -49,7 +72,9 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
return (InventoryCrate) this.inventory;
|
return (InventoryCrate) this.inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the sample stack that represent the total inventory */
|
/**
|
||||||
|
* Gets the sample stack that represent the total inventory
|
||||||
|
*/
|
||||||
public ItemStack getSampleStack()
|
public ItemStack getSampleStack()
|
||||||
{
|
{
|
||||||
if (this.sampleStack == null)
|
if (this.sampleStack == null)
|
||||||
|
@ -59,8 +84,10 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
return this.sampleStack;
|
return this.sampleStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Builds the sample stack using the inventory as a point of reference. Assumes all items match
|
/**
|
||||||
* each other, and only takes into account stack sizes */
|
* Builds the sample stack using the inventory as a point of reference. Assumes all items match
|
||||||
|
* each other, and only takes into account stack sizes
|
||||||
|
*/
|
||||||
public void buildSampleStack()
|
public void buildSampleStack()
|
||||||
{
|
{
|
||||||
ItemStack newSampleStack = null;
|
ItemStack newSampleStack = null;
|
||||||
|
@ -73,18 +100,28 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
if (slotStack != null && Item.itemsList[slotStack.itemID] != null && slotStack.stackSize > 0)
|
if (slotStack != null && Item.itemsList[slotStack.itemID] != null && slotStack.stackSize > 0)
|
||||||
{
|
{
|
||||||
if (newSampleStack == null)
|
if (newSampleStack == null)
|
||||||
|
{
|
||||||
newSampleStack = slotStack.copy();
|
newSampleStack = slotStack.copy();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
newSampleStack.stackSize += slotStack.stackSize;
|
newSampleStack.stackSize += slotStack.stackSize;
|
||||||
|
}
|
||||||
|
|
||||||
if (slotStack.stackSize > slotStack.getMaxStackSize())
|
if (slotStack.stackSize > slotStack.getMaxStackSize())
|
||||||
|
{
|
||||||
rebuildBase = true;
|
rebuildBase = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (newSampleStack == null || newSampleStack.itemID == 0 || newSampleStack.stackSize <= 0)
|
if (newSampleStack == null || newSampleStack.itemID == 0 || newSampleStack.stackSize <= 0)
|
||||||
|
{
|
||||||
this.sampleStack = this.getFilter() != null ? this.getFilter().copy() : null;
|
this.sampleStack = this.getFilter() != null ? this.getFilter().copy() : null;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
this.sampleStack = newSampleStack.copy();
|
this.sampleStack = newSampleStack.copy();
|
||||||
|
}
|
||||||
|
|
||||||
/* Rebuild inventory if the inventory is not valid */
|
/* Rebuild inventory if the inventory is not valid */
|
||||||
if (this.sampleStack != null && (rebuildBase || this.getInventory().getContainedItems().length > this.getSizeInventory()))
|
if (this.sampleStack != null && (rebuildBase || this.getInventory().getContainedItems().length > this.getSizeInventory()))
|
||||||
|
@ -99,7 +136,9 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
return BlockCrate.addStackToCrate(this, stack);
|
return BlockCrate.addStackToCrate(this, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds an item to the stack */
|
/**
|
||||||
|
* Adds an item to the stack
|
||||||
|
*/
|
||||||
public void addToStack(ItemStack stack, int amount)
|
public void addToStack(ItemStack stack, int amount)
|
||||||
{
|
{
|
||||||
if (stack != null)
|
if (stack != null)
|
||||||
|
@ -110,7 +149,9 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds the stack to the sample stack */
|
/**
|
||||||
|
* Adds the stack to the sample stack
|
||||||
|
*/
|
||||||
public void addToStack(ItemStack stack)
|
public void addToStack(ItemStack stack)
|
||||||
{
|
{
|
||||||
if (stack != null && stack.stackSize > 0)
|
if (stack != null && stack.stackSize > 0)
|
||||||
|
@ -128,6 +169,41 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack decrStackSize(int slot, int amount)
|
||||||
|
{
|
||||||
|
if (sampleStack != null)
|
||||||
|
{
|
||||||
|
ItemStack var3;
|
||||||
|
|
||||||
|
if (sampleStack.stackSize <= amount)
|
||||||
|
{
|
||||||
|
var3 = sampleStack;
|
||||||
|
sampleStack = null;
|
||||||
|
this.onInventoryChanged();
|
||||||
|
getInventory().buildInventory(getSampleStack());
|
||||||
|
return var3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var3 = sampleStack.splitStack(amount);
|
||||||
|
|
||||||
|
if (sampleStack.stackSize == 0)
|
||||||
|
{
|
||||||
|
sampleStack = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
getInventory().buildInventory(getSampleStack());
|
||||||
|
onInventoryChanged();
|
||||||
|
return var3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInventoryChanged()
|
public void onInventoryChanged()
|
||||||
{
|
{
|
||||||
|
@ -145,7 +221,9 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
return getSampleStack() == null || stack != null && (stack.isItemEqual(getSampleStack()) || (this.oreFilterEnabled && 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
|
||||||
|
*/
|
||||||
public int getSlotCount()
|
public int getSlotCount()
|
||||||
{
|
{
|
||||||
if (this.worldObj == null)
|
if (this.worldObj == null)
|
||||||
|
@ -155,20 +233,6 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
return TileCrate.getSlotCount(this.getBlockMetadata());
|
return TileCrate.getSlotCount(this.getBlockMetadata());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the slot count for the crate meta */
|
|
||||||
public static int getSlotCount(int metadata)
|
|
||||||
{
|
|
||||||
if (metadata >= 2)
|
|
||||||
{
|
|
||||||
return 256;
|
|
||||||
}
|
|
||||||
else if (metadata >= 1)
|
|
||||||
{
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUpdate()
|
public boolean canUpdate()
|
||||||
{
|
{
|
||||||
|
@ -214,7 +278,9 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** NBT Data */
|
/**
|
||||||
|
* NBT Data
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt)
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
|
@ -243,7 +309,9 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
}
|
}
|
||||||
this.oreFilterEnabled = nbt.getBoolean("oreFilter");
|
this.oreFilterEnabled = nbt.getBoolean("oreFilter");
|
||||||
if (nbt.hasKey("filter"))
|
if (nbt.hasKey("filter"))
|
||||||
|
{
|
||||||
filterStack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("filter"));
|
filterStack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("filter"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,8 +330,16 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
}
|
}
|
||||||
nbt.setBoolean("oreFilter", this.oreFilterEnabled);
|
nbt.setBoolean("oreFilter", this.oreFilterEnabled);
|
||||||
if (this.filterStack != null)
|
if (this.filterStack != null)
|
||||||
|
{
|
||||||
nbt.setCompoundTag("filter", filterStack.writeToNBT(new NBTTagCompound()));
|
nbt.setCompoundTag("filter", filterStack.writeToNBT(new NBTTagCompound()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getFilter()
|
||||||
|
{
|
||||||
|
return this.filterStack;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFilter(ItemStack filter)
|
public void setFilter(ItemStack filter)
|
||||||
|
@ -272,10 +348,4 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver,
|
||||||
this.onInventoryChanged();
|
this.onInventoryChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getFilter()
|
|
||||||
{
|
|
||||||
return this.filterStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,11 +215,11 @@ public class PartLevitator extends PartFace
|
||||||
|
|
||||||
if (retrieved != null)
|
if (retrieved != null)
|
||||||
{
|
{
|
||||||
EntityItem item = getItemWithPosition(retrieved);
|
EntityItem entityItem = getItemWithPosition(retrieved);
|
||||||
|
|
||||||
if (!world().isRemote)
|
if (!world().isRemote)
|
||||||
{
|
{
|
||||||
world().spawnEntityInWorld(item);
|
world().spawnEntityInWorld(entityItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
pushDelay = Settings.LEVITATOR_PUSH_DELAY;
|
pushDelay = Settings.LEVITATOR_PUSH_DELAY;
|
||||||
|
|
Loading…
Reference in a new issue