mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-12 00:07:29 +00:00
Fix crash when trying to open wireless magnet filter when terminal in baubles (#404)
This commit is contained in:
1 parent
59e596b0ba
commit
62117facd5
6 files changed
+16
-53
No files matched your search
@@ -9,6 +9,7 @@ import com.glodblock.github.util.Util;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public abstract class FCBaseContainer extends AEBaseContainer {
|
||||
|
||||
@@ -37,7 +38,7 @@ public abstract class FCBaseContainer extends AEBaseContainer {
|
||||
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;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.glodblock.github.common.item;
|
||||
|
||||
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;
|
||||
@@ -138,8 +137,7 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
|
||||
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;
|
||||
@@ -161,13 +159,7 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
|
||||
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
|
||||
@@ -191,12 +183,7 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ import net.minecraft.world.World;
|
||||
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 {
|
||||
|
||||
@@ -30,7 +30,7 @@ public abstract class ItemGuiFactory<T> implements IGuiFactory {
|
||||
@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;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public abstract class ItemGuiFactory<T> implements IGuiFactory {
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public abstract class PartOrItemGuiFactory<T> extends PartGuiFactory<T> {
|
||||
|
||||
@@ -31,7 +32,7 @@ public abstract class PartOrItemGuiFactory<T> extends PartGuiFactory<T> {
|
||||
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;
|
||||
}
|
||||
@@ -62,7 +63,7 @@ public abstract class PartOrItemGuiFactory<T> extends PartGuiFactory<T> {
|
||||
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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -266,7 +266,7 @@ public class WirelessMagnetCardFilterInventory extends BaseWirelessInventory imp
|
||||
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(
|
||||
|
||||
@@ -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);
|
||||
@@ -193,15 +191,6 @@ public final class Util {
|
||||
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();
|
||||
|
||||
@@ -222,7 +211,7 @@ public final class Util {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -470,13 +459,6 @@ public final class Util {
|
||||
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));
|
||||
@@ -484,14 +466,6 @@ public final class Util {
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user