mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 06:42:56 +00:00
Deduplicate a bit of code between GuiFluidGauge and GuiGasGauge
This commit is contained in:
3 files changed
+68
-90
No files matched your search
@@ -1,36 +1,22 @@
|
||||
package mekanism.client.gui.element.gauge;
|
||||
|
||||
import java.util.Arrays;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.client.gui.GuiMekanismTile;
|
||||
import mekanism.client.gui.IGuiWrapper;
|
||||
import mekanism.client.gui.element.GuiElement;
|
||||
import mekanism.client.render.MekanismRenderer;
|
||||
import mekanism.client.render.MekanismRenderer.FluidType;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.base.ITankManager;
|
||||
import mekanism.common.item.ItemGaugeDropper;
|
||||
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiFluidGauge extends GuiGauge<FluidStack> {
|
||||
|
||||
private final IFluidInfoHandler infoHandler;
|
||||
public class GuiFluidGauge extends GuiTankGauge<FluidStack, FluidTank> {
|
||||
|
||||
public GuiFluidGauge(IFluidInfoHandler handler, Type type, IGuiWrapper gui, ResourceLocation def, int x, int y) {
|
||||
super(type, gui, def, x, y);
|
||||
infoHandler = handler;
|
||||
super(type, gui, def, x, y, handler);
|
||||
}
|
||||
|
||||
public static GuiFluidGauge getDummy(Type type, IGuiWrapper gui, ResourceLocation def, int x, int y) {
|
||||
@@ -39,40 +25,11 @@ public class GuiFluidGauge extends GuiGauge<FluidStack> {
|
||||
return gauge;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyRenderColor() {
|
||||
MekanismRenderer.color(dummy ? dummyType : infoHandler.getTank().getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inBounds(int xAxis, int yAxis) {
|
||||
return xAxis >= xLocation + 1 && xAxis <= xLocation + width - 1 && yAxis >= yLocation + 1 && yAxis <= yLocation + height - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransmissionType getTransmission() {
|
||||
return TransmissionType.FLUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xAxis, int yAxis, int button) {
|
||||
if (inBounds(xAxis, yAxis)) {
|
||||
ItemStack stack = GuiElement.mc.player.inventory.getItemStack();
|
||||
if (guiObj instanceof GuiMekanismTile && !stack.isEmpty() && stack.getItem() instanceof ItemGaugeDropper) {
|
||||
TileEntity tile = ((GuiMekanismTile) guiObj).getTileEntity();
|
||||
if (tile instanceof ITankManager && ((ITankManager) tile).getTanks() != null) {
|
||||
int index = Arrays.asList(((ITankManager) tile).getTanks()).indexOf(infoHandler.getTank());
|
||||
if (index != -1) {
|
||||
if (button == 0 && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
button = 2;
|
||||
}
|
||||
Mekanism.packetHandler.sendToServer(new DropperUseMessage(Coord4D.get(tile), button, index));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScaledLevel() {
|
||||
if (dummy) {
|
||||
@@ -106,8 +63,12 @@ public class GuiFluidGauge extends GuiGauge<FluidStack> {
|
||||
return tank.getFluid() != null ? LangUtils.localizeFluidStack(tank.getFluid()) + ": " + amountStr : LangUtils.localize("gui.empty");
|
||||
}
|
||||
|
||||
public interface IFluidInfoHandler {
|
||||
@Override
|
||||
protected void applyRenderColor() {
|
||||
MekanismRenderer.color(dummy ? dummyType : infoHandler.getTank().getFluid());
|
||||
}
|
||||
|
||||
public interface IFluidInfoHandler extends ITankInfoHandler<FluidTank> {
|
||||
|
||||
FluidTank getTank();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,21 @@
|
||||
package mekanism.client.gui.element.gauge;
|
||||
|
||||
import java.util.Arrays;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasTank;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.client.gui.GuiMekanismTile;
|
||||
import mekanism.client.gui.IGuiWrapper;
|
||||
import mekanism.client.gui.element.GuiElement;
|
||||
import mekanism.client.render.MekanismRenderer;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.base.ITankManager;
|
||||
import mekanism.common.item.ItemGaugeDropper;
|
||||
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiGasGauge extends GuiGauge<Gas> {
|
||||
|
||||
private final IGasInfoHandler infoHandler;
|
||||
public class GuiGasGauge extends GuiTankGauge<Gas, GasTank> {
|
||||
|
||||
public GuiGasGauge(IGasInfoHandler handler, Type type, IGuiWrapper gui, ResourceLocation def, int x, int y) {
|
||||
super(type, gui, def, x, y);
|
||||
infoHandler = handler;
|
||||
super(type, gui, def, x, y, handler);
|
||||
}
|
||||
|
||||
public static GuiGasGauge getDummy(Type type, IGuiWrapper gui, ResourceLocation def, int x, int y) {
|
||||
@@ -38,35 +24,11 @@ public class GuiGasGauge extends GuiGauge<Gas> {
|
||||
return gauge;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inBounds(int xAxis, int yAxis) {
|
||||
return xAxis >= xLocation + 1 && xAxis <= xLocation + width - 1 && yAxis >= yLocation + 1 && yAxis <= yLocation + height - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransmissionType getTransmission() {
|
||||
return TransmissionType.GAS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xAxis, int yAxis, int button) {
|
||||
if (inBounds(xAxis, yAxis)) {
|
||||
ItemStack stack = GuiElement.mc.player.inventory.getItemStack();
|
||||
if (guiObj instanceof GuiMekanismTile && !stack.isEmpty() && stack.getItem() instanceof ItemGaugeDropper) {
|
||||
TileEntity tile = ((GuiMekanismTile) guiObj).getTileEntity();
|
||||
if (tile instanceof ITankManager && ((ITankManager) tile).getTanks() != null) {
|
||||
int index = Arrays.asList(((ITankManager) tile).getTanks()).indexOf(infoHandler.getTank());
|
||||
if (index != -1) {
|
||||
if (button == 0 && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
button = 2;
|
||||
}
|
||||
Mekanism.packetHandler.sendToServer(new DropperUseMessage(Coord4D.get(tile), button, index));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScaledLevel() {
|
||||
if (dummy) {
|
||||
@@ -105,8 +67,6 @@ public class GuiGasGauge extends GuiGauge<Gas> {
|
||||
}
|
||||
}
|
||||
|
||||
public interface IGasInfoHandler {
|
||||
|
||||
GasTank getTank();
|
||||
public interface IGasInfoHandler extends ITankInfoHandler<GasTank> {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package mekanism.client.gui.element.gauge;
|
||||
|
||||
import java.util.Arrays;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.client.gui.GuiMekanismTile;
|
||||
import mekanism.client.gui.IGuiWrapper;
|
||||
import mekanism.client.gui.element.GuiElement;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.base.ITankManager;
|
||||
import mekanism.common.item.ItemGaugeDropper;
|
||||
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class GuiTankGauge<T, TANK> extends GuiGauge<T> {
|
||||
|
||||
protected final ITankInfoHandler<TANK> infoHandler;
|
||||
|
||||
public GuiTankGauge(Type type, IGuiWrapper gui, ResourceLocation def, int x, int y, ITankInfoHandler<TANK> infoHandler) {
|
||||
super(type, gui, def, x, y);
|
||||
this.infoHandler = infoHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inBounds(int xAxis, int yAxis) {
|
||||
return xAxis >= xLocation + 1 && xAxis <= xLocation + width - 1 && yAxis >= yLocation + 1 && yAxis <= yLocation + height - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xAxis, int yAxis, int button) {
|
||||
if (inBounds(xAxis, yAxis)) {
|
||||
ItemStack stack = GuiElement.mc.player.inventory.getItemStack();
|
||||
if (guiObj instanceof GuiMekanismTile && !stack.isEmpty() && stack.getItem() instanceof ItemGaugeDropper) {
|
||||
TileEntity tile = ((GuiMekanismTile) guiObj).getTileEntity();
|
||||
if (tile instanceof ITankManager && ((ITankManager) tile).getTanks() != null) {
|
||||
int index = Arrays.asList(((ITankManager) tile).getTanks()).indexOf(infoHandler.getTank());
|
||||
if (index != -1) {
|
||||
if (button == 0 && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
button = 2;
|
||||
}
|
||||
Mekanism.packetHandler.sendToServer(new DropperUseMessage(Coord4D.get(tile), button, index));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface ITankInfoHandler<TANK> {
|
||||
|
||||
TANK getTank();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user