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,17 +3,17 @@ 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 LiquidData type = LiquidHandler.water;
private ModelPipe fourPipe;
private ModelLargePipe SixPipe;
private TileEntity[] ents = new TileEntity[6];
@ -40,26 +40,24 @@ public class RenderPipe extends TileEntitySpecialRenderer
}
public void render(DefautlLiquids type, TileEntity[] ents)
public void render(LiquidData type2, TileEntity[] ents)
{
switch (type.ordinal())
if (type2 == LiquidHandler.water)
{
case 0:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixSteamPipe.png");
break;
case 1:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixWaterPipe.png");
break;
case 2:
}
else if (type2 == LiquidHandler.lava)
{
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixLavaPipe.png");
break;
case 3:
}
else if (type2 == LiquidHandler.steam)
{
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixSteamPipe.png");
}
else
{
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixOilPipe.png");
break;
default:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/DefaultPipe.png");
break;
}
if (ents[0] != null)
SixPipe.renderBottom();

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;
@ -149,15 +150,15 @@ public class LiquidMechanics extends DummyModContainer
GameRegistry.registerTileEntity(TileEntityGenerator.class, "Generator");
// Liquid Item/Block common name writer
for (int i = 0; i < DefautlLiquids.values().length; i++)
for (int i = 0; i < LiquidHandler.allowedLiquids.size() - 1; i++)
{
// eValves
LanguageRegistry.addName((new ItemStack(blockReleaseValve, 1, i)), DefautlLiquids.getLiquid(i).displayerName + " Release Valve");
LanguageRegistry.addName((new ItemStack(blockReleaseValve, 1, i)),LiquidData.getName(LiquidHandler.getFromMeta(i)) + " Release Valve");
// pipes
LanguageRegistry.addName((new ItemStack(itemPipes, 1, i)), DefautlLiquids.getLiquid(i).displayerName + " Pipe");
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");
LanguageRegistry.addName((new ItemStack(itemTank, 1, i)), LiquidData.getName(LiquidHandler.getFromMeta(i)) + " Tank");
}
for (int i = 0; i < ItemParts.Parts.values().length; i++)
@ -181,65 +182,110 @@ public class LiquidMechanics extends DummyModContainer
public void PostInit(FMLPostInitializationEvent event)
{
proxy.postInit();
TabLiquidMechanics.setItemStack(new ItemStack(itemPipes, 1, DefautlLiquids.WATER.ordinal()));
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" }));
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()) });
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 });
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 });
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()) });
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 });
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) });
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 });
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 });
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()) });
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()) });
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, 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) });
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, 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) });
*/
GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, 2), new Object[] {
new ItemStack(itemParts, 1, Parts.Obby.ordinal()),
new ItemStack(Item.dyePowder, 1, 1) });
// 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) });
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, 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) });
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, 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) });
*/
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()) });
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 < DefautlLiquids.values().length - 1; i++)
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()), });
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;
@ -64,7 +64,7 @@ public class BlockMachine extends BlockContainer
if (filled != 0 && !entityplayer.capabilities.isCreativeMode)
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, DefautlLiquids.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, LiquidHandler.consumeItem(current));
}
return true;
@ -87,16 +87,15 @@ public class BlockMachine extends BlockContainer
{
if (current.stackSize > 1)
{
if (!entityplayer.inventory.addItemStackToInventory(liquidItem))
return false;
if (!entityplayer.inventory.addItemStackToInventory(liquidItem)) return false;
else
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, DefautlLiquids.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, LiquidHandler.consumeItem(current));
}
}
else
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, DefautlLiquids.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, LiquidHandler.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, liquidItem);
}
}
@ -111,6 +110,7 @@ public class BlockMachine extends BlockContainer
return false;
}
@Override
public int getRenderType()
{
@ -132,8 +132,7 @@ public class BlockMachine extends BlockContainer
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());
if (ent instanceof TileEntityTank) return new ItemStack(LiquidMechanics.itemTank, 1, LiquidHandler.getMeta(((TileEntityTank) ent).type));
return null;
}
@ -154,4 +153,5 @@ public class BlockMachine extends BlockContainer
{
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))
/**
* Gets the LiquidData linked to the liquid by name
*
* @param name
* - String name, not case sensitive
*/
public static LiquidData get(String name)
{
allowedLiquids.add(data);
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,13 +32,13 @@ 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++)
for (int i = 0; i < LiquidHandler.allowedLiquids.size() -1; i++)
{
par3List.add(new ItemStack(this, 1, i));
}
@ -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,13 +39,13 @@ 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++)
for (int i = 0; i < LiquidHandler.allowedLiquids.size() -1; i++)
{
par3List.add(new ItemStack(this, 1, i));
}
@ -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;
@ -120,12 +119,12 @@ public class ItemPipe extends Item
if (blockEntity instanceof TileEntityPipe)
{
TileEntityPipe pipeEntity = (TileEntityPipe) blockEntity;
DefautlLiquids dm = DefautlLiquids.getLiquid(par1ItemStack.getItemDamage());
pipeEntity.setType(dm);
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;
@ -35,11 +36,14 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
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 DefautlLiquids type = DefautlLiquids.DEFUALT;
private boolean converted = false;
public LiquidData type = LiquidHandler.air;
public LiquidTank tank = new LiquidTank(wMax);
@Override
@ -89,12 +93,12 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
if (count-- <= 0)
{
int bBlock = worldObj.getBlockId(xCoord, yCoord - 1, zCoord);
DefautlLiquids bellow = DefautlLiquids.getLiquidTypeByBlock(bBlock);
LiquidData bellow = LiquidHandler.getFromBlockID(bBlock);
if (bellow != null)
{
if (this.type != bellow && bellow != DefautlLiquids.DEFUALT)
if (this.type != bellow && bellow != LiquidHandler.air)
{
this.tank.setLiquid(DefautlLiquids.getStack(bellow, 0));
this.tank.setLiquid(LiquidHandler.getStack(bellow, 0));
this.type = bellow;
}
@ -103,7 +107,7 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
}
if (this.tank.getLiquid() == null)
{
this.tank.setLiquid(DefautlLiquids.getStack(this.type, 1));
this.tank.setLiquid(LiquidHandler.getStack(this.type, 1));
}
LiquidStack stack = tank.getLiquid();
@ -165,7 +169,7 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
{
if (this.ticks % 10 == 0)
{
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);
}
}
@ -193,16 +197,17 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
{
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);
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 == type.liquid.itemID && this.isValidLiquid(Block.blocksList[bBlock]))
if (bBlock == LiquidData.getStack(type).itemID && this.isValidLiquid(Block.blocksList[bBlock]))
{
// FMLLog.info("pumping " + bellow.displayerName + " blockID:" + bBlock + " Meta:" +
// FMLLog.info("pumping " + bellow.displayerName + " blockID:" +
// bBlock + " Meta:" +
// meta);
int f = this.tank.fill(DefautlLiquids.getStack(this.type, LiquidContainerRegistry.BUCKET_VOLUME), true);
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;
@ -216,7 +221,7 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
{
try
{
this.type = (DefautlLiquids.getLiquid(data.readInt()));
this.type = (LiquidHandler.get(data.readUTF()));
}
catch (Exception e)
{
@ -229,31 +234,46 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(par1NBTTagCompound);
int stored = par1NBTTagCompound.getInteger("liquid");
this.type = DefautlLiquids.getLiquid(par1NBTTagCompound.getInteger("type"));
this.tank.setLiquid(DefautlLiquids.getStack(this.type, stored));
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 stored = nbt.getInteger("liquid");
this.tank.setLiquid(LiquidHandler.getStack(this.type, stored));
}
/**
* 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 = 1;
if (this.tank.getLiquid() != null)
s = this.tank.getLiquid().amount;
par1NBTTagCompound.setInteger("liquid", s);
par1NBTTagCompound.setInteger("type", this.type.ordinal());
if (this.tank.getLiquid() != null) s = this.tank.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";
int liquid = 0;
if (this.tank.getLiquid() != null)
{
@ -263,7 +283,7 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
{
liquid = 0;
}
return liquid + "" + type.displayerName + " " + this.joulesReceived + "W " + this.percentPumped + "/20";
return liquid + "" + LiquidData.getName(type) + " " + this.joulesReceived + "W " + this.percentPumped + "/20";
}
@Override
@ -306,28 +326,30 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
}
@Override
public int presureOutput(DefautlLiquids type, ForgeDirection dir)
public int presureOutput(LiquidData type, ForgeDirection dir)
{
if (type == this.type)
return type.defaultPresure;
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;
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;
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,14 +23,14 @@ 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 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);
@ -38,7 +39,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
{
if (tank.getLiquid() == null)
{
tank.setLiquid(DefautlLiquids.getStack(this.type, 1));
tank.setLiquid(LiquidHandler.getStack(this.type, 1));
}
LiquidStack liquid = tank.getLiquid();
@ -51,7 +52,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
this.tradeDown();
this.tradeArround();
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, new Object[] { type.ordinal(), liquid.amount });
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, new Object[] { LiquidData.getName(type), liquid.amount });
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 20);
}
@ -61,34 +62,47 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
@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;
output += (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidData.getName(type);
if (stack != null)
return output;
return "0/4 " + this.type.displayerName;
return "0/4 " + LiquidData.getName(type);
}
@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.converted = nbt.getBoolean("converted");
if (!converted)
{
int t = nbt.getInteger("type");
this.type = LiquidHandler.getFromMeta(t);
this.converted = true;
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
else
{
super.writeToNBT(par1NBTTagCompound);
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 writeToNBT(NBTTagCompound nbt)
{
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));
}
@Override
@ -96,8 +110,8 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
{
try
{
this.type = DefautlLiquids.getLiquid(data.readInt());
this.tank.setLiquid(DefautlLiquids.getStack(this.type, data.readInt()));
this.type = LiquidHandler.get(data.readUTF());
this.tank.setLiquid(LiquidHandler.getStack(this.type, data.readInt()));
}
catch (Exception e)
{
@ -110,13 +124,13 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
// ----------------------------
// Liquid stuff
// ----------------------------
public void setType(DefautlLiquids dm)
public void setType(LiquidData dm)
{
this.type = dm;
}
public DefautlLiquids getType()
public LiquidData getType()
{
return this.type;
}
@ -124,7 +138,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (!DefautlLiquids.isStackEqual(resource, type))
if (!LiquidHandler.isEqual(resource, type))
return 0;
return this.fill(0, resource, doFill);
}
@ -137,7 +151,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
if (this.isFull())
{
int change = 1;
if (DefautlLiquids.getLiquid(resource).doesFlaot)
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); }
@ -145,8 +159,10 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
this.doUpdate = true;
return this.tank.fill(resource, doFill);
}
/**
* find out if this tank is actual full or not
*
* @return
*/
public boolean isFull()
@ -157,9 +173,12 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
return false;
return true;
}
/**
* finds the first fillable tank in either direction
* @param top - search up
*
* @param top
* - search up
* @return
*/
public TileEntityTank getFillAbleTank(boolean top)
@ -199,13 +218,13 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
if (tankIndex != 0) {return null;}
if (tankIndex != 0) { return null; }
LiquidStack stack = this.tank.getLiquid();
if(maxDrain <= this.tank.getLiquid().amount)
if (maxDrain <= this.tank.getLiquid().amount)
{
stack = DefautlLiquids.getStack(type, maxDrain);
stack = LiquidHandler.getStack(type, maxDrain);
}
if(doDrain)
if (doDrain)
{
this.tank.drain(maxDrain, doDrain);
}
@ -225,33 +244,33 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
}
@Override
public int presureOutput(DefautlLiquids type, ForgeDirection dir)
public int presureOutput(LiquidData 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;
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(DefautlLiquids type, ForgeDirection dir)
public boolean canPressureToo(LiquidData type, ForgeDirection dir)
{
if (type == this.type)
{
if (type.doesFlaot && dir == ForgeDirection.DOWN)
if (LiquidData.getCanFloat(type) && dir == ForgeDirection.DOWN)
return true;
if (!type.doesFlaot && dir == ForgeDirection.UP)
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
* cause this TE to trade liquid down if the liquid is in liquid state or up
* if in gas state.
*/
public void tradeDown()
@ -265,9 +284,9 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
this.tank.drain(f, true);
}
}
/**
* Cause this TE to trade liquid with
* the Tanks around it to level off
* Cause this TE to trade liquid with the Tanks around it to level off
*/
public void tradeArround()
{
@ -299,11 +318,11 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
LiquidStack filling = this.tank.getLiquid();
if (stack == null)
{
filling = DefautlLiquids.getStack(this.type, equalVol);
filling = LiquidHandler.getStack(this.type, equalVol);
}
else if (stack.amount < equalVol)
{
filling = DefautlLiquids.getStack(this.type, equalVol - stack.amount);
filling = LiquidHandler.getStack(this.type, equalVol - stack.amount);
}
else
{