Got rid of Enum system

What i have is not much diffrent but its a start to allowing more liquid
types without having to add them myself. The current method has 3
defualt liquids that are preset. The new system also uses String names
to ID liquid instead of Enums. A new class Called LiquidData will keep
track of the data need to ID, and use the Liquids.

In the process i also fixed a few crafting recipes that were
removed/messed up in a patch a while back.

Plan for new system
*Have default liquid type that come with textures/renders
*Have several univeral pipes that can accept all Liquid types
*Have a way of placeing a universal pipe and then converting to a
regulated pipe, pipe that only take one liquid type
*Have a tool for doing the above
*Change the release Valve to be univeral with a GUI to restrict flow and
Liquid type extracted
This commit is contained in:
Rseifert 2013-01-03 12:18:47 -05:00
parent 6401261e19
commit a3c43609ea
18 changed files with 1223 additions and 1129 deletions

View file

@ -1,6 +1,6 @@
package liquidmechanics.api;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidData;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ITankContainer;
@ -11,7 +11,7 @@ public interface ITankOutputer extends ITankContainer
* @param dir - direction pressure is being request to output
* @return pressure if can output for the type or direction
*/
public int presureOutput(DefautlLiquids type, ForgeDirection dir);
public int presureOutput(LiquidData type, ForgeDirection dir);
/**
* Quick way to check if the TE will output pressure
@ -20,5 +20,5 @@ public interface ITankOutputer extends ITankContainer
* @param dir - direction
* @return
*/
public boolean canPressureToo(DefautlLiquids type, ForgeDirection dir);
public boolean canPressureToo(LiquidData type, ForgeDirection dir);
}

View file

