Removed battery inventory
This commit is contained in:
parent
34a0cdfc6b
commit
8e27fb2364
19 changed files with 310 additions and 809 deletions
|
@ -6,15 +6,17 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.client.MinecraftForgeClient;
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import resonantinduction.battery.RenderBattery;
|
||||||
|
import resonantinduction.battery.TileBattery;
|
||||||
import resonantinduction.fx.FXElectricBolt;
|
import resonantinduction.fx.FXElectricBolt;
|
||||||
import resonantinduction.gui.GuiMultimeter;
|
import resonantinduction.gui.GuiMultimeter;
|
||||||
import resonantinduction.levitator.RenderLevitator;
|
import resonantinduction.levitator.RenderLevitator;
|
||||||
import resonantinduction.levitator.TileEntityEMContractor;
|
import resonantinduction.levitator.TileEMLevitator;
|
||||||
import resonantinduction.multimeter.PartMultimeter;
|
import resonantinduction.multimeter.PartMultimeter;
|
||||||
import resonantinduction.multimeter.RenderRIItem;
|
import resonantinduction.multimeter.RenderRIItem;
|
||||||
import resonantinduction.render.BlockRenderingHandler;
|
import resonantinduction.render.BlockRenderingHandler;
|
||||||
import resonantinduction.render.RenderTesla;
|
import resonantinduction.tesla.RenderTesla;
|
||||||
import resonantinduction.tesla.TileEntityTesla;
|
import resonantinduction.tesla.TileTesla;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
import codechicken.multipart.TMultiPart;
|
import codechicken.multipart.TMultiPart;
|
||||||
import codechicken.multipart.TileMultipart;
|
import codechicken.multipart.TileMultipart;
|
||||||
|
@ -39,8 +41,9 @@ public class ClientProxy extends CommonProxy
|
||||||
RenderingRegistry.registerBlockHandler(BlockRenderingHandler.INSTANCE);
|
RenderingRegistry.registerBlockHandler(BlockRenderingHandler.INSTANCE);
|
||||||
MinecraftForgeClient.registerItemRenderer(ResonantInduction.itemMultimeter.itemID, RenderRIItem.INSTANCE);
|
MinecraftForgeClient.registerItemRenderer(ResonantInduction.itemMultimeter.itemID, RenderRIItem.INSTANCE);
|
||||||
MinecraftForgeClient.registerItemRenderer(ResonantInduction.itemTransformer.itemID, RenderRIItem.INSTANCE);
|
MinecraftForgeClient.registerItemRenderer(ResonantInduction.itemTransformer.itemID, RenderRIItem.INSTANCE);
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTesla.class, new RenderTesla());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileTesla.class, new RenderTesla());
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEMContractor.class, new RenderLevitator());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEMLevitator.class, new RenderLevitator());
|
||||||
|
ClientRegistry.bindTileEntitySpecialRenderer(TileBattery.class, new RenderBattery());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,16 +21,16 @@ import org.modstats.Modstats;
|
||||||
|
|
||||||
import resonantinduction.battery.BlockBattery;
|
import resonantinduction.battery.BlockBattery;
|
||||||
import resonantinduction.battery.ItemBlockBattery;
|
import resonantinduction.battery.ItemBlockBattery;
|
||||||
import resonantinduction.battery.TileEntityBattery;
|
import resonantinduction.battery.TileBattery;
|
||||||
import resonantinduction.furnace.BlockAdvancedFurnace;
|
import resonantinduction.furnace.BlockAdvancedFurnace;
|
||||||
import resonantinduction.furnace.TileAdvancedFurnace;
|
import resonantinduction.furnace.TileAdvancedFurnace;
|
||||||
import resonantinduction.levitator.BlockEMContractor;
|
import resonantinduction.levitator.BlockEMContractor;
|
||||||
import resonantinduction.levitator.ItemBlockContractor;
|
import resonantinduction.levitator.ItemBlockContractor;
|
||||||
import resonantinduction.levitator.ItemLinker;
|
import resonantinduction.levitator.ItemLinker;
|
||||||
import resonantinduction.levitator.TileEntityEMContractor;
|
import resonantinduction.levitator.TileEMLevitator;
|
||||||
import resonantinduction.multimeter.ItemMultimeter;
|
import resonantinduction.multimeter.ItemMultimeter;
|
||||||
import resonantinduction.tesla.BlockTesla;
|
import resonantinduction.tesla.BlockTesla;
|
||||||
import resonantinduction.tesla.TileEntityTesla;
|
import resonantinduction.tesla.TileTesla;
|
||||||
import resonantinduction.transformer.ItemTransformer;
|
import resonantinduction.transformer.ItemTransformer;
|
||||||
import resonantinduction.wire.EnumWireMaterial;
|
import resonantinduction.wire.EnumWireMaterial;
|
||||||
import resonantinduction.wire.ItemWire;
|
import resonantinduction.wire.ItemWire;
|
||||||
|
@ -171,10 +171,10 @@ public class ResonantInduction
|
||||||
MAX_CONTRACTOR_DISTANCE = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Max EM Contractor Path", MAX_CONTRACTOR_DISTANCE).getInt(MAX_CONTRACTOR_DISTANCE);
|
MAX_CONTRACTOR_DISTANCE = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Max EM Contractor Path", MAX_CONTRACTOR_DISTANCE).getInt(MAX_CONTRACTOR_DISTANCE);
|
||||||
REPLACE_FURNACE = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Replace vanilla furnace", REPLACE_FURNACE).getBoolean(REPLACE_FURNACE);
|
REPLACE_FURNACE = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Replace vanilla furnace", REPLACE_FURNACE).getBoolean(REPLACE_FURNACE);
|
||||||
|
|
||||||
TileEntityEMContractor.ACCELERATION = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Acceleration", TileEntityEMContractor.ACCELERATION).getDouble(TileEntityEMContractor.ACCELERATION);
|
TileEMLevitator.ACCELERATION = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Acceleration", TileEMLevitator.ACCELERATION).getDouble(TileEMLevitator.ACCELERATION);
|
||||||
TileEntityEMContractor.MAX_REACH = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Reach", TileEntityEMContractor.MAX_REACH).getInt(TileEntityEMContractor.MAX_REACH);
|
TileEMLevitator.MAX_REACH = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Reach", TileEMLevitator.MAX_REACH).getInt(TileEMLevitator.MAX_REACH);
|
||||||
TileEntityEMContractor.MAX_SPEED = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Speed", TileEntityEMContractor.MAX_SPEED).getDouble(TileEntityEMContractor.MAX_SPEED);
|
TileEMLevitator.MAX_SPEED = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Speed", TileEMLevitator.MAX_SPEED).getDouble(TileEMLevitator.MAX_SPEED);
|
||||||
TileEntityEMContractor.PUSH_DELAY = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Push Delay", TileEntityEMContractor.PUSH_DELAY).getInt(TileEntityEMContractor.PUSH_DELAY);
|
TileEMLevitator.PUSH_DELAY = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Push Delay", TileEMLevitator.PUSH_DELAY).getInt(TileEMLevitator.PUSH_DELAY);
|
||||||
|
|
||||||
// Items
|
// Items
|
||||||
itemLinker = new ItemLinker(getNextItemID());
|
itemLinker = new ItemLinker(getNextItemID());
|
||||||
|
@ -205,9 +205,9 @@ public class ResonantInduction
|
||||||
GameRegistry.registerBlock(blockBattery, ItemBlockBattery.class, blockBattery.getUnlocalizedName());
|
GameRegistry.registerBlock(blockBattery, ItemBlockBattery.class, blockBattery.getUnlocalizedName());
|
||||||
|
|
||||||
// Tiles
|
// Tiles
|
||||||
GameRegistry.registerTileEntity(TileEntityTesla.class, blockTesla.getUnlocalizedName());
|
GameRegistry.registerTileEntity(TileTesla.class, blockTesla.getUnlocalizedName());
|
||||||
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
|
GameRegistry.registerTileEntity(TileEMLevitator.class, blockEMContractor.getUnlocalizedName());
|
||||||
GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName());
|
GameRegistry.registerTileEntity(TileBattery.class, blockBattery.getUnlocalizedName());
|
||||||
|
|
||||||
ResonantInduction.proxy.registerRenderers();
|
ResonantInduction.proxy.registerRenderers();
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,16 @@ import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.base.ListUtil;
|
import resonantinduction.base.ListUtil;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Essentially a pathfinder for multiblock battery structures.
|
||||||
|
*
|
||||||
|
* @author Aidancbrady
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class BatteryUpdateProtocol
|
public class BatteryUpdateProtocol
|
||||||
{
|
{
|
||||||
/** The battery nodes that have already been iterated over. */
|
/** The battery nodes that have already been iterated over. */
|
||||||
public Set<TileEntityBattery> iteratedNodes = new HashSet<TileEntityBattery>();
|
public Set<TileBattery> iteratedNodes = new HashSet<TileBattery>();
|
||||||
|
|
||||||
/** The structures found, all connected by some nodes to the pointer. */
|
/** The structures found, all connected by some nodes to the pointer. */
|
||||||
public SynchronizedBatteryData structureFound = null;
|
public SynchronizedBatteryData structureFound = null;
|
||||||
|
@ -29,6 +35,16 @@ public class BatteryUpdateProtocol
|
||||||
pointer = tileEntity;
|
pointer = tileEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateBatteries()
|
||||||
|
{
|
||||||
|
loopThrough(this.pointer);
|
||||||
|
|
||||||
|
if (structureFound != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loopThrough(TileEntity tile)
|
private void loopThrough(TileEntity tile)
|
||||||
{
|
{
|
||||||
if (structureFound == null)
|
if (structureFound == null)
|
||||||
|
@ -175,13 +191,13 @@ public class BatteryUpdateProtocol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iteratedNodes.add((TileEntityBattery) tile);
|
iteratedNodes.add((TileBattery) tile);
|
||||||
|
|
||||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
TileEntity tileEntity = new Vector3(tile).modifyPositionFromSide(side).getTileEntity(tile.worldObj);
|
TileEntity tileEntity = new Vector3(tile).modifyPositionFromSide(side).getTileEntity(tile.worldObj);
|
||||||
|
|
||||||
if (tileEntity instanceof TileEntityBattery)
|
if (tileEntity instanceof TileBattery)
|
||||||
{
|
{
|
||||||
if (!iteratedNodes.contains(tileEntity))
|
if (!iteratedNodes.contains(tileEntity))
|
||||||
{
|
{
|
||||||
|
@ -193,7 +209,7 @@ public class BatteryUpdateProtocol
|
||||||
|
|
||||||
private boolean isBattery(int x, int y, int z)
|
private boolean isBattery(int x, int y, int z)
|
||||||
{
|
{
|
||||||
if (pointer.worldObj.getBlockTileEntity(x, y, z) instanceof TileEntityBattery)
|
if (pointer.worldObj.getBlockTileEntity(x, y, z) instanceof TileBattery)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -201,98 +217,4 @@ public class BatteryUpdateProtocol
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disperseCells()
|
|
||||||
{
|
|
||||||
SynchronizedBatteryData oldStructure = null;
|
|
||||||
|
|
||||||
for (TileEntityBattery tile : iteratedNodes)
|
|
||||||
{
|
|
||||||
if (tile.structure.isMultiblock)
|
|
||||||
{
|
|
||||||
oldStructure = tile.structure;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldStructure != null)
|
|
||||||
{
|
|
||||||
int maxCells = iteratedNodes.size() * BatteryManager.CELLS_PER_BATTERY;
|
|
||||||
|
|
||||||
List<ItemStack> rejected = ListUtil.capRemains(oldStructure.inventory, maxCells);
|
|
||||||
ejectItems(rejected, new Vector3(pointer));
|
|
||||||
|
|
||||||
ArrayList<List<ItemStack>> inventories = ListUtil.split(ListUtil.cap(oldStructure.inventory, maxCells), iteratedNodes.size());
|
|
||||||
List<TileEntityBattery> iterList = ListUtil.asList(iteratedNodes);
|
|
||||||
|
|
||||||
boolean didVisibleInventory = false;
|
|
||||||
|
|
||||||
for (int i = 0; i < iterList.size(); i++)
|
|
||||||
{
|
|
||||||
TileEntityBattery tile = iterList.get(i);
|
|
||||||
tile.structure = SynchronizedBatteryData.getBase(tile, inventories.get(i));
|
|
||||||
|
|
||||||
if (!didVisibleInventory)
|
|
||||||
{
|
|
||||||
tile.structure.visibleInventory = oldStructure.visibleInventory;
|
|
||||||
didVisibleInventory = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ejectItems(List<ItemStack> items, Vector3 vec)
|
|
||||||
{
|
|
||||||
for (ItemStack itemStack : items)
|
|
||||||
{
|
|
||||||
float motion = 0.7F;
|
|
||||||
double motionX = (pointer.worldObj.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
|
||||||
double motionY = (pointer.worldObj.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
|
||||||
double motionZ = (pointer.worldObj.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
|
||||||
|
|
||||||
EntityItem entityItem = new EntityItem(pointer.worldObj, vec.x + motionX, vec.y + motionY, vec.z + motionZ, itemStack);
|
|
||||||
|
|
||||||
pointer.worldObj.spawnEntityInWorld(entityItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateBatteries()
|
|
||||||
{
|
|
||||||
loopThrough(pointer);
|
|
||||||
|
|
||||||
if (structureFound != null)
|
|
||||||
{
|
|
||||||
for (TileEntityBattery tileEntity : iteratedNodes)
|
|
||||||
{
|
|
||||||
if (!structureFound.locations.contains(new Vector3(tileEntity)))
|
|
||||||
{
|
|
||||||
disperseCells();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Vector3 obj : structureFound.locations)
|
|
||||||
{
|
|
||||||
TileEntityBattery tileEntity = (TileEntityBattery) obj.getTileEntity(pointer.worldObj);
|
|
||||||
|
|
||||||
structureFound.inventory = ListUtil.merge(structureFound.inventory, tileEntity.structure.inventory);
|
|
||||||
|
|
||||||
if (tileEntity.structure.hasVisibleInventory())
|
|
||||||
{
|
|
||||||
structureFound.visibleInventory = tileEntity.structure.visibleInventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
tileEntity.structure = structureFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ItemStack> rejected = ListUtil.capRemains(structureFound.inventory, structureFound.getMaxCells());
|
|
||||||
ejectItems(rejected, new Vector3(pointer));
|
|
||||||
|
|
||||||
structureFound.inventory = ListUtil.cap(structureFound.inventory, structureFound.getMaxCells());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
disperseCells();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
{
|
{
|
||||||
if (!entityPlayer.capabilities.isCreativeMode)
|
if (!entityPlayer.capabilities.isCreativeMode)
|
||||||
{
|
{
|
||||||
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
|
TileBattery tileEntity = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||||
ItemStack itemStack = ListUtil.getTop(tileEntity.structure.inventory);
|
ItemStack itemStack = ListUtil.getTop(tileEntity.structure.inventory);
|
||||||
|
|
||||||
if (tileEntity.structure.inventory.remove(itemStack))
|
if (tileEntity.structure.inventory.remove(itemStack))
|
||||||
|
@ -55,7 +55,7 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float xClick, float yClick, float zClick)
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float xClick, float yClick, float zClick)
|
||||||
{
|
{
|
||||||
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
|
TileBattery tileEntity = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||||
|
|
||||||
if (entityPlayer.isSneaking())
|
if (entityPlayer.isSneaking())
|
||||||
{
|
{
|
||||||
|
@ -154,7 +154,7 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
{
|
{
|
||||||
if (id == blockID)
|
if (id == blockID)
|
||||||
{
|
{
|
||||||
TileEntityBattery battery = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
|
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||||
|
|
||||||
battery.update();
|
battery.update();
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
{
|
{
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
{
|
||||||
TileEntityBattery battery = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
|
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||||
|
|
||||||
battery.update();
|
battery.update();
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
{
|
{
|
||||||
if (!world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
|
if (!world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
|
||||||
{
|
{
|
||||||
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
|
TileBattery tileEntity = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||||
|
|
||||||
if (!tileEntity.structure.isMultiblock)
|
if (!tileEntity.structure.isMultiblock)
|
||||||
{
|
{
|
||||||
|
@ -220,6 +220,6 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world)
|
public TileEntity createNewTileEntity(World world)
|
||||||
{
|
{
|
||||||
return new TileEntityBattery();
|
return new TileBattery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ import calclavia.lib.gui.ContainerBase;
|
||||||
|
|
||||||
public class ContainerBattery extends ContainerBase
|
public class ContainerBattery extends ContainerBase
|
||||||
{
|
{
|
||||||
private TileEntityBattery tileEntity;
|
private TileBattery tileEntity;
|
||||||
|
|
||||||
public ContainerBattery(InventoryPlayer inventory, TileEntityBattery unit)
|
public ContainerBattery(InventoryPlayer inventory, TileBattery unit)
|
||||||
{
|
{
|
||||||
super(unit);
|
super(unit);
|
||||||
tileEntity = unit;
|
tileEntity = unit;
|
||||||
|
|
|
@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.levitator.TileEntityEMContractor;
|
import resonantinduction.levitator.TileEMLevitator;
|
||||||
|
|
||||||
public class ItemBlockBattery extends ItemBlock
|
public class ItemBlockBattery extends ItemBlock
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,7 +50,6 @@ public class RenderBattery extends TileEntitySpecialRenderer
|
||||||
@Override
|
@Override
|
||||||
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
|
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
|
||||||
{
|
{
|
||||||
|
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
|
GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
|
||||||
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
|
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
|
||||||
|
|
|
@ -14,13 +14,6 @@ public class SynchronizedBatteryData
|
||||||
{
|
{
|
||||||
public Set<Vector3> locations = new HashSet<Vector3>();
|
public Set<Vector3> locations = new HashSet<Vector3>();
|
||||||
|
|
||||||
public List<ItemStack> inventory = new ArrayList<ItemStack>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Slot 0: Cell input slot Slot 1: Battery charge slot Slot 2: Battery discharge slot
|
|
||||||
*/
|
|
||||||
public ItemStack[] visibleInventory = new ItemStack[3];
|
|
||||||
|
|
||||||
public int length;
|
public int length;
|
||||||
|
|
||||||
public int width;
|
public int width;
|
||||||
|
@ -33,90 +26,20 @@ public class SynchronizedBatteryData
|
||||||
|
|
||||||
public boolean didTick;
|
public boolean didTick;
|
||||||
|
|
||||||
public boolean wroteInventory;
|
public boolean wroteNBT;
|
||||||
|
|
||||||
public int getVolume()
|
public int getVolume()
|
||||||
{
|
{
|
||||||
return length * width * height;
|
return length * width * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxCells()
|
public static SynchronizedBatteryData getBase(TileBattery tileEntity, List<ItemStack> inventory)
|
||||||
{
|
|
||||||
return getVolume() * BatteryManager.CELLS_PER_BATTERY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean addCell(ItemStack cell)
|
|
||||||
{
|
|
||||||
if (this.inventory.size() < this.getMaxCells())
|
|
||||||
{
|
|
||||||
this.inventory.add(cell);
|
|
||||||
this.sortInventory();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sortInventory()
|
|
||||||
{
|
|
||||||
Object[] array = ListUtil.copy(inventory).toArray();
|
|
||||||
|
|
||||||
ItemStack[] toSort = new ItemStack[array.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < array.length; i++)
|
|
||||||
{
|
|
||||||
toSort[i] = (ItemStack) array[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean cont = true;
|
|
||||||
ItemStack temp;
|
|
||||||
|
|
||||||
while (cont)
|
|
||||||
{
|
|
||||||
cont = false;
|
|
||||||
|
|
||||||
for (int i = 0; i < toSort.length - 1; i++)
|
|
||||||
{
|
|
||||||
if (((IEnergyItem) toSort[i].getItem()).getEnergy(toSort[i]) < ((IEnergyItem) toSort[i + 1].getItem()).getEnergy(toSort[i + 1]))
|
|
||||||
{
|
|
||||||
temp = toSort[i];
|
|
||||||
toSort[i] = toSort[i + 1];
|
|
||||||
toSort[i + 1] = temp;
|
|
||||||
cont = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inventory = new ArrayList<ItemStack>();
|
|
||||||
|
|
||||||
for (ItemStack itemStack : toSort)
|
|
||||||
{
|
|
||||||
inventory.add(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasVisibleInventory()
|
|
||||||
{
|
|
||||||
for (ItemStack itemStack : visibleInventory)
|
|
||||||
{
|
|
||||||
if (itemStack != null)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SynchronizedBatteryData getBase(TileEntityBattery tileEntity, List<ItemStack> inventory)
|
|
||||||
{
|
{
|
||||||
SynchronizedBatteryData structure = getBase(tileEntity);
|
SynchronizedBatteryData structure = getBase(tileEntity);
|
||||||
structure.inventory = inventory;
|
|
||||||
|
|
||||||
return structure;
|
return structure;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SynchronizedBatteryData getBase(TileEntityBattery tileEntity)
|
public static SynchronizedBatteryData getBase(TileBattery tileEntity)
|
||||||
{
|
{
|
||||||
SynchronizedBatteryData structure = new SynchronizedBatteryData();
|
SynchronizedBatteryData structure = new SynchronizedBatteryData();
|
||||||
structure.length = 1;
|
structure.length = 1;
|
||||||
|
|
196
src/resonantinduction/battery/TileBattery.java
Normal file
196
src/resonantinduction/battery/TileBattery.java
Normal file
|
@ -0,0 +1,196 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package resonantinduction.battery;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
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.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
import resonantinduction.ResonantInduction;
|
||||||
|
import resonantinduction.api.ICapacitor;
|
||||||
|
import resonantinduction.base.ListUtil;
|
||||||
|
import universalelectricity.api.item.IEnergyItem;
|
||||||
|
import universalelectricity.api.vector.Vector3;
|
||||||
|
import calclavia.lib.network.IPacketReceiver;
|
||||||
|
import calclavia.lib.network.IPacketSender;
|
||||||
|
import calclavia.lib.tile.TileEntityElectrical;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||||
|
import cpw.mods.fml.common.network.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A modular battery with no GUI.
|
||||||
|
*
|
||||||
|
* @author Calclavia, AidanBrady
|
||||||
|
*/
|
||||||
|
public class TileBattery extends TileEntityElectrical implements IPacketSender, IPacketReceiver
|
||||||
|
{
|
||||||
|
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||||
|
|
||||||
|
public SynchronizedBatteryData structure = SynchronizedBatteryData.getBase(this);
|
||||||
|
public SynchronizedBatteryData prevStructure;
|
||||||
|
|
||||||
|
public float clientEnergy;
|
||||||
|
public int clientCells;
|
||||||
|
public float clientMaxEnergy;
|
||||||
|
|
||||||
|
private EnumSet inputSides = EnumSet.allOf(ForgeDirection.class);
|
||||||
|
|
||||||
|
public TileBattery()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateEntity()
|
||||||
|
{
|
||||||
|
super.updateEntity();
|
||||||
|
|
||||||
|
if (!this.worldObj.isRemote)
|
||||||
|
{
|
||||||
|
if (this.ticks == 5 && !this.structure.isMultiblock)
|
||||||
|
{
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.prevStructure != this.structure)
|
||||||
|
{
|
||||||
|
for (EntityPlayer player : playersUsing)
|
||||||
|
{
|
||||||
|
player.closeScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.prevStructure = structure;
|
||||||
|
|
||||||
|
this.structure.wroteNBT = false;
|
||||||
|
this.structure.didTick = false;
|
||||||
|
|
||||||
|
if (this.playersUsing.size() > 0)
|
||||||
|
{
|
||||||
|
updateClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (EntityPlayer player : this.playersUsing)
|
||||||
|
{
|
||||||
|
PacketDispatcher.sendPacketToPlayer(ResonantInduction.PACKET_TILE.getPacket(this, this.getPacketData(0).toArray()), (Player) player);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.produce();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTransferThreshhold()
|
||||||
|
{
|
||||||
|
return this.structure.getVolume() * 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateClient()
|
||||||
|
{
|
||||||
|
PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateAllClients()
|
||||||
|
{
|
||||||
|
for (Vector3 vec : structure.locations)
|
||||||
|
{
|
||||||
|
TileBattery battery = (TileBattery) vec.getTileEntity(worldObj);
|
||||||
|
PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(battery, battery.getPacketData(0).toArray()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound nbtTags)
|
||||||
|
{
|
||||||
|
super.readFromNBT(nbtTags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
|
if (!structure.wroteNBT)
|
||||||
|
{
|
||||||
|
structure.wroteNBT = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
if (!worldObj.isRemote && (structure == null || !structure.didTick))
|
||||||
|
{
|
||||||
|
new BatteryUpdateProtocol(this).updateBatteries();
|
||||||
|
|
||||||
|
if (structure != null)
|
||||||
|
{
|
||||||
|
structure.didTick = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player)
|
||||||
|
{
|
||||||
|
structure.isMultiblock = data.readBoolean();
|
||||||
|
|
||||||
|
structure.height = data.readInt();
|
||||||
|
structure.length = data.readInt();
|
||||||
|
structure.width = data.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList getPacketData(int type)
|
||||||
|
{
|
||||||
|
ArrayList data = new ArrayList();
|
||||||
|
data.add(structure.isMultiblock);
|
||||||
|
|
||||||
|
data.add(structure.height);
|
||||||
|
data.add(structure.length);
|
||||||
|
data.add(structure.width);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumSet<ForgeDirection> getInputDirections()
|
||||||
|
{
|
||||||
|
return this.inputSides;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumSet<ForgeDirection> getOutputDirections()
|
||||||
|
{
|
||||||
|
return EnumSet.complementOf(this.inputSides);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles the input/output sides of the battery.
|
||||||
|
*/
|
||||||
|
public boolean toggleSide(ForgeDirection orientation)
|
||||||
|
{
|
||||||
|
if (this.inputSides.contains(orientation))
|
||||||
|
{
|
||||||
|
this.inputSides.remove(orientation);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.inputSides.add(orientation);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,545 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package resonantinduction.battery;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
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.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
import resonantinduction.ResonantInduction;
|
|
||||||
import resonantinduction.api.ICapacitor;
|
|
||||||
import resonantinduction.base.ListUtil;
|
|
||||||
import universalelectricity.api.item.IEnergyItem;
|
|
||||||
import universalelectricity.api.vector.Vector3;
|
|
||||||
import calclavia.lib.network.IPacketReceiver;
|
|
||||||
import calclavia.lib.network.IPacketSender;
|
|
||||||
import calclavia.lib.tile.TileEntityElectrical;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
|
||||||
import cpw.mods.fml.common.network.Player;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A modular battery with no GUI.
|
|
||||||
*
|
|
||||||
* @author Calclavia, AidanBrady
|
|
||||||
*/
|
|
||||||
public class TileEntityBattery extends TileEntityElectrical implements IPacketSender, IPacketReceiver, IInventory
|
|
||||||
{
|
|
||||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
|
||||||
|
|
||||||
public SynchronizedBatteryData structure = SynchronizedBatteryData.getBase(this);
|
|
||||||
public SynchronizedBatteryData prevStructure;
|
|
||||||
|
|
||||||
public float clientEnergy;
|
|
||||||
public int clientCells;
|
|
||||||
public float clientMaxEnergy;
|
|
||||||
|
|
||||||
private EnumSet inputSides = EnumSet.allOf(ForgeDirection.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity()
|
|
||||||
{
|
|
||||||
super.updateEntity();
|
|
||||||
|
|
||||||
if (!this.worldObj.isRemote)
|
|
||||||
{
|
|
||||||
if (this.ticks == 5 && !this.structure.isMultiblock)
|
|
||||||
{
|
|
||||||
this.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.structure.visibleInventory[0] != null)
|
|
||||||
{
|
|
||||||
if (structure.inventory.size() < structure.getMaxCells())
|
|
||||||
{
|
|
||||||
if (structure.visibleInventory[0].getItem() instanceof ICapacitor)
|
|
||||||
{
|
|
||||||
structure.inventory.add(structure.visibleInventory[0]);
|
|
||||||
structure.visibleInventory[0] = null;
|
|
||||||
structure.sortInventory();
|
|
||||||
updateAllClients();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempt to charge entities above it.
|
|
||||||
|
|
||||||
ItemStack chargeItem = null;
|
|
||||||
|
|
||||||
if (this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))
|
|
||||||
{
|
|
||||||
List<Entity> entities = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord + 1, this.zCoord, this.xCoord + 1, this.yCoord + 2, this.zCoord + 1));
|
|
||||||
|
|
||||||
electricItemLoop:
|
|
||||||
for (Entity entity : entities)
|
|
||||||
{
|
|
||||||
if (entity instanceof EntityPlayer)
|
|
||||||
{
|
|
||||||
IInventory inventory = ((EntityPlayer) entity).inventory;
|
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
|
||||||
{
|
|
||||||
ItemStack checkStack = inventory.getStackInSlot(i);
|
|
||||||
|
|
||||||
if (checkStack != null)
|
|
||||||
{
|
|
||||||
if (checkStack.getItem() instanceof IElectricalItem)
|
|
||||||
{
|
|
||||||
if (((IElectricalItem) checkStack.getItem()).recharge(checkStack, this.energy.extractEnergy((this.getTransferThreshhold(), false).getWatts(), false) > 0)
|
|
||||||
{
|
|
||||||
chargeItem = checkStack;
|
|
||||||
break electricItemLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (entity instanceof EntityItem)
|
|
||||||
{
|
|
||||||
ItemStack checkStack = ((EntityItem) entity).getEntityItem();
|
|
||||||
|
|
||||||
if (checkStack != null)
|
|
||||||
{
|
|
||||||
if (checkStack.getItem() instanceof IElectricalItem)
|
|
||||||
{
|
|
||||||
if (((IElectricalItem) checkStack.getItem()).recharge(checkStack, this.energy.extractEnergy((this.getTransferThreshhold(), false).getWatts(), false) > 0)
|
|
||||||
{
|
|
||||||
chargeItem = checkStack;
|
|
||||||
break electricItemLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chargeItem == null)
|
|
||||||
{
|
|
||||||
chargeItem = this.structure.visibleInventory[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chargeItem != null)
|
|
||||||
{
|
|
||||||
ItemStack itemStack = chargeItem;
|
|
||||||
IElectricalItem battery = (IElectricalItem) itemStack.getItem();
|
|
||||||
|
|
||||||
float energyStored = getMaxEnergyStored();
|
|
||||||
float batteryNeeded = battery.recharge(itemStack, this.energy.extractEnergy((this.getTransferThreshhold(), false).getWatts(), false);
|
|
||||||
float toGive = Math.min(energyStored, Math.min(battery.getTransfer(itemStack), batteryNeeded));
|
|
||||||
battery.recharge(itemStack, this.energy.extractEnergy((toGive, true).getWatts(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (structure.visibleInventory[2] != null)
|
|
||||||
{
|
|
||||||
ItemStack itemStack = structure.visibleInventory[2];
|
|
||||||
IElectricalItem battery = (IElectricalItem) itemStack.getItem();
|
|
||||||
|
|
||||||
float energyNeeded = getMaxEnergyStored() - getEnergyStored();
|
|
||||||
float batteryStored = battery.getElectricityStored(itemStack);
|
|
||||||
float toReceive = Math.min(energyNeeded, Math.min(this.getTransferThreshhold(), Math.min(battery.getTransfer(itemStack), batteryStored)));
|
|
||||||
battery.discharge(itemStack, receiveElectricity(toReceive, true), true);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (prevStructure != structure)
|
|
||||||
{
|
|
||||||
for (EntityPlayer player : playersUsing)
|
|
||||||
{
|
|
||||||
player.closeScreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.prevStructure = structure;
|
|
||||||
|
|
||||||
this.structure.wroteInventory = false;
|
|
||||||
this.structure.didTick = false;
|
|
||||||
|
|
||||||
if (this.playersUsing.size() > 0)
|
|
||||||
{
|
|
||||||
updateClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (EntityPlayer player : this.playersUsing)
|
|
||||||
{
|
|
||||||
PacketDispatcher.sendPacketToPlayer(ResonantInduction.PACKET_TILE.getPacket(this, this.getPacketData(0).toArray()), (Player) player);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.produce();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTransferThreshhold()
|
|
||||||
{
|
|
||||||
return this.structure.getVolume() * 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateClient()
|
|
||||||
{
|
|
||||||
PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAllClients()
|
|
||||||
{
|
|
||||||
for (Vector3 vec : structure.locations)
|
|
||||||
{
|
|
||||||
TileEntityBattery battery = (TileEntityBattery) vec.getTileEntity(worldObj);
|
|
||||||
PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(battery, battery.getPacketData(0).toArray()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound nbtTags)
|
|
||||||
{
|
|
||||||
super.readFromNBT(nbtTags);
|
|
||||||
|
|
||||||
// Main inventory
|
|
||||||
if (nbtTags.hasKey("Items"))
|
|
||||||
{
|
|
||||||
NBTTagList tagList = nbtTags.getTagList("Items");
|
|
||||||
structure.inventory = new ArrayList<ItemStack>();
|
|
||||||
|
|
||||||
for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
|
|
||||||
int slotID = tagCompound.getInteger("Slot");
|
|
||||||
structure.inventory.add(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Visible inventory
|
|
||||||
if (nbtTags.hasKey("VisibleItems"))
|
|
||||||
{
|
|
||||||
NBTTagList tagList = nbtTags.getTagList("VisibleItems");
|
|
||||||
structure.visibleInventory = new ItemStack[3];
|
|
||||||
|
|
||||||
for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
|
|
||||||
byte slotID = tagCompound.getByte("Slot");
|
|
||||||
|
|
||||||
if (slotID >= 0 && slotID < structure.visibleInventory.length)
|
|
||||||
{
|
|
||||||
if (slotID == 0)
|
|
||||||
{
|
|
||||||
setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setInventorySlotContents(slotID + 1, ItemStack.loadItemStackFromNBT(tagCompound));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.inputSides = EnumSet.noneOf(ForgeDirection.class);
|
|
||||||
|
|
||||||
NBTTagList tagList = nbtTags.getTagList("inputSides");
|
|
||||||
|
|
||||||
for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
|
|
||||||
byte side = tagCompound.getByte("side");
|
|
||||||
this.inputSides.add(ForgeDirection.getOrientation(side));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.inputSides.remove(ForgeDirection.UNKNOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT(NBTTagCompound nbt)
|
|
||||||
{
|
|
||||||
super.writeToNBT(nbt);
|
|
||||||
|
|
||||||
if (!structure.wroteInventory)
|
|
||||||
{
|
|
||||||
// Inventory
|
|
||||||
if (structure.inventory != null)
|
|
||||||
{
|
|
||||||
NBTTagList tagList = new NBTTagList();
|
|
||||||
|
|
||||||
for (int slotCount = 0; slotCount < structure.inventory.size(); slotCount++)
|
|
||||||
{
|
|
||||||
if (structure.inventory.get(slotCount) != null)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
|
||||||
tagCompound.setInteger("Slot", slotCount);
|
|
||||||
structure.inventory.get(slotCount).writeToNBT(tagCompound);
|
|
||||||
tagList.appendTag(tagCompound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nbt.setTag("Items", tagList);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Visible inventory
|
|
||||||
if (structure.visibleInventory != null)
|
|
||||||
{
|
|
||||||
NBTTagList tagList = new NBTTagList();
|
|
||||||
|
|
||||||
for (int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
|
|
||||||
{
|
|
||||||
if (slotCount > 0)
|
|
||||||
{
|
|
||||||
slotCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getStackInSlot(slotCount) != null)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
|
||||||
tagCompound.setByte("Slot", (byte) slotCount);
|
|
||||||
getStackInSlot(slotCount).writeToNBT(tagCompound);
|
|
||||||
tagList.appendTag(tagCompound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nbt.setTag("VisibleItems", tagList);
|
|
||||||
}
|
|
||||||
|
|
||||||
structure.wroteInventory = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the input sides.
|
|
||||||
*/
|
|
||||||
NBTTagList tagList = new NBTTagList();
|
|
||||||
Iterator<ForgeDirection> it = this.inputSides.iterator();
|
|
||||||
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
ForgeDirection dir = it.next();
|
|
||||||
|
|
||||||
if (dir != ForgeDirection.UNKNOWN)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
|
||||||
tagCompound.setByte("side", (byte) dir.ordinal());
|
|
||||||
tagList.appendTag(tagCompound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nbt.setTag("inputSides", tagList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
if (!worldObj.isRemote && (structure == null || !structure.didTick))
|
|
||||||
{
|
|
||||||
new BatteryUpdateProtocol(this).updateBatteries();
|
|
||||||
|
|
||||||
if (structure != null)
|
|
||||||
{
|
|
||||||
structure.didTick = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player)
|
|
||||||
{
|
|
||||||
structure.isMultiblock = data.readBoolean();
|
|
||||||
|
|
||||||
clientEnergy = data.readFloat();
|
|
||||||
clientCells = data.readInt();
|
|
||||||
clientMaxEnergy = data.readFloat();
|
|
||||||
|
|
||||||
structure.height = data.readInt();
|
|
||||||
structure.length = data.readInt();
|
|
||||||
structure.width = data.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList getPacketData(int type)
|
|
||||||
{
|
|
||||||
ArrayList data = new ArrayList();
|
|
||||||
data.add(structure.isMultiblock);
|
|
||||||
|
|
||||||
data.add(structure.inventory.size());
|
|
||||||
|
|
||||||
data.add(structure.height);
|
|
||||||
data.add(structure.length);
|
|
||||||
data.add(structure.width);
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSizeInventory()
|
|
||||||
{
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getStackInSlot(int i)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
return structure.visibleInventory[0];
|
|
||||||
}
|
|
||||||
else if (i == 1)
|
|
||||||
{
|
|
||||||
if (!worldObj.isRemote)
|
|
||||||
{
|
|
||||||
return ListUtil.getTop(structure.inventory);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return structure.tempStack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return structure.visibleInventory[i - 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack decrStackSize(int slotID, int amount)
|
|
||||||
{
|
|
||||||
if (getStackInSlot(slotID) != null)
|
|
||||||
{
|
|
||||||
ItemStack tempStack;
|
|
||||||
|
|
||||||
if (getStackInSlot(slotID).stackSize <= amount)
|
|
||||||
{
|
|
||||||
tempStack = getStackInSlot(slotID);
|
|
||||||
setInventorySlotContents(slotID, null);
|
|
||||||
return tempStack;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tempStack = getStackInSlot(slotID).splitStack(amount);
|
|
||||||
|
|
||||||
if (getStackInSlot(slotID).stackSize == 0)
|
|
||||||
{
|
|
||||||
setInventorySlotContents(slotID, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tempStack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getStackInSlotOnClosing(int i)
|
|
||||||
{
|
|
||||||
return getStackInSlot(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
structure.visibleInventory[0] = itemstack;
|
|
||||||
}
|
|
||||||
else if (i == 1)
|
|
||||||
{
|
|
||||||
if (itemstack == null)
|
|
||||||
{
|
|
||||||
if (!worldObj.isRemote)
|
|
||||||
{
|
|
||||||
structure.inventory.remove(ListUtil.getTop(structure.inventory));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
structure.tempStack = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (worldObj.isRemote)
|
|
||||||
{
|
|
||||||
structure.tempStack = itemstack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
structure.visibleInventory[i - 1] = itemstack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getInvName()
|
|
||||||
{
|
|
||||||
return "Battery";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInvNameLocalized()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInventoryStackLimit()
|
|
||||||
{
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void openChest()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void closeChest()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isItemValidForSlot(int i, ItemStack itemsSack)
|
|
||||||
{
|
|
||||||
return itemsSack.getItem() instanceof IEnergyItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumSet<ForgeDirection> getInputDirections()
|
|
||||||
{
|
|
||||||
return this.inputSides;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumSet<ForgeDirection> getOutputDirections()
|
|
||||||
{
|
|
||||||
return EnumSet.complementOf(this.inputSides);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles the input/output sides of the battery.
|
|
||||||
*/
|
|
||||||
public boolean toggleSide(ForgeDirection orientation)
|
|
||||||
{
|
|
||||||
if (this.inputSides.contains(orientation))
|
|
||||||
{
|
|
||||||
this.inputSides.remove(orientation);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.inputSides.add(orientation);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -32,7 +32,7 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
|
public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
|
||||||
{
|
{
|
||||||
TileEntityEMContractor contractor = (TileEntityEMContractor) world.getBlockTileEntity(par2, par3, par4);
|
TileEMLevitator contractor = (TileEMLevitator) world.getBlockTileEntity(par2, par3, par4);
|
||||||
|
|
||||||
if (entityPlayer.getCurrentEquippedItem() != null)
|
if (entityPlayer.getCurrentEquippedItem() != null)
|
||||||
{
|
{
|
||||||
|
@ -53,9 +53,9 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
|
||||||
|
|
||||||
if (linkVec != null)
|
if (linkVec != null)
|
||||||
{
|
{
|
||||||
if (linkVec.getTileEntity(world) instanceof TileEntityEMContractor)
|
if (linkVec.getTileEntity(world) instanceof TileEMLevitator)
|
||||||
{
|
{
|
||||||
contractor.setLink((TileEntityEMContractor) linkVec.getTileEntity(world), true);
|
contractor.setLink((TileEMLevitator) linkVec.getTileEntity(world), true);
|
||||||
|
|
||||||
if (world.isRemote)
|
if (world.isRemote)
|
||||||
{
|
{
|
||||||
|
@ -88,7 +88,7 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
|
||||||
@Override
|
@Override
|
||||||
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
|
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
|
||||||
{
|
{
|
||||||
TileEntityEMContractor tileContractor = (TileEntityEMContractor) world.getBlockTileEntity(x, y, z);
|
TileEMLevitator tileContractor = (TileEMLevitator) world.getBlockTileEntity(x, y, z);
|
||||||
|
|
||||||
if (!world.isRemote && !tileContractor.isLatched())
|
if (!world.isRemote && !tileContractor.isLatched())
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,7 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world)
|
public TileEntity createNewTileEntity(World world)
|
||||||
{
|
{
|
||||||
return new TileEntityEMContractor();
|
return new TileEMLevitator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class ItemBlockContractor extends ItemBlock
|
||||||
|
|
||||||
if (place)
|
if (place)
|
||||||
{
|
{
|
||||||
TileEntityEMContractor tileContractor = (TileEntityEMContractor) world.getBlockTileEntity(x, y, z);
|
TileEMLevitator tileContractor = (TileEMLevitator) world.getBlockTileEntity(x, y, z);
|
||||||
tileContractor.setDirection(ForgeDirection.getOrientation(side));
|
tileContractor.setDirection(ForgeDirection.getOrientation(side));
|
||||||
|
|
||||||
if (!tileContractor.isLatched())
|
if (!tileContractor.isLatched())
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class PathfinderEMContractor
|
||||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||||
Vector3 neighbor = this.target.clone().translate(new Vector3(direction.offsetX, direction.offsetY, direction.offsetZ));
|
Vector3 neighbor = this.target.clone().translate(new Vector3(direction.offsetX, direction.offsetY, direction.offsetZ));
|
||||||
|
|
||||||
if (!TileEntityEMContractor.canBePath(this.world, neighbor))
|
if (!TileEMLevitator.canBePath(this.world, neighbor))
|
||||||
{
|
{
|
||||||
blockCount++;
|
blockCount++;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public class PathfinderEMContractor
|
||||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||||
Vector3 neighbor = currentNode.clone().modifyPositionFromSide(direction);
|
Vector3 neighbor = currentNode.clone().modifyPositionFromSide(direction);
|
||||||
|
|
||||||
if (TileEntityEMContractor.canBePath(this.world, neighbor))
|
if (TileEMLevitator.canBePath(this.world, neighbor))
|
||||||
{
|
{
|
||||||
double tentativeG = this.gScore.get(currentNode) + currentNode.distance(neighbor);
|
double tentativeG = this.gScore.get(currentNode) + currentNode.distance(neighbor);
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class RenderLevitator extends TileEntitySpecialRenderer
|
||||||
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
|
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
|
||||||
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
|
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
|
||||||
|
|
||||||
switch (((TileEntityEMContractor) t).getDirection())
|
switch (((TileEMLevitator) t).getDirection())
|
||||||
{
|
{
|
||||||
case DOWN:
|
case DOWN:
|
||||||
GL11.glRotatef(180, 0, 0, 1);
|
GL11.glRotatef(180, 0, 0, 1);
|
||||||
|
@ -50,7 +50,7 @@ public class RenderLevitator extends TileEntitySpecialRenderer
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((TileEntityEMContractor) t).suck)
|
if (((TileEMLevitator) t).suck)
|
||||||
{
|
{
|
||||||
this.bindTexture(TEXTURE);
|
this.bindTexture(TEXTURE);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public class RenderLevitator extends TileEntitySpecialRenderer
|
||||||
this.bindTexture(TEXTURE_PUSH);
|
this.bindTexture(TEXTURE_PUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((TileEntityEMContractor) t).canFunction() && !ResonantInduction.proxy.isPaused())
|
if (((TileEMLevitator) t).canFunction() && !ResonantInduction.proxy.isPaused())
|
||||||
{
|
{
|
||||||
MODEL_SPIN.render(0.0625f);
|
MODEL_SPIN.render(0.0625f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.fluids.IFluidBlock;
|
import net.minecraftforge.fluids.IFluidBlock;
|
||||||
import resonantinduction.ResonantInduction;
|
import resonantinduction.ResonantInduction;
|
||||||
import resonantinduction.tesla.TileEntityTesla;
|
import resonantinduction.tesla.TileTesla;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
import calclavia.lib.InventoryHelper;
|
import calclavia.lib.InventoryHelper;
|
||||||
import calclavia.lib.network.IPacketReceiver;
|
import calclavia.lib.network.IPacketReceiver;
|
||||||
|
@ -36,7 +36,7 @@ import com.google.common.io.ByteArrayDataInput;
|
||||||
* @author AidanBrady
|
* @author AidanBrady
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TileEntityEMContractor extends TileEntityAdvanced implements IPacketReceiver, IPacketSender
|
public class TileEMLevitator extends TileEntityAdvanced implements IPacketReceiver, IPacketSender
|
||||||
{
|
{
|
||||||
public static int MAX_REACH = 40;
|
public static int MAX_REACH = 40;
|
||||||
public static int PUSH_DELAY = 5;
|
public static int PUSH_DELAY = 5;
|
||||||
|
@ -59,11 +59,11 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
|
||||||
private ThreadEMPathfinding thread;
|
private ThreadEMPathfinding thread;
|
||||||
private PathfinderEMContractor pathfinder;
|
private PathfinderEMContractor pathfinder;
|
||||||
private Set<EntityItem> pathfindingTrackers = new HashSet<EntityItem>();
|
private Set<EntityItem> pathfindingTrackers = new HashSet<EntityItem>();
|
||||||
private TileEntityEMContractor linked;
|
private TileEMLevitator linked;
|
||||||
private int lastCalcTime = 0;
|
private int lastCalcTime = 0;
|
||||||
|
|
||||||
/** Color of beam */
|
/** Color of beam */
|
||||||
private int dyeID = TileEntityTesla.DEFAULT_COLOR;
|
private int dyeID = TileTesla.DEFAULT_COLOR;
|
||||||
private Vector3 tempLinkVector;
|
private Vector3 tempLinkVector;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,9 +82,9 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
|
||||||
|
|
||||||
if (tempLinkVector != null)
|
if (tempLinkVector != null)
|
||||||
{
|
{
|
||||||
if (tempLinkVector.getTileEntity(worldObj) instanceof TileEntityEMContractor)
|
if (tempLinkVector.getTileEntity(worldObj) instanceof TileEMLevitator)
|
||||||
{
|
{
|
||||||
setLink((TileEntityEMContractor) tempLinkVector.getTileEntity(worldObj), true);
|
setLink((TileEMLevitator) tempLinkVector.getTileEntity(worldObj), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
tempLinkVector = null;
|
tempLinkVector = null;
|
||||||
|
@ -164,7 +164,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
|
||||||
{
|
{
|
||||||
Vector3 result = pathfinder.results.get(i).clone();
|
Vector3 result = pathfinder.results.get(i).clone();
|
||||||
|
|
||||||
if (TileEntityEMContractor.canBePath(worldObj, result))
|
if (TileEMLevitator.canBePath(worldObj, result))
|
||||||
{
|
{
|
||||||
if (i - 1 >= 0)
|
if (i - 1 >= 0)
|
||||||
{
|
{
|
||||||
|
@ -552,7 +552,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
|
||||||
/**
|
/**
|
||||||
* Link between two TileEntities, do pathfinding operation.
|
* Link between two TileEntities, do pathfinding operation.
|
||||||
*/
|
*/
|
||||||
public void setLink(TileEntityEMContractor tileEntity, boolean setOpponent)
|
public void setLink(TileEMLevitator tileEntity, boolean setOpponent)
|
||||||
{
|
{
|
||||||
if (linked != null && setOpponent)
|
if (linked != null && setOpponent)
|
||||||
{
|
{
|
||||||
|
@ -580,7 +580,7 @@ public class TileEntityEMContractor extends TileEntityAdvanced implements IPacke
|
||||||
|
|
||||||
if (start.distance(target) < ResonantInduction.MAX_CONTRACTOR_DISTANCE)
|
if (start.distance(target) < ResonantInduction.MAX_CONTRACTOR_DISTANCE)
|
||||||
{
|
{
|
||||||
if (TileEntityEMContractor.canBePath(worldObj, start) && TileEntityEMContractor.canBePath(worldObj, target))
|
if (TileEMLevitator.canBePath(worldObj, start) && TileEMLevitator.canBePath(worldObj, target))
|
||||||
{
|
{
|
||||||
thread = new ThreadEMPathfinding(new PathfinderEMContractor(worldObj, target), start);
|
thread = new ThreadEMPathfinding(new PathfinderEMContractor(worldObj, target), start);
|
||||||
thread.start();
|
thread.start();
|
|
@ -9,9 +9,12 @@ import net.minecraft.world.IBlockAccess;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import resonantinduction.battery.BlockBattery;
|
||||||
|
import resonantinduction.battery.RenderBattery;
|
||||||
import resonantinduction.levitator.BlockEMContractor;
|
import resonantinduction.levitator.BlockEMContractor;
|
||||||
import resonantinduction.levitator.RenderLevitator;
|
import resonantinduction.levitator.RenderLevitator;
|
||||||
import resonantinduction.tesla.BlockTesla;
|
import resonantinduction.tesla.BlockTesla;
|
||||||
|
import resonantinduction.tesla.RenderTesla;
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||||
|
@ -49,7 +52,7 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
|
||||||
RenderLevitator.MODEL.render(0.0625f);
|
RenderLevitator.MODEL.render(0.0625f);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
/*else if (block instanceof BlockBattery)
|
else if (block instanceof BlockBattery)
|
||||||
{
|
{
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glTranslated(0.5, 1.42, 0.5);
|
GL11.glTranslated(0.5, 1.42, 0.5);
|
||||||
|
@ -57,7 +60,7 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
|
||||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderBattery.TEXTURE);
|
FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderBattery.TEXTURE);
|
||||||
RenderBattery.MODEL.render(0.0625f);
|
RenderBattery.MODEL.render(0.0625f);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,14 +34,14 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider
|
||||||
{
|
{
|
||||||
super.onBlockAdded(world, x, y, z);
|
super.onBlockAdded(world, x, y, z);
|
||||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||||
((TileEntityTesla) tileEntity).updatePositionStatus();
|
((TileTesla) tileEntity).updatePositionStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
|
||||||
{
|
{
|
||||||
TileEntity t = world.getBlockTileEntity(x, y, z);
|
TileEntity t = world.getBlockTileEntity(x, y, z);
|
||||||
TileEntityTesla tileEntity = ((TileEntityTesla) t).getControllingTelsa();
|
TileTesla tileEntity = ((TileTesla) t).getControllingTelsa();
|
||||||
|
|
||||||
if (entityPlayer.getCurrentEquippedItem() != null)
|
if (entityPlayer.getCurrentEquippedItem() != null)
|
||||||
{
|
{
|
||||||
|
@ -86,9 +86,9 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider
|
||||||
int dimID = link.getLinkDim(entityPlayer.getCurrentEquippedItem());
|
int dimID = link.getLinkDim(entityPlayer.getCurrentEquippedItem());
|
||||||
World otherWorld = MinecraftServer.getServer().worldServerForDimension(dimID);
|
World otherWorld = MinecraftServer.getServer().worldServerForDimension(dimID);
|
||||||
|
|
||||||
if (linkVec.getTileEntity(otherWorld) instanceof TileEntityTesla)
|
if (linkVec.getTileEntity(otherWorld) instanceof TileTesla)
|
||||||
{
|
{
|
||||||
tileEntity.setLink(new Vector3(((TileEntityTesla) linkVec.getTileEntity(otherWorld)).getTopTelsa()), dimID, true);
|
tileEntity.setLink(new Vector3(((TileTesla) linkVec.getTileEntity(otherWorld)).getTopTelsa()), dimID, true);
|
||||||
|
|
||||||
entityPlayer.addChatMessage("Linked " + this.getLocalizedName() + " with " + " [" + (int) linkVec.x + ", " + (int) linkVec.y + ", " + (int) linkVec.z + "]");
|
entityPlayer.addChatMessage("Linked " + this.getLocalizedName() + " with " + " [" + (int) linkVec.x + ", " + (int) linkVec.y + ", " + (int) linkVec.z + "]");
|
||||||
|
|
||||||
|
@ -132,13 +132,13 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider
|
||||||
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
|
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
|
||||||
{
|
{
|
||||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||||
((TileEntityTesla) tileEntity).updatePositionStatus();
|
((TileTesla) tileEntity).updatePositionStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world)
|
public TileEntity createNewTileEntity(World world)
|
||||||
{
|
{
|
||||||
return new TileEntityTesla();
|
return new TileTesla();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package resonantinduction.render;
|
package resonantinduction.tesla;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
|
@ -41,7 +41,7 @@ import cpw.mods.fml.common.network.PacketDispatcher;
|
||||||
* @author Calclavia
|
* @author Calclavia
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPacketSender, IPacketReceiver
|
public class TileTesla extends TileEntityElectrical implements ITesla, IPacketSender, IPacketReceiver
|
||||||
{
|
{
|
||||||
public final static int DEFAULT_COLOR = 12;
|
public final static int DEFAULT_COLOR = 12;
|
||||||
public final long TRANSFER_CAP = 10000;
|
public final long TRANSFER_CAP = 10000;
|
||||||
|
@ -54,14 +54,14 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
private boolean doTransfer = true;
|
private boolean doTransfer = true;
|
||||||
|
|
||||||
/** Prevents transfer loops */
|
/** Prevents transfer loops */
|
||||||
private final Set<TileEntityTesla> outputBlacklist = new HashSet<TileEntityTesla>();
|
private final Set<TileTesla> outputBlacklist = new HashSet<TileTesla>();
|
||||||
private final Set<TileEntityTesla> connectedTeslas = new HashSet<TileEntityTesla>();
|
private final Set<TileTesla> connectedTeslas = new HashSet<TileTesla>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caching
|
* Caching
|
||||||
*/
|
*/
|
||||||
private TileEntityTesla topCache = null;
|
private TileTesla topCache = null;
|
||||||
private TileEntityTesla controlCache = null;
|
private TileTesla controlCache = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quantum Tesla
|
* Quantum Tesla
|
||||||
|
@ -75,7 +75,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
private int zapCounter = 0;
|
private int zapCounter = 0;
|
||||||
private boolean isLinkedClient;
|
private boolean isLinkedClient;
|
||||||
|
|
||||||
public TileEntityTesla()
|
public TileTesla()
|
||||||
{
|
{
|
||||||
this.energy = new EnergyStorage(TRANSFER_CAP);
|
this.energy = new EnergyStorage(TRANSFER_CAP);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
|
|
||||||
if (this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && ((this.worldObj.isRemote && this.doTransfer) || (this.energy.getEnergy() > 0 && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))))
|
if (this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && ((this.worldObj.isRemote && this.doTransfer) || (this.energy.getEnergy() > 0 && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))))
|
||||||
{
|
{
|
||||||
final TileEntityTesla topTesla = this.getTopTelsa();
|
final TileTesla topTesla = this.getTopTelsa();
|
||||||
final Vector3 topTeslaVector = new Vector3(topTesla);
|
final Vector3 topTeslaVector = new Vector3(topTesla);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,9 +119,9 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
{
|
{
|
||||||
TileEntity transferTile = this.linked.getTileEntity(dimWorld);
|
TileEntity transferTile = this.linked.getTileEntity(dimWorld);
|
||||||
|
|
||||||
if (transferTile instanceof TileEntityTesla && !transferTile.isInvalid())
|
if (transferTile instanceof TileTesla && !transferTile.isInvalid())
|
||||||
{
|
{
|
||||||
this.transfer(((TileEntityTesla) transferTile), Math.min(this.energy.getEmptySpace(), TRANSFER_CAP));
|
this.transfer(((TileTesla) transferTile), Math.min(this.energy.getEmptySpace(), TRANSFER_CAP));
|
||||||
|
|
||||||
if (this.zapCounter % 5 == 0 && ResonantInduction.SOUND_FXS)
|
if (this.zapCounter % 5 == 0 && ResonantInduction.SOUND_FXS)
|
||||||
{
|
{
|
||||||
|
@ -149,14 +149,14 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
*/
|
*/
|
||||||
if (!this.connectedTeslas.contains(tesla) && tesla.canTeslaTransfer(this))
|
if (!this.connectedTeslas.contains(tesla) && tesla.canTeslaTransfer(this))
|
||||||
{
|
{
|
||||||
if (tesla instanceof TileEntityTesla)
|
if (tesla instanceof TileTesla)
|
||||||
{
|
{
|
||||||
if (((TileEntityTesla) tesla).getHeight() <= 1)
|
if (((TileTesla) tesla).getHeight() <= 1)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tesla = ((TileEntityTesla) tesla).getControllingTelsa();
|
tesla = ((TileTesla) tesla).getControllingTelsa();
|
||||||
}
|
}
|
||||||
|
|
||||||
transferTeslaCoils.add(tesla);
|
transferTeslaCoils.add(tesla);
|
||||||
|
@ -207,10 +207,10 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
|
|
||||||
Vector3 targetVector = new Vector3((TileEntity) tesla);
|
Vector3 targetVector = new Vector3((TileEntity) tesla);
|
||||||
|
|
||||||
if (tesla instanceof TileEntityTesla)
|
if (tesla instanceof TileTesla)
|
||||||
{
|
{
|
||||||
((TileEntityTesla) tesla).getControllingTelsa().outputBlacklist.add(this);
|
((TileTesla) tesla).getControllingTelsa().outputBlacklist.add(this);
|
||||||
targetVector = new Vector3(((TileEntityTesla) tesla).getTopTelsa());
|
targetVector = new Vector3(((TileTesla) tesla).getTopTelsa());
|
||||||
}
|
}
|
||||||
|
|
||||||
double distance = topTeslaVector.distance(targetVector);
|
double distance = topTeslaVector.distance(targetVector);
|
||||||
|
@ -393,8 +393,8 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
|
|
||||||
public void updatePositionStatus()
|
public void updatePositionStatus()
|
||||||
{
|
{
|
||||||
boolean isTop = new Vector3(this).translate(new Vector3(0, 1, 0)).getTileEntity(this.worldObj) instanceof TileEntityTesla;
|
boolean isTop = new Vector3(this).translate(new Vector3(0, 1, 0)).getTileEntity(this.worldObj) instanceof TileTesla;
|
||||||
boolean isBottom = new Vector3(this).translate(new Vector3(0, -1, 0)).getTileEntity(this.worldObj) instanceof TileEntityTesla;
|
boolean isBottom = new Vector3(this).translate(new Vector3(0, -1, 0)).getTileEntity(this.worldObj) instanceof TileTesla;
|
||||||
|
|
||||||
if (isTop && isBottom)
|
if (isTop && isBottom)
|
||||||
{
|
{
|
||||||
|
@ -415,7 +415,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
*
|
*
|
||||||
* @return The highest Tesla coil in this tower.
|
* @return The highest Tesla coil in this tower.
|
||||||
*/
|
*/
|
||||||
public TileEntityTesla getTopTelsa()
|
public TileTesla getTopTelsa()
|
||||||
{
|
{
|
||||||
if (this.topCache != null)
|
if (this.topCache != null)
|
||||||
{
|
{
|
||||||
|
@ -424,16 +424,16 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
|
|
||||||
this.connectedTeslas.clear();
|
this.connectedTeslas.clear();
|
||||||
Vector3 checkPosition = new Vector3(this);
|
Vector3 checkPosition = new Vector3(this);
|
||||||
TileEntityTesla returnTile = this;
|
TileTesla returnTile = this;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
TileEntity t = checkPosition.getTileEntity(this.worldObj);
|
TileEntity t = checkPosition.getTileEntity(this.worldObj);
|
||||||
|
|
||||||
if (t instanceof TileEntityTesla)
|
if (t instanceof TileTesla)
|
||||||
{
|
{
|
||||||
this.connectedTeslas.add((TileEntityTesla) t);
|
this.connectedTeslas.add((TileTesla) t);
|
||||||
returnTile = (TileEntityTesla) t;
|
returnTile = (TileTesla) t;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -452,7 +452,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TileEntityTesla getControllingTelsa()
|
public TileTesla getControllingTelsa()
|
||||||
{
|
{
|
||||||
if (this.controlCache != null)
|
if (this.controlCache != null)
|
||||||
{
|
{
|
||||||
|
@ -460,15 +460,15 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 checkPosition = new Vector3(this);
|
Vector3 checkPosition = new Vector3(this);
|
||||||
TileEntityTesla returnTile = this;
|
TileTesla returnTile = this;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
TileEntity t = checkPosition.getTileEntity(this.worldObj);
|
TileEntity t = checkPosition.getTileEntity(this.worldObj);
|
||||||
|
|
||||||
if (t instanceof TileEntityTesla)
|
if (t instanceof TileTesla)
|
||||||
{
|
{
|
||||||
returnTile = (TileEntityTesla) t;
|
returnTile = (TileTesla) t;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -496,9 +496,9 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
{
|
{
|
||||||
TileEntity t = new Vector3(this).translate(new Vector3(0, y, 0)).getTileEntity(this.worldObj);
|
TileEntity t = new Vector3(this).translate(new Vector3(0, y, 0)).getTileEntity(this.worldObj);
|
||||||
|
|
||||||
if (t instanceof TileEntityTesla)
|
if (t instanceof TileTesla)
|
||||||
{
|
{
|
||||||
this.connectedTeslas.add((TileEntityTesla) t);
|
this.connectedTeslas.add((TileTesla) t);
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -584,9 +584,9 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
{
|
{
|
||||||
TileEntity tileEntity = this.linked.getTileEntity(otherWorld);
|
TileEntity tileEntity = this.linked.getTileEntity(otherWorld);
|
||||||
|
|
||||||
if (tileEntity instanceof TileEntityTesla)
|
if (tileEntity instanceof TileTesla)
|
||||||
{
|
{
|
||||||
((TileEntityTesla) tileEntity).setLink(null, this.linkDim, false);
|
((TileTesla) tileEntity).setLink(null, this.linkDim, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -600,9 +600,9 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
|
||||||
{
|
{
|
||||||
TileEntity tileEntity = this.linked.getTileEntity(newOtherWorld);
|
TileEntity tileEntity = this.linked.getTileEntity(newOtherWorld);
|
||||||
|
|
||||||
if (tileEntity instanceof TileEntityTesla)
|
if (tileEntity instanceof TileTesla)
|
||||||
{
|
{
|
||||||
((TileEntityTesla) tileEntity).setLink(new Vector3(this), this.worldObj.provider.dimensionId, false);
|
((TileTesla) tileEntity).setLink(new Vector3(this), this.worldObj.provider.dimensionId, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue