nothing much
Moved some stuff around, and made LiquidHandler able to be used in the api folder to help other people work with this mod. The api is not actual needed to work with this mod but it contains helpers to make life easier. Also added a method to LiquidHandler to get the name of a LiquidStack which for some reason can't be directly gotten from the liquidStack itself. Too get it i had to iterate over the hashMap used to store liquids. If the LiquidStack is linked to a LiquidData it will use the LiquidData name first. Also removed PipeInstance since its not actual needed anymore now that PipeColor is directly linked the pipe as well as the PipeBlock metadata.
This commit is contained in:
parent
42474bc8ec
commit
1e5c47ad3f
16 changed files with 94 additions and 59 deletions
|
@ -1,6 +1,6 @@
|
|||
package liquidmechanics.api;
|
||||
|
||||
import liquidmechanics.common.handlers.LiquidData;
|
||||
import liquidmechanics.api.helpers.LiquidData;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.liquids.ITankContainer;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package liquidmechanics.common.handlers;
|
||||
package liquidmechanics.api.helpers;
|
||||
|
||||
import liquidmechanics.api.helpers.PipeColor;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
|
||||
public class LiquidData
|
|
@ -1,11 +1,10 @@
|
|||
package liquidmechanics.common.handlers;
|
||||
package liquidmechanics.api.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import liquidmechanics.api.helpers.PipeColor;
|
||||
import liquidmechanics.common.LiquidMechanics;
|
||||
import liquidmechanics.common.tileentity.TileEntityPipe;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
|
@ -37,8 +36,6 @@ public class LiquidHandler
|
|||
allowedLiquids.add(lava);
|
||||
unkown = new LiquidData("Unknown", LiquidDictionary.getOrCreateLiquid("Unknown", new LiquidStack(20, 1)), PipeColor.NONE, false, 0);
|
||||
allowedLiquids.add(unkown);
|
||||
waste = new LiquidData("Waste", LiquidDictionary.getOrCreateLiquid("Waste", new LiquidStack(LiquidMechanics.blockWasteLiquid, 1)), PipeColor.BROWN, false, 40);
|
||||
allowedLiquids.add(waste);
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
|
@ -61,6 +58,10 @@ public class LiquidHandler
|
|||
else if (event.Name.equalsIgnoreCase("steam"))
|
||||
{
|
||||
this.steam = new LiquidData("steam", event.Liquid, PipeColor.ORANGE, true, 100);
|
||||
}else if(event.Name.equalsIgnoreCase("Waste"))
|
||||
{
|
||||
this.waste = new LiquidData("Waste", event.Liquid, PipeColor.BROWN, false, 40);
|
||||
this.allowedLiquids.add(waste);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +88,29 @@ public class LiquidHandler
|
|||
}
|
||||
return unkown;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the name of the liquidStack using either LiquidData or
|
||||
* running threw the LiquidDirectory mapping
|
||||
*/
|
||||
public static String getName(LiquidStack stack)
|
||||
{
|
||||
if(get(stack) != unkown)
|
||||
{
|
||||
return get(stack).getName();
|
||||
}else
|
||||
{
|
||||
Map<String, LiquidStack> l = LiquidDictionary.getLiquids();
|
||||
for(Entry<String, LiquidStack> liquid : l.entrySet())
|
||||
{
|
||||
LiquidStack t = liquid.getValue();
|
||||
if(isEqual(t,stack))
|
||||
{
|
||||
return liquid.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "unkown";
|
||||
}
|
||||
/**
|
||||
* creates a new LiquidStack using type and vol
|
||||
*/
|
|
@ -1,7 +1,5 @@
|
|||
package liquidmechanics.api.helpers;
|
||||
|
||||
import liquidmechanics.common.handlers.LiquidData;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
|
||||
public enum PipeColor
|
||||
{
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package liquidmechanics.api.helpers;
|
||||
|
||||
import liquidmechanics.common.handlers.LiquidData;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package liquidmechanics.client.render;
|
||||
|
||||
import liquidmechanics.api.helpers.LiquidData;
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.client.model.ModelPump;
|
||||
import liquidmechanics.common.LiquidMechanics;
|
||||
import liquidmechanics.common.handlers.LiquidData;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
import liquidmechanics.common.tileentity.TileEntityPump;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package liquidmechanics.client.render;
|
||||
|
||||
import liquidmechanics.api.helpers.LiquidData;
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.api.helpers.PipeColor;
|
||||
import liquidmechanics.api.helpers.connectionHelper;
|
||||
import liquidmechanics.client.model.ModelLiquidTank;
|
||||
import liquidmechanics.client.model.ModelLiquidTankCorner;
|
||||
import liquidmechanics.common.LiquidMechanics;
|
||||
import liquidmechanics.common.handlers.LiquidData;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
import liquidmechanics.common.tileentity.TileEntityTank;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
|
|
@ -2,6 +2,8 @@ package liquidmechanics.common;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import liquidmechanics.api.helpers.LiquidData;
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.api.helpers.PipeColor;
|
||||
import liquidmechanics.common.block.BlockGenerator;
|
||||
import liquidmechanics.common.block.BlockPumpMachine;
|
||||
|
@ -10,7 +12,6 @@ import liquidmechanics.common.block.BlockReleaseValve;
|
|||
import liquidmechanics.common.block.BlockRod;
|
||||
import liquidmechanics.common.block.BlockTank;
|
||||
import liquidmechanics.common.block.BlockWasteLiquid;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
import liquidmechanics.common.item.ItemGuage;
|
||||
import liquidmechanics.common.item.ItemLiquidMachine;
|
||||
import liquidmechanics.common.item.ItemParts;
|
||||
|
@ -28,6 +29,7 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.liquids.LiquidDictionary;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
@ -255,5 +257,6 @@ public class LiquidMechanics extends DummyModContainer
|
|||
// add Default Liquids to current list, done last to let other mods use
|
||||
// there liquid data first if used
|
||||
LiquidHandler.addDefaultLiquids();
|
||||
LiquidStack waste = LiquidDictionary.getOrCreateLiquid("Waste", new LiquidStack(LiquidMechanics.blockWasteLiquid, 1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import java.util.List;
|
|||
|
||||
import universalelectricity.prefab.BlockMachine;
|
||||
import universalelectricity.prefab.tile.TileEntityAdvanced;
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.client.render.BlockRenderHelper;
|
||||
import liquidmechanics.common.LiquidMechanics;
|
||||
import liquidmechanics.common.MetaGroup;
|
||||
import liquidmechanics.common.TabLiquidMechanics;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
import liquidmechanics.common.tileentity.TileEntityPump;
|
||||
import liquidmechanics.common.tileentity.TileEntityTank;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
|
|
|
@ -2,10 +2,10 @@ package liquidmechanics.common.block;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.client.render.BlockRenderHelper;
|
||||
import liquidmechanics.common.LiquidMechanics;
|
||||
import liquidmechanics.common.TabLiquidMechanics;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
import liquidmechanics.common.tileentity.TileEntityPump;
|
||||
import liquidmechanics.common.tileentity.TileEntityTank;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package liquidmechanics.common.handlers;
|
||||
|
||||
import liquidmechanics.api.helpers.PipeColor;
|
||||
import liquidmechanics.common.tileentity.TileEntityPipe;
|
||||
/**
|
||||
* used to keep track of a pipe, its meta, and if Universal
|
||||
*/
|
||||
public class PipeInstance
|
||||
{
|
||||
public PipeColor color;
|
||||
public TileEntityPipe pipe;
|
||||
//colors
|
||||
public PipeInstance(PipeColor cc, TileEntityPipe pipe)
|
||||
{
|
||||
this.color = cc;
|
||||
this.pipe = pipe;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package liquidmechanics.common.handlers;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.api.helpers.PipeColor;
|
||||
import liquidmechanics.common.tileentity.TileEntityPipe;
|
||||
import liquidmechanics.common.tileentity.TileEntityTank;
|
||||
|
|
|
@ -3,11 +3,11 @@ package liquidmechanics.common.tileentity;
|
|||
import liquidmechanics.api.IColor;
|
||||
import liquidmechanics.api.IReadOut;
|
||||
import liquidmechanics.api.IPressure;
|
||||
import liquidmechanics.api.helpers.LiquidData;
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.api.helpers.PipeColor;
|
||||
import liquidmechanics.api.helpers.connectionHelper;
|
||||
import liquidmechanics.common.LiquidMechanics;
|
||||
import liquidmechanics.common.handlers.LiquidData;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
import liquidmechanics.common.handlers.UpdateConverter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
|
|
@ -4,10 +4,10 @@ import java.util.EnumSet;
|
|||
|
||||
import liquidmechanics.api.IReadOut;
|
||||
import liquidmechanics.api.IPressure;
|
||||
import liquidmechanics.api.helpers.LiquidData;
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.common.LiquidMechanics;
|
||||
import liquidmechanics.common.MetaGroup;
|
||||
import liquidmechanics.common.handlers.LiquidData;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
|
|
@ -7,12 +7,11 @@ import java.util.List;
|
|||
|
||||
import liquidmechanics.api.IPressure;
|
||||
import liquidmechanics.api.IReadOut;
|
||||
import liquidmechanics.api.helpers.LiquidData;
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.api.helpers.PipeColor;
|
||||
import liquidmechanics.api.helpers.connectionHelper;
|
||||
import liquidmechanics.common.block.BlockReleaseValve;
|
||||
import liquidmechanics.common.handlers.LiquidData;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
import liquidmechanics.common.handlers.PipeInstance;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -31,7 +30,7 @@ public class TileEntityReleaseValve extends TileEntity implements IPressure, IRe
|
|||
public boolean[] allowed = new boolean[PipeColor.values().length];
|
||||
public TileEntity[] connected = new TileEntity[6];
|
||||
|
||||
private List<PipeInstance> output = new ArrayList<PipeInstance>();
|
||||
private List<TileEntityPipe> output = new ArrayList<TileEntityPipe>();
|
||||
private List<ILiquidTank> input = new ArrayList<ILiquidTank>();
|
||||
|
||||
private int ticks = 0;
|
||||
|
@ -85,9 +84,9 @@ public class TileEntityReleaseValve extends TileEntity implements IPressure, IRe
|
|||
LiquidData data = LiquidHandler.get(stack);
|
||||
if (data != LiquidHandler.unkown)
|
||||
{
|
||||
for (PipeInstance pipe : output)
|
||||
for (TileEntityPipe pipe : output)
|
||||
{
|
||||
if (pipe.color == data.getColor() && (pipe.pipe.stored.getLiquid() == null || pipe.pipe.stored.getLiquid().amount < pipe.pipe.stored.getCapacity())) { return pipe.pipe; }
|
||||
if (pipe.getColor() == data.getColor() && (pipe.stored.getLiquid() == null || pipe.stored.getLiquid().amount < pipe.stored.getCapacity())) { return pipe; }
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -152,7 +151,7 @@ public class TileEntityReleaseValve extends TileEntity implements IPressure, IRe
|
|||
}
|
||||
else
|
||||
{
|
||||
this.output.add(new PipeInstance(pipe.getColor(), pipe));
|
||||
this.output.add(pipe);
|
||||
}
|
||||
}
|
||||
else if (ent instanceof ITankContainer)
|
||||
|
|
|
@ -5,11 +5,11 @@ import javax.swing.colorchooser.ColorSelectionModel;
|
|||
import liquidmechanics.api.IColor;
|
||||
import liquidmechanics.api.IReadOut;
|
||||
import liquidmechanics.api.IPressure;
|
||||
import liquidmechanics.api.helpers.LiquidData;
|
||||
import liquidmechanics.api.helpers.LiquidHandler;
|
||||
import liquidmechanics.api.helpers.PipeColor;
|
||||
import liquidmechanics.api.helpers.connectionHelper;
|
||||
import liquidmechanics.common.LiquidMechanics;
|
||||
import liquidmechanics.common.handlers.LiquidData;
|
||||
import liquidmechanics.common.handlers.LiquidHandler;
|
||||
import liquidmechanics.common.handlers.UpdateConverter;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -37,7 +37,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
|
|||
|
||||
public static final int LMax = 4;
|
||||
private int count, count2 = 0;
|
||||
|
||||
|
||||
public int pVolume = 0;
|
||||
|
||||
public LiquidTank tank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME * LMax);
|
||||
|
@ -55,16 +55,17 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
|
|||
{
|
||||
this.tradeDown();
|
||||
this.tradeArround();
|
||||
this.fillPipe();
|
||||
int volume = liquid.amount;
|
||||
|
||||
if (volume != pVolume)
|
||||
{
|
||||
LiquidStack stack = new LiquidStack(0,0,0);
|
||||
if(this.tank.getLiquid() != null)
|
||||
LiquidStack stack = new LiquidStack(0, 0, 0);
|
||||
if (this.tank.getLiquid() != null)
|
||||
{
|
||||
stack = this.tank.getLiquid();
|
||||
}
|
||||
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, new Object[] {stack.itemID,stack.amount,stack.itemMeta});
|
||||
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, new Object[] { stack.itemID, stack.amount, stack.itemMeta });
|
||||
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 20);
|
||||
}
|
||||
pVolume = volume;
|
||||
|
@ -77,7 +78,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
|
|||
public String getMeterReading(EntityPlayer user, ForgeDirection side)
|
||||
{
|
||||
if (tank.getLiquid() == null) { return "Empty"; }
|
||||
return (tank.getLiquid().amount/ LiquidContainerRegistry.BUCKET_VOLUME) + "/" + (tank.getCapacity() / LiquidContainerRegistry.BUCKET_VOLUME)
|
||||
return (tank.getLiquid().amount / LiquidContainerRegistry.BUCKET_VOLUME) + "/" + (tank.getCapacity() / LiquidContainerRegistry.BUCKET_VOLUME)
|
||||
+ " " + LiquidHandler.get(tank.getLiquid()).getName();
|
||||
}
|
||||
|
||||
|
@ -107,7 +108,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
|
|||
{
|
||||
try
|
||||
{
|
||||
this.tank.setLiquid(new LiquidStack(data.readInt(),data.readInt(),data.readInt()));
|
||||
this.tank.setLiquid(new LiquidStack(data.readInt(), data.readInt(), data.readInt()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -120,7 +121,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
|
|||
@Override
|
||||
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
|
||||
{
|
||||
if (resource == null || (!LiquidHandler.isEqual(resource, color.getLiquidData().getStack())&& this.color != PipeColor.NONE)) { return 0; }
|
||||
if (resource == null || (!LiquidHandler.isEqual(resource, color.getLiquidData().getStack()) && this.color != PipeColor.NONE)) { return 0; }
|
||||
return this.fill(0, resource, doFill);
|
||||
}
|
||||
|
||||
|
@ -281,6 +282,37 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
|
|||
}
|
||||
}
|
||||
|
||||
/** Causes this to fill a pipe either above or bellow based on liquid data */
|
||||
public void fillPipe()
|
||||
{
|
||||
if (this.tank.getLiquid() == null || this.tank.getLiquid().amount <= 0) { return; }
|
||||
LiquidData data = LiquidHandler.get(this.tank.getLiquid());
|
||||
if (data != null)
|
||||
{
|
||||
|
||||
int change = -1;
|
||||
if (data.getCanFloat())
|
||||
{
|
||||
change = 1;
|
||||
}
|
||||
TileEntity ent = worldObj.getBlockTileEntity(xCoord, yCoord + change, zCoord);
|
||||
if (ent instanceof TileEntityPipe)
|
||||
{
|
||||
PipeColor c = ((TileEntityPipe) ent).getColor();
|
||||
if (c == PipeColor.NONE || c == this.color)
|
||||
{
|
||||
int vol = LiquidContainerRegistry.BUCKET_VOLUME;
|
||||
if (this.tank.getLiquid().amount < vol)
|
||||
{
|
||||
vol = this.tank.getLiquid().amount;
|
||||
}
|
||||
int f = ((TileEntityPipe) ent).fill(0, LiquidHandler.getStack(this.tank.getLiquid(), vol), true);
|
||||
this.tank.drain(f, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(Object obj)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue