Renew Replenisher (#435)

This commit is contained in:
lc-1337 authored and GitHub committed 2026-05-27 08:41:28 +02:00
1 parent 4a030a52b6
commit 0a84d208f3
6 files changed
+243 -220

No files matched your search

@@ -1,101 +1,105 @@
package com.glodblock.github.client.gui;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerSuperStockReplenisher;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
import appeng.api.storage.StorageName;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IAEStackType;
import appeng.client.gui.AEBaseGui;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotFake;
import appeng.client.gui.slots.VirtualMEPhantomSlot;
import appeng.client.gui.slots.VirtualMEPhantomSlotPrecise;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketVirtualSlot;
import appeng.util.item.AEItemStack;
import appeng.util.item.AEFluidStackType;
import appeng.util.item.AEItemStackType;
public class GuiSuperStockReplenisher extends AEBaseGui {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/superStockReplenisher.png");
private final DecimalFormat df = new DecimalFormat("#.#");
private Map<Integer, IAEStack<?>> list = new HashMap<>();
private final ContainerSuperStockReplenisher containerSuperStockReplenisher;
private final VirtualMEPhantomSlotPrecise[] configFluidsSlots = new VirtualMEPhantomSlotPrecise[9];
private final VirtualMEPhantomSlotPrecise[] configItemsSlots = new VirtualMEPhantomSlotPrecise[63];
public GuiSuperStockReplenisher(InventoryPlayer ipl, TileSuperStockReplenisher tile) {
super(new ContainerSuperStockReplenisher(ipl, tile));
this.containerSuperStockReplenisher = (ContainerSuperStockReplenisher) inventorySlots;
this.ySize = 251;
this.xSize = 216;
}
@Override
protected void handleMouseClick(Slot slot, int slotIdx, int ctrlDown, int mouseButton) {
if (mouseButton == 3) {
if (slot instanceof SlotFake) {
if (slot.getHasStack()) {
IAEItemStack stack = AEItemStack.create(slot.getStack());
((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
for (int i = 0; i < this.inventorySlots.inventorySlots.size(); i++) {
if (slot.equals(this.inventorySlots.inventorySlots.get(i))) {
NetworkHandler.instance
.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_PATTERN_VALUE_AMOUNT));
NetworkHandler.instance
.sendToServer(new PacketVirtualSlot(StorageName.CRAFTING_INPUT, i, stack));
}
}
return;
}
public void initGui() {
super.initGui();
this.initSlots();
}
private void initSlots() {
final int xo = 8;
final int yo = 8;
for (int i = 0; i < 9; i++) {
VirtualMEPhantomSlotPrecise slot = new VirtualMEPhantomSlotPrecise(
xo + i * 18,
yo,
this.containerSuperStockReplenisher.configFluidsSlots,
i,
this::acceptType);
this.configFluidsSlots[i] = slot;
this.registerVirtualSlots(slot);
}
final int iyo = 29;
for (int y = 0; y < 7; y++) {
for (int ix = 0; ix < 9; ix++) {
VirtualMEPhantomSlotPrecise slot = new VirtualMEPhantomSlotPrecise(
xo + ix * 18,
iyo + y * 18,
this.containerSuperStockReplenisher.configItemsSlots,
y * 9 + ix,
this::acceptType);
this.configItemsSlots[y * 9 + ix] = slot;
this.registerVirtualSlots(slot);
}
}
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
}
@Override
public void func_146977_a(Slot s) {
if (s instanceof SlotFake) {
this.drawFillStatus(s);
}
super.func_146977_a(s);
}
private void drawFillStatus(VirtualMEPhantomSlotPrecise virtualSlot) {
final int offsetX = virtualSlot.getX() - 8;
final int offsetY = virtualSlot.getY() - 12;
final IAEStack<?> aes = virtualSlot.getAEStack();
final long stackSize = aes != null ? aes.getStackSize() : 0;
final int slotIndex = virtualSlot.getStorageName() == StorageName.NONE ? virtualSlot.getSlotIndex()
: virtualSlot.getSlotIndex() + 100;
private void drawFillStatus(Slot slotIn) {
int offsetX = slotIn.xDisplayPosition - 8;
int offsetY = slotIn.yDisplayPosition - 11;
ItemStack itemstack = slotIn.getStack();
int slotInt = slotIn.slotNumber;
if (itemstack != null) {
if (stackSize != 0) {
String s = "0%";
if (slotInt > 0 && slotInt < 10) {
IAEStack<?> aeStack = list.get(slotInt - 1);
if (aeStack != null)
s = (int) (((float) aeStack.getStackSize() / ItemFluidPacket.getFluidAmount(itemstack)) * 100)
+ "%";
} else if (slotInt > 9 && slotInt < 73) {
IAEStack<?> aeStack = list.get(slotInt + 90);
if (aeStack != null && itemstack.stackSize > 0) {
long i = aeStack.getStackSize();
s = (int) (((float) i / itemstack.stackSize) * 100) + "%";
}
}
IAEStack<?> aeStack = list.get(slotIndex);
if (aeStack != null) s = df.format((float) aeStack.getStackSize() / stackSize * 100) + "%";
float scale = 0.5f;
float shiftX = 2;
float shiftY = 1;
final float inverseScaleFactor = 1.0f / scale;
final int X = (int) (((float) offsetX - shiftX + 10.0f) * inverseScaleFactor);
final int Y = (int) (((float) offsetY - shiftY + 16.0f - 7.0f * scale) * inverseScaleFactor);
final int X = (int) (((float) offsetX - shiftX + 10.0f) * inverseScaleFactor) + 1;
final int Y = (int) (((float) offsetY - shiftY + 16.0f - 7.0f * scale) * inverseScaleFactor) + 2;
GL11.glTranslatef(0.0f, 0.0f, 200.0f);
GL11.glScaled(scale, scale, scale);
this.fontRendererObj.drawStringWithShadow(s, X, Y, 16777215);
@@ -104,9 +108,15 @@ public class GuiSuperStockReplenisher extends AEBaseGui {
}
}
private void drawVirtualSlots() {
for (VirtualMEPhantomSlotPrecise slot : this.configFluidsSlots) this.drawFillStatus(slot);
for (VirtualMEPhantomSlotPrecise slot : this.configItemsSlots) this.drawFillStatus(slot);
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
this.drawVirtualSlots();
}
@Override
@@ -118,4 +128,9 @@ public class GuiSuperStockReplenisher extends AEBaseGui {
public void update(Map<Integer, IAEStack<?>> map) {
this.list = map;
}
private boolean acceptType(VirtualMEPhantomSlot slot, IAEStackType<?> type, int mouseButton) {
if (slot.getStorageName() == StorageName.NONE) return type == AEFluidStackType.FLUID_STACK_TYPE;
else return type == AEItemStackType.ITEM_STACK_TYPE;
}
}
@@ -3,63 +3,57 @@ package com.glodblock.github.client.gui.container;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.FCBaseItemCell;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFake;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.SPacketSuperStockReplenisherUpdate;
import com.glodblock.github.util.FluidPrimaryGui;
import appeng.api.storage.StorageName;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.client.gui.implementations.GuiPatternItemRenamer;
import appeng.client.gui.implementations.GuiPatternValueAmount;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.container.PrimaryGui;
import appeng.container.interfaces.IVirtualSlotHolder;
import appeng.container.interfaces.IVirtualSlotSource;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.SlotPatternOutputs;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketVirtualSlot;
import appeng.container.sync.SyncManager;
import appeng.container.sync.handlers.AEStackInventorySyncHandler;
import appeng.items.storage.ItemBasicStorageCell;
import appeng.tile.inventory.IAEStackInventory;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
public class ContainerSuperStockReplenisher extends AEBaseContainer
implements IOptionalSlotHost, IVirtualSlotHolder, IVirtualSlotSource {
public class ContainerSuperStockReplenisher extends AEBaseContainer implements IVirtualSlotSource {
private final TileSuperStockReplenisher tile;
private final IInventory configFluids;
private final IInventory configItems;
private int lastUpdated = 0;
private int lastUpdated = 1337;
private final IAEStackInventory configFluids;
public final AEStackInventorySyncHandler configFluidsSlots;
private final IAEStackInventory configItems;
public final AEStackInventorySyncHandler configItemsSlots;
public ContainerSuperStockReplenisher(InventoryPlayer ipl, TileSuperStockReplenisher tile) {
super(ipl, tile);
this.tile = tile;
configFluids = tile.getConfigFluid();
configItems = tile.getConfigItems();
this.configFluids = tile.getConfigFluids();
this.configItems = tile.getConfigItems();
final IInventory cell = tile.getCell();
final int x = 8;
final int fy = 8;
final SyncManager sm = this.getSyncManager();
this.configFluidsSlots = sm.root().aeStackInventory("fluidConfig", this.configFluids);
this.configItemsSlots = sm.root().aeStackInventory("itemConfig", this.configItems);
this.addSlotToContainer(
new SlotRestrictedInput(
@@ -67,56 +61,33 @@ public class ContainerSuperStockReplenisher extends AEBaseContainer
cell,
0,
173,
fy,
8,
this.getInventoryPlayer()));
for (int i = 0; i < 9; i++) {
addSlotToContainer(new OptionalFluidSlotFake(configFluids, this, i, x, fy, i, 0, 0));
}
final int io = 29;
for (int y = 0; y < 7; y++) {
for (int ix = 0; ix < 9; ix++) {
this.addSlotToContainer(new SlotPatternOutputs(configItems, this, y * 9 + ix, x, io, ix, y, y));
}
}
bindPlayerInventory(ipl, 0, 251 - 82);
}
@Override
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer player) {
if (slotId == 0 && player.inventory.getItemStack() == null && isConfigurated()) {
return null;
}
if (slotId == 0 && player.inventory.getItemStack() == null && isConfigurated()) return null;
return super.slotClick(slotId, clickedButton, mode, player);
}
@Override
public boolean isSlotEnabled(int idx) {
return true;
}
@Override
public void addCraftingToCrafters(ICrafting p_75132_1_) {
super.addCraftingToCrafters(p_75132_1_);
lastUpdated = 24;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (Platform.isClient()) return;
if (lastUpdated > 20) {
lastUpdated = 0;
if (this.lastUpdated > 20) {
this.lastUpdated = 0;
Map<Integer, IAEStack<?>> tmp = new HashMap<>();
for (int i = 0; i < tile.getInternalFluid().getSlots(); i++) {
tmp.put(i, tile.getInternalFluid().getFluidInSlot(i));
for (int i = 0; i < this.tile.getInternalFluid().getSlots(); i++) {
tmp.put(i, this.tile.getInternalFluid().getFluidInSlot(i));
}
for (int i = 0; i < tile.getInternalInventory().getSizeInventory(); i++) {
tmp.put(i + 100, AEItemStack.create(tile.getInternalInventory().getStackInSlot(i)));
for (int i = 0; i < this.tile.getInternalInventory().getSizeInventory(); i++) {
tmp.put(i + 100, AEItemStack.create(this.tile.getInternalInventory().getStackInSlot(i)));
}
for (final Object g : this.crafters) {
@@ -125,20 +96,16 @@ public class ContainerSuperStockReplenisher extends AEBaseContainer
}
}
}
lastUpdated++;
this.lastUpdated++;
}
private boolean isConfigurated() {
for (int i = 0; i < configItems.getSizeInventory(); i++) {
if (configItems.getStackInSlot(i) != null) {
return true;
}
}
for (int i = 0; i < configFluids.getSizeInventory(); i++) {
if (configFluids.getStackInSlot(i) != null) {
return true;
}
}
for (int i = 0; i < this.configItems.getSizeInventory(); i++)
if (this.configItems.getAEStackInSlot(i) != null) return true;
for (int i = 0; i < this.configFluids.getSizeInventory(); i++)
if (this.configFluids.getAEStackInSlot(i) != null) return true;
return false;
}
@@ -167,10 +134,6 @@ public class ContainerSuperStockReplenisher extends AEBaseContainer
return super.isValidForSlot(s, is);
}
public TileSuperStockReplenisher getTile() {
return tile;
}
@Override
public PrimaryGui createPrimaryGui() {
ContainerOpenContext context = getOpenContext();
@@ -181,40 +144,18 @@ public class ContainerSuperStockReplenisher extends AEBaseContainer
context.getSide());
}
@Override
public void receiveSlotStacks(StorageName invName, Int2ObjectMap<IAEStack<?>> slotStacks) {
var entry = slotStacks.int2ObjectEntrySet().iterator().next();
IAEStack<?> aes = entry.getValue();
int slotIndex = entry.getIntKey();
if (Platform.isServer()) {
for (ICrafting crafter : this.crafters) {
final EntityPlayerMP emp = (EntityPlayerMP) crafter;
NetworkHandler.instance.sendTo(new PacketVirtualSlot(invName, slotIndex, aes), emp);
}
} else {
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if (gs instanceof GuiPatternValueAmount gpva) {
gpva.update();
} else if (gs instanceof GuiPatternItemRenamer gpir) {
gpir.update();
}
}
}
@Override
public void updateVirtualSlot(StorageName invName, int slotId, IAEStack<?> aes) {
if (aes instanceof IAEItemStack ais) {
ItemStack newIs;
if (ais.getItem() instanceof ItemFluidPacket) {
newIs = ais.getItemStack();
newIs.stackSize = 1;
ItemFluidPacket.setFluidAmount(newIs, aes.getStackSize());
} else {
newIs = ais.getItemStack();
if (aes != null && aes.getStackSize() > Integer.MAX_VALUE) aes.setStackSize(Integer.MAX_VALUE);
switch (invName) {
case NONE -> {
this.configFluids.putAEStackInSlot(slotId, aes);
this.configFluidsSlots.markDirty();
}
case CONFIG -> {
this.configItems.putAEStackInSlot(slotId, aes);
this.configItemsSlots.markDirty();
}
this.inventorySlots.get(slotId).putStack(newIs);
}
}
}