@ -1,6 +1,7 @@
package liquidmechanics.api.helpers;
import liquidmechanics.common.handlers.DefautlLiquids;
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;
@ -49,9 +50,9 @@ public class TankHelper
return 0;
LiquidStack liquid = resource.copy();
TileEntity[] connected = TankHelper.getSourounding(world, center.intX(), center.intY(), center.intZ());
DefautlLiquids type = DefautlLiquids.getLiquid(liquid);
LiquidData type = LiquidHandler.get(liquid);
ForgeDirection firstTrade = ForgeDirection.UP;
if (!type.doesFlaot)
if (!LiquidData.getCanFloat(type))
firstTrade = ForgeDirection.DOWN;
for (int i = 0; i < 6; i++)
{
@ -64,7 +65,7 @@ public class TankHelper
boolean validTank = false;
for (int t = 0; t < tanks.length; t++)
{
if (tanks[t].getLiquid() != null && DefautlLiquids.isStackEqual(tanks[t].getLiquid(), liquid))
if (tanks[t].getLiquid() != null && LiquidHandler.isEqual(tanks[t].getLiquid(), liquid))
{
validTank = true;
break;

View file

@ -3,84 +3,82 @@ package liquidmechanics.client.render;
import liquidmechanics.client.model.ModelLargePipe;
import liquidmechanics.client.model.ModelPipe;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidData;
import liquidmechanics.common.handlers.LiquidHandler;
import liquidmechanics.common.tileentity.TileEntityPipe;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
public class RenderPipe extends TileEntitySpecialRenderer
{
private DefautlLiquids type = DefautlLiquids.DEFUALT;
private ModelPipe fourPipe;
private ModelLargePipe SixPipe;
private TileEntity[] ents = new TileEntity[6];
private LiquidData type = LiquidHandler.water;
private ModelPipe fourPipe;
private ModelLargePipe SixPipe;
private TileEntity[] ents = new TileEntity[6];
public RenderPipe()
{
fourPipe = new ModelPipe();
SixPipe = new ModelLargePipe();
}
public RenderPipe()
{
fourPipe = new ModelPipe();
SixPipe = new ModelLargePipe();
}
public void renderAModelAt(TileEntity te, double d, double d1, double d2, float f)
{
// Texture file
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
if (te instanceof TileEntityPipe)
{
type = ((TileEntityPipe) te).getType();
ents = ((TileEntityPipe) te).connectedBlocks;
}
this.render(type, ents);
GL11.glPopMatrix();
public void renderAModelAt(TileEntity te, double d, double d1, double d2, float f)
{
// Texture file
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
if (te instanceof TileEntityPipe)
{
type = ((TileEntityPipe) te).getType();
ents = ((TileEntityPipe) te).connectedBlocks;
}
this.render(type, ents);
GL11.glPopMatrix();
}
}
public void render(DefautlLiquids type, TileEntity[] ents)
{
public void render(LiquidData type2, TileEntity[] ents)
{
switch (type.ordinal())
{
case 0:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixSteamPipe.png");
break;
case 1:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixWaterPipe.png");
break;
case 2:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixLavaPipe.png");
break;
case 3:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixOilPipe.png");
break;
default:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/DefaultPipe.png");
break;
}
if (ents[0] != null)
SixPipe.renderBottom();
if (ents[1] != null)
SixPipe.renderTop();
if (ents[3] != null)
SixPipe.renderFront();
if (ents[2] != null)
SixPipe.renderBack();
if (ents[5] != null)
SixPipe.renderRight();
if (ents[4] != null)
SixPipe.renderLeft();
SixPipe.renderMiddle();
if (type2 == LiquidHandler.water)
{
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixWaterPipe.png");
}
else if (type2 == LiquidHandler.lava)
{
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixLavaPipe.png");
}
else if (type2 == LiquidHandler.steam)
{
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixSteamPipe.png");
}
else
{
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixOilPipe.png");
}
if (ents[0] != null)
SixPipe.renderBottom();
if (ents[1] != null)
SixPipe.renderTop();
if (ents[3] != null)
SixPipe.renderFront();
if (ents[2] != null)
SixPipe.renderBack();
if (ents[5] != null)
SixPipe.renderRight();
if (ents[4] != null)
SixPipe.renderLeft();
SixPipe.renderMiddle();
}
}
@Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{
this.renderAModelAt((TileEntityPipe) tileEntity, var2, var4, var6, var8);
}
@Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{
this.renderAModelAt((TileEntityPipe) tileEntity, var2, var4, var6, var8);
}
}

View file

@ -2,7 +2,8 @@ package liquidmechanics.client.render;
import liquidmechanics.client.model.ModelPump;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids;
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;
@ -22,9 +23,9 @@ public class RenderPump extends TileEntitySpecialRenderer
public void renderAModelAt(TileEntityPump tileEntity, double d, double d1, double d2, float f)
{
DefautlLiquids type = tileEntity.type;
LiquidData type = tileEntity.type;
int meta = tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
switch (type.ordinal())
switch (LiquidHandler.getMeta(type))
{
default:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pumps/Pump.png");

View file

@ -4,7 +4,8 @@ import liquidmechanics.api.helpers.TankHelper;
import liquidmechanics.client.model.ModelLiquidTank;
import liquidmechanics.client.model.ModelLiquidTankCorner;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids;
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;
@ -15,7 +16,7 @@ import org.lwjgl.opengl.GL11;
public class RenderTank extends TileEntitySpecialRenderer
{
private DefautlLiquids type = DefautlLiquids.DEFUALT;
private LiquidData type = LiquidHandler.air;
private ModelLiquidTank model;
private ModelLiquidTankCorner modelC;
private int pos = 0;
@ -57,7 +58,7 @@ public class RenderTank extends TileEntitySpecialRenderer
}
else
{
switch (type.ordinal())
switch (LiquidHandler.getMeta(type))
{
// case 0:
// bindTextureByName(BasicPipesMain.textureFile+"/pipes/SixSteamPipe.png");break;

View file

@ -2,27 +2,27 @@ package liquidmechanics.common;
import java.io.File;
import liquidmechanics.common.block.BlockReleaseValve;
import liquidmechanics.common.block.BlockGenerator;
import liquidmechanics.common.block.BlockPipe;
import liquidmechanics.common.block.BlockMachine;
import liquidmechanics.common.block.BlockPipe;
import liquidmechanics.common.block.BlockReleaseValve;
import liquidmechanics.common.block.BlockRod;
import liquidmechanics.common.block.BlockSteam;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidData;
import liquidmechanics.common.handlers.LiquidHandler;
import liquidmechanics.common.item.ItemEValve;
import liquidmechanics.common.item.ItemGuage;
import liquidmechanics.common.item.ItemMachine;
import liquidmechanics.common.item.ItemParts;
import liquidmechanics.common.item.ItemParts.Parts;
import liquidmechanics.common.item.ItemPipe;
import liquidmechanics.common.item.ItemTank;
import liquidmechanics.common.item.ItemParts.Parts;
import liquidmechanics.common.tileentity.TileEntityReleaseValve;
import liquidmechanics.common.tileentity.TileEntityGenerator;
import liquidmechanics.common.tileentity.TileEntityPipe;
import liquidmechanics.common.tileentity.TileEntityPump;
import liquidmechanics.common.tileentity.TileEntityReleaseValve;
import liquidmechanics.common.tileentity.TileEntityRod;
import liquidmechanics.common.tileentity.TileEntityTank;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -31,6 +31,7 @@ import net.minecraftforge.common.Configuration;
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 universalelectricity.prefab.network.PacketManager;
import cpw.mods.fml.common.DummyModContainer;
@ -58,188 +59,233 @@ import cpw.mods.fml.common.registry.LanguageRegistry;
@NetworkMod(channels = { LiquidMechanics.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
public class LiquidMechanics extends DummyModContainer
{
// TODO Change in Version Release
public static final String VERSION = "0.2.3";
// TODO Change in Version Release
public static final String VERSION = "0.2.3";
// Constants
public static final String NAME = "Liquid Mechanics";
public static final String CHANNEL = "liquidMech";
// Constants
public static final String NAME = "Liquid Mechanics";
public static final String CHANNEL = "liquidMech";
public static final String PATH = "/liquidmechanics/";
public static final String RESOURCE_PATH = PATH + "resource/";
public static final String BLOCK_TEXTURE_FILE = RESOURCE_PATH + "blocks.png";
public static final String ITEM_TEXTURE_FILE = RESOURCE_PATH + "items.png";
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir() + "/UniversalElectricity/", NAME + ".cfg"));
public static final String PATH = "/liquidmechanics/";
public static final String RESOURCE_PATH = PATH + "resource/";
public static final String BLOCK_TEXTURE_FILE = RESOURCE_PATH + "blocks.png";
public static final String ITEM_TEXTURE_FILE = RESOURCE_PATH + "items.png";
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir() + "/UniversalElectricity/", NAME + ".cfg"));
public final static int BLOCK_ID_PREFIX = 3100;
public final static int LIQUID_ID_PREFIX = 200;
public final static int ITEM_ID_PREFIX = 13200;
public final static int BLOCK_ID_PREFIX = 3100;
public final static int LIQUID_ID_PREFIX = 200;
public final static int ITEM_ID_PREFIX = 13200;
public static Block blockPipe;
public static Block blockMachine;
public static Block blockRod;
public static Block blockGenerator;
public static Block blockReleaseValve;
public static Block blockSteamBlock;
public static Block blockPipe;
public static Block blockMachine;
public static Block blockRod;
public static Block blockGenerator;
public static Block blockReleaseValve;
public static Block blockSteamBlock;
public static LiquidStack liquidSteam;
public static LiquidStack liquidSteam;
public static Item itemParts;
public static Item itemPipes;
public static Item itemGauge;
public static Item itemOilBucket;
public static Item itemTank;
public static Item itemParts;
public static Item itemPipes;
public static Item itemGauge;
public static Item itemOilBucket;
public static Item itemTank;
@SidedProxy(clientSide = "liquidmechanics.client.ClientProxy", serverSide = "liquidmechanics.common.CommonProxy")
public static CommonProxy proxy;
@SidedProxy(clientSide = "liquidmechanics.client.ClientProxy", serverSide = "liquidmechanics.common.CommonProxy")
public static CommonProxy proxy;
@Instance(NAME)
public static LiquidMechanics instance;
@Instance(NAME)
public static LiquidMechanics instance;
@PreInit
public void preInit(FMLPreInitializationEvent event)
{
instance = this;
@PreInit
public void preInit(FMLPreInitializationEvent event)
{
instance = this;
CONFIGURATION.load();
CONFIGURATION.load();
// Blocks
blockPipe = new BlockPipe(this.CONFIGURATION.getBlock("Pipes", BLOCK_ID_PREFIX).getInt());
blockMachine = new BlockMachine(this.CONFIGURATION.getBlock("Machines", BLOCK_ID_PREFIX + 1).getInt());
blockRod = new BlockRod(this.CONFIGURATION.getBlock("Mechanical Rod", BLOCK_ID_PREFIX + 3).getInt());
blockGenerator = new BlockGenerator((this.CONFIGURATION.getBlock("Generator", BLOCK_ID_PREFIX + 4).getInt()));
blockReleaseValve = new BlockReleaseValve((this.CONFIGURATION.getBlock("Release Valve", BLOCK_ID_PREFIX + 5).getInt()));
// Blocks
blockPipe = new BlockPipe(this.CONFIGURATION.getBlock("Pipes", BLOCK_ID_PREFIX).getInt());
blockMachine = new BlockMachine(this.CONFIGURATION.getBlock("Machines", BLOCK_ID_PREFIX + 1).getInt());
blockRod = new BlockRod(this.CONFIGURATION.getBlock("Mechanical Rod", BLOCK_ID_PREFIX + 3).getInt());
blockGenerator = new BlockGenerator((this.CONFIGURATION.getBlock("Generator", BLOCK_ID_PREFIX + 4).getInt()));
blockReleaseValve = new BlockReleaseValve((this.CONFIGURATION.getBlock("Release Valve", BLOCK_ID_PREFIX + 5).getInt()));
// Liquid Blocks
blockSteamBlock = new BlockSteam(this.CONFIGURATION.getBlock("SteamBlock", LIQUID_ID_PREFIX).getInt());
// Liquid Blocks
blockSteamBlock = new BlockSteam(this.CONFIGURATION.getBlock("SteamBlock", LIQUID_ID_PREFIX).getInt());
// Items
itemParts = new ItemParts(this.CONFIGURATION.getItem("Parts", ITEM_ID_PREFIX).getInt());
itemPipes = new ItemPipe(this.CONFIGURATION.getItem("PipeItem", ITEM_ID_PREFIX + 1).getInt());
// Items
itemParts = new ItemParts(this.CONFIGURATION.getItem("Parts", ITEM_ID_PREFIX).getInt());
itemPipes = new ItemPipe(this.CONFIGURATION.getItem("PipeItem", ITEM_ID_PREFIX + 1).getInt());
// Valve item
itemGauge = new ItemGuage(this.CONFIGURATION.getItem("PipeGuage", ITEM_ID_PREFIX + 3).getInt());
itemTank = new ItemTank(this.CONFIGURATION.getItem("TankItem", ITEM_ID_PREFIX + 5).getInt());
// Valve item
itemGauge = new ItemGuage(this.CONFIGURATION.getItem("PipeGuage", ITEM_ID_PREFIX + 3).getInt());
itemTank = new ItemTank(this.CONFIGURATION.getItem("TankItem", ITEM_ID_PREFIX + 5).getInt());
// Liquid Registry
liquidSteam = LiquidDictionary.getOrCreateLiquid("Steam", new LiquidStack(blockSteamBlock, LiquidContainerRegistry.BUCKET_VOLUME));
CONFIGURATION.save();
// Liquid Registry
liquidSteam = LiquidDictionary.getOrCreateLiquid("Steam", new LiquidStack(blockSteamBlock, LiquidContainerRegistry.BUCKET_VOLUME));
CONFIGURATION.save();
proxy.preInit();
proxy.preInit();
// block registry
GameRegistry.registerBlock(blockPipe, "Pipe");
GameRegistry.registerBlock(blockReleaseValve, ItemEValve.class, "Electric Valve");
GameRegistry.registerBlock(blockRod, "Mechanical Rod");
GameRegistry.registerBlock(blockGenerator, "Generator");
GameRegistry.registerBlock(blockMachine, ItemMachine.class, "Machines");
GameRegistry.registerBlock(blockSteamBlock, "Steam");
}
// block registry
GameRegistry.registerBlock(blockPipe, "Pipe");
GameRegistry.registerBlock(blockReleaseValve, ItemEValve.class, "Electric Valve");
GameRegistry.registerBlock(blockRod, "Mechanical Rod");
GameRegistry.registerBlock(blockGenerator, "Generator");
GameRegistry.registerBlock(blockMachine, ItemMachine.class, "Machines");
GameRegistry.registerBlock(blockSteamBlock, "Steam");
}
@Init
public void Init(FMLInitializationEvent event)
{
proxy.Init();
// TileEntities
GameRegistry.registerTileEntity(TileEntityPipe.class, "Pipe");
GameRegistry.registerTileEntity(TileEntityPump.class, "Pump");
GameRegistry.registerTileEntity(TileEntityRod.class, "Rod");
GameRegistry.registerTileEntity(TileEntityReleaseValve.class, "Valve");
GameRegistry.registerTileEntity(TileEntityTank.class, "Tank");
GameRegistry.registerTileEntity(TileEntityGenerator.class, "Generator");
@Init
public void Init(FMLInitializationEvent event)
{
proxy.Init();
// TileEntities
GameRegistry.registerTileEntity(TileEntityPipe.class, "Pipe");
GameRegistry.registerTileEntity(TileEntityPump.class, "Pump");
GameRegistry.registerTileEntity(TileEntityRod.class, "Rod");
GameRegistry.registerTileEntity(TileEntityReleaseValve.class, "Valve");
GameRegistry.registerTileEntity(TileEntityTank.class, "Tank");
GameRegistry.registerTileEntity(TileEntityGenerator.class, "Generator");
// Liquid Item/Block common name writer
for (int i = 0; i < DefautlLiquids.values().length; i++)
{
// eValves
LanguageRegistry.addName((new ItemStack(blockReleaseValve, 1, i)), DefautlLiquids.getLiquid(i).displayerName + " Release Valve");
// pipes
LanguageRegistry.addName((new ItemStack(itemPipes, 1, i)), DefautlLiquids.getLiquid(i).displayerName + " Pipe");
// Liquid Item/Block common name writer
for (int i = 0; i < LiquidHandler.allowedLiquids.size() - 1; i++)
{
// eValves
LanguageRegistry.addName((new ItemStack(blockReleaseValve, 1, i)),LiquidData.getName(LiquidHandler.getFromMeta(i)) + " Release Valve");
// pipes
LanguageRegistry.addName((new ItemStack(itemPipes, 1, i)), LiquidData.getName(LiquidHandler.getFromMeta(i)) + " Pipe");
// Storage Tanks
LanguageRegistry.addName((new ItemStack(itemTank, 1, i)), DefautlLiquids.getLiquid(i).displayerName + " Tank");
}
// Storage Tanks
LanguageRegistry.addName((new ItemStack(itemTank, 1, i)), LiquidData.getName(LiquidHandler.getFromMeta(i)) + " Tank");
}
for (int i = 0; i < ItemParts.Parts.values().length; i++)
{
// parts
LanguageRegistry.addName((new ItemStack(itemParts, 1, i)), ItemParts.Parts.values()[i].name);
}
for (int i = 0; i < ItemParts.Parts.values().length; i++)
{
// parts
LanguageRegistry.addName((new ItemStack(itemParts, 1, i)), ItemParts.Parts.values()[i].name);
}
// machines
LanguageRegistry.addName((new ItemStack(blockMachine, 1, 0)), "Pump");
LanguageRegistry.addName((new ItemStack(blockMachine, 1, 4)), "Water Condensor");
// machines
LanguageRegistry.addName((new ItemStack(blockMachine, 1, 0)), "Pump");
LanguageRegistry.addName((new ItemStack(blockMachine, 1, 4)), "Water Condensor");
LanguageRegistry.addName((new ItemStack(blockGenerator, 1)), "Generator");
// mechanical rod
LanguageRegistry.addName((new ItemStack(blockRod, 1)), "Geared Rod");
// Tools
LanguageRegistry.addName((new ItemStack(itemGauge, 1, 0)), "Pipe Gauge");
}
LanguageRegistry.addName((new ItemStack(blockGenerator, 1)), "Generator");
// mechanical rod
LanguageRegistry.addName((new ItemStack(blockRod, 1)), "Geared Rod");
// Tools
LanguageRegistry.addName((new ItemStack(itemGauge, 1, 0)), "Pipe Gauge");
}
@PostInit
public void PostInit(FMLPostInitializationEvent event)
{
proxy.postInit();
TabLiquidMechanics.setItemStack(new ItemStack(itemPipes, 1, DefautlLiquids.WATER.ordinal()));
// generator
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.blockGenerator, 1), new Object[] { "@T@", "OVO", "@T@", 'T', new ItemStack(LiquidMechanics.blockRod, 1), '@', "plateSteel", 'O', "basicCircuit", 'V', "motor" }));
// pipe gauge
GameRegistry.addRecipe(new ItemStack(this.itemGauge, 1, 0), new Object[] { "TVT", " T ", 'V', new ItemStack(itemParts, 1, 7), 'T', new ItemStack(itemParts, 1, Parts.Iron.ordinal()) });
// iron tube
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Bronze.ordinal()), new Object[] { "@@@", '@', Item.ingotIron });
// obby tube
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Obby.ordinal()), new Object[] { "@@@", '@', Block.obsidian });
// nether tube
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Nether.ordinal()), new Object[] { "N@N", 'N', Block.netherrack, '@', new ItemStack(itemParts, 2, Parts.Obby.ordinal()) });
// seal
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Seal.ordinal()), new Object[] { "@@", "@@", '@', Item.leather });
// slime steal
GameRegistry.addShapelessRecipe(new ItemStack(itemParts, 1, Parts.SlimeSeal.ordinal()), new Object[] { new ItemStack(itemParts, 1, Parts.Seal.ordinal()), new ItemStack(Item.slimeBall, 1) });
// part valve
GameRegistry.addRecipe(new ItemStack(itemParts, 1, Parts.Valve.ordinal()), new Object[] { "T@T", 'T', new ItemStack(itemParts, 1, Parts.Iron.ordinal()), '@', Block.lever });
@PostInit
public void PostInit(FMLPostInitializationEvent event)
{
proxy.postInit();
TabLiquidMechanics.setItemStack(new ItemStack(itemPipes, 1, 1));
// generator
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.blockGenerator, 1), new Object[] {
"@T@", "OVO", "@T@",
'T', new ItemStack(LiquidMechanics.blockRod, 1),
'@', "plateSteel",
'O', "basicCircuit",
'V', "motor" }));
// pipe gauge
GameRegistry.addRecipe(new ItemStack(this.itemGauge, 1, 0), new Object[] {
"TVT", " T ",
'V', new ItemStack(itemParts, 1, 7),
'T', new ItemStack(itemParts, 1, Parts.Iron.ordinal()) });
// iron tube
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Iron.ordinal()), new Object[] {
"@@@",
'@', Item.ingotIron });
// bronze tube
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(itemParts, 2, Parts.Bronze.ordinal()), new Object[] {
"@@@",
'@', "ingotBronze" }));
// obby tube
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Obby.ordinal()), new Object[] {
"@@@",
'@', Block.obsidian });
// nether tube
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Nether.ordinal()), new Object[] {
"N@N",
'N', Block.netherrack,
'@', new ItemStack(itemParts, 2, Parts.Obby.ordinal()) });
// seal
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Seal.ordinal()), new Object[] {
"@@", "@@",
'@', Item.leather });
// slime steal
GameRegistry.addShapelessRecipe(new ItemStack(itemParts, 1, Parts.SlimeSeal.ordinal()), new Object[] {
new ItemStack(itemParts, 1, Parts.Seal.ordinal()),
new ItemStack(Item.slimeBall, 1) });
// part valve
GameRegistry.addRecipe(new ItemStack(itemParts, 1, Parts.Valve.ordinal()), new Object[] {
"T@T",
'T', new ItemStack(itemParts, 1, Parts.Iron.ordinal()),
'@', Block.lever });
// unfinished tank
GameRegistry.addRecipe(new ItemStack(itemParts, 1, Parts.Tank.ordinal()), new Object[] { " @ ", "@ @", " @ ", '@', Item.ingotIron });
// mechanical rod
GameRegistry.addRecipe(new ItemStack(blockRod, 1), new Object[] { "I@I", 'I', Item.ingotIron, '@', new ItemStack(itemParts, 1, Parts.Iron.ordinal()) });
// unfinished tank
GameRegistry.addRecipe(new ItemStack(itemParts, 1, Parts.Tank.ordinal()), new Object[] {
" @ ", "@ @", " @ ",
'@', Item.ingotIron });
// mechanical rod
GameRegistry.addRecipe(new ItemStack(blockRod, 1), new Object[] {
"I@I",
'I', Item.ingotIron,
'@', new ItemStack(itemParts, 1, Parts.Iron.ordinal()) });
// steam pipe
GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, DefautlLiquids.STEAM.ordinal()), new Object[] { new ItemStack(itemParts, 1, Parts.Iron.ordinal()), new ItemStack(itemParts, 1, Parts.Seal.ordinal()) });
// water pipe
GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, DefautlLiquids.WATER.ordinal()), new Object[] { new ItemStack(itemParts, 1, Parts.Iron.ordinal()), new ItemStack(itemParts, 1, Parts.Seal.ordinal()), new ItemStack(Item.dyePowder, 1, 4) });
// lava pipe
GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, DefautlLiquids.LAVA.ordinal()), new Object[] { new ItemStack(itemParts, 1, Parts.Obby.ordinal()), new ItemStack(Item.dyePowder, 1, 1) });
/*
* GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, Liquid.OIL.ordinal()), new
* Object[] { new ItemStack(parts, 1, basicParts.Iron.ordinal()), new ItemStack(parts, 1,
* basicParts.Seal.ordinal()), new ItemStack(Item.dyePowder, 1, 0) });
* GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, Liquid.FUEL.ordinal()), new
* Object[] { new ItemStack(parts, 1, basicParts.Iron.ordinal()), new ItemStack(parts, 1,
* basicParts.Seal.ordinal()), new ItemStack(Item.dyePowder, 1, 11) });
*/
// steam tank
GameRegistry.addShapelessRecipe(new ItemStack(itemTank, 1, DefautlLiquids.STEAM.ordinal()), new Object[] { new ItemStack(itemParts, 1, Parts.Tank.ordinal()), new ItemStack(itemParts, 1, Parts.Seal.ordinal()), new ItemStack(Item.dyePowder, 1, 15) });
// water tank
GameRegistry.addShapelessRecipe(new ItemStack(itemTank, 1, DefautlLiquids.WATER.ordinal()), new Object[] { new ItemStack(itemParts, 1, Parts.Tank.ordinal()), new ItemStack(itemParts, 1, Parts.Seal.ordinal()), new ItemStack(Item.dyePowder, 1, 4) });
// lava tank
GameRegistry.addShapelessRecipe(new ItemStack(itemTank, 1, DefautlLiquids.LAVA.ordinal()), new Object[] { new ItemStack(itemParts, 1, Parts.Tank.ordinal()), Block.obsidian, Block.obsidian, Block.obsidian, Block.obsidian });
/*
* GameRegistry.addShapelessRecipe(new ItemStack(itemTank, 1, Liquid.OIL.ordinal()), new
* Object[] { new ItemStack(parts, 1, basicParts.Tank.ordinal()), new ItemStack(parts, 1,
* basicParts.Seal.ordinal()), new ItemStack(Item.dyePowder, 1, 0) });
*
* GameRegistry.addShapelessRecipe(new ItemStack(itemTank, 1, Liquid.FUEL.ordinal()), new
* Object[] { new ItemStack(parts, 1, basicParts.Tank.ordinal()), new ItemStack(parts, 1,
* basicParts.Seal.ordinal()), new ItemStack(Item.dyePowder, 1, 11) });
*/
// pump
GameRegistry.addRecipe(new ItemStack(blockMachine, 1, 0), new Object[] { "@T@", "BPB", "@P@", '@', new ItemStack(Item.ingotIron, 2), 'B', new ItemStack(itemParts, 1, Parts.Valve.ordinal()), 'P', new ItemStack(Block.pistonBase), 'T', new ItemStack(itemParts, 1, Parts.Tank.ordinal()) });
// steam pipe
GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, 0), new Object[] {
new ItemStack(itemParts, 1, Parts.Iron.ordinal()),
new ItemStack(itemParts, 1, Parts.Seal.ordinal()) });
// water pipe
GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, 1), new Object[] {
new ItemStack(itemParts, 1, Parts.Iron.ordinal()),
new ItemStack(itemParts, 1, Parts.Seal.ordinal()),
new ItemStack(Item.dyePowder, 1, 4) });
// lava pipe
GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, 2), new Object[] {
new ItemStack(itemParts, 1, Parts.Obby.ordinal()),
new ItemStack(Item.dyePowder, 1, 1) });
// eVavles
for (int i = 0; i < DefautlLiquids.values().length - 1; i++)
{
GameRegistry.addRecipe(new ItemStack(blockMachine, 1, i), new Object[] { " P ", "PVP", " P ", 'P', new ItemStack(itemPipes, 1, i), 'V', new ItemStack(itemParts, 1, Parts.Valve.ordinal()), });
}
}
// steam tank
GameRegistry.addShapelessRecipe(new ItemStack(itemTank, 1, 0), new Object[] {
new ItemStack(itemParts, 1, Parts.Tank.ordinal()),
new ItemStack(itemParts, 1, Parts.Seal.ordinal()),
new ItemStack(Item.dyePowder, 1, 15) });
// water tank
GameRegistry.addShapelessRecipe(new ItemStack(itemTank, 1, 1), new Object[] {
new ItemStack(itemParts, 1, Parts.Tank.ordinal()),
new ItemStack(itemParts, 1, Parts.Seal.ordinal()),
new ItemStack(Item.dyePowder, 1, 4) });
// lava tank
GameRegistry.addShapelessRecipe(new ItemStack(itemTank, 1, 2), new Object[] {
new ItemStack(itemParts, 1, Parts.Tank.ordinal()), Block.obsidian, Block.obsidian, Block.obsidian, Block.obsidian });
// pump
GameRegistry.addRecipe(new ItemStack(blockMachine, 1, 0), new Object[] {
"@T@", "BPB", "@P@",
'@', new ItemStack(Item.ingotIron, 2),
'B', new ItemStack(itemParts, 1, Parts.Valve.ordinal()),
'P', new ItemStack(Block.pistonBase),
'T', new ItemStack(itemParts, 1, Parts.Tank.ordinal()) });
// eVavles
for (int i = 0; i < LiquidHandler.allowedLiquids.size() - 1; i++)
{
GameRegistry.addRecipe(new ItemStack(blockMachine, 1, i), new Object[] {
" P ", "PVP", " P ",
'P', new ItemStack(itemPipes, 1, i),
'V', new ItemStack(itemParts, 1, Parts.Valve.ordinal()), });
}
//reg ore directory for parts
OreDictionary.registerOre("bronzeTube", new ItemStack(itemParts, 1, Parts.Bronze.ordinal()));
//add Default Liquids to current list, done last to let other mods use there liquid data first if used
LiquidHandler.addDefaultLiquids();
}
}

View file

@ -3,7 +3,7 @@ package liquidmechanics.common.block;
import liquidmechanics.client.render.BlockRenderHelper;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.TabLiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidHandler;
import liquidmechanics.common.tileentity.TileEntityPump;
import liquidmechanics.common.tileentity.TileEntityTank;
import net.minecraft.block.BlockContainer;
@ -19,139 +19,139 @@ import net.minecraftforge.liquids.LiquidStack;
public class BlockMachine extends BlockContainer
{
public BlockMachine(int id)
{
super(id, Material.iron);
this.setBlockName("Machine");
this.setCreativeTab(TabLiquidMechanics.INSTANCE);
this.setRequiresSelfNotify();
this.blockIndexInTexture = 26;
this.setHardness(1f);
this.setResistance(5f);
}
public BlockMachine(int id)
{
super(id, Material.iron);
this.setBlockName("Machine");
this.setCreativeTab(TabLiquidMechanics.INSTANCE);
this.setRequiresSelfNotify();
this.blockIndexInTexture = 26;
this.setHardness(1f);
this.setResistance(5f);
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ)
{
ItemStack current = entityplayer.inventory.getCurrentItem();
if (current != null)
{
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ)
{
ItemStack current = entityplayer.inventory.getCurrentItem();
if (current != null)
{
LiquidStack liquid = LiquidContainerRegistry.getLiquidForFilledItem(current);
LiquidStack liquid = LiquidContainerRegistry.getLiquidForFilledItem(current);
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityTank)
{
TileEntityTank tank = (TileEntityTank) tileEntity;
if (tileEntity instanceof TileEntityTank)
{
TileEntityTank tank = (TileEntityTank) tileEntity;
// Handle filled containers
if (liquid != null)
{
int filled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
// Handle filled containers
if (liquid != null)
{
int filled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
if (filled != 0 && !entityplayer.capabilities.isCreativeMode)
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, DefautlLiquids.consumeItem(current));
}
if (filled != 0 && !entityplayer.capabilities.isCreativeMode)
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, LiquidHandler.consumeItem(current));
}
return true;
return true;
// Handle empty containers
}
else
{
// Handle empty containers
}
else
{
LiquidStack stack = tank.tank.getLiquid();
if (stack != null)
{
ItemStack liquidItem = LiquidContainerRegistry.fillLiquidContainer(stack, current);
LiquidStack stack = tank.tank.getLiquid();
if (stack != null)
{
ItemStack liquidItem = LiquidContainerRegistry.fillLiquidContainer(stack, current);
liquid = LiquidContainerRegistry.getLiquidForFilledItem(liquidItem);
liquid = LiquidContainerRegistry.getLiquidForFilledItem(liquidItem);
if (liquid != null)
{
if (!entityplayer.capabilities.isCreativeMode)
{
if (current.stackSize > 1)
{
if (!entityplayer.inventory.addItemStackToInventory(liquidItem))
return false;
else
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, DefautlLiquids.consumeItem(current));
}
}
else
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, DefautlLiquids.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, liquidItem);
}
}
tank.tank.drain(liquid.amount, true);
return true;
}
}
}
}
}
if (liquid != null)
{
if (!entityplayer.capabilities.isCreativeMode)
{
if (current.stackSize > 1)
{
if (!entityplayer.inventory.addItemStackToInventory(liquidItem)) return false;
else
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, LiquidHandler.consumeItem(current));
}
}
else
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, LiquidHandler.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, liquidItem);
}
}
tank.tank.drain(liquid.amount, true);
return true;
}
}
}
}
}
return false;
return false;
}
@Override
public int getRenderType()
{
return BlockRenderHelper.renderID;
}
}
@Override
public int damageDropped(int meta)
{
if (meta < 4) { return 0; }
return meta;
}
@Override
public int getRenderType()
{
return BlockRenderHelper.renderID;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta < 4)
new ItemStack(LiquidMechanics.blockMachine, 1, 0);
// if(meta == 4) ;
TileEntity ent = world.getBlockTileEntity(x, y, z);
if (ent instanceof TileEntityTank)
new ItemStack(LiquidMechanics.itemTank, 1, ((TileEntityTank) ent).type.ordinal());
return null;
}
@Override
public int damageDropped(int meta)
{
if (meta < 4) { return 0; }
return meta;
}
@Override
public TileEntity createNewTileEntity(World var1, int meta)
{
if (meta < 4) { return new TileEntityPump(); }
if (meta == 4)
{
// return new TileEntityCondenser();
}
if (meta == 5) { return new TileEntityTank(); }
return null;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta < 4)
new ItemStack(LiquidMechanics.blockMachine, 1, 0);
// if(meta == 4) ;
TileEntity ent = world.getBlockTileEntity(x, y, z);
if (ent instanceof TileEntityTank) return new ItemStack(LiquidMechanics.itemTank, 1, LiquidHandler.getMeta(((TileEntityTank) ent).type));
return null;
}
@Override
public TileEntity createNewTileEntity(World var1, int meta)
{
if (meta < 4) { return new TileEntityPump(); }
if (meta == 4)
{
// return new TileEntityCondenser();
}
if (meta == 5) { return new TileEntityTank(); }
return null;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return null;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return null;
}
}

