Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import appeng.api.storage.ITerminalHost;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.util.Platform;

public abstract class FCBaseContainer extends AEBaseContainer {

Expand Down Expand Up @@ -37,7 +38,7 @@ private int lockSlot() {
if (isWirelessTerminal()) {
if (this.host instanceof IFluidPortableCell) {
final int slotIndex = ((IFluidPortableCell) this.host).getInventorySlot();
if (Util.GuiHelper.decodeInvType(slotIndex).getLeft() == Util.GuiHelper.InvType.PLAYER_INV) {
if (slotIndex <= Platform.baublesSlotsOffset) {
this.lockPlayerInventorySlot(slotIndex);
}
return slotIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static appeng.util.Platform.baublesSlotsOffset;
import static appeng.util.Platform.nextEnum;
import static com.glodblock.github.util.Util.GuiHelper.decodeInvType;
import static net.minecraft.client.gui.GuiScreen.isShiftKeyDown;

import java.util.Arrays;
Expand Down Expand Up @@ -138,8 +137,7 @@ public void switchTerminal(EntityPlayer player, ImmutablePair<Integer, ItemStack
private void openGui(final ItemStack is, final World w, final EntityPlayer player, final Object mode,
final int slotIndex) {
final GuiBridge aeGui;
final int slot = slotIndex == Integer.MIN_VALUE ? player.inventory.currentItem : slotIndex;
final ImmutablePair<Util.GuiHelper.InvType, Integer> invSlotPair = decodeInvType(slotIndex);
final int slot = slotIndex == Integer.MIN_VALUE ? player.inventory.currentItem : slotIndex;;

switch (mode instanceof UltraTerminalModes utm ? utm : getMode(is)) {
case CRAFTING -> aeGui = GuiBridge.GUI_CRAFTING_TERMINAL;
Expand All @@ -161,13 +159,7 @@ private void openGui(final ItemStack is, final World w, final EntityPlayer playe
default -> aeGui = GuiBridge.GUI_ME;
}

Platform.openGUI(
player,
null,
null,
aeGui,
invSlotPair.getLeft() == Util.GuiHelper.InvType.PLAYER_INV ? slotIndex
: invSlotPair.getRight() + baublesSlotsOffset);
Platform.openGUI(player, null, null, aeGui, slotIndex);
}

@Override
Expand All @@ -191,12 +183,7 @@ public void onWornTick(ItemStack itemStack, EntityLivingBase entityLivingBase) {
if (handler != null) {
for (int i = 0; i < handler.getSizeInventory(); ++i) {
if (handler.getStackInSlot(i) == itemStack) {
onUpdate(
itemStack,
null,
player,
Util.GuiHelper.encodeType(i, Util.GuiHelper.InvType.PLAYER_BAUBLES),
false);
onUpdate(itemStack, null, player, i + baublesSlotsOffset, false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import net.minecraftforge.common.util.ForgeDirection;

import com.glodblock.github.inventory.item.IItemInventory;
import com.glodblock.github.util.Util;

import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.util.Platform;

public abstract class ItemGuiFactory<T> implements IGuiFactory {

Expand All @@ -30,7 +30,7 @@ protected T getInventory(Object inv) {
@Nullable
@Override
public Object createServerGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face) {
ItemStack item = Util.getWirelessTerminal(player, x);
ItemStack item = Platform.getItemFromPlayerInventoryBySlotIndex(player, x);
if (item == null || !(item.getItem() instanceof IItemInventory)) {
return null;
}
Expand All @@ -57,7 +57,7 @@ public Object createServerGui(EntityPlayer player, World world, int x, int y, in
@Nullable
@Override
public Object createClientGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face) {
ItemStack item = Util.getWirelessTerminal(player, x);
ItemStack item = Platform.getItemFromPlayerInventoryBySlotIndex(player, x);
if (item == null || !(item.getItem() instanceof IItemInventory)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.util.Platform;

public abstract class PartOrItemGuiFactory<T> extends PartGuiFactory<T> {

Expand All @@ -31,7 +32,7 @@ protected T getItemInventory(Object inv) {
public Object createServerGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face) {
ImmutablePair<Util.GuiHelper.GuiType, Integer> result = Util.GuiHelper.decodeType(y);
if (result.getLeft() == Util.GuiHelper.GuiType.ITEM) {
ItemStack item = Util.getWirelessTerminal(player, x);
ItemStack item = Platform.getItemFromPlayerInventoryBySlotIndex(player, x);
if (item == null || !(item.getItem() instanceof IItemInventory)) {
return null;
}
Expand Down Expand Up @@ -62,7 +63,7 @@ public Object createServerGui(EntityPlayer player, World world, int x, int y, in
public Object createClientGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face) {
ImmutablePair<Util.GuiHelper.GuiType, Integer> result = Util.GuiHelper.decodeType(y);
if (result.left == Util.GuiHelper.GuiType.ITEM) {
ItemStack item = Util.getWirelessTerminal(player, x);
ItemStack item = Platform.getItemFromPlayerInventoryBySlotIndex(player, x);
if (item == null || !(item.getItem() instanceof IItemInventory)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static class FilterCache {
public static WirelessMagnetCardFilterInventory getFilter(ItemStack is, int slot, IGridNode gridNode,
EntityPlayer player) {
WirelessMagnetCardFilterInventory cachedInv = cache.get(player.getUniqueID());
if (cachedInv != null && cachedInv.checkCache(is)) {
if (cachedInv != null && cachedInv.checkCache(is) && gridNode == cachedInv.grid) {
return cachedInv;
} else {
WirelessMagnetCardFilterInventory newInv = new WirelessMagnetCardFilterInventory(
Expand Down
34 changes: 4 additions & 30 deletions src/main/java/com/glodblock/github/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ public final class Util {
public static int drainItemPower(AEBaseContainer c, InventoryPlayer ip, int slot, int ticks, double pm,
IFluidPortableCell wt) {
if (slot != -1) {
final ItemStack currentItem = getWirelessTerminal(ip.player, slot);
final ItemStack currentItem = Platform.getItemFromPlayerInventoryBySlotIndex(ip.player, slot);
if (wt != null) {
if (currentItem != wt.getItemStack()) {
if (currentItem != null) {
if (Platform.isSameItem(wt.getItemStack(), currentItem)) {
if (GuiHelper.decodeInvType(slot).getLeft() == GuiHelper.InvType.PLAYER_INV) {
if (slot <= Platform.baublesSlotsOffset) {
ip.setInventorySlotContents(slot, wt.getItemStack());
} else {
BaublesApi.getBaubles(ip.player).setInventorySlotContents(
GuiHelper.decodeInvType(slot).getRight(),
wt.getItemStack());
BaublesApi.getBaubles(ip.player).setInventorySlotContents(slot, wt.getItemStack());
}
} else {
c.setValidContainer(false);
Expand Down Expand Up @@ -193,15 +191,6 @@ public static IMEInventoryHandler<?> getWirelessInv(ItemStack is, EntityPlayer p
return new NullInventory<>();
}

public static ItemStack getWirelessTerminal(EntityPlayer player, int x) {
ImmutablePair<GuiHelper.InvType, Integer> result = GuiHelper.decodeInvType(x);
if (result.getLeft() == GuiHelper.InvType.PLAYER_INV) {
return player.inventory.getStackInSlot(result.getRight());
} else {
return BaublesApi.getBaubles(player).getStackInSlot(result.getRight());
}
}

public static ImmutablePair<Integer, ItemStack> getUltraWirelessTerm(EntityPlayer player) {
int invSize = player.inventory.getSizeInventory();

Expand All @@ -222,7 +211,7 @@ public static ImmutablePair<Integer, ItemStack> getUltraWirelessTerm(EntityPlaye
for (int i = 0; i < invSize; ++i) {
ItemStack is = handler.getStackInSlot(i);
if (is != null && is.getItem() instanceof ItemWirelessUltraTerminal) {
return new ImmutablePair<>(GuiHelper.encodeType(i, GuiHelper.InvType.PLAYER_BAUBLES), is);
return new ImmutablePair<>(i + Platform.baublesSlotsOffset, is);
}
}
}
Expand Down Expand Up @@ -470,28 +459,13 @@ public static int encodeType(int y, GuiType type) {
return value | (type.ordinal() << 29) | y;
}

public static int encodeType(int x, InvType type) {
if (Math.abs(x) > (1 << 28)) {
throw new IllegalArgumentException("out of range");
}
return value | (type.ordinal() << 29) | x;
}

public static ImmutablePair<GuiType, Integer> decodeType(int y) {
if (Math.abs(y) > (1 << 28)) {
return new ImmutablePair<>(GuiType.values()[y >> 29 & 1], y - (3 << 29 & y));
} else {
return new ImmutablePair<>(GuiType.TILE, y);
}
}

public static ImmutablePair<InvType, Integer> decodeInvType(int x) {
if (Math.abs(x) > (1 << 28)) {
return new ImmutablePair<>(InvType.values()[x >> 29 & 1], x - (3 << 29 & x));
} else {
return new ImmutablePair<>(InvType.PLAYER_INV, x);
}
}
}

public static int clamp(int value, int min, int max) {
Expand Down
Loading