More work on battery multi block
This commit is contained in:
parent
dea370c0e3
commit
c6eb7eba25
5 changed files with 81 additions and 11 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ public class TileEntityBase extends TileEntity
|
|||
{
|
||||
protected long ticks = 0;
|
||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ItemStack> 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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<ItemStack> inventory = new HashSet<ItemStack>();
|
||||
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue