mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-19 11:59:11 +00:00
Add NEI support for Genetics
This commit is contained in:
1 parent
2f796f4478
commit
4aaa092db9
34 files changed
+2598
-275
No files matched your search
@@ -0,0 +1,39 @@
|
||||
package binnie.core.nei;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.*;
|
||||
|
||||
public class NEIUtils {
|
||||
public static FluidStack getFluidStack(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) {
|
||||
fluidStack = new FluidStack(fluid, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
return fluidStack;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean areFluidsSameType(FluidStack fluidStack1, FluidStack fluidStack2) {
|
||||
if (fluidStack1 != null && fluidStack2 != null) {
|
||||
return fluidStack1.getFluid() == fluidStack2.getFluid();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package binnie.core.nei;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.GuiUsageRecipe;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PositionedFluidTank {
|
||||
|
||||
public FluidTank[] tanks;
|
||||
public FluidTank tank;
|
||||
public Rectangle position;
|
||||
public String overlayTexture;
|
||||
public Point overlayTexturePos;
|
||||
public boolean flowingTexture = false;
|
||||
public boolean showAmount = true;
|
||||
public boolean perTick = false;
|
||||
|
||||
public PositionedFluidTank(FluidTank[] tanks, Rectangle position, String overlayTexture, Point overlayTexturePos) {
|
||||
this.position = position;
|
||||
this.tanks = tanks;
|
||||
this.tank = tanks[0];
|
||||
this.overlayTexture = overlayTexture;
|
||||
this.overlayTexturePos = overlayTexturePos;
|
||||
}
|
||||
|
||||
public PositionedFluidTank(Collection<FluidStack> fluids, int capacity, Rectangle position, String overlayTexture, Point overlayTexturePos) {
|
||||
this(createFluidTanks(capacity, fluids), position, overlayTexture, overlayTexturePos);
|
||||
}
|
||||
|
||||
public PositionedFluidTank(FluidStack fluid, int capacity, Rectangle position, String overlayTexture, Point overlayTexturePos) {
|
||||
this(createFluidTanks(capacity, Collections.singletonList(fluid)), position, overlayTexture, overlayTexturePos);
|
||||
}
|
||||
|
||||
public PositionedFluidTank(FluidStack fluid, int capacity, Rectangle position) {
|
||||
this(fluid, capacity, position, null, null);
|
||||
}
|
||||
|
||||
private static FluidTank[] createFluidTanks(int capacity, Collection<FluidStack> fluidStacks) {
|
||||
FluidTank[] tanks = new FluidTank[fluidStacks.size()];
|
||||
int i = 0;
|
||||
for (FluidStack fluidStack : fluidStacks) {
|
||||
tanks[i++] = new FluidTank(fluidStacks != null ? fluidStack.copy() : null, capacity);
|
||||
}
|
||||
return tanks;
|
||||
}
|
||||
|
||||
public List<String> handleTooltip(List<String> currenttip) {
|
||||
if (this.tank == null || this.tank.getFluid() == null || this.tank.getFluid().getFluid() == null || this.tank.getFluid().amount <= 0) {
|
||||
return currenttip;
|
||||
}
|
||||
currenttip.add(this.tank.getFluid().getLocalizedName());
|
||||
if (this.showAmount) {
|
||||
currenttip.add(EnumChatFormatting.GRAY.toString() + this.tank.getFluid().amount + (this.perTick ? " mB/t" : " mB"));
|
||||
}
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
public boolean transfer(boolean usage) {
|
||||
if (this.tank.getFluid() != null && this.tank.getFluid().amount > 0) {
|
||||
if (usage) {
|
||||
return GuiUsageRecipe.openRecipeGui("liquid", this.tank.getFluid());
|
||||
} else {
|
||||
return GuiCraftingRecipe.openRecipeGui("liquid", this.tank.getFluid());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
if (this.tank == null || this.tank.getFluid() == null || this.tank.getFluid().getFluid() == null || this.tank.getFluid().amount <= 0) {
|
||||
return;
|
||||
}
|
||||
final IIcon fluidIcon;
|
||||
if (this.flowingTexture && this.tank.getFluid().getFluid().getFlowingIcon() != null) {
|
||||
fluidIcon = this.tank.getFluid().getFluid().getFlowingIcon();
|
||||
} else if (this.tank.getFluid().getFluid().getStillIcon() != null) {
|
||||
fluidIcon = this.tank.getFluid().getFluid().getStillIcon();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
GuiDraw.changeTexture(TextureMap.locationBlocksTexture);
|
||||
int color = this.tank.getFluid().getFluid().getColor(this.tank.getFluid());
|
||||
GL11.glColor3ub((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF));
|
||||
|
||||
int amount = Math.max(Math.min(this.position.height, this.tank.getFluid().amount * this.position.height / this.tank.getCapacity()), 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;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertexWithUV(drawX, drawY + drawHeight, 0, minU, minV + (maxV - minV) * drawHeight / 16F);
|
||||
tessellator.addVertexWithUV(drawX + drawWidth, drawY + drawHeight, 0, minU + (maxU - minU) * drawWidth / 16F, minV + (maxV - minV) * drawHeight / 16F);
|
||||
tessellator.addVertexWithUV(drawX + drawWidth, drawY, 0, minU + (maxU - minU) * drawWidth / 16F, minV);
|
||||
tessellator.addVertexWithUV(drawX, drawY, 0, minU, minV);
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.overlayTexture != null && this.overlayTexturePos != null) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GuiDraw.changeTexture(this.overlayTexture);
|
||||
GuiDraw.drawTexturedModalRect(this.position.x, this.position.y, this.overlayTexturePos.x, this.overlayTexturePos.y, this.position.width, this.position.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPermutationToRender(int index) {
|
||||
this.tank = this.tanks[index];
|
||||
}
|
||||
|
||||
public int getPermutationCount() {
|
||||
return this.tanks.length;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package binnie.core.nei;
|
||||
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PositionedStackAdv extends PositionedStack {
|
||||
|
||||
private final List<String> tooltip = new ArrayList<>();
|
||||
|
||||
public PositionedStackAdv(Object object, int x, int y) {
|
||||
super(object, x, y);
|
||||
}
|
||||
|
||||
public PositionedStackAdv(Object object, int x, int y, List<String> tooltip) {
|
||||
super(object, x, y);
|
||||
this.addToTooltip(tooltip);
|
||||
}
|
||||
|
||||
public Rectangle getRect() {
|
||||
return new Rectangle(this.relx - 1, this.rely - 1, 18, 18);
|
||||
}
|
||||
|
||||
public List<String> handleTooltip(GuiRecipe guiRecipe, List<String> currenttip) {
|
||||
if (!this.tooltip.isEmpty()) {
|
||||
for (String tip : this.tooltip) {
|
||||
currenttip.add(tip);
|
||||
}
|
||||
}
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
public PositionedStackAdv addToTooltip(List<String> lines) {
|
||||
for (String tip : lines) {
|
||||
this.tooltip.add(tip);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public PositionedStackAdv addToTooltip(String line) {
|
||||
this.tooltip.add(line);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
package binnie.core.nei;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RecipeHandlerBase extends TemplateRecipeHandler {
|
||||
|
||||
public void prepare() {
|
||||
}
|
||||
|
||||
public void changeToGuiTexture() {
|
||||
GuiDraw.changeTexture(this.getGuiTexture());
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
public void addTransferRect(int x, int y, int width, int height) {
|
||||
this.transferRects.add(new RecipeTransferRect(new Rectangle(x, y, width, height), this.getOverlayIdentifier()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int recipe) {
|
||||
super.drawForeground(recipe);
|
||||
this.drawFluidTanks(recipe);
|
||||
this.changeToGuiTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object... results) {
|
||||
if (outputId.equals("liquid") && results[0] instanceof FluidStack && ((FluidStack) results[0]).getFluid() != null) {
|
||||
this.loadCraftingRecipes((FluidStack) results[0]);
|
||||
} else if (outputId.equals(this.getOverlayIdentifier())) {
|
||||
this.loadAllRecipes();
|
||||
} else {
|
||||
super.loadCraftingRecipes(outputId, results);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadAllRecipes() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(ItemStack result) {
|
||||
FluidStack fluid = NEIUtils.getFluidStack(result);
|
||||
if (fluid != null && fluid.getFluid() != null) {
|
||||
this.loadCraftingRecipes(fluid);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadCraftingRecipes(FluidStack result) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(String inputId, Object... ingredients) {
|
||||
if (inputId.equals("liquid") && ingredients[0] instanceof FluidStack && ((FluidStack) ingredients[0]).getFluid() != null) {
|
||||
this.loadUsageRecipes((FluidStack) ingredients[0]);
|
||||
} else {
|
||||
super.loadUsageRecipes(inputId, ingredients);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(ItemStack ingred) {
|
||||
FluidStack fluid = NEIUtils.getFluidStack(ingred);
|
||||
if (fluid != null && fluid.getFluid() != null) {
|
||||
this.loadUsageRecipes(fluid);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUsageRecipes(FluidStack ingredient) {
|
||||
}
|
||||
|
||||
@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.width - 176) / 2 - offset.x, mouse.y - (guiRecipe.height - Math.min(Math.max(guiRecipe.height - 68, 166), 370)) / 2 - 10 - offset.y);
|
||||
currenttip = this.provideTooltip(guiRecipe, currenttip, crecipe, relMouse);
|
||||
}
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
public List<String> provideTooltip(GuiRecipe guiRecipe, List<String> currenttip, CachedBaseRecipe crecipe, Point relMouse) {
|
||||
if (crecipe.getFluidTanks() != null) {
|
||||
for (PositionedFluidTank tank : crecipe.getFluidTanks()) {
|
||||
if (tank.position.contains(relMouse)) {
|
||||
tank.handleTooltip(currenttip);
|
||||
}
|
||||
}
|
||||
}
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiRecipe guiRecipe, ItemStack itemStack, List<String> currenttip, int recipe) {
|
||||
super.handleItemTooltip(guiRecipe, itemStack, currenttip, recipe);
|
||||
CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
|
||||
Point mouse = GuiDraw.getMousePosition();
|
||||
Point offset = guiRecipe.getRecipePosition(recipe);
|
||||
Point relMouse = new Point(mouse.x - (guiRecipe.width - 176) / 2 - offset.x, mouse.y - (guiRecipe.height - Math.min(Math.max(guiRecipe.height - 68, 166), 370)) / 2 - 10 - offset.y);
|
||||
|
||||
currenttip = this.provideItemTooltip(guiRecipe, itemStack, currenttip, crecipe, relMouse);
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
public List<String> provideItemTooltip(GuiRecipe guiRecipe, ItemStack itemStack, List<String> currenttip, CachedBaseRecipe crecipe, Point relMouse) {
|
||||
for (PositionedStack stack : crecipe.getIngredients()) {
|
||||
if (stack instanceof PositionedStackAdv && ((PositionedStackAdv) stack).getRect().contains(relMouse)) {
|
||||
currenttip = ((PositionedStackAdv) stack).handleTooltip(guiRecipe, currenttip);
|
||||
}
|
||||
}
|
||||
for (PositionedStack stack : crecipe.getOtherStacks()) {
|
||||
if (stack instanceof PositionedStackAdv && ((PositionedStackAdv) stack).getRect().contains(relMouse)) {
|
||||
currenttip = ((PositionedStackAdv) stack).handleTooltip(guiRecipe, currenttip);
|
||||
}
|
||||
}
|
||||
PositionedStack stack = crecipe.getResult();
|
||||
if (stack instanceof PositionedStackAdv && ((PositionedStackAdv) stack).getRect().contains(relMouse)) {
|
||||
currenttip = ((PositionedStackAdv) stack).handleTooltip(guiRecipe, 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);
|
||||
|
||||
if (crecipe.getFluidTanks() != null) {
|
||||
for (PositionedFluidTank tank : crecipe.getFluidTanks()) {
|
||||
Point mouse = GuiDraw.getMousePosition();
|
||||
Point offset = guiRecipe.getRecipePosition(recipe);
|
||||
Point relMouse = new Point(mouse.x - (guiRecipe.width - 176) / 2 - offset.x, mouse.y - (guiRecipe.height - Math.min(Math.max(guiRecipe.height - 68, 166), 370)) / 2 - 10 - offset.y);
|
||||
|
||||
if (tank.position.contains(relMouse)) {
|
||||
return tank.transfer(usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void drawFluidTanks(int recipe) {
|
||||
CachedRecipe cachedRecipe = this.arecipes.get(recipe);
|
||||
if (cachedRecipe instanceof CachedBaseRecipe) {
|
||||
CachedBaseRecipe crecipe = (CachedBaseRecipe) cachedRecipe;
|
||||
if (crecipe.getFluidTanks() != null) {
|
||||
for (PositionedFluidTank fluidTank : crecipe.getFluidTanks()) {
|
||||
fluidTank.draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class CachedBaseRecipe extends CachedRecipe {
|
||||
|
||||
public List<PositionedFluidTank> getFluidTanks() {
|
||||
List<PositionedFluidTank> tanks = new ArrayList<>();
|
||||
PositionedFluidTank tank = this.getFluidTank();
|
||||
if (tank != null) {
|
||||
tanks.add(tank);
|
||||
}
|
||||
return tanks;
|
||||
}
|
||||
|
||||
public PositionedFluidTank getFluidTank() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user