mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-24 05:54:27 +00:00
Tanks in the Vat NEI handler can be clicked to look up crafting/usage of the fluids
This commit is contained in:
1 parent
061e8adb09
commit
e73d518519
2 files changed
+130
-77
No files matched your search
@@ -8,15 +8,15 @@ import java.util.List;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.RecipeInfo;
|
||||
import codechicken.nei.recipe.GuiUsageRecipe;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
@@ -25,13 +25,12 @@ import crazypants.enderio.machine.recipe.RecipeInput;
|
||||
import crazypants.enderio.machine.still.GuiVat;
|
||||
import crazypants.enderio.machine.still.VatRecipeManager;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.FluidUtil;
|
||||
|
||||
public class VatRecipeHandler extends TemplateRecipeHandler {
|
||||
|
||||
private Rectangle inTankBounds = new Rectangle(25, 1, 15, 47);
|
||||
private Rectangle outTankBounds = new Rectangle(127, 1, 15, 47);
|
||||
private Rectangle inTankBoundsLower = new Rectangle(25, 70, 15, 47);
|
||||
private Rectangle outTankBoundsLower = new Rectangle(127, 70, 15, 47);
|
||||
|
||||
public VatRecipeHandler() {
|
||||
}
|
||||
@@ -65,64 +64,77 @@ public class VatRecipeHandler extends TemplateRecipeHandler {
|
||||
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(149, 32, 16, 16), "EnderIOVat", new Object[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(final ItemStack result) {
|
||||
if(result == null) {
|
||||
return;
|
||||
}
|
||||
if(FluidContainerRegistry.isFilledContainer(result)) {
|
||||
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(result);
|
||||
if(fluid != null) {
|
||||
List<IRecipe> recipes = VatRecipeManager.getInstance().getRecipes();
|
||||
for (IRecipe recipe : recipes) {
|
||||
FluidStack output = recipe.getOutputs()[0].getFluidOutput();
|
||||
if(output.isFluidEqual(fluid)) {
|
||||
InnerVatRecipe res = new InnerVatRecipe(recipe.getEnergyRequired(), recipe.getInputs(), output);
|
||||
arecipes.add(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object... results) {
|
||||
if(outputId.equals("EnderIOVat") && getClass() == VatRecipeHandler.class) {
|
||||
if(outputId.equals("liquid")) {
|
||||
loadCraftingRecipes((FluidStack) results[0]);
|
||||
} else if(outputId.equals("EnderIOVat") && getClass() == VatRecipeHandler.class) {
|
||||
List<IRecipe> recipes = VatRecipeManager.getInstance().getRecipes();
|
||||
for (IRecipe recipe : recipes) {
|
||||
FluidStack output = recipe.getOutputs()[0].getFluidOutput();
|
||||
InnerVatRecipe res = new InnerVatRecipe(recipe.getEnergyRequired(), recipe.getInputs(), output);
|
||||
arecipes.add(res);
|
||||
}
|
||||
|
||||
} else {
|
||||
super.loadCraftingRecipes(outputId, results);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(ItemStack ingredient) {
|
||||
public void loadCraftingRecipes(ItemStack result) {
|
||||
FluidStack fluid = FluidUtil.getFluidFromItem(result);
|
||||
if(fluid != null) {
|
||||
loadCraftingRecipes(fluid);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadCraftingRecipes(FluidStack result) {
|
||||
List<IRecipe> recipes = VatRecipeManager.getInstance().getRecipes();
|
||||
for (IRecipe recipe : recipes) {
|
||||
boolean addRecipe = false;
|
||||
if(recipe.isValidInput(0, ingredient) || recipe.isValidInput(1, ingredient)) {
|
||||
addRecipe = true;
|
||||
} else if(FluidContainerRegistry.isFilledContainer(ingredient)) {
|
||||
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(ingredient);
|
||||
if(fluid != null) {
|
||||
if(recipe.isValidInput(fluid)) {
|
||||
addRecipe = true;
|
||||
}
|
||||
}
|
||||
FluidStack output = recipe.getOutputs()[0].getFluidOutput();
|
||||
if(output.isFluidEqual(result)) {
|
||||
InnerVatRecipe res = new InnerVatRecipe(recipe.getEnergyRequired(), recipe.getInputs(), output);
|
||||
arecipes.add(res);
|
||||
}
|
||||
if(addRecipe) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(String inputId, Object... ingredients) {
|
||||
if(inputId.equals("liquid")) {
|
||||
loadUsageRecipes((FluidStack) ingredients[0]);
|
||||
} else {
|
||||
super.loadUsageRecipes(inputId, ingredients);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(ItemStack ingredient) {
|
||||
FluidStack fluid = FluidUtil.getFluidFromItem(ingredient);
|
||||
if(fluid != null) {
|
||||
loadUsageRecipes(fluid);
|
||||
}
|
||||
|
||||
List<IRecipe> recipes = VatRecipeManager.getInstance().getRecipes();
|
||||
for (IRecipe recipe : recipes) {
|
||||
if(recipe.isValidInput(0, ingredient) || recipe.isValidInput(1, ingredient)) {
|
||||
FluidStack output = recipe.getOutputs()[0].getFluidOutput();
|
||||
InnerVatRecipe res = new InnerVatRecipe(recipe.getEnergyRequired(), recipe.getInputs(), output);
|
||||
res.setIngredientPermutation(res.inputs, ingredient);
|
||||
arecipes.add(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUsageRecipes(FluidStack ingredient) {
|
||||
List<IRecipe> recipes = VatRecipeManager.getInstance().getRecipes();
|
||||
for (IRecipe recipe : recipes) {
|
||||
if(recipe.isValidInput(ingredient)) {
|
||||
FluidStack output = recipe.getOutputs()[0].getFluidOutput();
|
||||
InnerVatRecipe res = new InnerVatRecipe(recipe.getEnergyRequired(), recipe.getInputs(), output);
|
||||
arecipes.add(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,7 +148,8 @@ public class VatRecipeHandler extends TemplateRecipeHandler {
|
||||
public void drawExtras(int recipeIndex) {
|
||||
InnerVatRecipe rec = (InnerVatRecipe) arecipes.get(recipeIndex);
|
||||
if(rec.inFluid != null && rec.inFluid.getFluid() != null) {
|
||||
RenderUtil.renderGuiTank(rec.inFluid, rec.inFluid.amount, rec.inFluid.amount, inTankBounds.x, inTankBounds.y, 0, inTankBounds.width, inTankBounds.height);
|
||||
RenderUtil.renderGuiTank(rec.inFluid, rec.inFluid.amount, rec.inFluid.amount, inTankBounds.x, inTankBounds.y, 0, inTankBounds.width,
|
||||
inTankBounds.height);
|
||||
}
|
||||
|
||||
if(rec.result != null && rec.result.getFluid() != null) {
|
||||
@@ -164,40 +177,69 @@ public class VatRecipeHandler extends TemplateRecipeHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiRecipe gui, List<String> arg1, int recipeIndex) {
|
||||
|
||||
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipeIndex) {
|
||||
InnerVatRecipe rec = (InnerVatRecipe) arecipes.get(recipeIndex);
|
||||
Point pos = GuiDraw.getMousePosition();
|
||||
Point offset = gui.getRecipePosition(recipeIndex);
|
||||
Point relMouse = new Point(pos.x - ((gui.width - 176) / 2) - offset.x, pos.y - ((gui.height - 166) / 2) - offset.y);
|
||||
|
||||
int[] offset = RecipeInfo.getGuiOffset(gui);
|
||||
Point relMouse = new Point(pos.x - ((gui.width - 176) / 2) - offset[0], pos.y - ((gui.height - 166) / 2) - offset[1]);
|
||||
|
||||
if(mouseInBounds(relMouse)) {
|
||||
if(recipeIndex % 2 == 0 && inTankBounds.union(outTankBounds).contains(relMouse)) {
|
||||
return getVatFluid(recipeIndex, arg1, inTankBounds.contains(relMouse));
|
||||
}
|
||||
else if(recipeIndex % 2 == 1 && inTankBoundsLower.union(outTankBoundsLower).contains(relMouse)) {
|
||||
return getVatFluid(recipeIndex, arg1, inTankBoundsLower.contains(relMouse));
|
||||
if(inTankBounds.contains(relMouse) || outTankBounds.contains(relMouse)) {
|
||||
if(inTankBounds.contains(relMouse)) {
|
||||
if(rec.inFluid != null && rec.inFluid.getFluid() != null) {
|
||||
currenttip.add(rec.inFluid.getFluid().getLocalizedName(rec.inFluid));
|
||||
}
|
||||
} else {
|
||||
if(rec.result != null && rec.result.getFluid() != null) {
|
||||
currenttip.add(rec.result.getFluid().getLocalizedName(rec.result));
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.handleTooltip(gui, arg1, recipeIndex);
|
||||
return super.handleTooltip(gui, currenttip, recipeIndex);
|
||||
}
|
||||
|
||||
private boolean mouseInBounds(Point mouse) {
|
||||
return inTankBounds.contains(mouse) || outTankBounds.contains(mouse) || inTankBoundsLower.contains(mouse) || outTankBoundsLower.contains(mouse);
|
||||
}
|
||||
|
||||
private List<String> getVatFluid(int index, List<String> list, boolean in) {
|
||||
InnerVatRecipe rec = (InnerVatRecipe) arecipes.get(index);
|
||||
if(in) {
|
||||
if(rec.inFluid != null && rec.inFluid.getFluid() != null) {
|
||||
list.add(rec.inFluid.getFluid().getLocalizedName(rec.inFluid));
|
||||
@Override
|
||||
public boolean mouseClicked(GuiRecipe gui, int button, int recipeIndex) {
|
||||
if(button == 0) {
|
||||
if(this.transferFluidTanks(gui, recipeIndex, false)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if(rec.result != null && rec.result.getFluid() != null) {
|
||||
list.add(rec.result.getFluid().getLocalizedName(rec.result));
|
||||
} else if(button == 1) {
|
||||
if(this.transferFluidTanks(gui, recipeIndex, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return super.mouseClicked(gui, button, recipeIndex);
|
||||
}
|
||||
|
||||
private boolean transferFluidTanks(GuiRecipe gui, int recipeIndex, boolean usage) {
|
||||
InnerVatRecipe rec = (InnerVatRecipe) arecipes.get(recipeIndex);
|
||||
Point pos = GuiDraw.getMousePosition();
|
||||
Point offset = gui.getRecipePosition(recipeIndex);
|
||||
Point relMouse = new Point(pos.x - ((gui.width - 176) / 2) - offset.x, pos.y - ((gui.height - 166) / 2) - offset.y);
|
||||
|
||||
if(inTankBounds.contains(relMouse)) {
|
||||
transferFluidTank(rec.inFluid, usage);
|
||||
}
|
||||
else if(outTankBounds.contains(relMouse)) {
|
||||
transferFluidTank(rec.result, usage);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean transferFluidTank(FluidStack tank, boolean usage) {
|
||||
if(tank != null && tank.amount > 0) {
|
||||
if(usage) {
|
||||
if(!GuiUsageRecipe.openRecipeGui("liquid", new Object[] { tank.copy() })) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(!GuiCraftingRecipe.openRecipeGui("liquid", new Object[] { tank.copy() })) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<ItemStack> getInputs(RecipeInput input) {
|
||||
|
||||
@@ -5,16 +5,19 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemPotion;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import crazypants.enderio.Log;
|
||||
@@ -72,16 +75,24 @@ public class FluidUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FluidStack getFluidFromItem(ItemStack item) {
|
||||
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(item);
|
||||
if(fluid == null) {
|
||||
if(item.getItem() == Items.water_bucket) {
|
||||
fluid = new FluidStack(FluidRegistry.WATER, 1000);
|
||||
} else if(item.getItem() == Items.lava_bucket) {
|
||||
fluid = new FluidStack(FluidRegistry.LAVA, 1000);
|
||||
public static FluidStack getFluidFromItem(ItemStack stack) {
|
||||
if(stack != null) {
|
||||
FluidStack fluidStack = null;
|
||||
if(stack.getItem() instanceof IFluidContainerItem) {
|
||||
fluidStack = ((IFluidContainerItem) stack.getItem()).getFluid(stack);
|
||||
}
|
||||
if(fluidStack == null) {
|
||||
fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
}
|
||||
if(fluidStack == null && Block.getBlockFromItem(stack.getItem()) instanceof IFluidBlock) {
|
||||
Fluid fluid = ((IFluidBlock) Block.getBlockFromItem(stack.getItem())).getFluid();
|
||||
if(fluid != null) {
|
||||
return new FluidStack(fluid, 1000);
|
||||
}
|
||||
}
|
||||
return fluidStack;
|
||||
}
|
||||
return fluid;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack getEmptyContainer(ItemStack stack) {
|
||||
@@ -132,13 +143,13 @@ public class FluidUtil {
|
||||
IFluidHandler target = getFluidHandler(te.getWorldObj(), loc);
|
||||
if(target == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
FluidTankInfo[] infos = from.getTankInfo(fromDir);
|
||||
boolean res = false;
|
||||
if(infos != null) {
|
||||
if(infos != null) {
|
||||
for (FluidTankInfo info : infos) {
|
||||
if(info.fluid != null && info.fluid.amount > 0 && from.canDrain(fromDir, info.fluid.getFluid())) {
|
||||
FluidStack maxDrain = new FluidStack(info.fluid.getFluid(), maxVolume);
|
||||
FluidStack maxDrain = new FluidStack(info.fluid.getFluid(), maxVolume);
|
||||
FluidStack canDrain = from.drain(fromDir, maxDrain, false);
|
||||
if(canDrain != null && canDrain.amount > 0) {
|
||||
int filled = target.fill(fromDir.getOpposite(), canDrain, true);
|
||||
@@ -148,7 +159,7 @@ public class FluidUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user