diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 93fae1de..84549981 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -9,6 +9,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.Configuration; import net.minecraftforge.oredict.ShapedOreRecipe; +import resonantinduction.battery.BatteryMultiblockManager; import resonantinduction.battery.BlockBattery; import resonantinduction.battery.ItemCapacitor; import resonantinduction.battery.TileEntityBattery; @@ -35,6 +36,8 @@ import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; +import cpw.mods.fml.common.registry.TickRegistry; +import cpw.mods.fml.relauncher.Side; /** * @author Calclavia @@ -160,6 +163,8 @@ public class ResonantInduction GameRegistry.registerTileEntity(TileEntityMultimeter.class, blockMultimeter.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName()); + + TickRegistry.registerTickHandler(new BatteryMultiblockManager(), Side.SERVER); ResonantInduction.proxy.registerRenderers(); diff --git a/src/resonantinduction/base/TileEntityBase.java b/src/resonantinduction/base/TileEntityBase.java index 0a09c75a..c6cd3576 100644 --- a/src/resonantinduction/base/TileEntityBase.java +++ b/src/resonantinduction/base/TileEntityBase.java @@ -19,6 +19,7 @@ public class TileEntityBase extends TileEntity { protected long ticks = 0; public Set playersUsing = new HashSet(); + public boolean doPacket = true; public void initiate() { @@ -35,9 +36,12 @@ public class TileEntityBase extends TileEntity this.initiate(); } - for (EntityPlayer player : this.playersUsing) + if(doPacket && !worldObj.isRemote) { - PacketDispatcher.sendPacketToPlayer(this.getDescriptionPacket(), (Player) player); + for (EntityPlayer player : this.playersUsing) + { + PacketDispatcher.sendPacketToPlayer(this.getDescriptionPacket(), (Player) player); + } } } } diff --git a/src/resonantinduction/battery/BatteryMultiblockManager.java b/src/resonantinduction/battery/BatteryMultiblockManager.java index b5e31a33..b5b5a31a 100644 --- a/src/resonantinduction/battery/BatteryMultiblockManager.java +++ b/src/resonantinduction/battery/BatteryMultiblockManager.java @@ -24,7 +24,7 @@ public class BatteryMultiblockManager implements ITickHandler * Grabs an inventory from the world's caches, and removes all the world's references to it. * @param world - world the cache is stored in * @param id - inventory ID to pull - * @return correct Dynamic Tank inventory cache + * @return correct Battery inventory cache */ public static BatteryCache pullInventory(World world, int id) { @@ -47,10 +47,10 @@ public class BatteryMultiblockManager implements ITickHandler } /** - * Updates a dynamic tank cache with the defined inventory ID with the parameterized values. - * @param inventoryID - inventory ID of the dynamic tank - * @param fluid - cached fluid of the dynamic tank - * @param inventory - inventory of the dynamic tank + * Updates a battery cache with the defined inventory ID with the parameterized values. + * @param inventoryID - inventory ID of the battery + * @param fluid - cached fluid of the battery + * @param inventory - inventory of the battery * @param tileEntity - dynamic tank TileEntity */ public static void updateCache(int inventoryID, HashSet inventory, TileEntityBattery tileEntity) @@ -73,7 +73,7 @@ public class BatteryMultiblockManager implements ITickHandler } /** - * Grabs a unique inventory ID for a dynamic tank. + * Grabs a unique inventory ID for a battery. * @return unique inventory ID */ public static int getUniqueInventoryID() diff --git a/src/resonantinduction/battery/BlockBattery.java b/src/resonantinduction/battery/BlockBattery.java index 2b20ad1c..183eebd9 100644 --- a/src/resonantinduction/battery/BlockBattery.java +++ b/src/resonantinduction/battery/BlockBattery.java @@ -11,13 +11,10 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; -import net.minecraft.util.MathHelper; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import resonantinduction.base.BlockBase; -import resonantinduction.multimeter.TileEntityMultimeter; /** * A block that detects power. @@ -66,6 +63,31 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider return true; } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, int id) + { + if(!world.isRemote) + { + if(id == blockID) + { + TileEntityBattery battery = (TileEntityBattery)world.getBlockTileEntity(x, y, z); + + battery.update(); + } + } + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemstack) + { + if(!world.isRemote) + { + TileEntityBattery battery = (TileEntityBattery)world.getBlockTileEntity(x, y, z); + + battery.update(); + } + } @Override public boolean renderAsNormalBlock() diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index 82f62da7..9586e0d0 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -9,6 +9,8 @@ import java.util.Set; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; import resonantinduction.api.IBattery; import resonantinduction.base.TileEntityBase; @@ -20,16 +22,53 @@ import resonantinduction.base.TileEntityBase; public class TileEntityBattery extends TileEntityBase { public Set inventory = new HashSet(); + private byte[] sideStatus = new byte[] { 0, 0, 0, 0, 0, 0 }; public SynchronizedBatteryData structure; public int inventoryID; + + public TileEntityBattery() + { + doPacket = false; + } @Override public void updateEntity() { + super.updateEntity(); + } + + @Override + public void readFromNBT(NBTTagCompound nbtTags) + { + super.readFromNBT(nbtTags); + + if(structure == null) + { + inventoryID = nbtTags.getInteger("inventoryID"); + + if(inventoryID != -1) + { + //inventory + } + } + } + @Override + public void writeToNBT(NBTTagCompound nbtTags) + { + super.writeToNBT(nbtTags); + + nbtTags.setInteger("inventoryID", inventoryID); + + //inventory + } + + public void update() + { + } public float getMaxEnergyStored()