refactor 5

This commit is contained in:
GlodBlock committed 2023-01-22 19:37:44 +08:00
1 parent d9449622b9
commit 5b62c4fdc8
17 files changed
+204 -510

No files matched your search

@@ -120,9 +120,10 @@ public class GuiDualInterface extends GuiUpgradeable {
@Override
protected void actionPerformed(final GuiButton btn) {
super.actionPerformed(btn);
final boolean backwards = Mouse.isButtonDown(1);
if (btn == null) {
return;
}
if (btn == this.priority) {
if (isTile()) {
FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(GuiType.PRIORITY_TILE));
@@ -149,7 +150,7 @@ public class GuiDualInterface extends GuiUpgradeable {
if (btn == this.insertionMode) {
NetworkHandler.instance.sendToServer(new PacketConfigButton(this.insertionMode.getSetting(), backwards));
}
if (btn == this.sidelessMode && this.sidelessMode != null) {
if (btn == this.sidelessMode) {
NetworkHandler.instance.sendToServer(new PacketConfigButton(this.sidelessMode.getSetting(), backwards));
}
}
@@ -7,23 +7,21 @@ import appeng.core.localization.GuiText;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerFluidInterface;
import com.glodblock.github.common.parts.PartFluidInterface;
import com.glodblock.github.common.tile.TileFluidInterface;
import com.glodblock.github.inventory.IAEFluidTank;
import com.glodblock.github.inventory.IDualHost;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.gui.MouseRegionManager;
import com.glodblock.github.inventory.gui.TankMouseHandler;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.CPacketSwitchGuis;
import com.glodblock.github.util.NameConst;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import com.glodblock.github.util.RenderUtil;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
@@ -34,20 +32,12 @@ public class GuiFluidInterface extends AEBaseGui {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/interface_fluid.png");
private static final int TANK_X = 35, TANK_X_OFF = 18, TANK_Y = 53;
private static final int TANK_WIDTH = 16, TANK_HEIGHT = 68;
private final ContainerFluidInterface cont;
private GuiTabButton switcher;
private final MouseRegionManager mouseRegions = new MouseRegionManager(this);
public GuiFluidInterface(InventoryPlayer ipl, TileFluidInterface tile) {
super(new ContainerFluidInterface(ipl, tile));
this.cont = (ContainerFluidInterface) inventorySlots;
this.ySize = 231;
this.addMouseRegin();
}
public GuiFluidInterface(InventoryPlayer ipl, PartFluidInterface tile) {
public GuiFluidInterface(InventoryPlayer ipl, IDualHost tile) {
super(new ContainerFluidInterface(ipl, tile));
this.cont = (ContainerFluidInterface) inventorySlots;
this.ySize = 231;
@@ -61,11 +51,7 @@ public class GuiFluidInterface extends AEBaseGui {
TANK_Y,
TANK_WIDTH,
TANK_HEIGHT,
new TankMouseHandler(
isPart()
? ((PartFluidInterface) cont.getTile()).getInternalFluid()
: ((TileFluidInterface) cont.getTile()).getInternalFluid(),
i));
new TankMouseHandler(cont.getTile().getInternalFluid(), i));
}
}
@@ -98,19 +84,14 @@ public class GuiFluidInterface extends AEBaseGui {
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
GL11.glColor4f(1F, 1F, 1F, 1F);
IAEFluidTank fluidInv;
if (isPart()) {
fluidInv = ((PartFluidInterface) cont.getTile()).getInternalFluid();
} else {
fluidInv = ((TileFluidInterface) cont.getTile()).getInternalFluid();
}
IAEFluidTank fluidInv = cont.getTile().getInternalFluid();
mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
for (int i = 0; i < 6; i++) {
if (!isPart()) {
fontRendererObj.drawString(dirName(i), TANK_X + i * TANK_X_OFF + 5, 22, 0x404040);
}
renderFluidIntoGui(
RenderUtil.renderFluidIntoGui(
this,
TANK_X + i * TANK_X_OFF,
TANK_Y,
TANK_WIDTH,
@@ -132,29 +113,6 @@ public class GuiFluidInterface extends AEBaseGui {
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize);
}
public void renderFluidIntoGui(
int x, int y, int width, int height, @Nullable IAEFluidStack aeFluidStack, int capacity) {
if (aeFluidStack != null) {
GL11.glDisable(2896);
GL11.glColor3f(1.0F, 1.0F, 1.0F);
int hi = (int) (height * ((double) aeFluidStack.getStackSize() / capacity));
if (aeFluidStack.getStackSize() > 0 && hi > 0) {
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
IIcon fluidIcon = aeFluidStack.getFluid().getStillIcon();
GL11.glColor3f(
(float) (aeFluidStack.getFluid().getColor() >> 16 & 255) / 255.0F,
(float) (aeFluidStack.getFluid().getColor() >> 8 & 255) / 255.0F,
(float) (aeFluidStack.getFluid().getColor() & 255) / 255.0F);
for (int th = 0; th <= hi; th += 16) {
if (hi - th <= 0) break;
this.drawTexturedModelRectFromIcon(
x, y + height - Math.min(16, hi - th) - th, fluidIcon, width, Math.min(16, hi - th));
}
GL11.glColor3f(1.0F, 1.0F, 1.0F);
}
}
}
@Override
protected void actionPerformed(final GuiButton btn) {
super.actionPerformed(btn);
@@ -166,18 +124,9 @@ public class GuiFluidInterface extends AEBaseGui {
public void update(int id, IAEFluidStack stack) {
if (id >= 100) {
id -= 100;
if (isPart()) {
((PartFluidInterface) cont.getTile()).setConfig(id, stack);
} else {
((TileFluidInterface) cont.getTile()).setConfig(id, stack);
}
cont.getTile().setConfig(id - 100, stack);
} else {
if (isPart()) {
((PartFluidInterface) cont.getTile()).setFluidInv(id, stack);
} else {
((TileFluidInterface) cont.getTile()).setFluidInv(id, stack);
}
cont.getTile().setFluidInv(id, stack);
}
}
@@ -11,12 +11,10 @@ import com.glodblock.github.inventory.gui.ButtonMouseHandler;
import com.glodblock.github.inventory.gui.MouseRegionManager;
import com.glodblock.github.inventory.gui.TankMouseHandler;
import com.glodblock.github.util.NameConst;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import com.glodblock.github.util.RenderUtil;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
@@ -40,7 +38,7 @@ public class GuiIngredientBuffer extends AEBaseGui {
TANK_Y,
TANK_WIDTH,
TANK_HEIGHT,
new TankMouseHandler(cont.getTile().getFluidInventory(), i));
new TankMouseHandler(cont.getTile().getInternalFluid(), i));
mouseRegions.addRegion(
TANK_X + 10 + 22 * i, TANK_Y + TANK_HEIGHT + 2, 7, 7, ButtonMouseHandler.dumpTank(cont, i));
}
@@ -65,10 +63,11 @@ public class GuiIngredientBuffer extends AEBaseGui {
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
GL11.glColor4f(1F, 1F, 1F, 1F);
IAEFluidTank fluidInv = cont.getTile().getFluidInventory();
IAEFluidTank fluidInv = cont.getTile().getInternalFluid();
mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
for (int i = 0; i < 4; i++) {
renderFluidIntoGui(
RenderUtil.renderFluidIntoGui(
this,
TANK_X + i * TANK_X_OFF,
TANK_Y,
TANK_WIDTH,
@@ -77,34 +76,10 @@ public class GuiIngredientBuffer extends AEBaseGui {
fluidInv.getTankInfo(ForgeDirection.UNKNOWN)[i].capacity);
}
GL11.glColor4f(1F, 1F, 1F, 1F);
mouseRegions.render(mouseX, mouseY);
}
public void renderFluidIntoGui(
int x, int y, int width, int height, @Nullable IAEFluidStack aeFluidStack, int capacity) {
if (aeFluidStack != null) {
GL11.glDisable(2896);
GL11.glColor3f(1.0F, 1.0F, 1.0F);
int hi = (int) (height * ((double) aeFluidStack.getStackSize() / capacity));
if (aeFluidStack.getStackSize() > 0 && hi > 0) {
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
IIcon fluidIcon = aeFluidStack.getFluid().getStillIcon();
GL11.glColor3f(
(float) (aeFluidStack.getFluid().getColor() >> 16 & 255) / 255.0F,
(float) (aeFluidStack.getFluid().getColor() >> 8 & 255) / 255.0F,
(float) (aeFluidStack.getFluid().getColor() & 255) / 255.0F);
for (int th = 0; th <= hi; th += 16) {
if (hi - th <= 0) break;
this.drawTexturedModelRectFromIcon(
x, y + height - Math.min(16, hi - th) - th, fluidIcon, width, Math.min(16, hi - th));
}
GL11.glColor3f(1.0F, 1.0F, 1.0F);
}
}
}
public void update(int slot, IAEFluidStack aeFluidStack) {
cont.getTile().getFluidInventory().setFluidInSlot(slot, aeFluidStack);
cont.getTile().getInternalFluid().setFluidInSlot(slot, aeFluidStack);
}
}
@@ -11,12 +11,10 @@ import com.glodblock.github.inventory.gui.ButtonMouseHandler;
import com.glodblock.github.inventory.gui.MouseRegionManager;
import com.glodblock.github.inventory.gui.TankMouseHandler;
import com.glodblock.github.util.NameConst;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import com.glodblock.github.util.RenderUtil;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
@@ -40,7 +38,7 @@ public class GuiLargeIngredientBuffer extends AEBaseGui {
TANK_Y,
TANK_WIDTH,
TANK_HEIGHT,
new TankMouseHandler(cont.getTile().getFluidInventory(), i));
new TankMouseHandler(cont.getTile().getInternalFluid(), i));
mouseRegions.addRegion(
TANK_X + 10 + 22 * i, TANK_Y + TANK_HEIGHT + 2, 7, 7, ButtonMouseHandler.dumpTank(cont, i));
}
@@ -66,10 +64,11 @@ public class GuiLargeIngredientBuffer extends AEBaseGui {
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
GL11.glColor4f(1F, 1F, 1F, 1F);
IAEFluidTank fluidInv = cont.getTile().getFluidInventory();
IAEFluidTank fluidInv = cont.getTile().getInternalFluid();
mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
for (int i = 0; i < 7; i++) {
renderFluidIntoGui(
RenderUtil.renderFluidIntoGui(
this,
TANK_X + i * TANK_X_OFF,
TANK_Y,
TANK_WIDTH,
@@ -78,34 +77,10 @@ public class GuiLargeIngredientBuffer extends AEBaseGui {
fluidInv.getTankInfo(ForgeDirection.UNKNOWN)[i].capacity);
}
GL11.glColor4f(1F, 1F, 1F, 1F);
mouseRegions.render(mouseX, mouseY);
}
public void renderFluidIntoGui(
int x, int y, int width, int height, @Nullable IAEFluidStack aeFluidStack, int capacity) {
if (aeFluidStack != null) {
GL11.glDisable(2896);
GL11.glColor3f(1.0F, 1.0F, 1.0F);
int hi = (int) (height * ((double) aeFluidStack.getStackSize() / capacity));
if (aeFluidStack.getStackSize() > 0 && hi > 0) {
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
IIcon fluidIcon = aeFluidStack.getFluid().getStillIcon();
GL11.glColor3f(
(float) (aeFluidStack.getFluid().getColor() >> 16 & 255) / 255.0F,
(float) (aeFluidStack.getFluid().getColor() >> 8 & 255) / 255.0F,
(float) (aeFluidStack.getFluid().getColor() & 255) / 255.0F);
for (int th = 0; th <= hi; th += 16) {
if (hi - th <= 0) break;
this.drawTexturedModelRectFromIcon(
x, y + height - Math.min(16, hi - th) - th, fluidIcon, width, Math.min(16, hi - th));
}
GL11.glColor3f(1.0F, 1.0F, 1.0F);
}
}
}
public void update(int slot, IAEFluidStack aeFluidStack) {
cont.getTile().getFluidInventory().setFluidInSlot(slot, aeFluidStack);
cont.getTile().getInternalFluid().setFluidInSlot(slot, aeFluidStack);
}
}
@@ -6,8 +6,7 @@ import appeng.container.slot.IOptionalSlotHost;
import appeng.util.item.AEFluidStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.parts.PartFluidInterface;
import com.glodblock.github.common.tile.TileFluidInterface;
import com.glodblock.github.inventory.IDualHost;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly;
import com.glodblock.github.network.SPacketFluidUpdate;
import java.util.HashMap;
@@ -19,9 +18,9 @@ import net.minecraft.inventory.IInventory;
public class ContainerFluidInterface extends AEBaseContainer implements IOptionalSlotHost {
private final Object tile;
private final IDualHost tile;
public ContainerFluidInterface(InventoryPlayer ipl, TileFluidInterface tile) {
public ContainerFluidInterface(InventoryPlayer ipl, IDualHost tile) {
super(ipl, tile);
this.tile = tile;
IInventory inv = tile.getConfig();
@@ -34,20 +33,7 @@ public class ContainerFluidInterface extends AEBaseContainer implements IOptiona
bindPlayerInventory(ipl, 0, 149);
}
public ContainerFluidInterface(InventoryPlayer ipl, PartFluidInterface tile) {
super(ipl, tile);
this.tile = tile;
IInventory inv = tile.getConfig();
final int y = 35;
final int x = 35;
for (int i = 0; i < 6; i++) {
addSlotToContainer(new OptionalFluidSlotFakeTypeOnly(
inv, tile.getDualityFluid().getConfig(), this, i, x, y, i, 0, 0));
}
bindPlayerInventory(ipl, 0, 149);
}
public Object getTile() {
public IDualHost getTile() {
return tile;
}
@@ -60,28 +46,15 @@ public class ContainerFluidInterface extends AEBaseContainer implements IOptiona
public void detectAndSendChanges() {
super.detectAndSendChanges();
Map<Integer, IAEFluidStack> tmp = new HashMap<>();
if (tile instanceof TileFluidInterface) {
for (int i = 0; i < ((TileFluidInterface) tile).getInternalFluid().getSlots(); i++) {
tmp.put(i, ((TileFluidInterface) tile).getInternalFluid().getFluidInSlot(i));
}
for (int i = 0; i < ((TileFluidInterface) tile).getConfig().getSizeInventory(); i++) {
tmp.put(
i + 100,
AEFluidStack.create(ItemFluidPacket.getFluidStack(
((TileFluidInterface) tile).getConfig().getStackInSlot(i))));
}
} else {
for (int i = 0; i < ((PartFluidInterface) tile).getInternalFluid().getSlots(); i++) {
tmp.put(i, ((PartFluidInterface) tile).getInternalFluid().getFluidInSlot(i));
}
for (int i = 0; i < ((PartFluidInterface) tile).getConfig().getSizeInventory(); i++) {
tmp.put(
i + 100,
AEFluidStack.create(ItemFluidPacket.getFluidStack(
((PartFluidInterface) tile).getConfig().getStackInSlot(i))));
}
for (int i = 0; i < tile.getInternalFluid().getSlots(); i++) {
tmp.put(i, tile.getInternalFluid().getFluidInSlot(i));
}
for (int i = 0; i < tile.getConfig().getSizeInventory(); i++) {
tmp.put(
i + 100,
AEFluidStack.create(
ItemFluidPacket.getFluidStack(tile.getConfig().getStackInSlot(i))));
}
for (final Object g : this.crafters) {
if (g instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(new SPacketFluidUpdate(tmp), (EntityPlayerMP) g);
@@ -22,10 +22,14 @@ public class ContainerIngredientBuffer extends AEBaseContainer implements ITankD
super(ipl, tile);
this.tile = tile;
IInventory inv = tile.getInternalInventory();
addSlots(inv);
bindPlayerInventory(ipl, 0, 140);
}
protected void addSlots(IInventory inv) {
for (int i = 0; i < 9; i++) {
addSlotToContainer(new SlotNormal(inv, i, 8 + 18 * i, 108));
}
bindPlayerInventory(ipl, 0, 140);
}
public TileIngredientBuffer getTile() {
@@ -34,13 +38,13 @@ public class ContainerIngredientBuffer extends AEBaseContainer implements ITankD
@Override
public boolean canDumpTank(int index) {
return tile.getFluidInventory().getFluidInSlot(index) != null;
return tile.getInternalFluid().getFluidInSlot(index) != null;
}
@Override
public void dumpTank(int index) {
if (index >= 0 && index < tile.getFluidInventory().getSlots()) {
tile.getFluidInventory().setFluidInSlot(index, null);
if (index >= 0 && index < tile.getInternalFluid().getSlots()) {
tile.getInternalFluid().setFluidInSlot(index, null);
}
}
@@ -48,8 +52,8 @@ public class ContainerIngredientBuffer extends AEBaseContainer implements ITankD
public void detectAndSendChanges() {
super.detectAndSendChanges();
Map<Integer, IAEFluidStack> tmp = new HashMap<>();
for (int i = 0; i < tile.getFluidInventory().getSlots(); i++) {
tmp.put(i, tile.getFluidInventory().getFluidInSlot(i));
for (int i = 0; i < tile.getInternalFluid().getSlots(); i++) {
tmp.put(i, tile.getInternalFluid().getFluidInSlot(i));
}
for (final Object g : this.crafters) {
if (g instanceof EntityPlayer) {
@@ -1,62 +1,21 @@
package com.glodblock.github.client.gui.container;
import appeng.api.storage.data.IAEFluidStack;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotNormal;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.ITankDump;
import com.glodblock.github.common.tile.TileLargeIngredientBuffer;
import com.glodblock.github.network.SPacketFluidUpdate;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
public class ContainerLargeIngredientBuffer extends AEBaseContainer implements ITankDump {
private final TileLargeIngredientBuffer tile;
public class ContainerLargeIngredientBuffer extends ContainerIngredientBuffer {
public ContainerLargeIngredientBuffer(InventoryPlayer ipl, TileLargeIngredientBuffer tile) {
super(ipl, tile);
this.tile = tile;
IInventory inv = tile.getInternalInventory();
}
protected void addSlots(IInventory inv) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new SlotNormal(inv, i * 9 + j, 8 + 18 * j, 72 + 18 * i));
}
}
bindPlayerInventory(ipl, 0, 140);
}
public TileLargeIngredientBuffer getTile() {
return tile;
}
@Override
public boolean canDumpTank(int index) {
return tile.getFluidInventory().getFluidInSlot(index) != null;
}
@Override
public void dumpTank(int index) {
if (index >= 0 && index < tile.getFluidInventory().getSlots()) {
tile.getFluidInventory().setFluidInSlot(index, null);
}
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
Map<Integer, IAEFluidStack> tmp = new HashMap<>();
for (int i = 0; i < tile.getFluidInventory().getSlots(); i++) {
tmp.put(i, tile.getFluidInventory().getFluidInSlot(i));
}
for (final Object g : this.crafters) {
if (g instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(new SPacketFluidUpdate(tmp), (EntityPlayerMP) g);
}
}
}
}