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; package liquidmechanics.api;
import liquidmechanics.common.handlers.DefautlLiquids; import liquidmechanics.common.handlers.LiquidData;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ITankContainer; import net.minecraftforge.liquids.ITankContainer;
@ -11,7 +11,7 @@ public interface ITankOutputer extends ITankContainer
* @param dir - direction pressure is being request to output * @param dir - direction pressure is being request to output
* @return pressure if can output for the type or direction * @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 * Quick way to check if the TE will output pressure
@ -20,5 +20,5 @@ public interface ITankOutputer extends ITankContainer
* @param dir - direction * @param dir - direction
* @return * @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; 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.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -49,9 +50,9 @@ public class TankHelper
return 0; return 0;
LiquidStack liquid = resource.copy(); LiquidStack liquid = resource.copy();
TileEntity[] connected = TankHelper.getSourounding(world, center.intX(), center.intY(), center.intZ()); 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; ForgeDirection firstTrade = ForgeDirection.UP;
if (!type.doesFlaot) if (!LiquidData.getCanFloat(type))
firstTrade = ForgeDirection.DOWN; firstTrade = ForgeDirection.DOWN;
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
@ -64,7 +65,7 @@ public class TankHelper
boolean validTank = false; boolean validTank = false;
for (int t = 0; t < tanks.length; t++) 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; validTank = true;
break; break;

View file

@ -3,84 +3,82 @@ package liquidmechanics.client.render;
import liquidmechanics.client.model.ModelLargePipe; import liquidmechanics.client.model.ModelLargePipe;
import liquidmechanics.client.model.ModelPipe; import liquidmechanics.client.model.ModelPipe;
import liquidmechanics.common.LiquidMechanics; 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 liquidmechanics.common.tileentity.TileEntityPipe;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
public class RenderPipe extends TileEntitySpecialRenderer public class RenderPipe extends TileEntitySpecialRenderer
{ {
private DefautlLiquids type = DefautlLiquids.DEFUALT; private LiquidData type = LiquidHandler.water;
private ModelPipe fourPipe; private ModelPipe fourPipe;
private ModelLargePipe SixPipe; private ModelLargePipe SixPipe;
private TileEntity[] ents = new TileEntity[6]; private TileEntity[] ents = new TileEntity[6];
public RenderPipe() public RenderPipe()
{ {
fourPipe = new ModelPipe(); fourPipe = new ModelPipe();
SixPipe = new ModelLargePipe(); SixPipe = new ModelLargePipe();
} }
public void renderAModelAt(TileEntity te, double d, double d1, double d2, float f) public void renderAModelAt(TileEntity te, double d, double d1, double d2, float f)
{ {
// Texture file // Texture file
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F); GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F); GL11.glScalef(1.0F, -1F, -1F);
if (te instanceof TileEntityPipe) if (te instanceof TileEntityPipe)
{ {
type = ((TileEntityPipe) te).getType(); type = ((TileEntityPipe) te).getType();
ents = ((TileEntityPipe) te).connectedBlocks; ents = ((TileEntityPipe) te).connectedBlocks;
} }
this.render(type, ents); this.render(type, ents);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
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/SixWaterPipe.png");
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixSteamPipe.png"); }
break; else if (type2 == LiquidHandler.lava)
case 1: {
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixWaterPipe.png"); bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixLavaPipe.png");
break; }
case 2: else if (type2 == LiquidHandler.steam)
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixLavaPipe.png"); {
break; bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixSteamPipe.png");
case 3: }
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixOilPipe.png"); else
break; {
default: bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/SixOilPipe.png");
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pipes/DefaultPipe.png"); }
break; if (ents[0] != null)
} SixPipe.renderBottom();
if (ents[0] != null) if (ents[1] != null)
SixPipe.renderBottom(); SixPipe.renderTop();
if (ents[1] != null) if (ents[3] != null)
SixPipe.renderTop(); SixPipe.renderFront();
if (ents[3] != null) if (ents[2] != null)
SixPipe.renderFront(); SixPipe.renderBack();
if (ents[2] != null) if (ents[5] != null)
SixPipe.renderBack(); SixPipe.renderRight();
if (ents[5] != null) if (ents[4] != null)
SixPipe.renderRight(); SixPipe.renderLeft();
if (ents[4] != null) SixPipe.renderMiddle();
SixPipe.renderLeft();
SixPipe.renderMiddle();
} }
@Override @Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{ {
this.renderAModelAt((TileEntityPipe) tileEntity, var2, var4, var6, 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.client.model.ModelPump;
import liquidmechanics.common.LiquidMechanics; 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 liquidmechanics.common.tileentity.TileEntityPump;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; 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) 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); int meta = tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
switch (type.ordinal()) switch (LiquidHandler.getMeta(type))
{ {
default: default:
bindTextureByName(LiquidMechanics.RESOURCE_PATH + "pumps/Pump.png"); 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.ModelLiquidTank;
import liquidmechanics.client.model.ModelLiquidTankCorner; import liquidmechanics.client.model.ModelLiquidTankCorner;
import liquidmechanics.common.LiquidMechanics; 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 liquidmechanics.common.tileentity.TileEntityTank;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -15,7 +16,7 @@ import org.lwjgl.opengl.GL11;
public class RenderTank extends TileEntitySpecialRenderer public class RenderTank extends TileEntitySpecialRenderer
{ {
private DefautlLiquids type = DefautlLiquids.DEFUALT; private LiquidData type = LiquidHandler.air;
private ModelLiquidTank model; private ModelLiquidTank model;
private ModelLiquidTankCorner modelC; private ModelLiquidTankCorner modelC;
private int pos = 0; private int pos = 0;
@ -57,7 +58,7 @@ public class RenderTank extends TileEntitySpecialRenderer
} }
else else
{ {
switch (type.ordinal()) switch (LiquidHandler.getMeta(type))
{ {
// case 0: // case 0:
// bindTextureByName(BasicPipesMain.textureFile+"/pipes/SixSteamPipe.png");break; // bindTextureByName(BasicPipesMain.textureFile+"/pipes/SixSteamPipe.png");break;

View file

@ -2,27 +2,27 @@ package liquidmechanics.common;
import java.io.File; import java.io.File;
import liquidmechanics.common.block.BlockReleaseValve;
import liquidmechanics.common.block.BlockGenerator; import liquidmechanics.common.block.BlockGenerator;
import liquidmechanics.common.block.BlockPipe;
import liquidmechanics.common.block.BlockMachine; import liquidmechanics.common.block.BlockMachine;
import liquidmechanics.common.block.BlockPipe;
import liquidmechanics.common.block.BlockReleaseValve;
import liquidmechanics.common.block.BlockRod; import liquidmechanics.common.block.BlockRod;
import liquidmechanics.common.block.BlockSteam; 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.ItemEValve;
import liquidmechanics.common.item.ItemGuage; import liquidmechanics.common.item.ItemGuage;
import liquidmechanics.common.item.ItemMachine; import liquidmechanics.common.item.ItemMachine;
import liquidmechanics.common.item.ItemParts; import liquidmechanics.common.item.ItemParts;
import liquidmechanics.common.item.ItemParts.Parts;
import liquidmechanics.common.item.ItemPipe; import liquidmechanics.common.item.ItemPipe;
import liquidmechanics.common.item.ItemTank; 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.TileEntityGenerator;
import liquidmechanics.common.tileentity.TileEntityPipe; import liquidmechanics.common.tileentity.TileEntityPipe;
import liquidmechanics.common.tileentity.TileEntityPump; import liquidmechanics.common.tileentity.TileEntityPump;
import liquidmechanics.common.tileentity.TileEntityReleaseValve;
import liquidmechanics.common.tileentity.TileEntityRod; import liquidmechanics.common.tileentity.TileEntityRod;
import liquidmechanics.common.tileentity.TileEntityTank; import liquidmechanics.common.tileentity.TileEntityTank;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -31,6 +31,7 @@ import net.minecraftforge.common.Configuration;
import net.minecraftforge.liquids.LiquidContainerRegistry; import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary; import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack; import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
import universalelectricity.prefab.network.PacketManager; import universalelectricity.prefab.network.PacketManager;
import cpw.mods.fml.common.DummyModContainer; 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) @NetworkMod(channels = { LiquidMechanics.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
public class LiquidMechanics extends DummyModContainer public class LiquidMechanics extends DummyModContainer
{ {
// TODO Change in Version Release // TODO Change in Version Release
public static final String VERSION = "0.2.3"; public static final String VERSION = "0.2.3";
// Constants // Constants
public static final String NAME = "Liquid Mechanics"; public static final String NAME = "Liquid Mechanics";
public static final String CHANNEL = "liquidMech"; public static final String CHANNEL = "liquidMech";
public static final String PATH = "/liquidmechanics/"; public static final String PATH = "/liquidmechanics/";
public static final String RESOURCE_PATH = PATH + "resource/"; public static final String RESOURCE_PATH = PATH + "resource/";
public static final String BLOCK_TEXTURE_FILE = RESOURCE_PATH + "blocks.png"; 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 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 Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir() + "/UniversalElectricity/", NAME + ".cfg"));
public final static int BLOCK_ID_PREFIX = 3100; public final static int BLOCK_ID_PREFIX = 3100;
public final static int LIQUID_ID_PREFIX = 200; public final static int LIQUID_ID_PREFIX = 200;
public final static int ITEM_ID_PREFIX = 13200; public final static int ITEM_ID_PREFIX = 13200;
public static Block blockPipe; public static Block blockPipe;
public static Block blockMachine; public static Block blockMachine;
public static Block blockRod; public static Block blockRod;
public static Block blockGenerator; public static Block blockGenerator;
public static Block blockReleaseValve; public static Block blockReleaseValve;
public static Block blockSteamBlock; public static Block blockSteamBlock;
public static LiquidStack liquidSteam; public static LiquidStack liquidSteam;
public static Item itemParts; public static Item itemParts;
public static Item itemPipes; public static Item itemPipes;
public static Item itemGauge; public static Item itemGauge;
public static Item itemOilBucket; public static Item itemOilBucket;
public static Item itemTank; public static Item itemTank;
@SidedProxy(clientSide = "liquidmechanics.client.ClientProxy", serverSide = "liquidmechanics.common.CommonProxy") @SidedProxy(clientSide = "liquidmechanics.client.ClientProxy", serverSide = "liquidmechanics.common.CommonProxy")
public static CommonProxy proxy; public static CommonProxy proxy;
@Instance(NAME) @Instance(NAME)
public static LiquidMechanics instance; public static LiquidMechanics instance;
@PreInit @PreInit
public void preInit(FMLPreInitializationEvent event) public void preInit(FMLPreInitializationEvent event)
{ {
instance = this; instance = this;
CONFIGURATION.load(); CONFIGURATION.load();
// Blocks // Blocks
blockPipe = new BlockPipe(this.CONFIGURATION.getBlock("Pipes", BLOCK_ID_PREFIX).getInt()); blockPipe = new BlockPipe(this.CONFIGURATION.getBlock("Pipes", BLOCK_ID_PREFIX).getInt());
blockMachine = new BlockMachine(this.CONFIGURATION.getBlock("Machines", BLOCK_ID_PREFIX + 1).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()); 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())); 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())); blockReleaseValve = new BlockReleaseValve((this.CONFIGURATION.getBlock("Release Valve", BLOCK_ID_PREFIX + 5).getInt()));
// Liquid Blocks // Liquid Blocks
blockSteamBlock = new BlockSteam(this.CONFIGURATION.getBlock("SteamBlock", LIQUID_ID_PREFIX).getInt()); blockSteamBlock = new BlockSteam(this.CONFIGURATION.getBlock("SteamBlock", LIQUID_ID_PREFIX).getInt());
// Items // Items
itemParts = new ItemParts(this.CONFIGURATION.getItem("Parts", ITEM_ID_PREFIX).getInt()); itemParts = new ItemParts(this.CONFIGURATION.getItem("Parts", ITEM_ID_PREFIX).getInt());
itemPipes = new ItemPipe(this.CONFIGURATION.getItem("PipeItem", ITEM_ID_PREFIX + 1).getInt()); itemPipes = new ItemPipe(this.CONFIGURATION.getItem("PipeItem", ITEM_ID_PREFIX + 1).getInt());
// Valve item // Valve item
itemGauge = new ItemGuage(this.CONFIGURATION.getItem("PipeGuage", ITEM_ID_PREFIX + 3).getInt()); itemGauge = new ItemGuage(this.CONFIGURATION.getItem("PipeGuage", ITEM_ID_PREFIX + 3).getInt());
itemTank = new ItemTank(this.CONFIGURATION.getItem("TankItem", ITEM_ID_PREFIX + 5).getInt()); itemTank = new ItemTank(this.CONFIGURATION.getItem("TankItem", ITEM_ID_PREFIX + 5).getInt());
// Liquid Registry // Liquid Registry
liquidSteam = LiquidDictionary.getOrCreateLiquid("Steam", new LiquidStack(blockSteamBlock, LiquidContainerRegistry.BUCKET_VOLUME)); liquidSteam = LiquidDictionary.getOrCreateLiquid("Steam", new LiquidStack(blockSteamBlock, LiquidContainerRegistry.BUCKET_VOLUME));
CONFIGURATION.save(); CONFIGURATION.save();
proxy.preInit(); proxy.preInit();
// block registry // block registry
GameRegistry.registerBlock(blockPipe, "Pipe"); GameRegistry.registerBlock(blockPipe, "Pipe");
GameRegistry.registerBlock(blockReleaseValve, ItemEValve.class, "Electric Valve"); GameRegistry.registerBlock(blockReleaseValve, ItemEValve.class, "Electric Valve");
GameRegistry.registerBlock(blockRod, "Mechanical Rod"); GameRegistry.registerBlock(blockRod, "Mechanical Rod");
GameRegistry.registerBlock(blockGenerator, "Generator"); GameRegistry.registerBlock(blockGenerator, "Generator");
GameRegistry.registerBlock(blockMachine, ItemMachine.class, "Machines"); GameRegistry.registerBlock(blockMachine, ItemMachine.class, "Machines");
GameRegistry.registerBlock(blockSteamBlock, "Steam"); GameRegistry.registerBlock(blockSteamBlock, "Steam");
} }
@Init @Init
public void Init(FMLInitializationEvent event) public void Init(FMLInitializationEvent event)
{ {
proxy.Init(); proxy.Init();
// TileEntities // TileEntities
GameRegistry.registerTileEntity(TileEntityPipe.class, "Pipe"); GameRegistry.registerTileEntity(TileEntityPipe.class, "Pipe");
GameRegistry.registerTileEntity(TileEntityPump.class, "Pump"); GameRegistry.registerTileEntity(TileEntityPump.class, "Pump");
GameRegistry.registerTileEntity(TileEntityRod.class, "Rod"); GameRegistry.registerTileEntity(TileEntityRod.class, "Rod");
GameRegistry.registerTileEntity(TileEntityReleaseValve.class, "Valve"); GameRegistry.registerTileEntity(TileEntityReleaseValve.class, "Valve");
GameRegistry.registerTileEntity(TileEntityTank.class, "Tank"); GameRegistry.registerTileEntity(TileEntityTank.class, "Tank");
GameRegistry.registerTileEntity(TileEntityGenerator.class, "Generator"); GameRegistry.registerTileEntity(TileEntityGenerator.class, "Generator");
// Liquid Item/Block common name writer // 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 // 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 // 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 // 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++) for (int i = 0; i < ItemParts.Parts.values().length; i++)
{ {
// parts // parts
LanguageRegistry.addName((new ItemStack(itemParts, 1, i)), ItemParts.Parts.values()[i].name); LanguageRegistry.addName((new ItemStack(itemParts, 1, i)), ItemParts.Parts.values()[i].name);
} }
// machines // machines
LanguageRegistry.addName((new ItemStack(blockMachine, 1, 0)), "Pump"); LanguageRegistry.addName((new ItemStack(blockMachine, 1, 0)), "Pump");
LanguageRegistry.addName((new ItemStack(blockMachine, 1, 4)), "Water Condensor"); LanguageRegistry.addName((new ItemStack(blockMachine, 1, 4)), "Water Condensor");
LanguageRegistry.addName((new ItemStack(blockGenerator, 1)), "Generator"); LanguageRegistry.addName((new ItemStack(blockGenerator, 1)), "Generator");
// mechanical rod // mechanical rod
LanguageRegistry.addName((new ItemStack(blockRod, 1)), "Geared Rod"); LanguageRegistry.addName((new ItemStack(blockRod, 1)), "Geared Rod");
// Tools // Tools
LanguageRegistry.addName((new ItemStack(itemGauge, 1, 0)), "Pipe Gauge"); LanguageRegistry.addName((new ItemStack(itemGauge, 1, 0)), "Pipe Gauge");
} }
@PostInit @PostInit
public void PostInit(FMLPostInitializationEvent event) public void PostInit(FMLPostInitializationEvent event)
{ {
proxy.postInit(); proxy.postInit();
TabLiquidMechanics.setItemStack(new ItemStack(itemPipes, 1, DefautlLiquids.WATER.ordinal())); TabLiquidMechanics.setItemStack(new ItemStack(itemPipes, 1, 1));
// generator // 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[] {
// pipe gauge "@T@", "OVO", "@T@",
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()) }); 'T', new ItemStack(LiquidMechanics.blockRod, 1),
// iron tube '@', "plateSteel",
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Bronze.ordinal()), new Object[] { "@@@", '@', Item.ingotIron }); 'O', "basicCircuit",
// obby tube 'V', "motor" }));
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Obby.ordinal()), new Object[] { "@@@", '@', Block.obsidian }); // pipe gauge
// nether tube GameRegistry.addRecipe(new ItemStack(this.itemGauge, 1, 0), new Object[] {
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Nether.ordinal()), new Object[] { "N@N", 'N', Block.netherrack, '@', new ItemStack(itemParts, 2, Parts.Obby.ordinal()) }); "TVT", " T ",
// seal 'V', new ItemStack(itemParts, 1, 7),
GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Seal.ordinal()), new Object[] { "@@", "@@", '@', Item.leather }); 'T', new ItemStack(itemParts, 1, Parts.Iron.ordinal()) });
// slime steal // iron tube
GameRegistry.addShapelessRecipe(new ItemStack(itemParts, 1, Parts.SlimeSeal.ordinal()), new Object[] { new ItemStack(itemParts, 1, Parts.Seal.ordinal()), new ItemStack(Item.slimeBall, 1) }); GameRegistry.addRecipe(new ItemStack(itemParts, 2, Parts.Iron.ordinal()), new Object[] {
// 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 }); '@', 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 // 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[] {
// mechanical rod " @ ", "@ @", " @ ",
GameRegistry.addRecipe(new ItemStack(blockRod, 1), new Object[] { "I@I", 'I', Item.ingotIron, '@', new ItemStack(itemParts, 1, Parts.Iron.ordinal()) }); '@', 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 // 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[] {
// water pipe new ItemStack(itemParts, 1, Parts.Iron.ordinal()),
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) }); new ItemStack(itemParts, 1, Parts.Seal.ordinal()) });
// lava pipe // water 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, 1), new Object[] {
/* new ItemStack(itemParts, 1, Parts.Iron.ordinal()),
* GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, Liquid.OIL.ordinal()), new new ItemStack(itemParts, 1, Parts.Seal.ordinal()),
* Object[] { new ItemStack(parts, 1, basicParts.Iron.ordinal()), new ItemStack(parts, 1, new ItemStack(Item.dyePowder, 1, 4) });
* basicParts.Seal.ordinal()), new ItemStack(Item.dyePowder, 1, 0) }); // lava pipe
* GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, Liquid.FUEL.ordinal()), new GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1, 2), new Object[] {
* Object[] { new ItemStack(parts, 1, basicParts.Iron.ordinal()), new ItemStack(parts, 1, new ItemStack(itemParts, 1, Parts.Obby.ordinal()),
* basicParts.Seal.ordinal()), new ItemStack(Item.dyePowder, 1, 11) }); 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) });
// 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()) });
// eVavles // steam tank
for (int i = 0; i < DefautlLiquids.values().length - 1; i++) GameRegistry.addShapelessRecipe(new ItemStack(itemTank, 1, 0), new Object[] {
{ new ItemStack(itemParts, 1, Parts.Tank.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()), }); 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.client.render.BlockRenderHelper;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.TabLiquidMechanics; import liquidmechanics.common.TabLiquidMechanics;
import liquidmechanics.common.handlers.DefautlLiquids; import liquidmechanics.common.handlers.LiquidHandler;
import liquidmechanics.common.tileentity.TileEntityPump; import liquidmechanics.common.tileentity.TileEntityPump;
import liquidmechanics.common.tileentity.TileEntityTank; import liquidmechanics.common.tileentity.TileEntityTank;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
@ -19,139 +19,139 @@ import net.minecraftforge.liquids.LiquidStack;
public class BlockMachine extends BlockContainer public class BlockMachine extends BlockContainer
{ {
public BlockMachine(int id) public BlockMachine(int id)
{ {
super(id, Material.iron); super(id, Material.iron);
this.setBlockName("Machine"); this.setBlockName("Machine");
this.setCreativeTab(TabLiquidMechanics.INSTANCE); this.setCreativeTab(TabLiquidMechanics.INSTANCE);
this.setRequiresSelfNotify(); this.setRequiresSelfNotify();
this.blockIndexInTexture = 26; this.blockIndexInTexture = 26;
this.setHardness(1f); this.setHardness(1f);
this.setResistance(5f); this.setResistance(5f);
} }
@Override @Override
public boolean isOpaqueCube() public boolean isOpaqueCube()
{ {
return false; return false;
} }
@Override @Override
public boolean renderAsNormalBlock() public boolean renderAsNormalBlock()
{ {
return false; return false;
} }
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ) 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(); ItemStack current = entityplayer.inventory.getCurrentItem();
if (current != null) 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) if (tileEntity instanceof TileEntityTank)
{ {
TileEntityTank tank = (TileEntityTank) tileEntity; TileEntityTank tank = (TileEntityTank) tileEntity;
// Handle filled containers // Handle filled containers
if (liquid != null) if (liquid != null)
{ {
int filled = tank.fill(ForgeDirection.UNKNOWN, liquid, true); int filled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
if (filled != 0 && !entityplayer.capabilities.isCreativeMode) 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; return true;
// Handle empty containers // Handle empty containers
} }
else else
{ {
LiquidStack stack = tank.tank.getLiquid(); LiquidStack stack = tank.tank.getLiquid();
if (stack != null) if (stack != null)
{ {
ItemStack liquidItem = LiquidContainerRegistry.fillLiquidContainer(stack, current); ItemStack liquidItem = LiquidContainerRegistry.fillLiquidContainer(stack, current);
liquid = LiquidContainerRegistry.getLiquidForFilledItem(liquidItem); liquid = LiquidContainerRegistry.getLiquidForFilledItem(liquidItem);
if (liquid != null) if (liquid != null)
{ {
if (!entityplayer.capabilities.isCreativeMode) if (!entityplayer.capabilities.isCreativeMode)
{ {
if (current.stackSize > 1) if (current.stackSize > 1)
{ {
if (!entityplayer.inventory.addItemStackToInventory(liquidItem)) if (!entityplayer.inventory.addItemStackToInventory(liquidItem)) return false;
return false; else
else {
{ entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, LiquidHandler.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, DefautlLiquids.consumeItem(current)); }
} }
} else
else {
{ entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, LiquidHandler.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, DefautlLiquids.consumeItem(current)); entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, liquidItem);
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, liquidItem); }
} }
} tank.tank.drain(liquid.amount, true);
tank.tank.drain(liquid.amount, true); return true;
return true; }
} }
} }
} }
} }
}
return false; return false;
} }
@Override
public int getRenderType()
{
return BlockRenderHelper.renderID;
}
@Override @Override
public int damageDropped(int meta) public int getRenderType()
{ {
if (meta < 4) { return 0; } return BlockRenderHelper.renderID;
return meta; }
}
@Override @Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) public int damageDropped(int meta)
{ {
int meta = world.getBlockMetadata(x, y, z); if (meta < 4) { return 0; }
if (meta < 4) return meta;
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 @Override
public TileEntity createNewTileEntity(World var1, int meta) public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{ {
if (meta < 4) { return new TileEntityPump(); } int meta = world.getBlockMetadata(x, y, z);
if (meta == 4) if (meta < 4)
{ new ItemStack(LiquidMechanics.blockMachine, 1, 0);
// return new TileEntityCondenser(); // if(meta == 4) ;
} TileEntity ent = world.getBlockTileEntity(x, y, z);
if (meta == 5) { return new TileEntityTank(); } if (ent instanceof TileEntityTank) return new ItemStack(LiquidMechanics.itemTank, 1, LiquidHandler.getMeta(((TileEntityTank) ent).type));
return null; 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 java.util.Random;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.LiquidHandler;
import liquidmechanics.common.tileentity.TileEntityPipe; import liquidmechanics.common.tileentity.TileEntityPipe;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
@ -93,7 +94,9 @@ public class BlockPipe extends BlockContainer
int meta = 0; int meta = 0;
if (ent instanceof TileEntityPipe) 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); return new ItemStack(LiquidMechanics.itemPipes, 1, 0);
} }
@ -107,7 +110,7 @@ public class BlockPipe extends BlockContainer
if (ent instanceof TileEntityPipe) if (ent instanceof TileEntityPipe)
{ {
TileEntityPipe pipe = (TileEntityPipe) ent; TileEntityPipe pipe = (TileEntityPipe) ent;
int meta = pipe.type.ordinal(); int meta = LiquidHandler.getMeta(pipe.type);
float var8 = furnaceRand.nextFloat() * 0.8F + 0.1F; float var8 = furnaceRand.nextFloat() * 0.8F + 0.1F;
float var9 = furnaceRand.nextFloat() * 0.8F + 0.1F; float var9 = furnaceRand.nextFloat() * 0.8F + 0.1F;
float var10 = 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); 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 class LiquidData
{ {
public final boolean isAGas; private boolean isAGas;
public final int defaultPresure; private int defaultPresure;
public final LiquidStack sampleStack; 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.sampleStack = stack;
this.isAGas = gas; this.isAGas = gas;
this.defaultPresure = dPressure; 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 java.util.List;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.tileentity.TileEntityPipe;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.liquids.LiquidDictionary; import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack; import net.minecraftforge.liquids.LiquidStack;
@ -18,19 +20,23 @@ public class LiquidHandler
public static LiquidData steam; public static LiquidData steam;
public static LiquidData water; public static LiquidData water;
public static LiquidData lava; public static LiquidData lava;
//public static LiquidData oil; TODO add public static LiquidData air;
//public static LiquidData fuel;
// public static LiquidData oil; TODO add
// public static LiquidData fuel;
/** /**
* Called to add the default liquids to the allowed list * Called to add the default liquids to the allowed list
*/ */
public static void addDefaultLiquids() 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); 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); 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); allowedLiquids.add(lava);
air = new LiquidData("Air", LiquidDictionary.getOrCreateLiquid("Air", new LiquidStack(0, 1)), false, 0);
allowedLiquids.add(air);
} }
@ForgeSubscribe @ForgeSubscribe
@ -38,16 +44,107 @@ public class LiquidHandler
{ {
// TODO use this to add new liquid types to the data list // TODO use this to add new liquid types to the data list
// or something along the lines of IDing liquids for use // 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 java.util.List;
import liquidmechanics.common.LiquidMechanics; 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 liquidmechanics.common.tileentity.TileEntityReleaseValve;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -32,16 +32,16 @@ public class ItemEValve extends ItemBlock
@Override @Override
public String getItemNameIS(ItemStack itemstack) public String getItemNameIS(ItemStack itemstack)
{ {
return "eValve"; return "release Valve";
} }
@Override @Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) 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)); par3List.add(new ItemStack(this, 1, i));
} }
} }
@Override @Override
@ -114,10 +114,10 @@ public class ItemEValve extends ItemBlock
if (blockEntity instanceof TileEntityReleaseValve) if (blockEntity instanceof TileEntityReleaseValve)
{ {
TileEntityReleaseValve pipeEntity = (TileEntityReleaseValve) blockEntity; TileEntityReleaseValve pipeEntity = (TileEntityReleaseValve) blockEntity;
DefautlLiquids dm = DefautlLiquids.getLiquid(itemstack.getItemDamage()); LiquidData dm = LiquidHandler.getFromMeta(itemstack.getItemDamage());
pipeEntity.setType(dm); pipeEntity.setType(dm);
pipeEntity.tank.setLiquid(DefautlLiquids.getStack(dm, 1)); world.setBlockMetadata(x, y, z, itemstack.getItemDamage() & 15);
world.setBlockMetadata(x, y, z, dm.ordinal() & 15); pipeEntity.converted = true;
} }
} }

View file

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

View file

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

View file

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

View file

@ -6,7 +6,8 @@ import liquidmechanics.api.IReadOut;
import liquidmechanics.api.ITankOutputer; import liquidmechanics.api.ITankOutputer;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.MetaGroupingHelper; 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.block.Block;
import net.minecraft.entity.player.EntityPlayer; 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 class TileEntityPump extends TileEntityElectricityReceiver implements IPacketReceiver, IReadOut, ITankOutputer
{ {
public final double WATTS_PER_TICK = 400; public final double WATTS_PER_TICK = 400;
double percentPumped = 0.0; double percentPumped = 0.0;
double joulesReceived = 0; double joulesReceived = 0;
int wMax = LiquidContainerRegistry.BUCKET_VOLUME * 2;
int disableTimer = 0; int wMax = LiquidContainerRegistry.BUCKET_VOLUME * 2;
int count = 0; 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; @Override
public LiquidTank tank = new LiquidTank(wMax); public void initiate()
{
this.registerConnections();
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, LiquidMechanics.blockMachine.blockID);
}
@Override public void registerConnections()
public void initiate() {
{ int notchMeta = MetaGroupingHelper.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
this.registerConnections(); ForgeDirection facing = ForgeDirection.getOrientation(notchMeta).getOpposite();
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, LiquidMechanics.blockMachine.blockID); 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() @Override
{ public void onDisable(int duration)
int notchMeta = MetaGroupingHelper.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); {
ForgeDirection facing = ForgeDirection.getOrientation(notchMeta).getOpposite(); disableTimer = duration;
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 @Override
public void onDisable(int duration) public boolean isDisabled()
{ {
disableTimer = duration; if (disableTimer <= 0) { return false; }
} return true;
}
@Override @Override
public boolean isDisabled() public void updateEntity()
{ {
if (disableTimer <= 0) { return false; } super.updateEntity();
return true;
}
@Override if (!this.worldObj.isRemote)
public void updateEntity() {
{ if (count-- <= 0)
super.updateEntity(); {
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) }
{ count = 40;
if (count-- <= 0) }
{ if (this.tank.getLiquid() == null)
int bBlock = worldObj.getBlockId(xCoord, yCoord - 1, zCoord); {
DefautlLiquids bellow = DefautlLiquids.getLiquidTypeByBlock(bBlock); this.tank.setLiquid(LiquidHandler.getStack(this.type, 1));
if (bellow != null) }
{ LiquidStack stack = tank.getLiquid();
if (this.type != bellow && bellow != DefautlLiquids.DEFUALT)
{
this.tank.setLiquid(DefautlLiquids.getStack(bellow, 0));
this.type = bellow;
}
} if (stack != null)
count = 40; {
} for (int i = 0; i < 6; i++)
if (this.tank.getLiquid() == null) {
{ ForgeDirection dir = ForgeDirection.getOrientation(i);
this.tank.setLiquid(DefautlLiquids.getStack(this.type, 1)); TileEntity tile = worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
}
LiquidStack stack = tank.getLiquid();
if (stack != null) if (tile instanceof ITankContainer)
{ {
for (int i = 0; i < 6; i++) int moved = ((ITankContainer) tile).fill(dir.getOpposite(), stack, true);
{ tank.drain(moved, true);
ForgeDirection dir = ForgeDirection.getOrientation(i); if (stack.amount <= 0)
TileEntity tile = worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ); 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)); for (int i = 2; i < 6; i++)
ForgeDirection facing = ForgeDirection.getOrientation(notchMeta).getOpposite(); {
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++) if (this.canPump(xCoord, yCoord - 1, zCoord))
{ {
ForgeDirection dir = ForgeDirection.getOrientation(i); network.startRequesting(this, WATTS_PER_TICK / this.getVoltage(), this.getVoltage());
if (dir != facing) this.joulesReceived = Math.max(Math.min(this.joulesReceived + network.consumeElectricity(this).getWatts(), WATTS_PER_TICK), 0);
{ }
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, new Vector3(this), dir); else
ElectricityNetwork network = ElectricityNetwork.getNetworkFromTileEntity(inputTile, dir); {
if (network != null) network.stopRequesting(this);
{ }
}
}
}
if (this.joulesReceived >= this.WATTS_PER_TICK - 50 && this.canPump(xCoord, yCoord - 1, zCoord))
{
if (this.canPump(xCoord, yCoord - 1, zCoord)) joulesReceived -= this.WATTS_PER_TICK;
{ if (percentPumped++ >= 20)
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); this.drainBlock(new Vector3(xCoord, yCoord - 1, zCoord));
} }
else }
{ }
network.stopRequesting(this);
}
}
}
}
if (this.joulesReceived >= this.WATTS_PER_TICK - 50 && this.canPump(xCoord, yCoord - 1, zCoord))
{
joulesReceived -= this.WATTS_PER_TICK; if (!this.worldObj.isRemote)
if (percentPumped++ >= 20) {
{ if (this.ticks % 10 == 0)
this.drainBlock(new Vector3(xCoord, yCoord - 1, zCoord)); {
} Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, LiquidData.getName(type));
} PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 60);
} }
}
}
if (!this.worldObj.isRemote) public boolean canPump(int x, int y, int z)
{ {
if (this.ticks % 10 == 0) // if (this.tank.getLiquid() == null) return false;
{ if (this.tank.getLiquid() != null && this.tank.getLiquid().amount >= this.wMax)
Packet packet = PacketManager.getPacket(LiquidMechanics.CHANNEL, this, this.type.ordinal()); return false;
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 60); 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) /**
{ * drains the block or in other words removes it
// if (this.tank.getLiquid() == null) return false; *
if (this.tank.getLiquid() != null && this.tank.getLiquid().amount >= this.wMax) * @param loc
return false; * @return true if the block was drained
if (this.isDisabled()) */
return false; public boolean drainBlock(Vector3 loc)
if (!this.isValidLiquid(Block.blocksList[worldObj.getBlockId(x, y, z)])) {
return false; int bBlock = worldObj.getBlockId(loc.intX(), loc.intY(), loc.intZ());
return true; 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;
}
/** @Override
* drains the block or in other words removes it public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput data)
* {
* @param loc try
* @return true if the block was drained {
*/ this.type = (LiquidHandler.get(data.readUTF()));
public boolean drainBlock(Vector3 loc) }
{ catch (Exception e)
int bBlock = worldObj.getBlockId(loc.intX(), loc.intY(), loc.intZ()); {
int meta = worldObj.getBlockMetadata(loc.intX(), loc.intY(), loc.intZ()); e.printStackTrace();
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 = (DefautlLiquids.getLiquid(data.readInt()));
}
catch (Exception e)
{
e.printStackTrace();
}
} /**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
/** this.converted = nbt.getBoolean("converted");
* Reads a tile entity from NBT. if (!converted)
*/ {
@Override int t = nbt.getInteger("type");
public void readFromNBT(NBTTagCompound par1NBTTagCompound) this.type = LiquidHandler.getFromMeta(t);
{ this.converted = true;
super.readFromNBT(par1NBTTagCompound); }
int stored = par1NBTTagCompound.getInteger("liquid"); else
this.type = DefautlLiquids.getLiquid(par1NBTTagCompound.getInteger("type")); {
this.tank.setLiquid(DefautlLiquids.getStack(this.type, stored)); this.type = LiquidHandler.get(nbt.getString("name"));
} }
if (this.type == null) type = LiquidHandler.air;
/** int stored = nbt.getInteger("liquid");
* Writes a tile entity to NBT. this.tank.setLiquid(LiquidHandler.getStack(this.type, stored));
*/ }
@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());
}
@Override /**
public String getMeterReading(EntityPlayer user, ForgeDirection side) * Writes a tile entity to NBT.
{ */
int liquid = 0; @Override
if (this.tank.getLiquid() != null) public void writeToNBT(NBTTagCompound nbt)
{ {
liquid = (this.tank.getLiquid().amount / LiquidContainerRegistry.BUCKET_VOLUME); super.writeToNBT(nbt);
} nbt.setBoolean("converted", this.converted);
else int s = 1;
{ if (this.tank.getLiquid() != null) s = this.tank.getLiquid().amount;
liquid = 0; nbt.setInteger("liquid", s);
}
return liquid + "" + type.displayerName + " " + this.joulesReceived + "W " + this.percentPumped + "/20";
}
@Override nbt.setString("name", LiquidData.getName(type));
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) }
{
return 0;
}
@Override @Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) public String getMeterReading(EntityPlayer user, ForgeDirection side)
{ {
return 0; 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 @Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{ {
return drain(0, maxDrain, doDrain); return 0;
} }
@Override @Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{ {
if (tankIndex == 0) return 0;
return tank.drain(maxDrain, doDrain); }
return null; @Override
} public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return drain(0, maxDrain, doDrain);
}
@Override @Override
public ILiquidTank[] getTanks(ForgeDirection direction) public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{ {
return new ILiquidTank[] { tank }; if (tankIndex == 0)
} return tank.drain(maxDrain, doDrain);
@Override return null;
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) }
{
return null;
}
@Override @Override
public int presureOutput(DefautlLiquids type, ForgeDirection dir) public ILiquidTank[] getTanks(ForgeDirection direction)
{ {
if (type == this.type) return new ILiquidTank[] { tank };
return type.defaultPresure; }
return 0;
}
@Override @Override
public boolean canPressureToo(DefautlLiquids type, ForgeDirection dir) public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{ {
if (type == this.type) return null;
return true; }
return false;
} @Override
/** public int presureOutput(LiquidData type, ForgeDirection dir)
* Checks to see if the given block type is valid for pumping {
* @param block if (type == this.type)
* @return return LiquidData.getPressure(type);
*/ return 0;
private boolean isValidLiquid(Block block) }
{
return DefautlLiquids.getLiquidFromBlock(block.blockID) != null; @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.ITankOutputer;
import liquidmechanics.api.helpers.TankHelper; import liquidmechanics.api.helpers.TankHelper;
import liquidmechanics.common.block.BlockReleaseValve; 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.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -18,11 +19,12 @@ import universalelectricity.prefab.implement.IRedstoneReceptor;
public class TileEntityReleaseValve extends TileEntity implements ITankOutputer, IReadOut, 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 LiquidTank tank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
public TileEntity[] connected = new TileEntity[6]; public TileEntity[] connected = new TileEntity[6];
private int count = 0; private int count = 0;
public boolean isPowered = false; public boolean isPowered = false;
public boolean converted = false;
@Override @Override
public void updateEntity() public void updateEntity()
@ -34,7 +36,7 @@ public class TileEntityReleaseValve extends TileEntity implements ITankOutputer,
BlockReleaseValve.checkForPower(worldObj, xCoord, yCoord, zCoord); BlockReleaseValve.checkForPower(worldObj, xCoord, yCoord, zCoord);
if (tank.getLiquid() == null) 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) 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++) for (int t = 0; t < tanks.length; t++)
{ {
LiquidStack ll = tanks[t].getLiquid(); 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; int drainVol = tank.getCapacity() - tank.getLiquid().amount - 1;
LiquidStack drained = ((ITankContainer) connected[i]).drain(t, drainVol, true); LiquidStack drained = ((ITankContainer) connected[i]).drain(t, drainVol, true);
@ -112,14 +114,14 @@ public class TileEntityReleaseValve extends TileEntity implements ITankOutputer,
} }
@Override @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; return 0;
} }
@Override @Override
public boolean canPressureToo(DefautlLiquids type, ForgeDirection dir) public boolean canPressureToo(LiquidData type, ForgeDirection dir)
{ {
if (type == this.type) if (type == this.type)
return true; return true;
@ -129,41 +131,49 @@ public class TileEntityReleaseValve extends TileEntity implements ITankOutputer,
@Override @Override
public String getMeterReading(EntityPlayer user, ForgeDirection side) public String getMeterReading(EntityPlayer user, ForgeDirection side)
{ {
if (type == null) return "Error: No Type";
String output = ""; String output = "";
LiquidStack stack = tank.getLiquid(); LiquidStack stack = tank.getLiquid();
if (stack != null) 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) if (stack != null)
return output; return output;
return "0/0 " + LiquidData.getName(type) + " on = " + !this.isPowered;
return "0/0 " + this.type.displayerName + " on = " + !this.isPowered;
} }
@Override @Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound) public void readFromNBT(NBTTagCompound nbt)
{ {
super.readFromNBT(par1NBTTagCompound); super.readFromNBT(nbt);
this.type = DefautlLiquids.getLiquid(par1NBTTagCompound.getInteger("type")); this.type = LiquidHandler.get(nbt.getString("name"));
int vol = par1NBTTagCompound.getInteger("liquid"); this.converted = nbt.getBoolean("converted");
this.tank.setLiquid(DefautlLiquids.getStack(type, vol)); 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. * Writes a tile entity to NBT.
*/ */
@Override @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; int s = 0;
LiquidStack stack = this.tank.getLiquid(); if (tank.getLiquid() != null) s = tank.getLiquid().amount;
if (stack != null) nbt.setInteger("liquid", s);
s = stack.amount;
par1NBTTagCompound.setInteger("liquid", s); nbt.setString("name", LiquidData.getName(type));
par1NBTTagCompound.setInteger("type", this.type.ordinal());
} }
public void setType(DefautlLiquids dm) public void setType(LiquidData dm)
{ {
this.type = dm; this.type = dm;

View file

@ -4,7 +4,8 @@ import liquidmechanics.api.IReadOut;
import liquidmechanics.api.ITankOutputer; import liquidmechanics.api.ITankOutputer;
import liquidmechanics.api.helpers.TankHelper; import liquidmechanics.api.helpers.TankHelper;
import liquidmechanics.common.LiquidMechanics; 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.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;
@ -22,297 +23,315 @@ import universalelectricity.prefab.network.PacketManager;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
public class TileEntityTank extends TileEntity implements IPacketReceiver, IReadOut, ITankOutputer public class TileEntityTank extends TileEntity implements IPacketReceiver, IReadOut, ITankOutputer
{ {
public TileEntity[] cc = { null, null, null, null, null, null }; 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; public static final int LMax = 4;
private int count = 0; private int count = 0;
private int count2 = 0; private int count2 = 0;
public boolean converted = false;
private boolean doUpdate = true; private boolean doUpdate = true;
public LiquidTank tank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME * LMax); public LiquidTank tank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME * LMax);
public void updateEntity() public void updateEntity()
{ {
if (tank.getLiquid() == null) if (tank.getLiquid() == null)
{ {
tank.setLiquid(DefautlLiquids.getStack(this.type, 1)); tank.setLiquid(LiquidHandler.getStack(this.type, 1));
} }
LiquidStack liquid = tank.getLiquid(); LiquidStack liquid = tank.getLiquid();
if (++count >= 20 && liquid != null) if (++count >= 20 && liquid != null)
{ {
count = 0; count = 0;
this.cc = TankHelper.getSourounding(worldObj, xCoord, yCoord, zCoord); this.cc = TankHelper.getSourounding(worldObj, xCoord, yCoord, zCoord);
if (!worldObj.isRemote) if (!worldObj.isRemote)
{ {
this.tradeDown(); this.tradeDown();
this.tradeArround(); 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); PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 20);
} }
} }
} }
@Override @Override
public String getMeterReading(EntityPlayer user, ForgeDirection side) public String getMeterReading(EntityPlayer user, ForgeDirection side)
{ {
String output = ""; if (type == null) return "Error: No Type";
LiquidStack stack = tank.getLiquid(); String output = "";
if (stack != null) LiquidStack stack = tank.getLiquid();
output += (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + " " + this.type.displayerName; if (stack != null)
if (stack != null) output += (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidData.getName(type);
return output; 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 @Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound) public void writeToNBT(NBTTagCompound nbt)
{ {
super.readFromNBT(par1NBTTagCompound); super.writeToNBT(nbt);
this.type = DefautlLiquids.getLiquid(par1NBTTagCompound.getInteger("type")); nbt.setBoolean("converted", this.converted);
int vol = par1NBTTagCompound.getInteger("liquid"); int s = 0;
this.tank.setLiquid(DefautlLiquids.getStack(type, vol)); if (tank.getLiquid() != null) s = tank.getLiquid().amount;
} nbt.setInteger("liquid", s);
@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 nbt.setString("name", LiquidData.getName(type));
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");
}
} @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 LiquidData getType()
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) {
{ return this.type;
if (!DefautlLiquids.isStackEqual(resource, type)) }
return 0;
return this.fill(0, resource, doFill);
}
@Override @Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{ {
if (resource == null || tankIndex != 0) if (!LiquidHandler.isEqual(resource, type))
return 0; return 0;
if (this.isFull()) return this.fill(0, resource, doFill);
{ }
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 @Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{ {
return this.drain(0, maxDrain, doDrain); 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) * find out if this tank is actual full or not
{ *
if (tankIndex != 0) {return null;} * @return
LiquidStack stack = this.tank.getLiquid(); */
if(maxDrain <= this.tank.getLiquid().amount) public boolean isFull()
{ {
stack = DefautlLiquids.getStack(type, maxDrain); if (this.tank.getLiquid() == null)
} return false;
if(doDrain) if (this.tank.getLiquid().amount > 0 && this.tank.getLiquid().amount < this.tank.getCapacity())
{ return false;
this.tank.drain(maxDrain, doDrain); return true;
} }
return stack;
}
@Override /**
public ILiquidTank[] getTanks(ForgeDirection direction) * finds the first fillable tank in either direction
{ *
return new ILiquidTank[] { tank }; * @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 @Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{ {
return null; return this.drain(0, maxDrain, doDrain);
} }
@Override @Override
public int presureOutput(DefautlLiquids type, ForgeDirection dir) public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{ {
if (type == this.type) if (tankIndex != 0) { return null; }
{ LiquidStack stack = this.tank.getLiquid();
if (type.doesFlaot && dir == ForgeDirection.DOWN) if (maxDrain <= this.tank.getLiquid().amount)
return type.defaultPresure; {
if (!type.doesFlaot && dir == ForgeDirection.UP) stack = LiquidHandler.getStack(type, maxDrain);
return type.defaultPresure; }
} if (doDrain)
return 0; {
} this.tank.drain(maxDrain, doDrain);
}
return stack;
}
@Override @Override
public boolean canPressureToo(DefautlLiquids type, ForgeDirection dir) public ILiquidTank[] getTanks(ForgeDirection direction)
{ {
if (type == this.type) return new ILiquidTank[] { tank };
{ }
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;
if (ents[i] instanceof TileEntityTank && ((TileEntityTank) ents[i]).type == this.type && !((TileEntityTank) ents[i]).isFull()) @Override
{ public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
LiquidStack stack = ((TileEntityTank) ents[i]).tank.getLiquid(); {
LiquidStack filling = this.tank.getLiquid(); return null;
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 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);
}
}
}
} }