Skip to content

Commit

Permalink
Fix LevelTerminal data recursion and few in fixes gui
Browse files Browse the repository at this point in the history
  • Loading branch information
Laiff committed Oct 14, 2023
1 parent cbc113d commit be752e8
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void initGui() {
protected void repositionSlots() {
for (final Object obj : this.inventorySlots.inventorySlots) {
if (obj instanceof final AppEngSlot slot) {
slot.yDisplayPosition = this.ySize + slot.getY() - 78 - 7;
slot.yDisplayPosition = this.ySize + slot.getY() - 78 - 4;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.glodblock.github.network.CPacketLevelMaintainer;
import com.glodblock.github.network.CPacketLevelMaintainer.Action;
import com.glodblock.github.network.CPacketLevelTerminalCommands;
import com.glodblock.github.util.Ae2ReflectClient;
import com.glodblock.github.util.FCGuiColors;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
Expand All @@ -46,7 +45,6 @@
import appeng.api.util.DimensionalCoord;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.render.AppEngRenderItem;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotFake;
import appeng.core.sync.network.NetworkHandler;
Expand All @@ -64,7 +62,6 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
private final ContainerLevelMaintainer cont;
private final Component[] component = new Component[TileLevelMaintainer.REQ_COUNT];
private final MouseRegionManager mouseRegions = new MouseRegionManager(this);
private final AppEngRenderItem stackSizeRenderer = Ae2ReflectClient.getStackSizeRenderer(this);
private FCGuiTextField input;
private int lastWorkingTick;
private int refreshTick;
Expand Down Expand Up @@ -219,7 +216,6 @@ public void func_146977_a(final Slot s) {
public boolean drawSlot0(Slot slot) {
if (slot instanceof SlotFake) {
IAEItemStack stack = ((SlotFluidConvertingFake) slot).getAeStack();
GL11.glEnable(GL11.GL_DEPTH_TEST);
super.func_146977_a(new SlotSingleItem(slot));
if (stack == null) return true;
IAEItemStack fake = stack.copy();
Expand All @@ -228,16 +224,17 @@ public boolean drawSlot0(Slot slot) {
} else {
fake.setStackSize(0);
}
float lastZLevel = this.zLevel;
this.zLevel = 0f;
GL11.glTranslatef(0.0f, 0.0f, 200.0f);
stackSizeRenderer.setAeStack(fake);
stackSizeRenderer.renderItemOverlayIntoGUI(
aeRenderItem.renderItemOverlayIntoGUI(
fontRendererObj,
mc.getTextureManager(),
fake.getItemStack(),
slot.xDisplayPosition,
slot.yDisplayPosition);
GL11.glTranslatef(0.0f, 0.0f, -200.0f);
this.zLevel = lastZLevel;
return false;
}
return true;
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/com/glodblock/github/client/gui/GuiLevelTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import com.glodblock.github.network.CPacketLevelTerminalCommands;
import com.glodblock.github.network.CPacketLevelTerminalCommands.Action;
import com.glodblock.github.network.CPacketRenamer;
import com.glodblock.github.util.Ae2ReflectClient;
import com.glodblock.github.util.FCGuiColors;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.NameConst;
Expand All @@ -69,7 +68,6 @@
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.IDropToFillTextField;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.client.render.AppEngRenderItem;
import appeng.client.render.BlockPosHighlighter;
import appeng.container.AEBaseContainer;
import appeng.container.slot.AppEngSlot;
Expand All @@ -95,7 +93,6 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/level_terminal.png");
protected int offsetY;
private static final int offsetX = 21;
private final AppEngRenderItem stackSizeRenderer = Ae2ReflectClient.getStackSizeRenderer(this);
protected static String searchFieldOutputsText = "";
protected static String searchFieldNamesText = "";
protected static String currentMode = "OFF";
Expand Down Expand Up @@ -497,6 +494,7 @@ private int drawEntry(LevelTerminalEntry entry, int viewY, int titleBottom, int
Tessellator.instance.startDrawingQuads();
int relY = 0;
final int slotLeftMargin = (VIEW_WIDTH - entry.rowSize * 18);
float lastZLevel = aeRenderItem.zLevel;

entry.dispY = viewY;
/* PASS 1: BG */
Expand Down Expand Up @@ -572,6 +570,9 @@ private int drawEntry(LevelTerminalEntry entry, int viewY, int titleBottom, int
if (stack != null) {

NBTTagCompound data = stack.getTagCompound();
ItemStack itemStack = data.hasKey(TLMTags.Stack.tagName)
? ItemStack.loadItemStackFromNBT(data.getCompoundTag(TLMTags.Stack.tagName))
: stack.copy();
long quantity = data.getLong(TLMTags.Quantity.tagName);
long batch = data.getLong(TLMTags.Batch.tagName);
State state = State.values()[data.getInteger(TLMTags.State.tagName)];
Expand All @@ -581,16 +582,16 @@ private int drawEntry(LevelTerminalEntry entry, int viewY, int titleBottom, int
GL11.glTranslatef(colLeft, viewY + rowYTop + 1, ITEM_STACK_Z);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
RenderHelper.enableGUIStandardItemLighting();
stackSizeRenderer.zLevel = 3.0f - 50.0f;
stackSizeRenderer.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), stack, 0, 0);
stackSizeRenderer.zLevel = 0.0f;
aeRenderItem.zLevel = 3.0f - 50.0f;
aeRenderItem.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), itemStack, 0, 0);
aeRenderItem.zLevel = 0.0f;
GL11.glTranslatef(0.0f, 0.0f, ITEM_STACK_OVERLAY_Z - ITEM_STACK_Z);
stack.stackSize = (int) quantity;
stackSizeRenderer.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack, 0, 0);
itemStack.stackSize = (int) quantity;
aeRenderItem.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), itemStack, 0, 0);
if (batch > 0) {
stack.stackSize = (int) batch;
stackSizeRenderer
.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack, 0, -11);
itemStack.stackSize = (int) batch;
aeRenderItem
.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), itemStack, 0, -11);
}
int color = switch (state) {
case Idle -> FCGuiColors.StateIdle.getColor();
Expand Down Expand Up @@ -635,6 +636,7 @@ private int drawEntry(LevelTerminalEntry entry, int viewY, int titleBottom, int
}
}
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
aeRenderItem.zLevel = lastZLevel;
return relY + 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,21 @@ public void detectAndSendChanges() {

public static ItemStack createLevelValues(ItemStack itemStack) {
var data = itemStack.hasTagCompound() ? itemStack.getTagCompound() : new NBTTagCompound();
var itemStackTag = new NBTTagCompound();
itemStack.writeToNBT(itemStackTag);
data.setTag(TLMTags.Stack.tagName, itemStackTag);
data.setLong(TLMTags.Quantity.tagName, itemStack.stackSize);
data.setLong(TLMTags.Batch.tagName, 0);
data.setBoolean(TLMTags.Enable.tagName, false);
if (!data.hasKey(TLMTags.Stack.tagName)) {
var itemStackTag = new NBTTagCompound();
itemStack.copy().writeToNBT(itemStackTag);
data.setTag(TLMTags.Stack.tagName, itemStackTag);
}
if (!data.hasKey(TLMTags.Quantity.tagName)) {
data.setLong(TLMTags.Quantity.tagName, itemStack.stackSize);
}
if (!data.hasKey(TLMTags.Batch.tagName)) {
data.setLong(TLMTags.Batch.tagName, 0);
}
if (!data.hasKey(TLMTags.Enable.tagName)) {
data.setBoolean(TLMTags.Enable.tagName, false);
}

data.setInteger(TLMTags.State.tagName, State.None.ordinal());
itemStack.setTagCompound(data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void doAction(final EntityPlayerMP player, final InventoryAction action,
}
valid.add(i);
}
if (valid.size() > 0) {
if (!valid.isEmpty()) {
int[] validIndices = Ints.toArray(valid);
NBTTagList tag = new NBTTagList();
for (int i = 0; i < valid.size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

import org.jetbrains.annotations.Nullable;

import com.glodblock.github.api.registries.ILevelViewable;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.item.ItemFluidDrop;
Expand Down Expand Up @@ -49,6 +51,7 @@
import appeng.tile.grid.AENetworkTile;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;

Expand Down Expand Up @@ -296,6 +299,27 @@ public void writeToNBTEvent(NBTTagCompound data) {
public void readFromNBTEvent(NBTTagCompound data) {
if (data.hasKey(TLMTags.RequestStacks.tagName)) {
requests.requestStacks.readFromNbt(data, TLMTags.RequestStacks.tagName);
if (Platform.isServer()) {
for (int i = 0; i < REQ_COUNT; i++) {
if (requests.requestStacks.getStack(i) != null) {
ItemStack storageStack = requests.requestStacks.getStack(i).getItemStack();
ItemStack itemStack = loadItemStackFromTag(storageStack);
ItemStack craftStack = removeRecursion(storageStack);
if (!ItemStack.areItemStacksEqual(itemStack, craftStack)) {
requests.updateStack(i, craftStack);
AELog.info(
"[TileLevelMaintainer] Replace craft stack from: " + itemStack.toString()
+ ":"
+ (itemStack.hasTagCompound() ? itemStack.getTagCompound() : "{no tags}")
+ "; with: "
+ craftStack
+ ":"
+ (craftStack.hasTagCompound() ? craftStack.getTagCompound()
: "{no tags}"));
}
}
}
}
} else {
// Migration from old data storage
long[] batches = new long[REQ_COUNT];
Expand Down Expand Up @@ -323,6 +347,18 @@ public void readFromNBTEvent(NBTTagCompound data) {
}
}

private ItemStack removeRecursion(ItemStack itemStack) {
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey(TLMTags.Stack.tagName)) {
return removeRecursion(loadItemStackFromTag(itemStack));
}
return itemStack;
}

@Nullable
private static ItemStack loadItemStackFromTag(ItemStack itemStack) {
return ItemStack.loadItemStackFromNBT(itemStack.getTagCompound().getCompoundTag(TLMTags.Stack.tagName));
}

@TileEvent(TileEventType.NETWORK_READ)
public boolean readFromStream(final ByteBuf data) {
final boolean oldPower = isPowered;
Expand Down Expand Up @@ -571,8 +607,7 @@ public long getBatchSize(int idx) {
public IAEItemStack getCraftItem(int idx) {
IAEItemStack is = requestStacks.getStack(idx);
if (is == null) return null;
ItemStack qis = ItemStack
.loadItemStackFromNBT(is.getItemStack().getTagCompound().getCompoundTag(TLMTags.Stack.tagName));
ItemStack qis = loadItemStackFromTag(is.getItemStack());
IAEItemStack qais = AEItemStack.create(qis);
qais.setStackSize(getBatchSize(idx));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ public ILevelViewable adapt(IGridHost gridHost) {
};

@NotNull
static public IInventory getPatchedInventory(IInventory inventory, long value, State state) {
static public IInventory getPatchedInventory(IInventory inventory, long quantity, State state) {
ItemStack itemStack = inventory.getStackInSlot(SLOT_IN).copy();
NBTTagCompound data = !itemStack.hasTagCompound() ? new NBTTagCompound() : itemStack.getTagCompound();
data.setLong(TLMTags.Quantity.tagName, value);
data.setInteger(TLMTags.State.tagName, state.ordinal());
if (!data.hasKey(TLMTags.Quantity.tagName) || data.getLong(TLMTags.Quantity.tagName) != quantity)
data.setLong(TLMTags.Quantity.tagName, quantity);
if (!data.hasKey(TLMTags.State.tagName) || data.getInteger(TLMTags.State.tagName) != state.ordinal())
data.setInteger(TLMTags.State.tagName, state.ordinal());
itemStack.setTagCompound(data);
inventory.setInventorySlotContents(SLOT_IN, itemStack);

Expand Down

0 comments on commit be752e8

Please sign in to comment.