diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 22fa2ba33..7f90f1278 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -27,19 +27,26 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; +import appeng.parts.automation.StackUpgradeInventory; +import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.items.IItemHandler; -public class ContainerMEPortableCell extends ContainerMEMonitorable implements IUpgradeableCellContainer { +public class ContainerMEPortableCell extends ContainerMEMonitorable implements IUpgradeableCellContainer, IAEAppEngInventory { protected final WirelessTerminalGuiObject wirelessTerminalGUIObject; private final int slot; private double powerMultiplier = 0.5; private int ticks = 0; + protected AppEngInternalInventory upgrades; public ContainerMEPortableCell(InventoryPlayer ip, WirelessTerminalGuiObject monitorable, boolean bindInventory) { super(ip, monitorable, bindInventory); @@ -52,44 +59,51 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I this.lockPlayerInventorySlot(ip.currentItem); } this.wirelessTerminalGUIObject = monitorable; + this.upgrades = new StackUpgradeInventory(wirelessTerminalGUIObject.getItemStack(), this, 2); + this.loadFromNBT(); + if (bindInventory) { this.bindPlayerInventory(ip, 0, 0); } this.setupUpgrades(); } + @Override public void detectAndSendChanges() { - final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + if (Platform.isServer()) { - if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { - this.setValidContainer(false); - } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { - if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { - this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); - } else { + final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + + if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { this.setValidContainer(false); - } - } - - // drain 1 ae t - this.ticks++; - if (this.ticks > 10) { - this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); - this.ticks = 0; - } - - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); + } else { + this.setValidContainer(false); + } } - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); - } + // drain 1 ae t + this.ticks++; + if (this.ticks > 10) { + this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.ticks = 0; + } - super.detectAndSendChanges(); + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + + super.detectAndSendChanges(); + } } private double getPowerMultiplier() { @@ -107,7 +121,6 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I @Override public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { - final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, upgradeSlot * 18, this.getInventoryPlayer())) @@ -116,4 +129,30 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I } } + @Override + public void onSlotChange(Slot s) { + super.detectAndSendChanges(); + } + + @Override + public void saveChanges() { + if (Platform.isServer()) { + NBTTagCompound tag = new NBTTagCompound(); + this.upgrades.writeToNBT(tag, "upgrades"); + + this.wirelessTerminalGUIObject.saveChanges(tag); + } + } + + private void loadFromNBT() { + NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); + if (data != null) { + upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); + } + } + + @Override + public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { + + } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java index 82b5b9aea..0fc9fecdf 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -22,8 +22,6 @@ package appeng.container.implementations; import appeng.container.ContainerNull; import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotCraftingTerm; -import appeng.core.AEConfig; -import appeng.core.localization.PlayerMessages; import appeng.helpers.IContainerCraftingPacket; import appeng.helpers.WirelessTerminalGuiObject; import appeng.tile.inventory.AppEngInternalInventory; @@ -58,6 +56,8 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i super(ip, gui, false); this.wirelessTerminalGUIObject = gui; + this.loadFromNBT(); + final IItemHandler crafting = this.craftingGrid; for (int y = 0; y < 3; y++) { @@ -70,7 +70,6 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i .getPowerSource(), this.wirelessTerminalGUIObject, crafting, crafting, this.output, 131, -72 + 18, this)); this.bindPlayerInventory(ip, 0, 0); - this.loadFromNBT(); this.onCraftMatrixChanged(new WrapperInvItemHandler(crafting)); } @@ -102,14 +101,17 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i if (Platform.isServer()) { NBTTagCompound tag = new NBTTagCompound(); this.craftingGrid.writeToNBT(tag, "craftingGrid"); + this.upgrades.writeToNBT(tag, "upgrades"); + this.wirelessTerminalGUIObject.saveChanges(tag); } } - private void loadFromNBT() { + protected void loadFromNBT() { NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); if (data != null) { this.craftingGrid.readFromNBT(data, "craftingGrid"); + upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index 5c6761b05..289d62a82 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -33,6 +33,7 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; +import appeng.parts.automation.StackUpgradeInventory; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; import appeng.util.helpers.ItemHandlerUtil; @@ -51,6 +52,8 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im private final int slot; protected AppEngInternalInventory output; protected AppEngInternalInventory pattern; + protected AppEngInternalInventory upgrades; + private double powerMultiplier = 0.5; private int ticks = 0; @@ -73,6 +76,7 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im this.lockPlayerInventorySlot(ip.currentItem); } this.wirelessTerminalGUIObject = gui; + upgrades = new StackUpgradeInventory(wirelessTerminalGUIObject.getItemStack(), this, 2); this.loadFromNBT(); @@ -110,36 +114,39 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im @Override public void detectAndSendChanges() { - final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + if (Platform.isServer()) { - if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { - this.setValidContainer(false); - } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { - if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { - this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); - } else { + final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + + if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { this.setValidContainer(false); - } - } - - // drain 1 ae t - this.ticks++; - if (this.ticks > 10) { - this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); - this.ticks = 0; - } - - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); + } else { + this.setValidContainer(false); + } } - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); - } + // drain 1 ae t + this.ticks++; + if (this.ticks > 10) { + this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.ticks = 0; + } - super.detectAndSendChanges(); + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + + super.detectAndSendChanges(); + } } private double getPowerMultiplier() { @@ -178,6 +185,8 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im this.output.writeToNBT(tag, "output"); this.pattern.writeToNBT(tag, "patterns"); + this.upgrades.writeToNBT(tag, "upgrades"); + this.wirelessTerminalGUIObject.saveChanges(tag); } } @@ -188,6 +197,7 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im ((AppEngInternalInventory) crafting).readFromNBT(data, "craftingGrid"); this.output.readFromNBT(data, "output"); this.pattern.readFromNBT(data, "patterns"); + upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); } } @@ -238,7 +248,6 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im @Override public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { - final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, upgradeSlot * 18 - 2, this.getInventoryPlayer())) diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java index bb730ca6e..0f7574b97 100644 --- a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -1,7 +1,12 @@ package appeng.fluids.container; import appeng.api.AEApi; -import appeng.api.config.*; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.config.Settings; +import appeng.api.config.SortDir; +import appeng.api.config.SortOrder; +import appeng.api.config.ViewItems; import appeng.api.implementations.IUpgradeableCellContainer; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.networking.IGridHost; @@ -36,6 +41,8 @@ import appeng.core.sync.packets.PacketValueConfig; import appeng.fluids.util.AEFluidStack; import appeng.helpers.InventoryAction; import appeng.helpers.WirelessTerminalGuiObject; +import appeng.parts.automation.StackUpgradeInventory; +import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; import appeng.util.Platform; @@ -45,7 +52,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IContainerListener; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.IFluidHandlerItem; @@ -74,6 +83,8 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE private int ticks = 0; private final int slot; + protected AppEngInternalInventory upgrades; + public ContainerMEPortableFluidCell(final InventoryPlayer ip, final IPortableCell monitorable) { this(ip, monitorable, null, true); } @@ -129,43 +140,45 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE this.bindPlayerInventory(ip, 0, 140); } hasPower = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier(), Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.001; + upgrades = new StackUpgradeInventory(wirelessTerminalGUIObject.getItemStack(), this, 2); + this.loadFromNBT(); this.setupUpgrades(); - } @Override public void detectAndSendChanges() { - final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); - - if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { - this.setValidContainer(false); - } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { - if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { - this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); - } else { - this.setValidContainer(false); - } - } - - // drain 1 ae t - this.ticks++; - if (this.ticks > 10) { - double power = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); - this.ticks = 0; - this.hasPower = power > 0.001; - } - - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); - } - - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); - } if (Platform.isServer()) { + final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + + if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { + this.setValidContainer(false); + } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); + } else { + this.setValidContainer(false); + } + } + + // drain 1 ae t + this.ticks++; + if (this.ticks > 10) { + double power = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.ticks = 0; + this.hasPower = power > 0.001; + } + + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + if (this.monitor != this.terminal.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))) { this.setValidContainer(false); } @@ -218,9 +231,7 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE } } //this.updatePowerStatus(); - } - super.detectAndSendChanges(); } @Override @@ -453,6 +464,11 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE } } + @Override + public void onSlotChange(Slot s) { + detectAndSendChanges(); + } + private void queueInventory(final IContainerListener c) { if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) { try { @@ -527,7 +543,6 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE @Override public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { - final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, 139 + upgradeSlot * 18, this.getInventoryPlayer())) @@ -536,14 +551,24 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE } } - @Override public void saveChanges() { + if (Platform.isServer()) { + NBTTagCompound tag = new NBTTagCompound(); + this.upgrades.writeToNBT(tag, "upgrades"); + this.wirelessTerminalGUIObject.saveChanges(tag); + } + } + + private void loadFromNBT() { + NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); + if (data != null) { + upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); + } } @Override public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { - } } diff --git a/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java index 214e55a15..c2ce18046 100644 --- a/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java +++ b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java @@ -37,16 +37,18 @@ public class ContainerWirelessFluidTerminal extends ContainerMEPortableFluidCell @Override public void detectAndSendChanges() { - super.detectAndSendChanges(); + if (Platform.isServer()) { + super.detectAndSendChanges(); - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); } - - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); } } } diff --git a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java index 8d4ebcc29..72504cc4b 100644 --- a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java @@ -331,7 +331,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II } } - private void loadFromNBT() { + public void loadFromNBT() { NBTTagCompound data = effectiveItem.getTagCompound(); if (data != null) { viewCell.readFromNBT(data);