View file

@ -3,6 +3,7 @@ package liquidmechanics.common.block;
import java.util.Random;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.LiquidHandler;
import liquidmechanics.common.tileentity.TileEntityPipe;
import net.minecraft.block.BlockContainer;
@ -93,7 +94,9 @@ public class BlockPipe extends BlockContainer
int meta = 0;
if (ent instanceof TileEntityPipe)
{
meta = ((TileEntityPipe) ent).type.ordinal();
TileEntityPipe pipe = (TileEntityPipe) ent;
meta = LiquidHandler.getMeta(pipe.type);
}
return new ItemStack(LiquidMechanics.itemPipes, 1, 0);
}
@ -107,7 +110,7 @@ public class BlockPipe extends BlockContainer
if (ent instanceof TileEntityPipe)
{
TileEntityPipe pipe = (TileEntityPipe) ent;
int meta = pipe.type.ordinal();
int meta = LiquidHandler.getMeta(pipe.type);
float var8 = furnaceRand.nextFloat() * 0.8F + 0.1F;
float var9 = furnaceRand.nextFloat() * 0.8F + 0.1F;
float var10 = furnaceRand.nextFloat() * 0.8F + 0.1F;
@ -119,5 +122,4 @@ public class BlockPipe extends BlockContainer
world.spawnEntityInWorld(var12);
}
}
}

View file

@ -1,142 +0,0 @@
package liquidmechanics.common.handlers;
import liquidmechanics.common.LiquidMechanics;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.liquids.ILiquid;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
/**
* Used to Quick refrence a Forge Liquid by name rather
* @author Rseifert
*
*/
@Deprecated
public enum DefautlLiquids
{
// -1 == null || unused
STEAM("Steam", LiquidDictionary.getOrCreateLiquid("Steam", new LiquidStack(LiquidMechanics.blockSteamBlock, 1)), true, 100),
WATER("Water", LiquidDictionary.getOrCreateLiquid("Water", new LiquidStack(Block.waterStill, 1)), false, 32),
LAVA("Lava", LiquidDictionary.getOrCreateLiquid("Lava", new LiquidStack(Block.lavaStill, 1)), false, 20),
DEFUALT("Empty", LiquidDictionary.getOrCreateLiquid("Air", new LiquidStack(0, 1)), false, 0);
public final boolean doesFlaot;
public final String displayerName;
public final int defaultPresure;
public final LiquidStack liquid;
private DefautlLiquids(String name, LiquidStack stack, boolean gas, int dPressure)
{
this.displayerName = name;
this.liquid = stack;
this.doesFlaot = gas;
this.defaultPresure = dPressure;
}
/**
* creates a new liquid stack using basic liquid type and the volume needed
*/
public static LiquidStack getStack(DefautlLiquids type, int vol)
{
return new LiquidStack(type.liquid.itemID, vol, type.liquid.itemMeta);
}
/**
* gets a liquid type from a liquidStack
*/
public static DefautlLiquids getLiquid(LiquidStack stack)
{
for (int i = 0; i < DefautlLiquids.values().length - 1; i++)
{
if (DefautlLiquids.isStackEqual(stack, DefautlLiquids.values()[i])) { return DefautlLiquids.values()[i]; }
}
return DefautlLiquids.DEFUALT;
}
/**
* Only use this if you are converting from the old system Or have a special
* need for it
*
* @param id
* of liquid
* @return Liquid Object
*/
public static DefautlLiquids getLiquid(int id)
{
if (id >= 0 && id < DefautlLiquids.values().length) { return DefautlLiquids.values()[id]; }
return DEFUALT;
}
/**
* get the liquid type by its block ID
*
* @param bBlock
* @return
*/
public static DefautlLiquids getLiquidTypeByBlock(int bBlock)
{
if (bBlock == Block.waterMoving.blockID)
return DefautlLiquids.DEFUALT;
if (bBlock == Block.lavaMoving.blockID)
return DefautlLiquids.DEFUALT;
for (int i = 0; i < DefautlLiquids.values().length - 1; i++)
{
DefautlLiquids selected = DefautlLiquids.getLiquid(i);
if (bBlock == selected.liquid.itemID) { return selected; }
}
return DefautlLiquids.DEFUALT;
}
public static LiquidStack getLiquidFromBlock(int blockId)
{
if (blockId == Block.waterStill.blockID) { return new LiquidStack(Block.waterStill.blockID, LiquidContainerRegistry.BUCKET_VOLUME, 0); }
if (blockId == Block.lavaStill.blockID) { return new LiquidStack(Block.lavaStill.blockID, LiquidContainerRegistry.BUCKET_VOLUME, 0); }
if (Block.blocksList[blockId] instanceof ILiquid)
{
ILiquid liquid = (ILiquid) Block.blocksList[blockId];
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;
}
/**
* Used to compare a liquidStack to a liquid type
*
* @param stack
* @param type
* @return
*/
public static boolean isStackEqual(LiquidStack stack, DefautlLiquids type)
{
if (stack == null)
return false;
if (type.liquid.itemID == stack.itemID && type.liquid.itemMeta == stack.itemMeta) { return true; }
return false;
}
public static boolean isStackEqual(LiquidStack stack, LiquidStack type)
{
if (stack == null || type == null)
return false;
if (type.itemID == stack.itemID && type.itemMeta == stack.itemMeta) { return true; }
return false;
}
public static ItemStack consumeItem(ItemStack stack)
{
if (stack.stackSize == 1)
{
if (stack.getItem().hasContainerItem()) return stack.getItem().getContainerItemStack(stack);
else return null;
}
else
{
stack.splitStack(1);
return stack;
}
}
}

View file

@ -4,14 +4,37 @@ import net.minecraftforge.liquids.LiquidStack;
public class LiquidData
{
public final boolean isAGas;
public final int defaultPresure;
public final LiquidStack sampleStack;
private boolean isAGas;
private int defaultPresure;
private LiquidStack sampleStack;
private String name;
public LiquidData(LiquidStack stack, boolean gas, int dPressure)
public LiquidData(String name, LiquidStack stack, boolean gas, int dPressure)
{
this.sampleStack = stack;
this.isAGas = gas;
this.defaultPresure = dPressure;
this.name = name;
}
public static String getName(LiquidData type)
{
if (type != null) { return type.name; }
return "unknown";
}
public static int getPressure(LiquidData type)
{
if (type != null) { return type.defaultPresure; }
return 0;
}
public static LiquidStack getStack(LiquidData type)
{
if (type != null) { return type.sampleStack; }
return new LiquidStack(0,1);
}
public static boolean getCanFloat(LiquidData type)
{
if (type != null) { return type.isAGas; }
return false;
}
}

View file

@ -4,7 +4,9 @@ import java.util.ArrayList;
import java.util.List;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.tileentity.TileEntityPipe;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
@ -18,19 +20,23 @@ public class LiquidHandler
public static LiquidData steam;
public static LiquidData water;
public static LiquidData lava;
//public static LiquidData oil; TODO add
//public static LiquidData fuel;
public static LiquidData air;
// public static LiquidData oil; TODO add
// public static LiquidData fuel;
/**
* Called to add the default liquids to the allowed list
*/
public static void addDefaultLiquids()
{
steam = new LiquidData(LiquidDictionary.getOrCreateLiquid("Steam", new LiquidStack(LiquidMechanics.blockSteamBlock, 1)), true, 100);
steam = new LiquidData("Steam", LiquidDictionary.getOrCreateLiquid("Steam", new LiquidStack(LiquidMechanics.blockSteamBlock, 1)), true, 100);
allowedLiquids.add(steam);
water = new LiquidData(LiquidDictionary.getOrCreateLiquid("Water", new LiquidStack(Block.waterStill, 1)), false, 32);
water = new LiquidData("water", LiquidDictionary.getOrCreateLiquid("Water", new LiquidStack(Block.waterStill, 1)), false, 32);
allowedLiquids.add(water);
lava = new LiquidData(LiquidDictionary.getOrCreateLiquid("Lava", new LiquidStack(Block.lavaStill, 1)), false, 20);
lava = new LiquidData("Lava", LiquidDictionary.getOrCreateLiquid("Lava", new LiquidStack(Block.lavaStill, 1)), false, 20);
allowedLiquids.add(lava);
air = new LiquidData("Air", LiquidDictionary.getOrCreateLiquid("Air", new LiquidStack(0, 1)), false, 0);
allowedLiquids.add(air);
}
@ForgeSubscribe
@ -38,16 +44,107 @@ public class LiquidHandler
{
// TODO use this to add new liquid types to the data list
// or something along the lines of IDing liquids for use
boolean used = false;
for (LiquidData dta : allowedLiquids)
{
}
LiquidData data = new LiquidData(event.Liquid, false, 32);
if (!used && !allowedLiquids.contains(data))
{
allowedLiquids.add(data);
}
}
/**
* Gets the LiquidData linked to the liquid by name
*
* @param name
* - String name, not case sensitive
*/
public static LiquidData get(String name)
{
for (LiquidData data : LiquidHandler.allowedLiquids)
{
if (LiquidData.getName(data).equalsIgnoreCase(name)) { return data; }
}
return air;
}
public static LiquidData get(LiquidStack stack)
{
for (LiquidData data : LiquidHandler.allowedLiquids)
{
if (isEqual(stack, data)) { return data; }
}
return air;
}
/**
* gets a liquid stack of type & volume
*/
public static LiquidStack getStack(LiquidData type, int vol)
{
if(type == null) return null;
return new LiquidStack(LiquidData.getStack(type).itemID, vol, LiquidData.getStack(type).itemMeta);
}
public static int getMeta(LiquidData type)
{
if (type == LiquidHandler.steam) return 0;
if (type == LiquidHandler.water) return 1;
if (type == LiquidHandler.lava) return 2;
return 20;
}
public static LiquidData getFromMeta(int meta)
{
switch (meta)
{
case 0:
return steam;
case 1:
return water;
case 2:
return lava;
}
return air;
}
public static LiquidData getFromBlockID(int id)
{
for (LiquidData data : allowedLiquids)
{
if (LiquidData.getStack(data).itemID == id) { return data; }
}
return air;
}
/**
* compare a stack with a liquid type to see if there the same
*
* @param stack
* @param type
* @return
*/
public static boolean isEqual(LiquidStack stack, LiquidData type)
{
if (stack == null || type == null)
return false;
if (LiquidData.getStack(type).itemID == stack.itemID && LiquidData.getStack(type).itemMeta == stack.itemMeta) { return true; }
return false;
}
public static boolean isEqual(LiquidStack stack, LiquidStack type)
{
if (stack == null || type == null)
return false;
if (type.itemID == stack.itemID && type.itemMeta == stack.itemMeta) { return true; }
return false;
}
public static ItemStack consumeItem(ItemStack stack)
{
if (stack.stackSize == 1)
{
if (stack.getItem().hasContainerItem()) return stack.getItem().getContainerItemStack(stack);
else return null;
}
else
{
stack.splitStack(1);
return stack;
}
}
}

