v5.5.4 Beta #5
*BlockWrapper for managing blocks without TEs. *Updated UE API. *Updated to the latest Forge. *Added support for GalactiCraft on solars. *Fixed container support for Electric Pump. *Better utilities.
This commit is contained in:
parent
de3679def5
commit
4cebdea5a0
10 changed files with 525 additions and 106 deletions
|
@ -83,7 +83,7 @@ public class GuiElectricPump extends GuiContainer
|
|||
drawTexturedModelRectFromIcon(width + yPos, height + xPos + 58 - renderRemaining - start, liquid.canonical().getRenderingIcon(), 16, 16 - (16 - renderRemaining));
|
||||
start = start + 16;
|
||||
|
||||
if (renderRemaining == 0 || scale == 0)
|
||||
if(renderRemaining == 0 || scale == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -734,7 +734,7 @@ public class BlockMachine extends BlockContainer implements IDismantleable
|
|||
PURIFICATION_CHAMBER(9, 15, 12000, TileEntityPurificationChamber.class, false),
|
||||
ENERGIZED_SMELTER(10, 16, 2000, TileEntityEnergizedSmelter.class, false),
|
||||
TELEPORTER(11, 13, 5000000, TileEntityTeleporter.class, false),
|
||||
ELECTRIC_PUMP(12, 17, 16000, TileEntityElectricPump.class, false);
|
||||
ELECTRIC_PUMP(12, 17, 10000, TileEntityElectricPump.class, false);
|
||||
|
||||
public int meta;
|
||||
public int guiId;
|
||||
|
|
51
src/minecraft/mekanism/common/BlockWrapper.java
Normal file
51
src/minecraft/mekanism/common/BlockWrapper.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package mekanism.common;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class BlockWrapper
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
|
||||
public BlockWrapper(int i, int j, int k)
|
||||
{
|
||||
x = i;
|
||||
y = j;
|
||||
z = k;
|
||||
}
|
||||
|
||||
public void write(NBTTagCompound nbtTags)
|
||||
{
|
||||
nbtTags.setInteger("x", x);
|
||||
nbtTags.setInteger("y", y);
|
||||
nbtTags.setInteger("z", z);
|
||||
}
|
||||
|
||||
public static BlockWrapper get(TileEntity tileEntity)
|
||||
{
|
||||
return new BlockWrapper(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
|
||||
public static BlockWrapper read(NBTTagCompound nbtTags)
|
||||
{
|
||||
return new BlockWrapper(nbtTags.getInteger("x"), nbtTags.getInteger("y"), nbtTags.getInteger("z"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof BlockWrapper && ((BlockWrapper)obj).x == x && ((BlockWrapper)obj).y == y && ((BlockWrapper)obj).z == z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int code = 1;
|
||||
code = 31 * code + x;
|
||||
code = 31 * code + y;
|
||||
code = 31 * code + z;
|
||||
return code;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import net.minecraft.inventory.Container;
|
|||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
|
||||
public class ContainerElectricPump extends Container
|
||||
|
@ -18,7 +19,7 @@ public class ContainerElectricPump extends Container
|
|||
{
|
||||
tileEntity = tentity;
|
||||
addSlotToContainer(new Slot(tentity, 0, 28, 20));
|
||||
addSlotToContainer(new Slot(tentity, 1, 28, 51));
|
||||
addSlotToContainer(new SlotOutput(tentity, 1, 28, 51));
|
||||
addSlotToContainer(new SlotDischarge(tentity, 2, 143, 35));
|
||||
int slotX;
|
||||
|
||||
|
@ -64,21 +65,67 @@ public class ContainerElectricPump extends Container
|
|||
|
||||
if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID)
|
||||
{
|
||||
if(slotID != 1)
|
||||
if(slotID != 2)
|
||||
{
|
||||
if (!mergeItemStack(slotStack, 1, 2, false))
|
||||
if (!mergeItemStack(slotStack, 2, 3, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(slotID == 1)
|
||||
else if(slotID == 2)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 2, inventorySlots.size(), false))
|
||||
if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(LiquidContainerRegistry.isEmptyContainer(slotStack))
|
||||
{
|
||||
if(slotID != 0)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 0, 1, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(slotID == 0)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(slotID == 1)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(slotID >= 3 && slotID <= 29)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 30, inventorySlots.size(), false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(slotID > 28)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 3, 29, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(slotStack.stackSize == 0)
|
||||
{
|
||||
|
|
|
@ -393,7 +393,7 @@ public class ItemBlockMachine extends ItemBlock implements IItemElectric, ICusto
|
|||
{
|
||||
if(data[0] instanceof ItemStack)
|
||||
{
|
||||
if(((ItemStack)data[0]).getItemDamage() != 11)
|
||||
if(((ItemStack)data[0]).getItemDamage() != 11 && ((ItemStack)data[0]).getItemDamage() != 12)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -28,15 +28,21 @@ import mekanism.api.InfuseObject;
|
|||
import mekanism.common.IFactory.RecipeType;
|
||||
import mekanism.common.Tier.EnergyCubeTier;
|
||||
import mekanism.common.Tier.FactoryTier;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.liquids.ILiquid;
|
||||
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
||||
import net.minecraftforge.liquids.LiquidDictionary;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
|
@ -49,6 +55,8 @@ import cpw.mods.fml.server.FMLServerHandler;
|
|||
*/
|
||||
public final class MekanismUtils
|
||||
{
|
||||
public static int[][] ADJACENT_COORDS = {{0, -1, 0}, {0, 1, 0}, {0, 0, -1}, {0, 0, 1}, {-1, 0, 0}, {1, 0, 0}};
|
||||
|
||||
/**
|
||||
* Checks for a new version of Mekanism.
|
||||
*/
|
||||
|
@ -543,4 +551,89 @@ public final class MekanismUtils
|
|||
return Direction.XP;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the coordinates at the side of a certain block as an int array.
|
||||
* @param wrapper - original block
|
||||
* @param dir - side
|
||||
* @return coords of the block at a certain side
|
||||
*/
|
||||
public static int[] getCoords(BlockWrapper wrapper, ForgeDirection dir)
|
||||
{
|
||||
return new int[] {wrapper.x + ADJACENT_COORDS[dir.ordinal()][0], wrapper.y + ADJACENT_COORDS[dir.ordinal()][1], wrapper.z + ADJACENT_COORDS[dir.ordinal()][2]};
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not a certain block is considered a liquid.
|
||||
* @param world - world the block is in
|
||||
* @param x - x coordinate
|
||||
* @param y - y coordinate
|
||||
* @param z - z coordinate
|
||||
* @return if the block is a liquid
|
||||
*/
|
||||
public static boolean isLiquid(World world, int x, int y, int z)
|
||||
{
|
||||
return getLiquidAndCleanup(world, x, y, z) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a liquid from a certain location, or removes it if it's a dead lava block.
|
||||
* @param world - world the block is in
|
||||
* @param x - x coordinate
|
||||
* @param y - y coordinate
|
||||
* @param z - z coordinate
|
||||
* @return the liquid at the certain location, null if it doesn't exist
|
||||
*/
|
||||
public static LiquidStack getLiquidAndCleanup(World world, int x, int y, int z)
|
||||
{
|
||||
int id = world.getBlockId(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if(id == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if((id == Block.waterStill.blockID || id == Block.waterMoving.blockID) && meta == 0)
|
||||
{
|
||||
return new LiquidStack(Block.waterStill.blockID, LiquidContainerRegistry.BUCKET_VOLUME, 0);
|
||||
}
|
||||
else if((id == Block.lavaStill.blockID || id == Block.lavaMoving.blockID) && meta == 0)
|
||||
{
|
||||
return new LiquidStack(Block.lavaStill.blockID, LiquidContainerRegistry.BUCKET_VOLUME, 0);
|
||||
}
|
||||
else if((id == Block.lavaStill.blockID || id == Block.lavaMoving.blockID) && meta != 0)
|
||||
{
|
||||
world.setBlockToAir(x, y, z);
|
||||
return null;
|
||||
}
|
||||
else if(Block.blocksList[id] instanceof ILiquid)
|
||||
{
|
||||
ILiquid liquid = (ILiquid)Block.blocksList[id];
|
||||
|
||||
if(liquid.isMetaSensitive())
|
||||
{
|
||||
return new LiquidStack(liquid.stillLiquidId(), LiquidContainerRegistry.BUCKET_VOLUME, liquid.stillLiquidMeta());
|
||||
}
|
||||
else {
|
||||
return new LiquidStack(liquid.stillLiquidId(), LiquidContainerRegistry.BUCKET_VOLUME, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance between one block and another.
|
||||
* @param blockOne - first block
|
||||
* @param blockTwo - second block
|
||||
* @return distance between the two blocks
|
||||
*/
|
||||
public static int getDistance(BlockWrapper blockOne, BlockWrapper blockTwo)
|
||||
{
|
||||
int subX = blockOne.x - blockTwo.x;
|
||||
int subY = blockOne.y - blockTwo.y;
|
||||
int subZ = blockOne.z - blockTwo.z;
|
||||
return (int)MathHelper.sqrt_double(subX * subX + subY * subY + subZ * subZ);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,50 @@
|
|||
package mekanism.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import buildcraft.api.core.Position;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import ic2.api.ElectricItem;
|
||||
import ic2.api.IElectricItem;
|
||||
import universalelectricity.core.item.ElectricItemHelper;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
import mekanism.api.InfusionType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.liquids.ILiquidTank;
|
||||
import net.minecraftforge.liquids.ITankContainer;
|
||||
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
import net.minecraftforge.liquids.LiquidTank;
|
||||
|
||||
public class TileEntityElectricPump extends TileEntityElectricBlock
|
||||
public class TileEntityElectricPump extends TileEntityElectricBlock implements ITankContainer
|
||||
{
|
||||
public LiquidTank liquidTank;
|
||||
|
||||
public Set<BlockWrapper> recurringNodes = new HashSet<BlockWrapper>();
|
||||
|
||||
public Random random = new Random();
|
||||
|
||||
public TileEntityElectricPump()
|
||||
{
|
||||
super("Electric Pump", 16000);
|
||||
liquidTank = new LiquidTank(16000);
|
||||
super("Electric Pump", 10000);
|
||||
liquidTank = new LiquidTank(10000);
|
||||
inventory = new ItemStack[3];
|
||||
liquidTank.setLiquid(new LiquidStack(Block.waterStill.blockID, 8000, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,7 +80,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock
|
|||
|
||||
if(inventory[0] != null)
|
||||
{
|
||||
if(liquidTank.getLiquid() != null && liquidTank.getLiquid().amount >= 1000)
|
||||
if(liquidTank.getLiquid() != null && liquidTank.getLiquid().amount >= LiquidContainerRegistry.BUCKET_VOLUME)
|
||||
{
|
||||
if(LiquidContainerRegistry.isEmptyContainer(inventory[0]))
|
||||
{
|
||||
|
@ -71,7 +90,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock
|
|||
{
|
||||
if(inventory[1] == null)
|
||||
{
|
||||
liquidTank.drain(1000, true);
|
||||
liquidTank.drain(LiquidContainerRegistry.BUCKET_VOLUME, true);
|
||||
|
||||
inventory[1] = tempStack;
|
||||
inventory[0].stackSize--;
|
||||
|
@ -83,7 +102,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock
|
|||
}
|
||||
else if(tempStack.isItemEqual(inventory[1]) && tempStack.getMaxStackSize() > inventory[1].stackSize)
|
||||
{
|
||||
liquidTank.drain(1000, true);
|
||||
liquidTank.drain(LiquidContainerRegistry.BUCKET_VOLUME, true);
|
||||
|
||||
inventory[1].stackSize++;
|
||||
inventory[0].stackSize--;
|
||||
|
@ -97,6 +116,93 @@ public class TileEntityElectricPump extends TileEntityElectricBlock
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0)
|
||||
{
|
||||
if(electricityStored >= 100 && (liquidTank.getLiquid() == null || liquidTank.getLiquid().amount+LiquidContainerRegistry.BUCKET_VOLUME <= 10000))
|
||||
{
|
||||
List<BlockWrapper> tempPumpList = Arrays.asList(recurringNodes.toArray(new BlockWrapper[recurringNodes.size()]));
|
||||
Collections.shuffle(tempPumpList);
|
||||
|
||||
for(BlockWrapper wrapper : tempPumpList)
|
||||
{
|
||||
if(MekanismUtils.isLiquid(worldObj, wrapper.x, wrapper.y, wrapper.z))
|
||||
{
|
||||
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquidAndCleanup(worldObj, wrapper.x, wrapper.y, wrapper.z).isLiquidEqual(liquidTank.getLiquid()))
|
||||
{
|
||||
setJoules(electricityStored - 100);
|
||||
liquidTank.fill(MekanismUtils.getLiquidAndCleanup(worldObj, wrapper.x, wrapper.y, wrapper.z), true);
|
||||
worldObj.setBlockToAir(wrapper.x, wrapper.y, wrapper.z);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
int x = MekanismUtils.getCoords(wrapper, orientation)[0];
|
||||
int y = MekanismUtils.getCoords(wrapper, orientation)[1];
|
||||
int z = MekanismUtils.getCoords(wrapper, orientation)[2];
|
||||
|
||||
if(MekanismUtils.getDistance(BlockWrapper.get(this), new BlockWrapper(x, y, z)) <= 60)
|
||||
{
|
||||
if(MekanismUtils.isLiquid(worldObj, x, y, z))
|
||||
{
|
||||
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquidAndCleanup(worldObj, x, y, z).isLiquidEqual(liquidTank.getLiquid()))
|
||||
{
|
||||
setJoules(electricityStored - 100);
|
||||
recurringNodes.add(new BlockWrapper(x, y, z));
|
||||
liquidTank.fill(MekanismUtils.getLiquidAndCleanup(worldObj, x, y, z), true);
|
||||
worldObj.setBlockToAir(x, y, z);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recurringNodes.remove(wrapper);
|
||||
}
|
||||
|
||||
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if(orientation != ForgeDirection.UP)
|
||||
{
|
||||
int x = MekanismUtils.getCoords(BlockWrapper.get(this), orientation)[0];
|
||||
int y = MekanismUtils.getCoords(BlockWrapper.get(this), orientation)[1];
|
||||
int z = MekanismUtils.getCoords(BlockWrapper.get(this), orientation)[2];
|
||||
|
||||
if(MekanismUtils.isLiquid(worldObj, x, y, z))
|
||||
{
|
||||
if(liquidTank.getLiquid() == null || MekanismUtils.getLiquidAndCleanup(worldObj, x, y, z).isLiquidEqual(liquidTank.getLiquid()))
|
||||
{
|
||||
setJoules(electricityStored - 100);
|
||||
recurringNodes.add(new BlockWrapper(x, y, z));
|
||||
liquidTank.fill(MekanismUtils.getLiquidAndCleanup(worldObj, x, y, z), true);
|
||||
worldObj.setBlockToAir(x, y, z);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(liquidTank.getLiquid() != null)
|
||||
{
|
||||
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(xCoord, yCoord, zCoord), orientation);
|
||||
|
||||
if(tileEntity instanceof ITankContainer)
|
||||
{
|
||||
liquidTank.drain(((ITankContainer)tileEntity).fill(orientation.getOpposite(), liquidTank.getLiquid(), true), true);
|
||||
|
||||
if(liquidTank.getLiquid() == null || liquidTank.getLiquid().amount <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,6 +216,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock
|
|||
int itemMeta = dataStream.readInt();
|
||||
|
||||
liquidTank.setLiquid(new LiquidStack(itemID, amount, itemMeta));
|
||||
|
||||
} catch(Exception e) {}
|
||||
|
||||
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
|
||||
|
@ -137,7 +244,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock
|
|||
|
||||
public int getScaledLiquidLevel(int i)
|
||||
{
|
||||
return liquidTank.getLiquid() != null ? liquidTank.getLiquid().amount*i / 16000 : 0;
|
||||
return liquidTank.getLiquid() != null ? liquidTank.getLiquid().amount*i / 10000 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -147,7 +254,21 @@ public class TileEntityElectricPump extends TileEntityElectricBlock
|
|||
|
||||
if(liquidTank.getLiquid() != null)
|
||||
{
|
||||
nbtTags.setTag("liquidTank", liquidTank.getLiquid().writeToNBT(new NBTTagCompound()));
|
||||
nbtTags.setTag("liquidTank", liquidTank.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
|
||||
for(BlockWrapper wrapper : recurringNodes)
|
||||
{
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
wrapper.write(tagCompound);
|
||||
tagList.appendTag(tagCompound);
|
||||
}
|
||||
|
||||
if(!tagList.tagList.isEmpty())
|
||||
{
|
||||
nbtTags.setTag("recurringNodes", tagList);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,9 +279,112 @@ public class TileEntityElectricPump extends TileEntityElectricBlock
|
|||
|
||||
if(nbtTags.hasKey("liquidTank"))
|
||||
{
|
||||
//liquidTank.setLiquid(LiquidStack.loadLiquidStackFromNBT(nbtTags));
|
||||
liquidTank.readFromNBT(nbtTags.getCompoundTag("liquidTank"));
|
||||
}
|
||||
|
||||
liquidTank.setLiquid(new LiquidStack(Block.waterStill.blockID, 8000, 0));
|
||||
if(nbtTags.hasKey("recurringNodes"))
|
||||
{
|
||||
NBTTagList tagList = nbtTags.getTagList("recurringNodes");
|
||||
|
||||
for(int i = 0; i < tagList.tagCount(); i++)
|
||||
{
|
||||
recurringNodes.add(BlockWrapper.read((NBTTagCompound)tagList.tagAt(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStackValidForSlot(int slotID, ItemStack itemstack)
|
||||
{
|
||||
if(slotID == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(slotID == 0)
|
||||
{
|
||||
return LiquidContainerRegistry.isEmptyContainer(itemstack);
|
||||
}
|
||||
else if(slotID == 2)
|
||||
{
|
||||
return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) ||
|
||||
(itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) ||
|
||||
itemstack.itemID == Item.redstone.itemID;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_102008_b(int slotID, ItemStack itemstack, int side)
|
||||
{
|
||||
if(slotID == 2)
|
||||
{
|
||||
return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0) ||
|
||||
(itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) &&
|
||||
(!(itemstack.getItem() instanceof IItemElectric) ||
|
||||
((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0));
|
||||
}
|
||||
else if(slotID == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
return drain(0, maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSizeInventorySide(int side)
|
||||
{
|
||||
if(side == 1)
|
||||
{
|
||||
return new int[] {0};
|
||||
}
|
||||
else if(side == 0)
|
||||
{
|
||||
return new int[] {1};
|
||||
}
|
||||
else {
|
||||
return new int[] {2};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
|
||||
{
|
||||
if(tankIndex == 0)
|
||||
{
|
||||
return liquidTank.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidTank[] getTanks(ForgeDirection direction)
|
||||
{
|
||||
return new ILiquidTank[] {liquidTank};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
|
||||
{
|
||||
return liquidTank;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class GuiBioGenerator extends GuiContainer
|
|||
fontRenderer.drawString(tileEntity.fullName, 45, 6, 0x404040);
|
||||
fontRenderer.drawString("Inventory", 8, (ySize - 96) + 2, 0x404040);
|
||||
fontRenderer.drawString(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00);
|
||||
fontRenderer.drawString("BioFuel: " + tileEntity.bioFuelSlot.liquidStored, 51, 35, 0x00CD00);
|
||||
fontRenderer.drawString("BioFuel: " + (tileEntity.bioFuelTank.getLiquid() != null ? tileEntity.bioFuelTank.getLiquid().amount : 0), 51, 35, 0x00CD00);
|
||||
fontRenderer.drawString(tileEntity.getVoltage() + "v", 51, 44, 0x00CD00);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
public final int GENERATION = 50;
|
||||
|
||||
/** The LiquidSlot biofuel instance for this generator. */
|
||||
public LiquidSlot bioFuelSlot = new LiquidSlot(24000, Mekanism.hooks.ForestryBiofuelID);
|
||||
public LiquidTank bioFuelTank = new LiquidTank(24000);
|
||||
|
||||
/** Which fuels work on this generator. */
|
||||
public static Map<Integer, Integer> fuels = new HashMap<Integer, Integer>();
|
||||
|
@ -56,7 +56,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
|
||||
if(Mekanism.hooks.ForestryLoaded)
|
||||
{
|
||||
fuels.put(Mekanism.hooks.ForestryBiofuelID, 16);
|
||||
fuels.put(Mekanism.hooks.ForestryBiofuelID, GENERATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,11 +108,10 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
{
|
||||
if(fuels.containsKey(liquid.itemID))
|
||||
{
|
||||
int liquidToAdd = liquid.amount*fuels.get(liquid.itemID);
|
||||
|
||||
if(bioFuelSlot.liquidStored+liquidToAdd <= bioFuelSlot.MAX_LIQUID)
|
||||
if(bioFuelTank.getLiquid() == null || bioFuelTank.getLiquid().amount+liquid.amount <= bioFuelTank.getCapacity())
|
||||
{
|
||||
bioFuelSlot.setLiquid(bioFuelSlot.liquidStored+liquidToAdd);
|
||||
bioFuelTank.fill(liquid, true);
|
||||
|
||||
if(LiquidContainerRegistry.isBucket(inventory[0]))
|
||||
{
|
||||
inventory[0] = new ItemStack(Item.bucketEmpty);
|
||||
|
@ -133,10 +132,10 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
ItemStack prevStack = inventory[0].copy();
|
||||
if(fuel > 0)
|
||||
{
|
||||
int fuelNeeded = bioFuelSlot.MAX_LIQUID - bioFuelSlot.liquidStored;
|
||||
int fuelNeeded = bioFuelTank.getLiquid() != null ? bioFuelTank.getCapacity() - bioFuelTank.getLiquid().amount : bioFuelTank.getCapacity();
|
||||
if(fuel <= fuelNeeded)
|
||||
{
|
||||
bioFuelSlot.liquidStored += fuel;
|
||||
bioFuelTank.fill(new LiquidStack(Mekanism.hooks.ForestryBiofuelID, fuel), true);
|
||||
inventory[0].stackSize--;
|
||||
|
||||
if(prevStack.isItemEqual(new ItemStack(Item.bucketLava)))
|
||||
|
@ -159,8 +158,9 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
{
|
||||
setActive(true);
|
||||
}
|
||||
bioFuelSlot.setLiquid(bioFuelSlot.liquidStored - 1);
|
||||
setJoules(electricityStored + GENERATION);
|
||||
|
||||
setJoules(electricityStored + fuels.get(bioFuelTank.getLiquid().itemID));
|
||||
bioFuelTank.drain(1, true);
|
||||
}
|
||||
else {
|
||||
if(!worldObj.isRemote)
|
||||
|
@ -206,7 +206,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
@Override
|
||||
public boolean canOperate()
|
||||
{
|
||||
return electricityStored < MAX_ELECTRICITY && bioFuelSlot.liquidStored > 0;
|
||||
return electricityStored < MAX_ELECTRICITY && bioFuelTank.getLiquid() != null && bioFuelTank.getLiquid().amount > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -214,7 +214,10 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
{
|
||||
super.readFromNBT(nbtTags);
|
||||
|
||||
bioFuelSlot.liquidStored = nbtTags.getInteger("bioFuelStored");
|
||||
if(nbtTags.hasKey("bioFuelTank"))
|
||||
{
|
||||
bioFuelTank.readFromNBT(nbtTags.getCompoundTag("bioFuelTank"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -222,7 +225,10 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
{
|
||||
super.writeToNBT(nbtTags);
|
||||
|
||||
nbtTags.setInteger("bioFuelStored", bioFuelSlot.liquidStored);
|
||||
if(bioFuelTank.getLiquid() != null)
|
||||
{
|
||||
nbtTags.setTag("bioFuelTank", bioFuelTank.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -243,7 +249,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
*/
|
||||
public int getScaledFuelLevel(int i)
|
||||
{
|
||||
return bioFuelSlot.liquidStored*i / bioFuelSlot.MAX_LIQUID;
|
||||
return bioFuelTank.getLiquid() != null ? bioFuelTank.getLiquid().amount*i / bioFuelTank.getCapacity() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -279,14 +285,28 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
public void handlePacketData(ByteArrayDataInput dataStream)
|
||||
{
|
||||
super.handlePacketData(dataStream);
|
||||
bioFuelSlot.liquidStored = dataStream.readInt();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
if(amount != 0)
|
||||
{
|
||||
bioFuelTank.setLiquid(new LiquidStack(Mekanism.hooks.ForestryBiofuelID, amount));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList getNetworkedData(ArrayList data)
|
||||
{
|
||||
super.getNetworkedData(data);
|
||||
data.add(bioFuelSlot.liquidStored);
|
||||
|
||||
if(bioFuelTank.getLiquid() != null)
|
||||
{
|
||||
data.add(bioFuelTank.getLiquid().amount);
|
||||
}
|
||||
else {
|
||||
data.add(0);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -310,9 +330,9 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
case 3:
|
||||
return new Object[] {(MAX_ELECTRICITY-electricityStored)};
|
||||
case 4:
|
||||
return new Object[] {bioFuelSlot.liquidStored};
|
||||
return new Object[] {bioFuelTank.getLiquid() != null ? bioFuelTank.getLiquid().amount : 0};
|
||||
case 5:
|
||||
return new Object[] {bioFuelSlot.MAX_LIQUID-bioFuelSlot.liquidStored};
|
||||
return new Object[] {bioFuelTank.getLiquid() != null ? bioFuelTank.getCapacity()-bioFuelTank.getLiquid().amount : 0};
|
||||
default:
|
||||
System.err.println("[Mekanism] Attempted to call unknown method with computer ID " + computer.getID());
|
||||
return null;
|
||||
|
@ -322,37 +342,17 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
@Override
|
||||
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
|
||||
{
|
||||
if(from != ForgeDirection.getOrientation(facing))
|
||||
{
|
||||
if(resource.itemID == Mekanism.hooks.ForestryBiofuelID)
|
||||
{
|
||||
int fuelTransfer = 0;
|
||||
int fuelNeeded = bioFuelSlot.MAX_LIQUID - bioFuelSlot.liquidStored;
|
||||
int attemptTransfer = resource.amount;
|
||||
|
||||
if(attemptTransfer <= fuelNeeded)
|
||||
{
|
||||
fuelTransfer = attemptTransfer;
|
||||
}
|
||||
else {
|
||||
fuelTransfer = fuelNeeded;
|
||||
}
|
||||
|
||||
if(doFill)
|
||||
{
|
||||
bioFuelSlot.setLiquid(bioFuelSlot.liquidStored + fuelTransfer);
|
||||
}
|
||||
|
||||
return fuelTransfer;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return fill(0, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
|
||||
{
|
||||
if(resource.itemID == Mekanism.hooks.ForestryBiofuelID && tankIndex == 0)
|
||||
{
|
||||
return bioFuelTank.fill(resource, doFill);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -371,12 +371,12 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements ITank
|
|||
@Override
|
||||
public ILiquidTank[] getTanks(ForgeDirection direction)
|
||||
{
|
||||
return new ILiquidTank[] {new LiquidTank(bioFuelSlot.liquidID, bioFuelSlot.liquidStored, bioFuelSlot.MAX_LIQUID)};
|
||||
return new ILiquidTank[] {bioFuelTank};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
|
||||
{
|
||||
return null;
|
||||
return bioFuelTank;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ import dan200.computer.api.IPeripheral;
|
|||
public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock implements IGasStorage, IEnergySink, ITankContainer, IPeripheral, ITubeConnection, IStrictEnergyAcceptor
|
||||
{
|
||||
/** This separator's water slot. */
|
||||
public LiquidSlot waterSlot = new LiquidSlot(24000, 9);
|
||||
public LiquidTank waterTank = new LiquidTank(24000);
|
||||
|
||||
/** The maximum amount of gas this block can store. */
|
||||
public int MAX_GAS = 2400;
|
||||
|
@ -107,9 +107,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
|
||||
if(liquid != null && liquid.itemID == Block.waterStill.blockID)
|
||||
{
|
||||
if(waterSlot.liquidStored+liquid.amount <= waterSlot.MAX_LIQUID)
|
||||
if(waterTank.getLiquid() == null || waterTank.getLiquid().amount+liquid.amount <= waterTank.getCapacity())
|
||||
{
|
||||
waterSlot.setLiquid(waterSlot.liquidStored + liquid.amount);
|
||||
waterTank.fill(liquid, true);
|
||||
|
||||
if(inventory[0].isItemEqual(new ItemStack(Item.bucketWater)))
|
||||
{
|
||||
|
@ -186,9 +186,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
}
|
||||
}
|
||||
|
||||
if(oxygenStored < MAX_GAS && hydrogenStored < MAX_GAS && waterSlot.liquidStored-2 >= 0 && electricityStored-4 > 0)
|
||||
if(oxygenStored < MAX_GAS && hydrogenStored < MAX_GAS && waterTank.getLiquid() != null && waterTank.getLiquid().amount-2 >= 0 && electricityStored-4 > 0)
|
||||
{
|
||||
waterSlot.setLiquid(waterSlot.liquidStored - 2);
|
||||
waterTank.drain(2, true);
|
||||
setJoules(electricityStored - 10);
|
||||
setGas(EnumGas.OXYGEN, oxygenStored + 1);
|
||||
setGas(EnumGas.HYDROGEN, hydrogenStored + 2);
|
||||
|
@ -389,7 +389,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
*/
|
||||
public int getScaledWaterLevel(int i)
|
||||
{
|
||||
return waterSlot.liquidStored*i / waterSlot.MAX_LIQUID;
|
||||
return waterTank.getLiquid() != null ? waterTank.getLiquid().amount*i / waterTank.getCapacity() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -422,7 +422,13 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
}
|
||||
|
||||
super.handlePacketData(dataStream);
|
||||
waterSlot.liquidStored = dataStream.readInt();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
if(amount != 0)
|
||||
{
|
||||
waterTank.setLiquid(new LiquidStack(Block.waterStill.blockID, dataStream.readInt(), 0));
|
||||
}
|
||||
|
||||
oxygenStored = dataStream.readInt();
|
||||
hydrogenStored = dataStream.readInt();
|
||||
outputType = EnumGas.getFromName(dataStream.readUTF());
|
||||
|
@ -433,7 +439,15 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
public ArrayList getNetworkedData(ArrayList data)
|
||||
{
|
||||
super.getNetworkedData(data);
|
||||
data.add(waterSlot.liquidStored);
|
||||
|
||||
if(waterTank.getLiquid() != null)
|
||||
{
|
||||
data.add(waterTank.getLiquid().amount);
|
||||
}
|
||||
else {
|
||||
data.add(0);
|
||||
}
|
||||
|
||||
data.add(oxygenStored);
|
||||
data.add(hydrogenStored);
|
||||
data.add(outputType.name);
|
||||
|
@ -514,37 +528,17 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
@Override
|
||||
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
|
||||
{
|
||||
if(from != ForgeDirection.getOrientation(facing))
|
||||
{
|
||||
if(resource.itemID == Block.waterStill.blockID)
|
||||
{
|
||||
int waterTransfer = 0;
|
||||
int waterNeeded = waterSlot.MAX_LIQUID - waterSlot.liquidStored;
|
||||
int attemptTransfer = resource.amount;
|
||||
|
||||
if(attemptTransfer <= waterNeeded)
|
||||
{
|
||||
waterTransfer = attemptTransfer;
|
||||
}
|
||||
else {
|
||||
waterTransfer = waterNeeded;
|
||||
}
|
||||
|
||||
if(doFill)
|
||||
{
|
||||
waterSlot.setLiquid(waterSlot.liquidStored + waterTransfer);
|
||||
}
|
||||
|
||||
return waterTransfer;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return fill(0, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
|
||||
{
|
||||
if(resource.itemID == Block.waterStill.blockID && tankIndex == 0)
|
||||
{
|
||||
return waterTank.fill(resource, doFill);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -563,13 +557,13 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
@Override
|
||||
public ILiquidTank[] getTanks(ForgeDirection direction)
|
||||
{
|
||||
return new ILiquidTank[] {new LiquidTank(waterSlot.liquidID, waterSlot.liquidStored, waterSlot.MAX_LIQUID)};
|
||||
return new ILiquidTank[] {waterTank};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
|
||||
{
|
||||
return null;
|
||||
return waterTank;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -579,7 +573,12 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
|
||||
hydrogenStored = nbtTags.getInteger("hydrogenStored");
|
||||
oxygenStored = nbtTags.getInteger("oxygenStored");
|
||||
waterSlot.liquidStored = nbtTags.getInteger("waterStored");
|
||||
|
||||
if(nbtTags.hasKey("waterTank"))
|
||||
{
|
||||
waterTank.readFromNBT(nbtTags.getCompoundTag("waterTank"));
|
||||
}
|
||||
|
||||
outputType = EnumGas.getFromName(nbtTags.getString("outputType"));
|
||||
dumpType = EnumGas.getFromName(nbtTags.getString("dumpType"));
|
||||
}
|
||||
|
@ -591,7 +590,12 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
|
||||
nbtTags.setInteger("hydrogenStored", hydrogenStored);
|
||||
nbtTags.setInteger("oxygenStored", oxygenStored);
|
||||
nbtTags.setInteger("waterStored", waterSlot.liquidStored);
|
||||
|
||||
if(waterTank.getLiquid() != null)
|
||||
{
|
||||
nbtTags.setTag("waterTank", waterTank.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
nbtTags.setString("outputType", outputType.name);
|
||||
nbtTags.setString("dumpType", dumpType.name);
|
||||
}
|
||||
|
@ -622,9 +626,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
case 3:
|
||||
return new Object[] {(MAX_ELECTRICITY-electricityStored)};
|
||||
case 4:
|
||||
return new Object[] {waterSlot.liquidStored};
|
||||
return new Object[] {waterTank.getLiquid() != null ? waterTank.getLiquid().amount : 0};
|
||||
case 5:
|
||||
return new Object[] {(waterSlot.MAX_LIQUID-waterSlot.liquidStored)};
|
||||
return new Object[] {waterTank.getLiquid() != null ? (waterTank.getCapacity()-waterTank.getLiquid().amount) : 0};
|
||||
case 6:
|
||||
return new Object[] {hydrogenStored};
|
||||
case 7:
|
||||
|
|
Loading…
Reference in a new issue