IndustrialElectrolyzer now uses fluids

IndustrialElectrolyzer now renders fluids in gui
IndustrialElectrolyzer recipe handler now renders fluids
This commit is contained in:
Gig 2015-06-26 17:56:09 +01:00
parent 6cc1071961
commit 6e74b9197b
6 changed files with 175 additions and 15 deletions

View file

@ -1,11 +1,17 @@
package techreborn.api.recipe.machines;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import techreborn.api.recipe.BaseRecipe;
import techreborn.tiles.TileGrinder;
import techreborn.tiles.TileIndustrialElectrolyzer;
public class IndustrialElectrolyzerRecipe extends BaseRecipe {
public FluidStack fluidStack;
public IndustrialElectrolyzerRecipe(ItemStack inputCells, ItemStack input2, ItemStack output1, ItemStack output2, ItemStack output3, ItemStack output4, int tickTime, int euPerTick)
public IndustrialElectrolyzerRecipe(ItemStack inputCells, ItemStack input2, FluidStack fluidStack, ItemStack output1, ItemStack output2, ItemStack output3, ItemStack output4, int tickTime, int euPerTick)
{
super("industrialElectrolyzerRecipe", tickTime, euPerTick);
if (inputCells != null)
@ -20,5 +26,49 @@ public class IndustrialElectrolyzerRecipe extends BaseRecipe {
addOutput(output3);
if (output4 != null)
addOutput(output4);
this.fluidStack = fluidStack;
}
@Override
public boolean canCraft(TileEntity tile) {
if (fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialElectrolyzer) {
TileIndustrialElectrolyzer grinder = (TileIndustrialElectrolyzer) tile;
if (grinder.tank.getFluid() == null) {
return false;
}
if (grinder.tank.getFluid().getFluidID() == fluidStack.getFluidID()) {
if (grinder.tank.getFluidAmount() >= fluidStack.amount) {
return true;
}
}
}
return false;
}
@Override
public boolean onCraft(TileEntity tile) {
if (fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialElectrolyzer) {
TileIndustrialElectrolyzer grinder = (TileIndustrialElectrolyzer) tile;
if (grinder.tank.getFluid() == null) {
return false;
}
if (grinder.tank.getFluid().getFluidID() == fluidStack.getFluidID()) {
if (grinder.tank.getFluidAmount() >= fluidStack.amount) {
if (grinder.tank.getFluidAmount() > 0) {
grinder.tank.setFluid(new FluidStack(fluidStack.getFluid(), grinder.tank.getFluidAmount() - fluidStack.amount));
} else {
grinder.tank.setFluid(null);
}
return true;
}
}
}
return false;
}
}

View file

@ -5,7 +5,7 @@ import net.minecraft.inventory.Slot;
import techreborn.client.SlotOutput;
import techreborn.tiles.TileIndustrialElectrolyzer;
public class ContainerIndustrialElectrolyzer extends TechRebornContainer {
public class ContainerIndustrialElectrolyzer extends ContainerCrafting {
EntityPlayer player;
@ -19,9 +19,9 @@ public class ContainerIndustrialElectrolyzer extends TechRebornContainer {
public int tickTime;
public ContainerIndustrialElectrolyzer(TileIndustrialElectrolyzer electrolyzer,
EntityPlayer player)
public ContainerIndustrialElectrolyzer(TileIndustrialElectrolyzer electrolyzer, EntityPlayer player)
{
super(electrolyzer.crafter);
tile = electrolyzer;
this.player = player;
@ -38,7 +38,6 @@ public class ContainerIndustrialElectrolyzer extends TechRebornContainer {
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)

View file

@ -1,18 +1,22 @@
package techreborn.client.gui;
import ic2.core.util.DrawUtil;
import codechicken.lib.gui.GuiDraw;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import techreborn.client.container.ContainerIndustrialElectrolyzer;
import techreborn.lib.ModInfo;
import techreborn.tiles.TileIndustrialElectrolyzer;
public class GuiIndustrialElectrolyzer extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation(
"techreborn", "textures/gui/industrial_electrolyzer.png");
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/industrial_electrolyzer.png");
TileIndustrialElectrolyzer eletrolyzer;
@ -27,22 +31,39 @@ public class GuiIndustrialElectrolyzer extends GuiContainer {
@Override
public void initGui() {
this.buttonList.clear();
// this.buttonList.clear();
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.buttonList.add(new GuiButton(0, k + 4, l + 4, 20, 20, "R"));
// this.buttonList.add(new GuiButton(0, k + 4, l + 4, 20, 20, "R"));
super.initGui();
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_,
int p_146976_2_, int p_146976_3_)
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_)
{
this.mc.getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
if (eletrolyzer.tank.getFluidAmount() != 0)
{
IIcon fluidIcon = eletrolyzer.tank.getFluid().getFluid().getIcon();
if (fluidIcon != null)
{
drawTexturedModalRect(k + 7, l + 15, 176, 31, 20, 55);
this.mc.renderEngine
.bindTexture(TextureMap.locationBlocksTexture);
int liquidHeight = eletrolyzer.tank.getFluidAmount() * 47
/ eletrolyzer.tank.getCapacity();
DrawUtil.drawRepeated(fluidIcon, k + 11, l + 19 + 47
- liquidHeight, 12.0D, liquidHeight, this.zLevel);
this.mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(k + 11, l + 19, 176, 86, 12, 47);
}
}
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_,

View file

@ -1,10 +1,19 @@
package techreborn.compat.nei.recipes;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.TemplateRecipeHandler.CachedRecipe;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.IIcon;
import techreborn.api.recipe.IBaseRecipeType;
import techreborn.api.recipe.machines.GrinderRecipe;
import techreborn.api.recipe.machines.IndustrialElectrolyzerRecipe;
import techreborn.client.gui.GuiIndustrialElectrolyzer;
import techreborn.compat.nei.recipes.GenericRecipeHander.CachedGenericRecipe;
import techreborn.util.ItemUtils;
import ic2.core.util.DrawUtil;
import java.util.List;
@ -60,4 +69,27 @@ public class IndustrialElectrolyzerRecipeHandler extends GenericRecipeHander imp
public INeiBaseRecipe getNeiBaseRecipe() {
return this;
}
@Override
public void drawBackground(int recipeIndex) {
super.drawBackground(recipeIndex);
CachedRecipe recipe = arecipes.get(recipeIndex);
if (recipe instanceof CachedGenericRecipe) {
if (((CachedGenericRecipe) recipe).recipie instanceof IndustrialElectrolyzerRecipe) {
IndustrialElectrolyzerRecipe grinderRecipe = (IndustrialElectrolyzerRecipe) ((CachedGenericRecipe) recipe).recipie;
if (grinderRecipe.fluidStack != null) {
IIcon fluidIcon = grinderRecipe.fluidStack.getFluid().getIcon();
if (fluidIcon != null) {
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
int liquidHeight = grinderRecipe.fluidStack.amount * 100 / 16000;
DrawUtil.drawRepeated(fluidIcon, 7, 22 + 47 - liquidHeight, 14.0D, liquidHeight, GuiDraw.gui.getZLevel());
}
GuiDraw.drawString(grinderRecipe.fluidStack.amount + "mb of " + grinderRecipe.fluidStack.getLocalizedName(), 14, 135, -1);
}
}
}
}
}

View file

@ -1919,7 +1919,7 @@ public class ModRecipes {
}
static void addIndustrialElectrolyzerRecipes() {
RecipeHandler.addRecipe(new IndustrialElectrolyzerRecipe(null, ItemDusts.getDustByName("chrome"), ItemGems.getGemByName("ruby"), null, null, null, 100, 128));
RecipeHandler.addRecipe(new IndustrialElectrolyzerRecipe(null, ItemDusts.getDustByName("chrome"), new FluidStack(FluidRegistry.WATER, 1000), ItemGems.getGemByName("ruby"), null, null, null, 100, 128));
}
}

View file

@ -9,17 +9,25 @@ import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import techreborn.api.recipe.RecipeCrafter;
import techreborn.init.ModBlocks;
import techreborn.init.ModFluids;
import techreborn.util.Inventory;
import techreborn.util.Tank;
import java.util.List;
public class TileIndustrialElectrolyzer extends TileMachineBase implements IWrenchable, IEnergyTile, IInventory, ISidedInventory {
public class TileIndustrialElectrolyzer extends TileMachineBase implements IWrenchable, IEnergyTile, IFluidHandler, IInventory, ISidedInventory {
public int tickTime;
public BasicSink energy;
public Inventory inventory = new Inventory(7, "TileIndustrialElectrolyzer", 64);
public Tank tank = new Tank("TileIndustrialElectrolyzer", 16000, this);
public RecipeCrafter crafter;
public TileIndustrialElectrolyzer()
@ -32,7 +40,7 @@ public class TileIndustrialElectrolyzer extends TileMachineBase implements IWren
inputs[1] = 1;
int[] outputs = new int[1];
outputs[0] = 2;
crafter = new RecipeCrafter("industrialelectrolyzerRecipe", this, energy, 2, 2, inventory, inputs, outputs);
crafter = new RecipeCrafter("industrialelectrolyzerRecipe", this, energy, 2, 1, inventory, inputs, outputs);
}
@Override
@ -93,6 +101,8 @@ public class TileIndustrialElectrolyzer extends TileMachineBase implements IWren
super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
energy.readFromNBT(tagCompound);
crafter.readFromNBT(tagCompound);
tank.readFromNBT(tagCompound);
}
@Override
@ -101,6 +111,8 @@ public class TileIndustrialElectrolyzer extends TileMachineBase implements IWren
super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
energy.writeToNBT(tagCompound);
tank.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
@Override
@ -207,4 +219,50 @@ public class TileIndustrialElectrolyzer extends TileMachineBase implements IWren
return slotIndex == 2 || slotIndex == 3 || slotIndex == 4 || slotIndex == 5;
}
/* IFluidHandler */
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if(resource.getFluid() == FluidRegistry.WATER || resource.getFluid() == ModFluids.fluidMercury || resource.getFluid() == ModFluids.fluidSodiumpersulfate) {
int filled = tank.fill(resource, doFill);
tank.compareAndUpdate();
return filled;
}
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
if (resource == null || !resource.isFluidEqual(tank.getFluid())) {
return null;
}
FluidStack fluidStack = tank.drain(resource.amount, doDrain);
tank.compareAndUpdate();
return fluidStack;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
FluidStack drained = tank.drain(maxDrain, doDrain);
tank.compareAndUpdate();
return drained;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
if(fluid == FluidRegistry.WATER || fluid == ModFluids.fluidMercury || fluid == ModFluids.fluidSodiumpersulfate) {
return true;
}
return false;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
return false;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
return new FluidTankInfo[] { tank.getInfo() };
}
}