Changed crate to update every few ticks to fix some cases crates would not sync to client

This commit is contained in:
Robert S 2014-04-24 15:49:02 -04:00
parent 159e8ecc26
commit 8aab86ae3a

View file

@ -1,11 +1,5 @@
package resonantinduction.archaic.crate; package resonantinduction.archaic.crate;
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;
@ -14,41 +8,49 @@ 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 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/> * <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;
/** private long updateTick = 1;
* Gets the slot count for the crate meta
*/ @Override
public void updateEntity()
{
super.updateEntity();
if (!worldObj.isRemote && ticks % updateTick == 0)
{
//Send desc packet, done already in onInventoryChanged()
onInventoryChanged();
updateTick = 5 + worldObj.rand.nextInt(50);
}
}
/** Gets the slot count for the crate meta */
public static int getSlotCount(int metadata) public static int getSlotCount(int metadata)
{ {
if (metadata >= 2) if (metadata >= 2)
@ -72,9 +74,7 @@ public class TileCrate extends TileExternalInventory
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)
@ -84,10 +84,8 @@ public class TileCrate extends TileExternalInventory
return this.sampleStack; return this.sampleStack;
} }
/** /** Builds the sample stack using the inventory as a point of reference. Assumes all items match
* 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 */
* each other, and only takes into account stack sizes
*/
public void buildSampleStack() public void buildSampleStack()
{ {
ItemStack newSampleStack = null; ItemStack newSampleStack = null;
@ -136,9 +134,7 @@ public class TileCrate extends TileExternalInventory
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)
@ -149,9 +145,7 @@ public class TileCrate extends TileExternalInventory
} }
} }
/** /** 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)
@ -221,9 +215,7 @@ public class TileCrate extends TileExternalInventory
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)
@ -233,12 +225,6 @@ public class TileCrate extends TileExternalInventory
return TileCrate.getSlotCount(this.getBlockMetadata()); return TileCrate.getSlotCount(this.getBlockMetadata());
} }
@Override
public boolean canUpdate()
{
return false;
}
@Override @Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra) public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{ {
@ -278,9 +264,7 @@ public class TileCrate extends TileExternalInventory
} }
} }
/** /** NBT Data */
* NBT Data
*/
@Override @Override
public void readFromNBT(NBTTagCompound nbt) public void readFromNBT(NBTTagCompound nbt)
{ {