mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-15 17:54:50 +00:00
Added fluid support in recipes (#1020)
This commit is contained in:
1 parent
3f38e6f39b
commit
fda7688807
31 files changed
+831
-127
No files matched your search
@@ -6,11 +6,19 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
@@ -230,9 +238,6 @@ public class PositionedStack implements Cloneable {
|
||||
return "PositionedStack(output='" + item.toString() + "')";
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link PositionedStack} that keeps its items but never draws them.
|
||||
*/
|
||||
public static class Placeholder extends PositionedStack {
|
||||
|
||||
public Placeholder(Object object, int x, int y, boolean genPerms) {
|
||||
@@ -246,4 +251,124 @@ public class PositionedStack implements Cloneable {
|
||||
@Override
|
||||
public void draw(int mousex, int mousey) {}
|
||||
}
|
||||
|
||||
public static class Fluid extends PositionedStack {
|
||||
|
||||
/** The tank size the fill level is measured against, in mB. 0 means "always render full". */
|
||||
public int capacity = 0;
|
||||
|
||||
private ItemStack cachedFluidItem;
|
||||
private FluidStack cachedFluidStack;
|
||||
|
||||
public Fluid(Object object, int x, int y, boolean genPerms) {
|
||||
super(object, x, y, genPerms);
|
||||
}
|
||||
|
||||
public Fluid(Object object, int x, int y) {
|
||||
this(object, x, y, true);
|
||||
}
|
||||
|
||||
public Fluid(Object object, int x, int y, int width, int height, int capacity) {
|
||||
super(object, x, y, false);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
protected FluidStack getFluidStack() {
|
||||
|
||||
if (this.item != this.cachedFluidItem) {
|
||||
this.cachedFluidItem = this.item;
|
||||
this.cachedFluidStack = StackInfo.isFluidDisplayItem(this.item) ? StackInfo.getFluid(this.item) : null;
|
||||
}
|
||||
|
||||
return this.cachedFluidStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTooltip() {
|
||||
final List<String> tooltip = new ArrayList<>();
|
||||
final List<String> customTooltip = super.getTooltip();
|
||||
final FluidStack fluidStack = getFluidStack();
|
||||
|
||||
if (fluidStack != null) {
|
||||
tooltip.add(
|
||||
EnumChatFormatting.GRAY + NEIClientUtils
|
||||
.translate("recipe.fluid.tank.amount", NEIClientUtils.formatFluid(fluidStack.amount)));
|
||||
}
|
||||
|
||||
if (customTooltip != null) {
|
||||
tooltip.addAll(customTooltip);
|
||||
}
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey) {
|
||||
final FluidStack fluidStack = getFluidStack();
|
||||
|
||||
if (fluidStack == null) {
|
||||
super.draw(mousex, mousey);
|
||||
return;
|
||||
}
|
||||
|
||||
final int tankCapacity = this.capacity > 0 ? this.capacity : fluidStack.amount;
|
||||
int fillHeight = tankCapacity > 0
|
||||
? (int) ((long) this.height * Math.min(fluidStack.amount, tankCapacity) / tankCapacity)
|
||||
: 0;
|
||||
|
||||
if (fluidStack.amount > 0 && fillHeight <= 0) {
|
||||
fillHeight = 1;
|
||||
}
|
||||
|
||||
if (fillHeight > 0) {
|
||||
drawFluid(this.relx, this.rely, this.width, this.height, fillHeight, fluidStack);
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawFluid(int x, int y, int width, int height, int fillHeight, FluidStack fluidStack) {
|
||||
final IIcon icon = fluidStack.getFluid().getIcon(fluidStack);
|
||||
|
||||
if (icon == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int color = fluidStack.getFluid().getColor(fluidStack);
|
||||
final float red = (color >> 16 & 0xFF) / 255F;
|
||||
final float green = (color >> 8 & 0xFF) / 255F;
|
||||
final float blue = (color & 0xFF) / 255F;
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
|
||||
GL11.glColor4f(red, green, blue, 1F);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
for (int tx = 0; tx < width; tx += 16) {
|
||||
final int tileWidth = Math.min(16, width - tx);
|
||||
final double u2 = icon.getMinU() + (icon.getMaxU() - icon.getMinU()) * tileWidth / 16D;
|
||||
|
||||
for (int ty = 0; ty < fillHeight; ty += 16) {
|
||||
final int tileHeight = Math.min(16, fillHeight - ty);
|
||||
final double v2 = icon.getMinV() + (icon.getMaxV() - icon.getMinV()) * tileHeight / 16D;
|
||||
final int bottomY = y + height - ty;
|
||||
final int topY = bottomY - tileHeight;
|
||||
|
||||
tessellator.addVertexWithUV(x + tx, bottomY, 0, icon.getMinU(), v2);
|
||||
tessellator.addVertexWithUV(x + tx + tileWidth, bottomY, 0, u2, v2);
|
||||
tessellator.addVertexWithUV(x + tx + tileWidth, topY, 0, u2, icon.getMinV());
|
||||
tessellator.addVertexWithUV(x + tx, topY, 0, icon.getMinU(), icon.getMinV());
|
||||
}
|
||||
}
|
||||
tessellator.draw();
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user