View file

@ -3,9 +3,9 @@ package liquidmechanics.common.item;
import java.util.List;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidData;
import liquidmechanics.common.handlers.LiquidHandler;
import liquidmechanics.common.tileentity.TileEntityReleaseValve;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@ -32,16 +32,16 @@ public class ItemEValve extends ItemBlock
@Override
public String getItemNameIS(ItemStack itemstack)
{
return "eValve";
return "release Valve";
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < DefautlLiquids.values().length - 1; i++)
{
par3List.add(new ItemStack(this, 1, i));
}
for (int i = 0; i < LiquidHandler.allowedLiquids.size() -1; i++)
{
par3List.add(new ItemStack(this, 1, i));
}
}
@Override
@ -114,10 +114,10 @@ public class ItemEValve extends ItemBlock
if (blockEntity instanceof TileEntityReleaseValve)
{
TileEntityReleaseValve pipeEntity = (TileEntityReleaseValve) blockEntity;
DefautlLiquids dm = DefautlLiquids.getLiquid(itemstack.getItemDamage());
LiquidData dm = LiquidHandler.getFromMeta(itemstack.getItemDamage());
pipeEntity.setType(dm);
pipeEntity.tank.setLiquid(DefautlLiquids.getStack(dm, 1));
world.setBlockMetadata(x, y, z, dm.ordinal() & 15);
world.setBlockMetadata(x, y, z, itemstack.getItemDamage() & 15);
pipeEntity.converted = true;
}
}

View file

@ -4,9 +4,8 @@ import java.util.List;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.TabLiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidHandler;
import liquidmechanics.common.tileentity.TileEntityPipe;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@ -40,16 +39,16 @@ public class ItemPipe extends Item
@Override
public String getItemNameIS(ItemStack itemstack)
{
return itemstack.getItemDamage() < DefautlLiquids.values().length ? DefautlLiquids.getLiquid(itemstack.getItemDamage()).displayerName + " Pipe" : "Empty Pipe";
return "pipe";
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < DefautlLiquids.values().length - 1; i++)
{
par3List.add(new ItemStack(this, 1, i));
}
for (int i = 0; i < LiquidHandler.allowedLiquids.size() -1; i++)
{
par3List.add(new ItemStack(this, 1, i));
}
}
public String getTextureFile()
@ -64,7 +63,7 @@ public class ItemPipe extends Item
}
@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
public boolean onItemUse(ItemStack itemstack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
int blockID = par3World.getBlockId(par4, par5, par6);
spawnID = LiquidMechanics.blockPipe.blockID;
@ -119,13 +118,13 @@ public class ItemPipe extends Item
TileEntity blockEntity = par3World.getBlockTileEntity(par4, par5, par6);
if (blockEntity instanceof TileEntityPipe)
{
TileEntityPipe pipeEntity = (TileEntityPipe) blockEntity;
DefautlLiquids dm = DefautlLiquids.getLiquid(par1ItemStack.getItemDamage());
pipeEntity.setType(dm);
TileEntityPipe pipeEntity = (TileEntityPipe) blockEntity;
pipeEntity.setType(LiquidHandler.getFromMeta(itemstack.getItemDamage()));
pipeEntity.converted = true;
}
}
--par1ItemStack.stackSize;
--itemstack.stackSize;
par3World.editingBlocks = false;
return true;
}

View file

@ -4,9 +4,9 @@ import java.util.List;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.TabLiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidData;
import liquidmechanics.common.handlers.LiquidHandler;
import liquidmechanics.common.tileentity.TileEntityTank;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@ -40,13 +40,13 @@ public class ItemTank extends Item
@Override
public String getItemNameIS(ItemStack itemstack)
{
return itemstack.getItemDamage() < DefautlLiquids.values().length ? DefautlLiquids.getLiquid(itemstack.getItemDamage()).displayerName + " Tank" : "unknown";
return "Tank";
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < DefautlLiquids.values().length; i++)
for (int i = 0; i < LiquidHandler.allowedLiquids.size() -1; i++)
{
par3List.add(new ItemStack(this, 1, i));
}
@ -120,8 +120,9 @@ public class ItemTank extends Item
if (blockEntity instanceof TileEntityTank)
{
TileEntityTank pipeEntity = (TileEntityTank) blockEntity;
DefautlLiquids dm = DefautlLiquids.getLiquid(par1ItemStack.getItemDamage());
LiquidData dm = LiquidHandler.getFromMeta(par1ItemStack.getItemDamage());
pipeEntity.setType(dm);
pipeEntity.converted = true;
}
}

View file

@ -4,7 +4,8 @@ import liquidmechanics.api.IReadOut;
import liquidmechanics.api.ITankOutputer;
import liquidmechanics.api.helpers.TankHelper;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidData;
import liquidmechanics.common.handlers.LiquidHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
@ -25,10 +26,10 @@ import com.google.common.io.ByteArrayDataInput;
public class TileEntityPipe extends TileEntity implements ITankContainer, IPacketReceiver, IReadOut
{
public DefautlLiquids type = DefautlLiquids.DEFUALT;
public LiquidData type = LiquidHandler.air;
private int count = 20;
private int count2, presure = 0;
public boolean converted = false;
protected boolean firstUpdate = true;
public TileEntity[] connectedBlocks = { null, null, null, null, null, null };
@ -64,7 +65,7 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IPacke
{
count2 = 5;
firstUpdate = false;
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, this.type.ordinal());
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, LiquidData.getName(type));
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 60);
}
@ -105,13 +106,13 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IPacke
}
// returns liquid type
public DefautlLiquids getType()
public LiquidData getType()
{
return this.type;
}
// used by the item to set the liquid type on spawn
public void setType(DefautlLiquids rType)
public void setType(LiquidData rType)
{
this.type = rType;
}
@ -124,7 +125,7 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IPacke
{
try
{
this.setType(DefautlLiquids.getLiquid(data.readInt()));
this.setType(LiquidHandler.get(data.readUTF()));
}
catch (Exception e)
{
@ -137,37 +138,52 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IPacke
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(par1NBTTagCompound);
this.type = DefautlLiquids.getLiquid(par1NBTTagCompound.getInteger("type"));
int vol = par1NBTTagCompound.getInteger("liquid");
this.stored.setLiquid(DefautlLiquids.getStack(type, vol));
super.readFromNBT(nbt);
this.converted = nbt.getBoolean("converted");
if (!converted)
{
int t = nbt.getInteger("type");
this.type = LiquidHandler.getFromMeta(t);
this.converted = true;
}
else
{
this.type = LiquidHandler.get(nbt.getString("name"));
}
if (this.type == null) type = LiquidHandler.air;
int vol = nbt.getInteger("liquid");
this.stored.setLiquid(LiquidHandler.getStack(type, vol));
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(par1NBTTagCompound);
super.writeToNBT(nbt);
nbt.setBoolean("converted", this.converted);
int s = 0;
LiquidStack stack = this.stored.getLiquid();
if (stack != null)
s = stack.amount;
par1NBTTagCompound.setInteger("liquid", s);
par1NBTTagCompound.setInteger("type", this.type.ordinal());
if (stored.getLiquid() != null) s = stored.getLiquid().amount;
nbt.setInteger("liquid", s);
nbt.setString("name", LiquidData.getName(type));
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
if (type == null) return "Error: No Type";
String output = "";
LiquidStack stack = stored.getLiquid();
if (stack != null)
output += (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + " " + this.type.displayerName;
output += (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidData.getName(type);
output += " @" + this.presure + "psi";
if (stack != null)
return output;
@ -178,8 +194,8 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IPacke
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
LiquidStack stack = stored.getLiquid();
if (stack == null) stored.setLiquid(DefautlLiquids.getStack(this.type, 1));
if (stack != null && DefautlLiquids.isStackEqual(resource, this.type)) return fill(0, resource, doFill);
if (stack == null) stored.setLiquid(LiquidHandler.getStack(this.type, 1));
if (stack != null && LiquidHandler.isEqual(resource, this.type)) return fill(0, resource, doFill);
return 0;
}
@ -224,7 +240,7 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IPacke
{
if (entity instanceof TileEntityPipe)
{
if (((TileEntityPipe) entity).type == this.type && this.type != DefautlLiquids.DEFUALT) { return true; }
if (((TileEntityPipe) entity).type == this.type) { return true; }
}
return false;
}

View file

@ -6,7 +6,8 @@ import liquidmechanics.api.IReadOut;
import liquidmechanics.api.ITankOutputer;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.MetaGroupingHelper;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidData;
import liquidmechanics.common.handlers.LiquidHandler;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
@ -32,302 +33,323 @@ import com.google.common.io.ByteArrayDataInput;
public class TileEntityPump extends TileEntityElectricityReceiver implements IPacketReceiver, IReadOut, ITankOutputer
{
public final double WATTS_PER_TICK = 400;
double percentPumped = 0.0;
double joulesReceived = 0;
int wMax = LiquidContainerRegistry.BUCKET_VOLUME * 2;
int disableTimer = 0;
int count = 0;
public final double WATTS_PER_TICK = 400;
double percentPumped = 0.0;
double joulesReceived = 0;
int wMax = LiquidContainerRegistry.BUCKET_VOLUME * 2;
int disableTimer = 0;
int count = 0;
private boolean converted = false;
public LiquidData type = LiquidHandler.air;
public LiquidTank tank = new LiquidTank(wMax);
public DefautlLiquids type = DefautlLiquids.DEFUALT;
public LiquidTank tank = new LiquidTank(wMax);
@Override
public void initiate()
{
this.registerConnections();
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, LiquidMechanics.blockMachine.blockID);
}
@Override
public void initiate()
{
this.registerConnections();
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, LiquidMechanics.blockMachine.blockID);
}
public void registerConnections()
{
int notchMeta = MetaGroupingHelper.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
ForgeDirection facing = ForgeDirection.getOrientation(notchMeta).getOpposite();
ForgeDirection[] dirs = new ForgeDirection[] { ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN };
ElectricityConnections.registerConnector(this, EnumSet.of(facing.getOpposite()));
for (int i = 2; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (dir != facing)
{
dirs[i] = dir;
}
}
ElectricityConnections.registerConnector(this, EnumSet.of(dirs[0], dirs[1], dirs[2], dirs[3], dirs[4], dirs[5]));
}
public void registerConnections()
{
int notchMeta = MetaGroupingHelper.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
ForgeDirection facing = ForgeDirection.getOrientation(notchMeta).getOpposite();
ForgeDirection[] dirs = new ForgeDirection[] { ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN, ForgeDirection.UNKNOWN };
ElectricityConnections.registerConnector(this, EnumSet.of(facing.getOpposite()));
for (int i = 2; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (dir != facing)
{
dirs[i] = dir;
}
}
ElectricityConnections.registerConnector(this, EnumSet.of(dirs[0], dirs[1], dirs[2], dirs[3], dirs[4], dirs[5]));
}
@Override
public void onDisable(int duration)
{
disableTimer = duration;
}
@Override
public void onDisable(int duration)
{
disableTimer = duration;
}
@Override
public boolean isDisabled()
{
if (disableTimer <= 0) { return false; }
return true;
}
@Override
public boolean isDisabled()
{
if (disableTimer <= 0) { return false; }
return true;
}
@Override
public void updateEntity()
{
super.updateEntity();
@Override
public void updateEntity()
{
super.updateEntity();
if (!this.worldObj.isRemote)
{
if (count-- <= 0)
{
int bBlock = worldObj.getBlockId(xCoord, yCoord - 1, zCoord);
LiquidData bellow = LiquidHandler.getFromBlockID(bBlock);
if (bellow != null)
{
if (this.type != bellow && bellow != LiquidHandler.air)
{
this.tank.setLiquid(LiquidHandler.getStack(bellow, 0));
this.type = bellow;
}
if (!this.worldObj.isRemote)
{
if (count-- <= 0)
{
int bBlock = worldObj.getBlockId(xCoord, yCoord - 1, zCoord);
DefautlLiquids bellow = DefautlLiquids.getLiquidTypeByBlock(bBlock);
if (bellow != null)
{
if (this.type != bellow && bellow != DefautlLiquids.DEFUALT)
{
this.tank.setLiquid(DefautlLiquids.getStack(bellow, 0));
this.type = bellow;
}
}
count = 40;
}
if (this.tank.getLiquid() == null)
{
this.tank.setLiquid(LiquidHandler.getStack(this.type, 1));
}
LiquidStack stack = tank.getLiquid();
}
count = 40;
}
if (this.tank.getLiquid() == null)
{
this.tank.setLiquid(DefautlLiquids.getStack(this.type, 1));
}
LiquidStack stack = tank.getLiquid();
if (stack != null)
{
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
TileEntity tile = worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
if (stack != null)
{
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
TileEntity tile = worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
if (tile instanceof ITankContainer)
{
int moved = ((ITankContainer) tile).fill(dir.getOpposite(), stack, true);
tank.drain(moved, true);
if (stack.amount <= 0)
break;
}
}
if (tile instanceof ITankContainer)
{
int moved = ((ITankContainer) tile).fill(dir.getOpposite(), stack, true);
tank.drain(moved, true);
if (stack.amount <= 0)
break;
}
}
}
}
int notchMeta = MetaGroupingHelper.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
ForgeDirection facing = ForgeDirection.getOrientation(notchMeta).getOpposite();
int notchMeta = MetaGroupingHelper.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
ForgeDirection facing = ForgeDirection.getOrientation(notchMeta).getOpposite();
for (int i = 2; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (dir != facing)
{
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, new Vector3(this), dir);
ElectricityNetwork network = ElectricityNetwork.getNetworkFromTileEntity(inputTile, dir);
if (network != null)
{
for (int i = 2; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (dir != facing)
{
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, new Vector3(this), dir);
ElectricityNetwork network = ElectricityNetwork.getNetworkFromTileEntity(inputTile, dir);
if (network != null)
{
if (this.canPump(xCoord, yCoord - 1, zCoord))
{
network.startRequesting(this, WATTS_PER_TICK / this.getVoltage(), this.getVoltage());
this.joulesReceived = Math.max(Math.min(this.joulesReceived + network.consumeElectricity(this).getWatts(), WATTS_PER_TICK), 0);
}
else
{
network.stopRequesting(this);
}
}
}
}
if (this.joulesReceived >= this.WATTS_PER_TICK - 50 && this.canPump(xCoord, yCoord - 1, zCoord))
{
if (this.canPump(xCoord, yCoord - 1, zCoord))
{
network.startRequesting(this, WATTS_PER_TICK / this.getVoltage(), this.getVoltage());
this.joulesReceived = Math.max(Math.min(this.joulesReceived + network.consumeElectricity(this).getWatts(), WATTS_PER_TICK), 0);
}
else
{
network.stopRequesting(this);
}
}
}
}
if (this.joulesReceived >= this.WATTS_PER_TICK - 50 && this.canPump(xCoord, yCoord - 1, zCoord))
{
joulesReceived -= this.WATTS_PER_TICK;
if (percentPumped++ >= 20)
{
this.drainBlock(new Vector3(xCoord, yCoord - 1, zCoord));
}
}
}
joulesReceived -= this.WATTS_PER_TICK;
if (percentPumped++ >= 20)
{
this.drainBlock(new Vector3(xCoord, yCoord - 1, zCoord));
}
}
}
if (!this.worldObj.isRemote)
{
if (this.ticks % 10 == 0)
{
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, LiquidData.getName(type));
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 60);
}
}
}
if (!this.worldObj.isRemote)
{
if (this.ticks % 10 == 0)
{
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, this.type.ordinal());
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 60);
}
}
}
public boolean canPump(int x, int y, int z)
{
// if (this.tank.getLiquid() == null) return false;
if (this.tank.getLiquid() != null && this.tank.getLiquid().amount >= this.wMax)
return false;
if (this.isDisabled())
return false;
if (!this.isValidLiquid(Block.blocksList[worldObj.getBlockId(x, y, z)]))
return false;
return true;
}
public boolean canPump(int x, int y, int z)
{
// if (this.tank.getLiquid() == null) return false;
if (this.tank.getLiquid() != null && this.tank.getLiquid().amount >= this.wMax)
return false;
if (this.isDisabled())
return false;
if (!this.isValidLiquid(Block.blocksList[worldObj.getBlockId(x, y, z)]))
return false;
return true;
}
/**
* drains the block or in other words removes it
*
* @param loc
* @return true if the block was drained
*/
public boolean drainBlock(Vector3 loc)
{
int bBlock = worldObj.getBlockId(loc.intX(), loc.intY(), loc.intZ());
int meta = worldObj.getBlockMetadata(loc.intX(), loc.intY(), loc.intZ());
LiquidData bellow = LiquidHandler.getFromBlockID(bBlock);
if (bBlock == Block.waterMoving.blockID || (bBlock == Block.waterStill.blockID && meta != 0))
return false;
if (bBlock == Block.lavaMoving.blockID || (bBlock == Block.lavaStill.blockID && meta != 0))
return false;
if (bBlock == LiquidData.getStack(type).itemID && this.isValidLiquid(Block.blocksList[bBlock]))
{
// FMLLog.info("pumping " + bellow.displayerName + " blockID:" +
// bBlock + " Meta:" +
// meta);
int f = this.tank.fill(LiquidHandler.getStack(this.type, LiquidContainerRegistry.BUCKET_VOLUME), true);
if (f > 0)
worldObj.setBlockWithNotify(loc.intX(), loc.intY(), loc.intZ(), 0);
percentPumped = 0;
return true;
}
return false;
}
/**
* drains the block or in other words removes it
*
* @param loc
* @return true if the block was drained
*/
public boolean drainBlock(Vector3 loc)
{
int bBlock = worldObj.getBlockId(loc.intX(), loc.intY(), loc.intZ());
int meta = worldObj.getBlockMetadata(loc.intX(), loc.intY(), loc.intZ());
DefautlLiquids bellow = DefautlLiquids.getLiquidTypeByBlock(bBlock);
if (bBlock == Block.waterMoving.blockID || (bBlock == Block.waterStill.blockID && meta != 0))
return false;
if (bBlock == Block.lavaMoving.blockID || (bBlock == Block.lavaStill.blockID && meta != 0))
return false;
if (bBlock == type.liquid.itemID && this.isValidLiquid(Block.blocksList[bBlock]))
{
// FMLLog.info("pumping " + bellow.displayerName + " blockID:" + bBlock + " Meta:" +
// meta);
int f = this.tank.fill(DefautlLiquids.getStack(this.type, LiquidContainerRegistry.BUCKET_VOLUME), true);
if (f > 0)
worldObj.setBlockWithNotify(loc.intX(), loc.intY(), loc.intZ(), 0);
percentPumped = 0;
return true;
}
return false;
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput data)
{
try
{
this.type = (LiquidHandler.get(data.readUTF()));
}
catch (Exception e)
{
e.printStackTrace();
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput data)
{
try
{
this.type = (DefautlLiquids.getLiquid(data.readInt()));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
int stored = par1NBTTagCompound.getInteger("liquid");
this.type = DefautlLiquids.getLiquid(par1NBTTagCompound.getInteger("type"));
this.tank.setLiquid(DefautlLiquids.getStack(this.type, stored));
}
this.converted = nbt.getBoolean("converted");
if (!converted)
{
int t = nbt.getInteger("type");
this.type = LiquidHandler.getFromMeta(t);
this.converted = true;
}
else
{
this.type = LiquidHandler.get(nbt.getString("name"));
}
if (this.type == null) type = LiquidHandler.air;
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
int s = 1;
if (this.tank.getLiquid() != null)
s = this.tank.getLiquid().amount;
par1NBTTagCompound.setInteger("liquid", s);
par1NBTTagCompound.setInteger("type", this.type.ordinal());
}
int stored = nbt.getInteger("liquid");
this.tank.setLiquid(LiquidHandler.getStack(this.type, stored));
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
int liquid = 0;
if (this.tank.getLiquid() != null)
{
liquid = (this.tank.getLiquid().amount / LiquidContainerRegistry.BUCKET_VOLUME);
}
else
{
liquid = 0;
}
return liquid + "" + type.displayerName + " " + this.joulesReceived + "W " + this.percentPumped + "/20";
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setBoolean("converted", this.converted);
int s = 1;
if (this.tank.getLiquid() != null) s = this.tank.getLiquid().amount;
nbt.setInteger("liquid", s);
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
return 0;
}
nbt.setString("name", LiquidData.getName(type));
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
return 0;
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
if (type == null) return "Error: No Type";
int liquid = 0;
if (this.tank.getLiquid() != null)
{
liquid = (this.tank.getLiquid().amount / LiquidContainerRegistry.BUCKET_VOLUME);
}
else
{
liquid = 0;
}
return liquid + "" + LiquidData.getName(type) + " " + this.joulesReceived + "W " + this.percentPumped + "/20";
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return drain(0, maxDrain, doDrain);
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
return 0;
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
if (tankIndex == 0)
return tank.drain(maxDrain, doDrain);
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
return 0;
}
return null;
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return drain(0, maxDrain, doDrain);
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { tank };
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
if (tankIndex == 0)
return tank.drain(maxDrain, doDrain);
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
return null;
}
return null;
}
@Override
public int presureOutput(DefautlLiquids type, ForgeDirection dir)
{
if (type == this.type)
return type.defaultPresure;
return 0;
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { tank };
}
@Override
public boolean canPressureToo(DefautlLiquids type, ForgeDirection dir)
{
if (type == this.type)
return true;
return false;
}
/**
* Checks to see if the given block type is valid for pumping
* @param block
* @return
*/
private boolean isValidLiquid(Block block)
{
return DefautlLiquids.getLiquidFromBlock(block.blockID) != null;
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
return null;
}
@Override
public int presureOutput(LiquidData type, ForgeDirection dir)
{
if (type == this.type)
return LiquidData.getPressure(type);
return 0;
}
@Override
public boolean canPressureToo(LiquidData type, ForgeDirection dir)
{
if (type == this.type)
return true;
return false;
}
/**
* Checks to see if the given block type is valid for pumping
*
* @param block
* @return
*/
private boolean isValidLiquid(Block block)
{
return LiquidHandler.getFromBlockID(block.blockID) != null;
}
}

