diff --git a/src/main/java/com/glodblock/github/loader/KeybindLoader.java b/src/main/java/com/glodblock/github/loader/KeybindLoader.java index 3d4f9629..585f215b 100644 --- a/src/main/java/com/glodblock/github/loader/KeybindLoader.java +++ b/src/main/java/com/glodblock/github/loader/KeybindLoader.java @@ -101,15 +101,15 @@ public class KeybindLoader implements Runnable { if (player == null) return; // Ensure the player has the wireless terminal - ImmutablePair terminalAndInventorySlot = Util.getUltraWirelessTerm(player); + ImmutablePair terminalAndInventorySlot = Util.getWirelessTerminal(player); if (terminalAndInventorySlot == null) { player.addChatMessage(new ChatComponentText("Could not find wireless terminal.")); return; } ItemStack terminal = terminalAndInventorySlot.getRight(); - if (terminal == null || !(terminal.getItem() instanceof ItemWirelessUltraTerminal)) { - player.addChatMessage(new ChatComponentText("Terminal must be universal version.")); + if (terminal == null) { + player.addChatMessage(new ChatComponentText("Could not find wireless terminal.")); return; } diff --git a/src/main/java/com/glodblock/github/network/CPacketPickBlockWithdraw.java b/src/main/java/com/glodblock/github/network/CPacketPickBlockWithdraw.java index 3db8e0aa..1049e62e 100644 --- a/src/main/java/com/glodblock/github/network/CPacketPickBlockWithdraw.java +++ b/src/main/java/com/glodblock/github/network/CPacketPickBlockWithdraw.java @@ -14,12 +14,13 @@ import net.minecraft.world.World; import org.apache.commons.lang3.tuple.ImmutablePair; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.inventory.item.WirelessCraftingTerminalInventory; import com.glodblock.github.util.Util; import appeng.api.AEApi; -import appeng.api.networking.IGridNode; +import appeng.api.config.Actionable; +import appeng.api.networking.security.PlayerSource; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import cpw.mods.fml.common.network.simpleimpl.IMessage; @@ -84,29 +85,28 @@ public class CPacketPickBlockWithdraw implements IMessage { } World world = player.worldObj; - // Ensure the player has the wireless terminal - ImmutablePair terminalAndInventorySlot = Util.getUltraWirelessTerm(player); + // Ensure the player has a wireless terminal + ImmutablePair terminalAndInventorySlot = Util.getWirelessTerminal(player); if (terminalAndInventorySlot == null) { return null; } - ItemStack terminalStack = terminalAndInventorySlot.getRight(); - if (terminalStack == null || !(terminalStack.getItem() instanceof ItemWirelessUltraTerminal)) { + ItemStack terminalItemStack = terminalAndInventorySlot.getRight(); + if (terminalItemStack == null) { return null; } - IGridNode wirelessGrid = Util.getWirelessGrid(terminalStack); - if (wirelessGrid == null) { + // Obtain the inventory handler for the AE2 wireless terminal. + // + // We can safely suppress this warning, as we are the one providing the storage type in + // the function call. + @SuppressWarnings("unchecked") + IMEInventoryHandler terminalInventory = (IMEInventoryHandler) Util + .getWirelessInv(terminalItemStack, player, StorageChannel.ITEMS); + if (terminalInventory == null) { return null; } - // Create the terminal inventory handler - WirelessCraftingTerminalInventory terminalInventory = new WirelessCraftingTerminalInventory( - terminalStack, - terminalAndInventorySlot.getLeft(), - wirelessGrid, - player); - // Get the target block Block targetBlock = world.getBlock(message.blockX, message.blockY, message.blockZ); if (targetBlock == Blocks.air) { @@ -170,15 +170,6 @@ public class CPacketPickBlockWithdraw implements IMessage { } } - // Ensure the wireless terminal is within network range, - // if not, move consolidated stack to the active slot and return - if (!Util.rangeCheck(terminalStack, player, wirelessGrid)) { - setSlotAsActiveSlot(player, consolidatedStackSlot); - - // TODO: Return out of network range player message. - return null; - } - // 5. Calculate withdrawal amount int amountToWithdraw = consolidatedStack == null ? itemToFind.getMaxStackSize() : itemToFind.getMaxStackSize() - consolidatedStack.stackSize; @@ -195,7 +186,8 @@ public class CPacketPickBlockWithdraw implements IMessage { } // 6. Extract items from the network - IAEStack extractedStack = terminalInventory.extractItems(targetAeItemStack); + PlayerSource source = new PlayerSource(player, null); + IAEStack extractedStack = terminalInventory.extractItems(targetAeItemStack, Actionable.MODULATE, source); if (extractedStack instanceof IAEItemStack extractedAeItemStack && extractedStack.getStackSize() > 0) { ItemStack itemsToGive = extractedAeItemStack.getItemStack(); // Update the player's inventory with the withdrawn items diff --git a/src/main/java/com/glodblock/github/util/Util.java b/src/main/java/com/glodblock/github/util/Util.java index 35cc4c5a..e5ec633d 100644 --- a/src/main/java/com/glodblock/github/util/Util.java +++ b/src/main/java/com/glodblock/github/util/Util.java @@ -196,6 +196,32 @@ public final class Util { } } + public static ImmutablePair getWirelessTerminal(EntityPlayer player) { + // Check player inventory for the wireless terminal. + int inventorySize = player.inventory.getSizeInventory(); + for (int i = 0; i < inventorySize; ++i) { + ItemStack is = player.inventory.getStackInSlot(i); + if (is != null && is.getItem() instanceof ToolWirelessTerminal) { + return new ImmutablePair<>(GuiHelper.encodeType(i, GuiHelper.InvType.PLAYER_BAUBLES), is); + } + } + + if (isBaublesLoaded) { + IInventory handler = BaublesApi.getBaubles(player); + if (handler != null) { + int baubleSlotCount = handler.getSizeInventory(); + for (int i = 0; i < baubleSlotCount; ++i) { + ItemStack is = handler.getStackInSlot(i); + if (is != null && is.getItem() instanceof ToolWirelessTerminal) { + return new ImmutablePair<>(GuiHelper.encodeType(i, GuiHelper.InvType.PLAYER_BAUBLES), is); + } + } + } + } + + return null; + } + public static ImmutablePair getUltraWirelessTerm(EntityPlayer player) { int invSize = player.inventory.getSizeInventory();