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.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.common.Configuration;
|
import net.minecraftforge.common.Configuration;
|
||||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||||
|
import resonantinduction.battery.BatteryMultiblockManager;
|
||||||
import resonantinduction.battery.BlockBattery;
|
import resonantinduction.battery.BlockBattery;
|
||||||
import resonantinduction.battery.ItemCapacitor;
|
import resonantinduction.battery.ItemCapacitor;
|
||||||
import resonantinduction.battery.TileEntityBattery;
|
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.network.NetworkRegistry;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
|
import cpw.mods.fml.common.registry.TickRegistry;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Calclavia
|
* @author Calclavia
|
||||||
|
@ -161,6 +164,8 @@ public class ResonantInduction
|
||||||
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
|
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
|
||||||
GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName());
|
GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName());
|
||||||
|
|
||||||
|
TickRegistry.registerTickHandler(new BatteryMultiblockManager(), Side.SERVER);
|
||||||
|
|
||||||
ResonantInduction.proxy.registerRenderers();
|
ResonantInduction.proxy.registerRenderers();
|
||||||
|
|
||||||
TabRI.ITEMSTACK = new ItemStack(blockTesla);
|
TabRI.ITEMSTACK = new ItemStack(blockTesla);
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class TileEntityBase extends TileEntity
|
||||||
{
|
{
|
||||||
protected long ticks = 0;
|
protected long ticks = 0;
|
||||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||||
|
public boolean doPacket = true;
|
||||||
|
|
||||||
public void initiate()
|
public void initiate()
|
||||||
{
|
{
|
||||||
|
@ -35,9 +36,12 @@ public class TileEntityBase extends TileEntity
|
||||||
this.initiate();
|
this.initiate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(doPacket && !worldObj.isRemote)
|
||||||
|
{
|
||||||
for (EntityPlayer player : this.playersUsing)
|
for (EntityPlayer player : this.playersUsing)
|
||||||
{
|
{
|
||||||
PacketDispatcher.sendPacketToPlayer(this.getDescriptionPacket(), (Player) player);
|
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.
|
* 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 world - world the cache is stored in
|
||||||
* @param id - inventory ID to pull
|
* @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)
|
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.
|
* Updates a battery cache with the defined inventory ID with the parameterized values.
|
||||||
* @param inventoryID - inventory ID of the dynamic tank
|
* @param inventoryID - inventory ID of the battery
|
||||||
* @param fluid - cached fluid of the dynamic tank
|
* @param fluid - cached fluid of the battery
|
||||||
* @param inventory - inventory of the dynamic tank
|
* @param inventory - inventory of the battery
|
||||||
* @param tileEntity - dynamic tank TileEntity
|
* @param tileEntity - dynamic tank TileEntity
|
||||||
*/
|
*/
|
||||||
public static void updateCache(int inventoryID, HashSet<ItemStack> inventory, TileEntityBattery 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
|
* @return unique inventory ID
|
||||||
*/
|
*/
|
||||||
public static int getUniqueInventoryID()
|
public static int getUniqueInventoryID()
|
||||||
|
|
|
@ -11,13 +11,10 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Icon;
|
import net.minecraft.util.Icon;
|
||||||
import net.minecraft.util.MathHelper;
|
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.ResonantInduction;
|
import resonantinduction.ResonantInduction;
|
||||||
import resonantinduction.base.BlockBase;
|
import resonantinduction.base.BlockBase;
|
||||||
import resonantinduction.multimeter.TileEntityMultimeter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A block that detects power.
|
* A block that detects power.
|
||||||
|
@ -67,6 +64,31 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
return true;
|
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
|
@Override
|
||||||
public boolean renderAsNormalBlock()
|
public boolean renderAsNormalBlock()
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,8 @@ import java.util.Set;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import resonantinduction.api.IBattery;
|
import resonantinduction.api.IBattery;
|
||||||
import resonantinduction.base.TileEntityBase;
|
import resonantinduction.base.TileEntityBase;
|
||||||
|
|
||||||
|
@ -20,14 +22,51 @@ import resonantinduction.base.TileEntityBase;
|
||||||
public class TileEntityBattery extends TileEntityBase
|
public class TileEntityBattery extends TileEntityBase
|
||||||
{
|
{
|
||||||
public Set<ItemStack> inventory = new HashSet<ItemStack>();
|
public Set<ItemStack> inventory = new HashSet<ItemStack>();
|
||||||
|
|
||||||
private byte[] sideStatus = new byte[] { 0, 0, 0, 0, 0, 0 };
|
private byte[] sideStatus = new byte[] { 0, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
public SynchronizedBatteryData structure;
|
public SynchronizedBatteryData structure;
|
||||||
|
|
||||||
public int inventoryID;
|
public int inventoryID;
|
||||||
|
|
||||||
|
public TileEntityBattery()
|
||||||
|
{
|
||||||
|
doPacket = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
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()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue