Use NEI fluid stacks in recipe handlers

This commit is contained in:
slprime committed 2026-09-26 12:29:45 +03:00
1 parent 6b65b8b1bf
commit 30bcf706fa
9 files changed
+53 -258

No files matched your search

+7 -7
View File
@@ -1,12 +1,12 @@
// Add your dependencies here
dependencies {
compileOnlyApi('com.github.GTNewHorizons:Angelica:2.2.13:api')
compileOnlyApi('com.github.GTNewHorizons:Angelica:2.2.19:api')
api("com.github.GTNewHorizons:Mantle:0.5.4:dev")
api("com.github.GTNewHorizons:ForgeMultipart:1.7.14:dev")
api("com.github.GTNewHorizons:ForgeMultipart:1.7.15:dev")
// gtnhlib is compileOnlyApi by us, but needed at runtime by nei, so require the correct version
api("com.github.GTNewHorizons:GTNHLib:0.11.48:dev")
implementation("com.github.GTNewHorizons:NotEnoughItems:2.8.139-GTNH:dev")
api("com.github.GTNewHorizons:GTNHLib:0.11.51:dev")
implementation("com.github.GTNewHorizons:NotEnoughItems:2.8.147-GTNH:dev")
compileOnlyApi("curse.maven:cofh-core-69162:2388751")
compileOnly("com.github.GTNewHorizons:inventory-tweaks:1.7.1:api")
compileOnly("com.github.GTNewHorizons:waila:1.19.34:api")
@@ -19,10 +19,10 @@ dependencies {
compileOnly("com.github.GTNewHorizons:Mobs-Info:0.6.0-GTNH:dev")
compileOnlyApi("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev")
compileOnlyApi("com.github.GTNewHorizons:Natura:2.8.24:dev")
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.2.23-GTNH:dev')
compileOnly('com.github.GTNewHorizons:SpecialMobs:3.7.6')
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.2.24-GTNH:dev')
compileOnly('com.github.GTNewHorizons:SpecialMobs:3.7.7')
runtimeOnly('com.github.GTNewHorizons:TiC-Tooltips:1.4.2:dev'){transitive = false}
runtimeOnly("com.github.GTNewHorizons:ServerUtilities:2.4.10:dev")
runtimeOnly("com.github.GTNewHorizons:ServerUtilities:2.4.13:dev")
// For testing scythe crop harvesting
@@ -18,62 +18,45 @@ public class RecipeHandlerAlloying extends RecipeHandlerBase {
public static final Rectangle OUTPUT_TANK = new Rectangle(118, 9, 18, 32);
public class CachedAlloyingRecipe extends CachedBaseRecipe {
public class CachedAlloyingRecipe extends CachedRecipe {
private final List<FluidTankElement> fluidTanks;
private int minAmount;
private final List<PositionedStack> inputs;
private final PositionedStack.Fluid output;
public CachedAlloyingRecipe(AlloyMix recipe) {
this.fluidTanks = new ArrayList<>();
this.inputs = new ArrayList<>();
int maxAmount = recipe.mixers.get(0).amount;
int mult = 1;
this.minAmount = maxAmount;
for (FluidStack stack : recipe.mixers) {
if (stack.amount > maxAmount) {
maxAmount = stack.amount;
}
if (stack.amount < this.minAmount) {
this.minAmount = stack.amount;
}
}
FluidTankElement tank = new FluidTankElement(OUTPUT_TANK, maxAmount * mult, recipe.result);
tank.fluid.amount *= mult;
this.fluidTanks.add(tank);
this.output = new PositionedStack.Fluid(
recipe.result,
OUTPUT_TANK.x,
OUTPUT_TANK.y,
OUTPUT_TANK.width,
OUTPUT_TANK.height,
maxAmount);
int width = 36 / recipe.mixers.size();
int counter = 0;
for (FluidStack stack : recipe.mixers) {
if (counter == recipe.mixers.size() - 1) {
tank = new FluidTankElement(
new Rectangle(21 + width * counter, 9, 36 - width * counter, 32),
maxAmount * mult,
stack);
} else {
tank = new FluidTankElement(
new Rectangle(21 + width * counter, 9, width, 32),
maxAmount * mult,
stack);
}
tank.fluid.amount *= mult;
this.fluidTanks.add(tank);
int tankWidth = counter == recipe.mixers.size() - 1 ? 36 - width * counter : width;
this.inputs.add(new PositionedStack.Fluid(stack, 21 + width * counter, 9, tankWidth, 32, maxAmount));
counter++;
}
}
@Override
public PositionedStack getIngredient() {
return null;
public List<PositionedStack> getIngredients() {
return this.inputs;
}
@Override
public PositionedStack getResult() {
return null;
}
@Override
public List<FluidTankElement> getFluidTanks() {
return this.fluidTanks;
return this.output;
}
}
@@ -1,56 +1,27 @@
package tconstruct.plugins.nei;
import static com.gtnewhorizon.gtnhlib.util.numberformatting.NumberFormatUtil.formatFluid;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.IFluidContainerItem;
import org.lwjgl.opengl.GL11;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.TemplateRecipeHandler;
public abstract class RecipeHandlerBase extends TemplateRecipeHandler {
public abstract class CachedBaseRecipe extends CachedRecipe {
public List<FluidTankElement> getFluidTanks() {
return null;
}
}
public abstract String getRecipeID();
public void loadCraftingRecipes(FluidStack result) {}
public void loadUsageRecipes(FluidStack ingredient) {}
@Override
public void drawForeground(int recipe) {
super.drawForeground(recipe);
this.drawFluidTanks(recipe);
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
try {
@@ -93,86 +64,6 @@ public abstract class RecipeHandlerBase extends TemplateRecipeHandler {
}
}
@Override
public List<String> handleTooltip(GuiRecipe<?> guiRecipe, List<String> currenttip, int recipe) {
super.handleTooltip(guiRecipe, currenttip, recipe);
CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
if (GuiContainerManager.shouldShowTooltip(guiRecipe)) {
Point mouse = GuiDraw.getMousePosition();
Point offset = guiRecipe.getRecipePosition(recipe);
Point relMouse = new Point(mouse.x - guiRecipe.guiLeft - offset.x, mouse.y - guiRecipe.guiTop - offset.y);
if (crecipe.getFluidTanks() != null) {
for (FluidTankElement tank : crecipe.getFluidTanks()) {
if (tank.position.contains(relMouse)) {
tank.handleTooltip(currenttip);
}
}
}
}
return currenttip;
}
@Override
public boolean keyTyped(GuiRecipe<?> gui, char keyChar, int keyCode, int recipe) {
if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) {
if (this.transferFluidTank(gui, recipe, false)) {
return true;
}
} else if (keyCode == NEIClientConfig.getKeyBinding("gui.usage")) {
if (this.transferFluidTank(gui, recipe, true)) {
return true;
}
}
return super.keyTyped(gui, keyChar, keyCode, recipe);
}
@Override
public boolean mouseClicked(GuiRecipe<?> gui, int button, int recipe) {
if (button == 0) {
if (this.transferFluidTank(gui, recipe, false)) {
return true;
}
} else if (button == 1) {
if (this.transferFluidTank(gui, recipe, true)) {
return true;
}
}
return super.mouseClicked(gui, button, recipe);
}
protected boolean transferFluidTank(GuiRecipe<?> guiRecipe, int recipe, boolean usage) {
CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
Point mouse = GuiDraw.getMousePosition();
Point offset = guiRecipe.getRecipePosition(recipe);
Point relMouse = new Point(mouse.x - guiRecipe.guiLeft - offset.x, mouse.y - guiRecipe.guiTop - offset.y);
if (crecipe.getFluidTanks() != null) {
for (FluidTankElement tank : crecipe.getFluidTanks()) {
if (tank.position.contains(relMouse)) {
if ((tank.fluid != null) && tank.fluid.amount > 0) {
if (usage) {
return GuiUsageRecipe.openRecipeGui("liquid", tank.fluid);
} else {
return GuiCraftingRecipe.openRecipeGui("liquid", tank.fluid);
}
}
}
}
}
return false;
}
public void drawFluidTanks(int recipe) {
CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
if (crecipe.getFluidTanks() != null) {
for (FluidTankElement fluidTank : crecipe.getFluidTanks()) {
fluidTank.draw();
}
}
}
public static List getSingleList(Object o) {
List list = new ArrayList();
list.add(o);
@@ -206,77 +97,4 @@ public abstract class RecipeHandlerBase extends TemplateRecipeHandler {
}
return fluidStack1.isFluidEqual(fluidStack2);
}
public static class FluidTankElement {
public Rectangle position;
public FluidStack fluid;
public int capacity;
public boolean flowingTexture = false;
public FluidTankElement(Rectangle position, int capacity, FluidStack fluid) {
this.position = position;
this.capacity = capacity;
this.fluid = fluid;
}
public List<String> handleTooltip(List<String> currenttip) {
if (this.fluid == null || this.fluid.getFluid() == null || this.fluid.amount <= 0) {
return currenttip;
}
currenttip.add(this.fluid.getLocalizedName());
currenttip.add(EnumChatFormatting.GRAY + formatFluid(this.fluid.amount));
return currenttip;
}
public void draw() {
if (this.fluid == null || this.fluid.getFluid() == null || this.fluid.amount <= 0) {
return;
}
IIcon fluidIcon;
if (this.flowingTexture && this.fluid.getFluid().getFlowingIcon() != null) {
fluidIcon = this.fluid.getFluid().getFlowingIcon();
} else if (this.fluid.getFluid().getStillIcon() != null) {
fluidIcon = this.fluid.getFluid().getStillIcon();
} else {
return;
}
GuiDraw.changeTexture(TextureMap.locationBlocksTexture);
int color = this.fluid.getFluid().getColor(this.fluid);
GL11.glColor3ub((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF));
GL11.glDisable(GL11.GL_BLEND);
int amount = Math
.max(Math.min(this.position.height, this.fluid.amount * this.position.height / this.capacity), 1);
int posY = this.position.y + this.position.height - amount;
for (int i = 0; i < this.position.width; i += 16) {
for (int j = 0; j < amount; j += 16) {
int drawWidth = Math.min(this.position.width - i, 16);
int drawHeight = Math.min(amount - j, 16);
int drawX = this.position.x + i;
int drawY = posY + j;
double minU = fluidIcon.getMinU();
double maxU = fluidIcon.getMaxU();
double minV = fluidIcon.getMinV();
double maxV = fluidIcon.getMaxV();
Tessellator tessellator = Tessellator.instance;
final double u = minU + (maxU - minU) * drawWidth / 16F;
final double v = minV + (maxV - minV) * drawHeight / 16F;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(drawX, drawY + drawHeight, 0, minU, v);
tessellator.addVertexWithUV(drawX + drawWidth, drawY + drawHeight, 0, u, v);
tessellator.addVertexWithUV(drawX + drawWidth, drawY, 0, u, minV);
tessellator.addVertexWithUV(drawX, drawY, 0, minU, minV);
tessellator.draw();
}
}
GL11.glEnable(GL11.GL_BLEND);
}
}
}
@@ -16,40 +16,32 @@ public abstract class RecipeHandlerCastingBase extends RecipeHandlerBase {
public static final Rectangle MOLTEN_FLOW = new Rectangle(60, 8, 6, 11);
public static final Rectangle MOLTEN_FLOW_NO_ITEM = new Rectangle(60, 8, 6, 27);
public class CachedCastingRecipe extends CachedBaseRecipe {
public class CachedCastingRecipe extends CachedRecipe {
private final List<PositionedStack> resources;
private final FluidTankElement metal;
private PositionedStack output;
public CachedCastingRecipe(CastingRecipe recipe) {
this.metal = new FluidTankElement(MOLTEN_FLOW, recipe.castingMetal.amount, recipe.castingMetal);
this.metal.flowingTexture = true;
this.resources = new ArrayList<>();
Rectangle flow = recipe.cast != null ? MOLTEN_FLOW : MOLTEN_FLOW_NO_ITEM;
this.resources.add(
new PositionedStack.Fluid(recipe.castingMetal, flow.x, flow.y, flow.width, flow.height, 0)
.setFlowingTexture(true));
if (recipe.cast != null) {
this.resources.add(new PositionedStack(recipe.cast, 55, 19));
} else {
this.metal.position = MOLTEN_FLOW_NO_ITEM;
}
this.output = new PositionedStack(recipe.output, 110, 18);
}
@Override
public List<PositionedStack> getIngredients() {
return getCycledIngredients(cycleticks / 20, this.resources);
return this.resources;
}
@Override
public PositionedStack getResult() {
return this.output;
}
@Override
public List<FluidTankElement> getFluidTanks() {
List<FluidTankElement> res = new ArrayList<>();
res.add(this.metal);
return res;
}
}
@Override
@@ -98,6 +90,7 @@ public abstract class RecipeHandlerCastingBase extends RecipeHandlerBase {
this.arecipes.add(irecipe);
}
}
super.loadUsageRecipes(ingred);
}
@Override
@@ -17,7 +17,7 @@ import tconstruct.library.crafting.DryingRackRecipes.DryingRecipe;
public class RecipeHandlerDryingRack extends RecipeHandlerBase {
public class CachedDryingRackRecipe extends CachedBaseRecipe {
public class CachedDryingRackRecipe extends CachedRecipe {
public PositionedStack input;
public PositionedStack output;
@@ -64,7 +64,7 @@ public class RecipeHandlerDryingRack extends RecipeHandlerBase {
public void drawBackground(int recipe) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(this.getGuiTexture());
GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 160, 65);
GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 160, 50);
}
@Override
@@ -3,7 +3,6 @@ package tconstruct.plugins.nei;
import static com.gtnewhorizon.gtnhlib.util.numberformatting.NumberFormatUtil.formatNumber;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
@@ -26,24 +25,33 @@ public class RecipeHandlerMelting extends RecipeHandlerBase {
public static final Rectangle MOLTEN_TANK = new Rectangle(115, 20, 18, 18);
public class CachedMeltingRecipe extends CachedBaseRecipe {
public class CachedMeltingRecipe extends CachedRecipe {
private final PositionedStack input;
private final int temperature;
private final FluidTankElement output;
private final PositionedStack.Fluid output;
public CachedMeltingRecipe(ItemStack input) {
this.input = new PositionedStack(input, 28, 21);
this.temperature = Smeltery.getLiquifyTemperature(input);
this.output = new FluidTankElement(MOLTEN_TANK, 1, Smeltery.getSmelteryResult(input));
this.output.capacity = this.output.fluid != null ? this.output.fluid.amount : 1000;
this(input, input);
}
public CachedMeltingRecipe(List<ItemStack> input) {
this(input, input.get(0));
}
private CachedMeltingRecipe(Object input, ItemStack first) {
this.input = new PositionedStack(input, 28, 21);
this.temperature = Smeltery.getLiquifyTemperature(input.get(0));
this.output = new FluidTankElement(MOLTEN_TANK, 1, Smeltery.getSmelteryResult(input.get(0)));
this.output.capacity = this.output.fluid != null ? this.output.fluid.amount : 1000;
this.temperature = Smeltery.getLiquifyTemperature(first);
FluidStack result = Smeltery.getSmelteryResult(first);
this.output = result != null
? new PositionedStack.Fluid(
result,
MOLTEN_TANK.x,
MOLTEN_TANK.y,
MOLTEN_TANK.width,
MOLTEN_TANK.height,
0)
: null;
}
@Override
@@ -53,14 +61,7 @@ public class RecipeHandlerMelting extends RecipeHandlerBase {
@Override
public PositionedStack getResult() {
return null;
}
@Override
public List<FluidTankElement> getFluidTanks() {
List<FluidTankElement> tanks = new ArrayList<>();
tanks.add(this.output);
return tanks;
return this.output;
}
}
@@ -31,7 +31,7 @@ import tconstruct.util.config.PHConstruct;
public class RecipeHandlerToolMaterials extends RecipeHandlerBase {
public class CachedToolMaterialsRecipe extends CachedBaseRecipe {
public class CachedToolMaterialsRecipe extends CachedRecipe {
public List<PositionedStack> toolParts;
public ToolMaterial material;
@@ -90,7 +90,7 @@ public class RecipeHandlerToolMaterials extends RecipeHandlerBase {
public void drawBackground(int recipe) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(this.getGuiTexture());
GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 160, 130);
GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 160, 110);
}
@Override
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB