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;
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.item.Item;
import net.minecraft.item.ItemStack;
@ -14,41 +8,49 @@ import net.minecraft.network.packet.Packet;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
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;
/**
* Basic single stack inventory.
import com.google.common.io.ByteArrayDataInput;
/** Basic single stack inventory.
* <p/>
* TODO: Add filter-locking feature. Put filter in, locks the crate to only use that item.
*
* @author DarkGuardsman
*/
public class TileCrate extends TileExternalInventory
implements IPacketReceiver, IExtendedStorage, IFilterable
* @author DarkGuardsman */
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;
/**
* delay from last click
*/
/** delay from last click */
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;
/**
* Collective total stack of all inv slots
*/
/** Collective total stack of all inv slots */
private ItemStack sampleStack;
private ItemStack filterStack;
/**
* Gets the slot count for the crate meta
*/
private long updateTick = 1;
@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)
{
if (metadata >= 2)
@ -72,9 +74,7 @@ public class TileCrate extends TileExternalInventory
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()
{
if (this.sampleStack == null)
@ -84,10 +84,8 @@ public class TileCrate extends TileExternalInventory
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()
{
ItemStack newSampleStack = null;
@ -136,9 +134,7 @@ public class TileCrate extends TileExternalInventory
return BlockCrate.addStackToCrate(this, stack);
}
/**
* Adds an item to the stack
*/
/** Adds an item to the stack */
public void addToStack(ItemStack stack, int amount)
{
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)
{
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)));
}
/**
* Gets the current slot count for the crate
*/
/** Gets the current slot count for the crate */
public int getSlotCount()
{
if (this.worldObj == null)
@ -233,12 +225,6 @@ public class TileCrate extends TileExternalInventory
return TileCrate.getSlotCount(this.getBlockMetadata());
}
@Override
public boolean canUpdate()
{
return false;
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
@ -278,9 +264,7 @@ public class TileCrate extends TileExternalInventory
}
}
/**
* NBT Data
*/
/** NBT Data */
@Override
public void readFromNBT(NBTTagCompound nbt)
{