Misc. improvements
This commit is contained in:
@@ -4,7 +4,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
|||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.inventory.InventoryHelper;
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.common.ForgeModContainer;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
@@ -16,7 +18,7 @@ import refinedstorage.apiimpl.storage.fluid.FluidUtils;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class FluidGridHandler implements IFluidGridHandler {
|
public class FluidGridHandler implements IFluidGridHandler {
|
||||||
private static final ItemStack EMPTY_BUCKET = new ItemStack(Items.BUCKET);
|
private static final ItemStack EMPTY_BUCKET = new ItemStack(FluidRegistry.isUniversalBucketEnabled() ? ForgeModContainer.getInstance().universalBucket : Items.BUCKET);
|
||||||
|
|
||||||
private INetworkMaster network;
|
private INetworkMaster network;
|
||||||
|
|
||||||
@@ -28,7 +30,7 @@ public class FluidGridHandler implements IFluidGridHandler {
|
|||||||
public void onExtract(int hash, boolean shift, EntityPlayerMP player) {
|
public void onExtract(int hash, boolean shift, EntityPlayerMP player) {
|
||||||
FluidStack stack = network.getFluidStorage().get(hash);
|
FluidStack stack = network.getFluidStorage().get(hash);
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null && (stack.getFluid() == FluidRegistry.WATER || stack.getFluid() == FluidRegistry.LAVA || FluidRegistry.getBucketFluids().contains(stack.getFluid()))) {
|
||||||
ItemStack bucket = NetworkUtils.extractItem(network, EMPTY_BUCKET, 1);
|
ItemStack bucket = NetworkUtils.extractItem(network, EMPTY_BUCKET, 1);
|
||||||
|
|
||||||
if (bucket == null) {
|
if (bucket == null) {
|
||||||
|
|||||||
126
src/main/java/refinedstorage/apiimpl/storage/fluid/FluidRenderer.java
Executable file
126
src/main/java/refinedstorage/apiimpl/storage/fluid/FluidRenderer.java
Executable file
@@ -0,0 +1,126 @@
|
|||||||
|
package refinedstorage.apiimpl.storage.fluid;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.client.renderer.VertexBuffer;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureMap;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This fluid renderer is copied over from JEI because Forge lacks a utility method for rendering fluids.
|
||||||
|
*
|
||||||
|
* @link https://github.com/mezz/JustEnoughItems/blob/1.10/src/main/java/mezz/jei/gui/ingredients/FluidStackRenderer.java
|
||||||
|
*/
|
||||||
|
public class FluidRenderer {
|
||||||
|
private static final int TEX_WIDTH = 16;
|
||||||
|
private static final int TEX_HEIGHT = 16;
|
||||||
|
private static final int MIN_FLUID_HEIGHT = 1;
|
||||||
|
|
||||||
|
private final int capacityMb;
|
||||||
|
private final int width;
|
||||||
|
private final int height;
|
||||||
|
|
||||||
|
public FluidRenderer(int capacityMb, int width, int height) {
|
||||||
|
this.capacityMb = capacityMb;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(Minecraft minecraft, final int xPosition, final int yPosition, FluidStack fluidStack) {
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.enableAlpha();
|
||||||
|
|
||||||
|
drawFluid(minecraft, xPosition, yPosition, fluidStack);
|
||||||
|
|
||||||
|
GlStateManager.color(1, 1, 1, 1);
|
||||||
|
|
||||||
|
GlStateManager.disableAlpha();
|
||||||
|
GlStateManager.disableBlend();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawFluid(Minecraft minecraft, final int xPosition, final int yPosition, FluidStack fluidStack) {
|
||||||
|
if (fluidStack == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Fluid fluid = fluidStack.getFluid();
|
||||||
|
if (fluid == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureMap textureMapBlocks = minecraft.getTextureMapBlocks();
|
||||||
|
ResourceLocation fluidStill = fluid.getStill();
|
||||||
|
TextureAtlasSprite fluidStillSprite = null;
|
||||||
|
if (fluidStill != null) {
|
||||||
|
fluidStillSprite = textureMapBlocks.getTextureExtry(fluidStill.toString());
|
||||||
|
}
|
||||||
|
if (fluidStillSprite == null) {
|
||||||
|
fluidStillSprite = textureMapBlocks.getMissingSprite();
|
||||||
|
}
|
||||||
|
|
||||||
|
int fluidColor = fluid.getColor(fluidStack);
|
||||||
|
|
||||||
|
int scaledAmount = (fluidStack.amount * height) / capacityMb;
|
||||||
|
if (fluidStack.amount > 0 && scaledAmount < MIN_FLUID_HEIGHT) {
|
||||||
|
scaledAmount = MIN_FLUID_HEIGHT;
|
||||||
|
}
|
||||||
|
if (scaledAmount > height) {
|
||||||
|
scaledAmount = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
minecraft.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||||
|
setGLColorFromInt(fluidColor);
|
||||||
|
|
||||||
|
final int xTileCount = width / TEX_WIDTH;
|
||||||
|
final int xRemainder = width - (xTileCount * TEX_WIDTH);
|
||||||
|
final int yTileCount = scaledAmount / TEX_HEIGHT;
|
||||||
|
final int yRemainder = scaledAmount - (yTileCount * TEX_HEIGHT);
|
||||||
|
|
||||||
|
final int yStart = yPosition + height;
|
||||||
|
|
||||||
|
for (int xTile = 0; xTile <= xTileCount; xTile++) {
|
||||||
|
for (int yTile = 0; yTile <= yTileCount; yTile++) {
|
||||||
|
int width = (xTile == xTileCount) ? xRemainder : TEX_WIDTH;
|
||||||
|
int height = (yTile == yTileCount) ? yRemainder : TEX_HEIGHT;
|
||||||
|
int x = xPosition + (xTile * TEX_WIDTH);
|
||||||
|
int y = yStart - ((yTile + 1) * TEX_HEIGHT);
|
||||||
|
if (width > 0 && height > 0) {
|
||||||
|
int maskTop = TEX_HEIGHT - height;
|
||||||
|
int maskRight = TEX_WIDTH - width;
|
||||||
|
|
||||||
|
drawFluidTexture(x, y, fluidStillSprite, maskTop, maskRight, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setGLColorFromInt(int color) {
|
||||||
|
float red = (color >> 16 & 0xFF) / 255.0F;
|
||||||
|
float green = (color >> 8 & 0xFF) / 255.0F;
|
||||||
|
float blue = (color & 0xFF) / 255.0F;
|
||||||
|
|
||||||
|
GlStateManager.color(red, green, blue, 1.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawFluidTexture(double xCoord, double yCoord, TextureAtlasSprite textureSprite, int maskTop, int maskRight, double zLevel) {
|
||||||
|
double uMin = (double) textureSprite.getMinU();
|
||||||
|
double uMax = (double) textureSprite.getMaxU();
|
||||||
|
double vMin = (double) textureSprite.getMinV();
|
||||||
|
double vMax = (double) textureSprite.getMaxV();
|
||||||
|
uMax = uMax - (maskRight / 16.0 * (uMax - uMin));
|
||||||
|
vMax = vMax - (maskTop / 16.0 * (vMax - vMin));
|
||||||
|
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
VertexBuffer vertexBuffer = tessellator.getBuffer();
|
||||||
|
vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
||||||
|
vertexBuffer.pos(xCoord, yCoord + 16, zLevel).tex(uMin, vMax).endVertex();
|
||||||
|
vertexBuffer.pos(xCoord + 16 - maskRight, yCoord + 16, zLevel).tex(uMax, vMax).endVertex();
|
||||||
|
vertexBuffer.pos(xCoord + 16 - maskRight, yCoord + maskTop, zLevel).tex(uMax, vMin).endVertex();
|
||||||
|
vertexBuffer.pos(xCoord, yCoord + maskTop, zLevel).tex(uMin, vMin).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package refinedstorage.gui;
|
package refinedstorage.gui;
|
||||||
|
|
||||||
import mezz.jei.gui.ingredients.FluidStackRenderer;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
@@ -15,6 +14,7 @@ import net.minecraftforge.fml.client.config.GuiCheckBox;
|
|||||||
import net.minecraftforge.items.SlotItemHandler;
|
import net.minecraftforge.items.SlotItemHandler;
|
||||||
import org.lwjgl.input.Mouse;
|
import org.lwjgl.input.Mouse;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
|
import refinedstorage.apiimpl.storage.fluid.FluidRenderer;
|
||||||
import refinedstorage.gui.sidebutton.SideButton;
|
import refinedstorage.gui.sidebutton.SideButton;
|
||||||
import refinedstorage.inventory.ItemHandlerFluid;
|
import refinedstorage.inventory.ItemHandlerFluid;
|
||||||
|
|
||||||
@@ -24,8 +24,7 @@ import java.util.*;
|
|||||||
public abstract class GuiBase extends GuiContainer {
|
public abstract class GuiBase extends GuiContainer {
|
||||||
private static final Map<String, ResourceLocation> TEXTURE_CACHE = new HashMap<>();
|
private static final Map<String, ResourceLocation> TEXTURE_CACHE = new HashMap<>();
|
||||||
|
|
||||||
// @TODO: Don't depend on JEI
|
public static final FluidRenderer FLUID_RENDERER = new FluidRenderer(Fluid.BUCKET_VOLUME, 16, 16);
|
||||||
public static final FluidStackRenderer FLUID_RENDERER = new FluidStackRenderer(Fluid.BUCKET_VOLUME, false, 16, 16, null);
|
|
||||||
|
|
||||||
protected static final int SIDE_BUTTON_WIDTH = 20;
|
protected static final int SIDE_BUTTON_WIDTH = 20;
|
||||||
protected static final int SIDE_BUTTON_HEIGHT = 20;
|
protected static final int SIDE_BUTTON_HEIGHT = 20;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package refinedstorage.gui;
|
package refinedstorage.gui;
|
||||||
|
|
||||||
import mezz.jei.gui.ingredients.FluidStackRenderer;
|
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
|
import refinedstorage.apiimpl.storage.fluid.FluidRenderer;
|
||||||
import refinedstorage.container.ContainerFluidInterface;
|
import refinedstorage.container.ContainerFluidInterface;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonCompare;
|
import refinedstorage.gui.sidebutton.SideButtonCompare;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import refinedstorage.tile.TileFluidInterface;
|
import refinedstorage.tile.TileFluidInterface;
|
||||||
|
|
||||||
public class GuiFluidInterface extends GuiBase {
|
public class GuiFluidInterface extends GuiBase {
|
||||||
private static final FluidStackRenderer TANK_IN_RENDERER = new FluidStackRenderer(TileFluidInterface.TANK_CAPACITY, true, 12, 47, null);
|
private static final FluidRenderer TANK_RENDERER = new FluidRenderer(TileFluidInterface.TANK_CAPACITY, 12, 47);
|
||||||
|
|
||||||
public GuiFluidInterface(ContainerFluidInterface container) {
|
public GuiFluidInterface(ContainerFluidInterface container) {
|
||||||
super(container, 211, 204);
|
super(container, 211, 204);
|
||||||
@@ -32,11 +32,11 @@ public class GuiFluidInterface extends GuiBase {
|
|||||||
drawTexture(x, y, 0, 0, width, height);
|
drawTexture(x, y, 0, 0, width, height);
|
||||||
|
|
||||||
if (TileFluidInterface.TANK_IN.getValue() != null) {
|
if (TileFluidInterface.TANK_IN.getValue() != null) {
|
||||||
TANK_IN_RENDERER.draw(mc, x + 46, y + 56, TileFluidInterface.TANK_IN.getValue());
|
TANK_RENDERER.draw(mc, x + 46, y + 56, TileFluidInterface.TANK_IN.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TileFluidInterface.TANK_OUT.getValue() != null) {
|
if (TileFluidInterface.TANK_OUT.getValue() != null) {
|
||||||
TANK_IN_RENDERER.draw(mc, x + 118, y + 56, TileFluidInterface.TANK_OUT.getValue());
|
TANK_RENDERER.draw(mc, x + 118, y + 56, TileFluidInterface.TANK_OUT.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ package refinedstorage.inventory;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
import refinedstorage.apiimpl.storage.fluid.FluidUtils;
|
import refinedstorage.apiimpl.storage.fluid.FluidUtils;
|
||||||
|
|
||||||
public class ItemHandlerFluid extends ItemHandlerBasic {
|
public class ItemHandlerFluid extends ItemHandlerBasic {
|
||||||
private FluidStack[] fluids;
|
private FluidStack[] fluids;
|
||||||
|
|
||||||
public ItemHandlerFluid(int size, TileEntity tile) {
|
public ItemHandlerFluid(int size, TileEntity tile) {
|
||||||
super(size, tile, s -> FluidUtils.getFluidFromStack(s, true) != null);
|
super(size, tile, s -> FluidUtils.getFluidFromStack(ItemHandlerHelper.copyStackWithSize(s, 1), true) != null);
|
||||||
|
|
||||||
this.fluids = new FluidStack[size];
|
this.fluids = new FluidStack[size];
|
||||||
}
|
}
|
||||||
@@ -23,7 +24,7 @@ public class ItemHandlerFluid extends ItemHandlerBasic {
|
|||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
fluids[slot] = null;
|
fluids[slot] = null;
|
||||||
} else {
|
} else {
|
||||||
fluids[slot] = FluidUtils.getFluidFromStack(stack, false);
|
fluids[slot] = FluidUtils.getFluidFromStack(ItemHandlerHelper.copyStackWithSize(stack, 1), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user