View file

@ -4,7 +4,8 @@ import liquidmechanics.api.IReadOut;
import liquidmechanics.api.ITankOutputer;
import liquidmechanics.api.helpers.TankHelper;
import liquidmechanics.common.block.BlockReleaseValve;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidData;
import liquidmechanics.common.handlers.LiquidHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -18,11 +19,12 @@ import universalelectricity.prefab.implement.IRedstoneReceptor;
public class TileEntityReleaseValve extends TileEntity implements ITankOutputer, IReadOut, IRedstoneReceptor
{
public DefautlLiquids type = DefautlLiquids.DEFUALT;
public LiquidData type = LiquidHandler.air;
public LiquidTank tank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
public TileEntity[] connected = new TileEntity[6];
private int count = 0;
public boolean isPowered = false;
public boolean converted = false;
@Override
public void updateEntity()
@ -34,7 +36,7 @@ public class TileEntityReleaseValve extends TileEntity implements ITankOutputer,
BlockReleaseValve.checkForPower(worldObj, xCoord, yCoord, zCoord);
if (tank.getLiquid() == null)
{
tank.setLiquid(DefautlLiquids.getStack(this.type, 1));
tank.setLiquid(LiquidHandler.getStack(this.type, 1));
}
if (tank.getLiquid() != null && tank.getLiquid().amount < tank.getCapacity() && !isPowered)
{
@ -47,7 +49,7 @@ public class TileEntityReleaseValve extends TileEntity implements ITankOutputer,
for (int t = 0; t < tanks.length; t++)
{
LiquidStack ll = tanks[t].getLiquid();
if (ll != null && DefautlLiquids.isStackEqual(ll, this.type))
if (ll != null && LiquidHandler.isEqual(ll, this.type))
{
int drainVol = tank.getCapacity() - tank.getLiquid().amount - 1;
LiquidStack drained = ((ITankContainer) connected[i]).drain(t, drainVol, true);
@ -112,14 +114,14 @@ public class TileEntityReleaseValve extends TileEntity implements ITankOutputer,
}
@Override
public int presureOutput(DefautlLiquids type, ForgeDirection dir)
public int presureOutput(LiquidData type, ForgeDirection dir)
{
if (type == this.type) { return type.defaultPresure; }
if (type == this.type) { return LiquidData.getPressure(type); }
return 0;
}
@Override
public boolean canPressureToo(DefautlLiquids type, ForgeDirection dir)
public boolean canPressureToo(LiquidData type, ForgeDirection dir)
{
if (type == this.type)
return true;
@ -129,41 +131,49 @@ public class TileEntityReleaseValve extends TileEntity implements ITankOutputer,
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
if (type == null) return "Error: No Type";
String output = "";
LiquidStack stack = tank.getLiquid();
if (stack != null)
output += (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + " " + this.type.displayerName + " on = " + !this.isPowered;
output += (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidData.getName(type) + " on = " + !this.isPowered;
if (stack != null)
return output;
return "0/0 " + this.type.displayerName + " on = " + !this.isPowered;
return "0/0 " + LiquidData.getName(type) + " on = " + !this.isPowered;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(par1NBTTagCompound);
this.type = DefautlLiquids.getLiquid(par1NBTTagCompound.getInteger("type"));
int vol = par1NBTTagCompound.getInteger("liquid");
this.tank.setLiquid(DefautlLiquids.getStack(type, vol));
super.readFromNBT(nbt);
this.type = LiquidHandler.get(nbt.getString("name"));
this.converted = nbt.getBoolean("converted");
if (!converted)
{
int t = nbt.getInteger("type");
this.type = LiquidHandler.getFromMeta(t);
this.converted = true;
}
if (this.type == null) type = LiquidHandler.air;
int vol = nbt.getInteger("liquid");
this.tank.setLiquid(LiquidHandler.getStack(type, vol));
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(par1NBTTagCompound);
super.writeToNBT(nbt);
nbt.setBoolean("converted", this.converted);
int s = 0;
LiquidStack stack = this.tank.getLiquid();
if (stack != null)
s = stack.amount;
par1NBTTagCompound.setInteger("liquid", s);
par1NBTTagCompound.setInteger("type", this.type.ordinal());
if (tank.getLiquid() != null) s = tank.getLiquid().amount;
nbt.setInteger("liquid", s);
nbt.setString("name", LiquidData.getName(type));
}
public void setType(DefautlLiquids dm)
public void setType(LiquidData dm)
{
this.type = dm;

View file

@ -4,7 +4,8 @@ import liquidmechanics.api.IReadOut;
import liquidmechanics.api.ITankOutputer;
import liquidmechanics.api.helpers.TankHelper;
import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids;
import liquidmechanics.common.handlers.LiquidData;
import liquidmechanics.common.handlers.LiquidHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
@ -22,297 +23,315 @@ import universalelectricity.prefab.network.PacketManager;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityTank extends TileEntity implements IPacketReceiver, IReadOut, ITankOutputer
{
public TileEntity[] cc = { null, null, null, null, null, null };
public DefautlLiquids type = DefautlLiquids.DEFUALT;
public static final int LMax = 4;
private int count = 0;
private int count2 = 0;
public TileEntity[] cc = { null, null, null, null, null, null };
public LiquidData type = LiquidHandler.air;
public static final int LMax = 4;
private int count = 0;
private int count2 = 0;
public boolean converted = false;
private boolean doUpdate = true;
public LiquidTank tank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME * LMax);
private boolean doUpdate = true;
public LiquidTank tank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME * LMax);
public void updateEntity()
{
if (tank.getLiquid() == null)
{
tank.setLiquid(DefautlLiquids.getStack(this.type, 1));
}
LiquidStack liquid = tank.getLiquid();
public void updateEntity()
{
if (tank.getLiquid() == null)
{
tank.setLiquid(LiquidHandler.getStack(this.type, 1));
}
LiquidStack liquid = tank.getLiquid();
if (++count >= 20 && liquid != null)
{
count = 0;
this.cc = TankHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
if (!worldObj.isRemote)
{
this.tradeDown();
this.tradeArround();
if (++count >= 20 && liquid != null)
{
count = 0;
this.cc = TankHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
if (!worldObj.isRemote)
{
this.tradeDown();
this.tradeArround();
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, new Object[] { type.ordinal(), liquid.amount });
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 20);
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, new Object[] { LiquidData.getName(type), liquid.amount });
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 20);
}
}
}
}
}
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
String output = "";
LiquidStack stack = tank.getLiquid();
if (stack != null)
output += (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + " " + this.type.displayerName;
if (stack != null)
return output;
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
if (type == null) return "Error: No Type";
String output = "";
LiquidStack stack = tank.getLiquid();
if (stack != null)
output += (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidData.getName(type);
if (stack != null)
return output;
return "0/4 " + LiquidData.getName(type);
}
return "0/4 " + this.type.displayerName;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.converted = nbt.getBoolean("converted");
if (!converted)
{
int t = nbt.getInteger("type");
this.type = LiquidHandler.getFromMeta(t);
this.converted = true;
}
else
{
this.type = LiquidHandler.get(nbt.getString("name"));
}
if (this.type == null) type = LiquidHandler.air;
int vol = nbt.getInteger("liquid");
this.tank.setLiquid(LiquidHandler.getStack(type, vol));
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
this.type = DefautlLiquids.getLiquid(par1NBTTagCompound.getInteger("type"));
int vol = par1NBTTagCompound.getInteger("liquid");
this.tank.setLiquid(DefautlLiquids.getStack(type, vol));
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
int s = 0;
LiquidStack stack = this.tank.getLiquid();
if (stack != null)
s = stack.amount;
par1NBTTagCompound.setInteger("liquid", s);
par1NBTTagCompound.setInteger("type", this.type.ordinal());
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setBoolean("converted", this.converted);
int s = 0;
if (tank.getLiquid() != null) s = tank.getLiquid().amount;
nbt.setInteger("liquid", s);
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput data)
{
try
{
this.type = DefautlLiquids.getLiquid(data.readInt());
this.tank.setLiquid(DefautlLiquids.getStack(this.type, data.readInt()));
}
catch (Exception e)
{
e.printStackTrace();
System.out.print("Fail reading data for Storage tank \n");
}
nbt.setString("name", LiquidData.getName(type));
}
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput data)
{
try
{
this.type = LiquidHandler.get(data.readUTF());
this.tank.setLiquid(LiquidHandler.getStack(this.type, data.readInt()));
}
catch (Exception e)
{
e.printStackTrace();
System.out.print("Fail reading data for Storage tank \n");
}
// ----------------------------
// Liquid stuff
// ----------------------------
public void setType(DefautlLiquids dm)
{
this.type = dm;
}
}
// ----------------------------
// Liquid stuff
// ----------------------------
public void setType(LiquidData dm)
{
this.type = dm;
public DefautlLiquids getType()
{
return this.type;
}
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (!DefautlLiquids.isStackEqual(resource, type))
return 0;
return this.fill(0, resource, doFill);
}
public LiquidData getType()
{
return this.type;
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if (resource == null || tankIndex != 0)
return 0;
if (this.isFull())
{
int change = 1;
if (DefautlLiquids.getLiquid(resource).doesFlaot)
change = -1;
TileEntity tank = worldObj.getBlockTileEntity(xCoord, yCoord + change, zCoord);
if (tank instanceof TileEntityTank) { return ((TileEntityTank) tank).tank.fill(resource, doFill); }
}
this.doUpdate = true;
return this.tank.fill(resource, doFill);
}
/**
* find out if this tank is actual full or not
* @return
*/
public boolean isFull()
{
if (this.tank.getLiquid() == null)
return false;
if (this.tank.getLiquid().amount > 0 && this.tank.getLiquid().amount < this.tank.getCapacity())
return false;
return true;
}
/**
* finds the first fillable tank in either direction
* @param top - search up
* @return
*/
public TileEntityTank getFillAbleTank(boolean top)
{
TileEntityTank tank = this;
boolean stop = false;
int y = tank.yCoord;
while (y > 6 && y < 255)
{
if (top)
{
y += 1;
}
else
{
y -= 1;
}
TileEntity ent = tank.worldObj.getBlockTileEntity(xCoord, y, zCoord);
if (ent instanceof TileEntityTank && ((TileEntityTank) ent).getType() == this.type && !((TileEntityTank) ent).isFull())
{
tank = (TileEntityTank) ent;
}
else
{
break;
}
}
return tank;
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (!LiquidHandler.isEqual(resource, type))
return 0;
return this.fill(0, resource, doFill);
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return this.drain(0, maxDrain, doDrain);
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if (resource == null || tankIndex != 0)
return 0;
if (this.isFull())
{
int change = 1;
if (LiquidData.getCanFloat(LiquidHandler.get(resource)))
change = -1;
TileEntity tank = worldObj.getBlockTileEntity(xCoord, yCoord + change, zCoord);
if (tank instanceof TileEntityTank) { return ((TileEntityTank) tank).tank.fill(resource, doFill); }
}
this.doUpdate = true;
return this.tank.fill(resource, doFill);
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
if (tankIndex != 0) {return null;}
LiquidStack stack = this.tank.getLiquid();
if(maxDrain <= this.tank.getLiquid().amount)
{
stack = DefautlLiquids.getStack(type, maxDrain);
}
if(doDrain)
{
this.tank.drain(maxDrain, doDrain);
}
return stack;
}
/**
* find out if this tank is actual full or not
*
* @return
*/
public boolean isFull()
{
if (this.tank.getLiquid() == null)
return false;
if (this.tank.getLiquid().amount > 0 && this.tank.getLiquid().amount < this.tank.getCapacity())
return false;
return true;
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { tank };
}
/**
* finds the first fillable tank in either direction
*
* @param top
* - search up
* @return
*/
public TileEntityTank getFillAbleTank(boolean top)
{
TileEntityTank tank = this;
boolean stop = false;
int y = tank.yCoord;
while (y > 6 && y < 255)
{
if (top)
{
y += 1;
}
else
{
y -= 1;
}
TileEntity ent = tank.worldObj.getBlockTileEntity(xCoord, y, zCoord);
if (ent instanceof TileEntityTank && ((TileEntityTank) ent).getType() == this.type && !((TileEntityTank) ent).isFull())
{
tank = (TileEntityTank) ent;
}
else
{
break;
}
}
return tank;
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
return null;
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return this.drain(0, maxDrain, doDrain);
}
@Override
public int presureOutput(DefautlLiquids type, ForgeDirection dir)
{
if (type == this.type)
{
if (type.doesFlaot && dir == ForgeDirection.DOWN)
return type.defaultPresure;
if (!type.doesFlaot && dir == ForgeDirection.UP)
return type.defaultPresure;
}
return 0;
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
if (tankIndex != 0) { return null; }
LiquidStack stack = this.tank.getLiquid();
if (maxDrain <= this.tank.getLiquid().amount)
{
stack = LiquidHandler.getStack(type, maxDrain);
}
if (doDrain)
{
this.tank.drain(maxDrain, doDrain);
}
return stack;
}
@Override
public boolean canPressureToo(DefautlLiquids type, ForgeDirection dir)
{
if (type == this.type)
{
if (type.doesFlaot && dir == ForgeDirection.DOWN)
return true;
if (!type.doesFlaot && dir == ForgeDirection.UP)
return true;
}
return false;
}
/**
* cause this TE to trade liquid down if
* the liquid is in liquid state or up
* if in gas state.
*/
public void tradeDown()
{
if (this.tank.getLiquid() == null || this.tank.getLiquid().amount <= 0)
return;
TileEntity ent = worldObj.getBlockTileEntity(xCoord, yCoord - 1, zCoord);
if (ent instanceof TileEntityTank && ((TileEntityTank) ent).type == this.type && !((TileEntityTank) ent).isFull())
{
int f = ((TileEntityTank) ent).tank.fill(this.tank.getLiquid(), true);
this.tank.drain(f, true);
}
}
/**
* Cause this TE to trade liquid with
* the Tanks around it to level off
*/
public void tradeArround()
{
if (this.tank.getLiquid() == null || this.tank.getLiquid().amount <= 0)
return;
TileEntity[] ents = TankHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
int commonVol = this.tank.getLiquid().amount;
int tanks = 1;
for (int i = 2; i < 6; i++)
{
if (ents[i] instanceof TileEntityTank && ((TileEntityTank) ents[i]).type == this.type)
{
tanks++;
if (((TileEntityTank) ents[i]).tank.getLiquid() != null)
{
commonVol += ((TileEntityTank) ents[i]).tank.getLiquid().amount;
}
}
}
int equalVol = commonVol / tanks;
for (int i = 2; i < 6; i++)
{
if (this.tank.getLiquid() == null || this.tank.getLiquid().amount <= equalVol)
break;
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { tank };
}
if (ents[i] instanceof TileEntityTank && ((TileEntityTank) ents[i]).type == this.type && !((TileEntityTank) ents[i]).isFull())
{
LiquidStack stack = ((TileEntityTank) ents[i]).tank.getLiquid();
LiquidStack filling = this.tank.getLiquid();
if (stack == null)
{
filling = DefautlLiquids.getStack(this.type, equalVol);
}
else if (stack.amount < equalVol)
{
filling = DefautlLiquids.getStack(this.type, equalVol - stack.amount);
}
else
{
filling = null;
}
int f = ((TileEntityTank) ents[i]).tank.fill(filling, true);
this.tank.drain(f, true);
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
return null;
}
}
}
@Override
public int presureOutput(LiquidData type, ForgeDirection dir)
{
if (type == this.type)
{
if (LiquidData.getCanFloat(type) && dir == ForgeDirection.DOWN)
return LiquidData.getPressure(type);
if (!LiquidData.getCanFloat(type) && dir == ForgeDirection.UP)
return LiquidData.getPressure(type);
}
return 0;
}
@Override
public boolean canPressureToo(LiquidData type, ForgeDirection dir)
{
if (type == this.type)
{
if (LiquidData.getCanFloat(type) && dir == ForgeDirection.DOWN)
return true;
if (!LiquidData.getCanFloat(type) && dir == ForgeDirection.UP)
return true;
}
return false;
}
/**
* cause this TE to trade liquid down if the liquid is in liquid state or up
* if in gas state.
*/
public void tradeDown()
{
if (this.tank.getLiquid() == null || this.tank.getLiquid().amount <= 0)
return;
TileEntity ent = worldObj.getBlockTileEntity(xCoord, yCoord - 1, zCoord);
if (ent instanceof TileEntityTank && ((TileEntityTank) ent).type == this.type && !((TileEntityTank) ent).isFull())
{
int f = ((TileEntityTank) ent).tank.fill(this.tank.getLiquid(), true);
this.tank.drain(f, true);
}
}
/**
* Cause this TE to trade liquid with the Tanks around it to level off
*/
public void tradeArround()
{
if (this.tank.getLiquid() == null || this.tank.getLiquid().amount <= 0)
return;
TileEntity[] ents = TankHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
int commonVol = this.tank.getLiquid().amount;
int tanks = 1;
for (int i = 2; i < 6; i++)
{
if (ents[i] instanceof TileEntityTank && ((TileEntityTank) ents[i]).type == this.type)
{
tanks++;
if (((TileEntityTank) ents[i]).tank.getLiquid() != null)
{
commonVol += ((TileEntityTank) ents[i]).tank.getLiquid().amount;
}
}
}
int equalVol = commonVol / tanks;
for (int i = 2; i < 6; i++)
{
if (this.tank.getLiquid() == null || this.tank.getLiquid().amount <= equalVol)
break;
if (ents[i] instanceof TileEntityTank && ((TileEntityTank) ents[i]).type == this.type && !((TileEntityTank) ents[i]).isFull())
{
LiquidStack stack = ((TileEntityTank) ents[i]).tank.getLiquid();
LiquidStack filling = this.tank.getLiquid();
if (stack == null)
{
filling = LiquidHandler.getStack(this.type, equalVol);
}
else if (stack.amount < equalVol)
{
filling = LiquidHandler.getStack(this.type, equalVol - stack.amount);
}
else
{
filling = null;
}
int f = ((TileEntityTank) ents[i]).tank.fill(filling, true);
this.tank.drain(f, true);
}
}
}
}