add upgrade slots

This commit is contained in:
PrototypeTrousers
2023-01-30 14:58:55 -03:00
parent 7c4e5679a3
commit 13c3067068
13 changed files with 198 additions and 97 deletions
@@ -0,0 +1,7 @@
package appeng.api.implementations;
public interface IUpgradeableCellContainer {
int availableUpgrades();
void setupUpgrades();
}
@@ -0,0 +1,41 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 AlgorithmX2
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package appeng.api.implementations;
import appeng.api.config.Upgrades;
import appeng.api.implementations.tiles.ISegmentedInventory;
import appeng.api.util.IConfigurableObject;
public interface IUpgradeableCellHost extends IConfigurableObject, ISegmentedInventory {
/**
* determine how many of an upgrade are installed.
*/
default int getInstalledUpgrades(Upgrades u) {
return 0;
}
}
@@ -20,14 +20,13 @@ package appeng.client.gui.implementations;
import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.container.implementations.ContainerMEPortableCell;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
public class GuiMEPortableCell extends GuiMEMonitorable { public class GuiMEPortableCell extends GuiMEMonitorable {
public GuiMEPortableCell(final InventoryPlayer inventoryPlayer, final IPortableCell te) { public GuiMEPortableCell(final InventoryPlayer inventoryPlayer, final IPortableCell te) {
super(inventoryPlayer, te, new ContainerMEPortableCell(inventoryPlayer, te)); super(inventoryPlayer, te);
} }
int defaultGetMaxRows() { int defaultGetMaxRows() {
@@ -19,9 +19,6 @@
package appeng.client.gui.implementations; package appeng.client.gui.implementations;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.container.implementations.ContainerWirelessCraftingTerminal;
import appeng.container.implementations.ContainerWirelessPatternTerminal; import appeng.container.implementations.ContainerWirelessPatternTerminal;
import appeng.helpers.WirelessTerminalGuiObject; import appeng.helpers.WirelessTerminalGuiObject;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
@@ -21,33 +21,29 @@ package appeng.container.implementations;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier; import appeng.api.config.PowerMultiplier;
import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.IUpgradeableCellContainer;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.container.interfaces.IInventorySlotAware; import appeng.container.interfaces.IInventorySlotAware;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AEConfig;
import appeng.core.localization.PlayerMessages;
import appeng.helpers.WirelessTerminalGuiObject; import appeng.helpers.WirelessTerminalGuiObject;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class ContainerMEPortableCell extends ContainerMEMonitorable { public class ContainerMEPortableCell extends ContainerMEMonitorable implements IUpgradeableCellContainer {
private double powerMultiplier = 0.5; protected final WirelessTerminalGuiObject wirelessTerminalGUIObject;
protected final IPortableCell civ;
private int ticks = 0;
private final int slot; private final int slot;
private double powerMultiplier = 0.5;
private int ticks = 0;
public ContainerMEPortableCell(final InventoryPlayer ip, final IPortableCell monitorable) {
this(ip, monitorable, null, true);
}
public ContainerMEPortableCell(final InventoryPlayer ip, final IPortableCell monitorable, IGuiItemObject iGuiItemObject) { public ContainerMEPortableCell(InventoryPlayer ip, WirelessTerminalGuiObject monitorable, boolean bindInventory) {
this(ip, monitorable, iGuiItemObject, true); super(ip, monitorable, bindInventory);
} if (monitorable != null) {
public ContainerMEPortableCell(InventoryPlayer ip, IPortableCell monitorable, IGuiItemObject iGuiItemObject, boolean bindInventory) {
super(ip, monitorable, iGuiItemObject, bindInventory);
if (monitorable instanceof IInventorySlotAware) {
final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot(); final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot();
this.lockPlayerInventorySlot(slotIndex); this.lockPlayerInventorySlot(slotIndex);
this.slot = slotIndex; this.slot = slotIndex;
@@ -55,21 +51,22 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable {
this.slot = -1; this.slot = -1;
this.lockPlayerInventorySlot(ip.currentItem); this.lockPlayerInventorySlot(ip.currentItem);
} }
this.civ = monitorable; this.wirelessTerminalGUIObject = monitorable;
if (bindInventory) { if (bindInventory) {
this.bindPlayerInventory(ip, 0, 0); this.bindPlayerInventory(ip, 0, 0);
} }
this.setupUpgrades();
} }
@Override @Override
public void detectAndSendChanges() { public void detectAndSendChanges() {
final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot);
if (this.civ == null || currentItem.isEmpty()) { if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) {
this.setValidContainer(false); this.setValidContainer(false);
} else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) { } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) {
if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) { if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) {
this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack());
} else { } else {
this.setValidContainer(false); this.setValidContainer(false);
} }
@@ -78,9 +75,20 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable {
// drain 1 ae t // drain 1 ae t
this.ticks++; this.ticks++;
if (this.ticks > 10) { if (this.ticks > 10) {
this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG);
this.ticks = 0; this.ticks = 0;
} }
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(); super.detectAndSendChanges();
} }
@@ -91,4 +99,21 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable {
void setPowerMultiplier(final double powerMultiplier) { void setPowerMultiplier(final double powerMultiplier) {
this.powerMultiplier = powerMultiplier; this.powerMultiplier = powerMultiplier;
} }
public int availableUpgrades() {
return 2;
}
@Override
public void setupUpgrades() {
if (wirelessTerminalGUIObject != null) {
final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades");
for (int a = 0; a < availableUpgrades(); a++) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, a * 18, this.getInventoryPlayer()))
.setNotDraggable());
}
}
}
} }
@@ -75,11 +75,6 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp
@GuiSync(96) @GuiSync(96)
public boolean substitute = false; public boolean substitute = false;
public ContainerPatternEncoder(InventoryPlayer ip, ITerminalHost monitorable) {
super(ip, monitorable);
patternTerminal = (AbstractPartEncoder) monitorable;
}
protected ContainerPatternEncoder(InventoryPlayer ip, ITerminalHost monitorable, boolean bindInventory) { protected ContainerPatternEncoder(InventoryPlayer ip, ITerminalHost monitorable, boolean bindInventory) {
super(ip, monitorable, bindInventory); super(ip, monitorable, bindInventory);
patternTerminal = (AbstractPartEncoder) monitorable; patternTerminal = (AbstractPartEncoder) monitorable;
@@ -550,8 +545,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp
this.updateOrderOfOutputSlots(); this.updateOrderOfOutputSlots();
} }
this.substitute = this.getPart().isSubstitution(); this.substitute = this.getPart().isSubstitution();
} } else if (iGuiItemObject != null) {
else if (iGuiItemObject != null) {
NBTTagCompound nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound(); NBTTagCompound nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound();
if (nbtTagCompound != null) { if (nbtTagCompound != null) {
if (nbtTagCompound.hasKey("isCraftingMode")) { if (nbtTagCompound.hasKey("isCraftingMode")) {
@@ -677,7 +671,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp
storage = this.getPart() storage = this.getPart()
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
} else if (iGuiItemObject != null) { } else if (iGuiItemObject != null) {
storage = ((ITerminalHost)iGuiItemObject).getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); storage = ((ITerminalHost) iGuiItemObject).getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
} }
final IItemList<IAEItemStack> all = storage.getStorageList(); final IItemList<IAEItemStack> all = storage.getStorageList();
@@ -720,7 +714,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp
if (!failed.isEmpty()) { if (!failed.isEmpty()) {
this.getCellInventory() this.getCellInventory()
.injectItems(AEItemStack.fromItemStack(failed), Actionable.MODULATE, .injectItems(AEItemStack.fromItemStack(failed), Actionable.MODULATE,
new MachineSource(this.getPart() != null? this.getPart() : (IActionHost) iGuiItemObject)); new MachineSource(this.getPart() != null ? this.getPart() : (IActionHost) iGuiItemObject));
} }
} }
} }
@@ -55,7 +55,7 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i
private IRecipe currentRecipe; private IRecipe currentRecipe;
public ContainerWirelessCraftingTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { public ContainerWirelessCraftingTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) {
super(ip, gui, gui, false); super(ip, gui, false);
this.wirelessTerminalGUIObject = gui; this.wirelessTerminalGUIObject = gui;
final IItemHandler crafting = this.craftingGrid; final IItemHandler crafting = this.craftingGrid;
@@ -67,7 +67,7 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i
} }
this.addSlotToContainer(this.outputSlot = new SlotCraftingTerm(this.getPlayerInv().player, this.getActionSource(), this this.addSlotToContainer(this.outputSlot = new SlotCraftingTerm(this.getPlayerInv().player, this.getActionSource(), this
.getPowerSource(), this.civ, crafting, crafting, this.output, 131, -72 + 18, this)); .getPowerSource(), this.wirelessTerminalGUIObject, crafting, crafting, this.output, 131, -72 + 18, this));
this.bindPlayerInventory(ip, 0, 0); this.bindPlayerInventory(ip, 0, 0);
this.loadFromNBT(); this.loadFromNBT();
@@ -75,21 +75,6 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i
this.onCraftMatrixChanged(new WrapperInvItemHandler(crafting)); this.onCraftMatrixChanged(new WrapperInvItemHandler(crafting));
} }
@Override
public void detectAndSendChanges() {
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()));
}
}
@Override @Override
public void onCraftMatrixChanged(IInventory inventory) { public void onCraftMatrixChanged(IInventory inventory) {
final ContainerNull cn = new ContainerNull(); final ContainerNull cn = new ContainerNull();
@@ -22,10 +22,9 @@ package appeng.container.implementations;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier; import appeng.api.config.PowerMultiplier;
import appeng.api.implementations.ICraftingPatternItem; import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.IUpgradeableCellContainer;
import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.container.interfaces.IInventorySlotAware;
import appeng.container.slot.OptionalSlotFake; import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.container.slot.SlotPatternOutputs; import appeng.container.slot.SlotPatternOutputs;
@@ -33,35 +32,27 @@ import appeng.container.slot.SlotPatternTerm;
import appeng.container.slot.SlotRestrictedInput; import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AEConfig; import appeng.core.AEConfig;
import appeng.core.localization.PlayerMessages; import appeng.core.localization.PlayerMessages;
import appeng.helpers.ItemStackHelper;
import appeng.helpers.WirelessTerminalGuiObject; import appeng.helpers.WirelessTerminalGuiObject;
import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform; import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil; import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.InvOperation; import appeng.util.inv.InvOperation;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTUtil;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import static appeng.helpers.PatternHelper.CRAFTING_GRID_DIMENSION; import static appeng.helpers.PatternHelper.CRAFTING_GRID_DIMENSION;
public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder implements IUpgradeableCellContainer {
private final WirelessTerminalGuiObject wirelessTerminalGUIObject; private final WirelessTerminalGuiObject wirelessTerminalGUIObject;
private double powerMultiplier = 0.5;
protected final IPortableCell civ;
private int ticks = 0;
private final int slot; private final int slot;
protected AppEngInternalInventory output; protected AppEngInternalInventory output;
protected AppEngInternalInventory pattern; protected AppEngInternalInventory pattern;
private double powerMultiplier = 0.5;
private int ticks = 0;
public ContainerWirelessPatternTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { public ContainerWirelessPatternTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) {
super(ip, gui, gui, false); super(ip, gui, gui, false);
@@ -81,7 +72,6 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder {
this.slot = -1; this.slot = -1;
this.lockPlayerInventorySlot(ip.currentItem); this.lockPlayerInventorySlot(ip.currentItem);
} }
this.civ = gui;
this.wirelessTerminalGUIObject = gui; this.wirelessTerminalGUIObject = gui;
this.loadFromNBT(); this.loadFromNBT();
@@ -114,17 +104,19 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder {
this.updateOrderOfOutputSlots(); this.updateOrderOfOutputSlots();
this.bindPlayerInventory(ip, 0, 0); this.bindPlayerInventory(ip, 0, 0);
this.setupUpgrades();
} }
@Override @Override
public void detectAndSendChanges() { public void detectAndSendChanges() {
final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot);
if (this.civ == null || currentItem.isEmpty()) { if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) {
this.setValidContainer(false); this.setValidContainer(false);
} else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) { } else if (this.wirelessTerminalGUIObject != null && !this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) {
if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) { if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) {
this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack());
} else { } else {
this.setValidContainer(false); this.setValidContainer(false);
} }
@@ -133,7 +125,7 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder {
// drain 1 ae t // drain 1 ae t
this.ticks++; this.ticks++;
if (this.ticks > 10) { if (this.ticks > 10) {
this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG);
this.ticks = 0; this.ticks = 0;
} }
@@ -237,4 +229,21 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder {
public boolean useRealItems() { public boolean useRealItems() {
return false; return false;
} }
@Override
public int availableUpgrades() {
return 2;
}
@Override
public void setupUpgrades() {
if (wirelessTerminalGUIObject != null) {
final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades");
for (int a = 0; a < availableUpgrades(); a++) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, -2 + a * 18, this.getInventoryPlayer()))
.setNotDraggable());
}
}
}
} }
@@ -31,7 +31,7 @@ public class ContainerWirelessTerm extends ContainerMEPortableCell {
private final WirelessTerminalGuiObject wirelessTerminalGUIObject; private final WirelessTerminalGuiObject wirelessTerminalGUIObject;
public ContainerWirelessTerm(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { public ContainerWirelessTerm(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) {
super(ip, gui); super(ip, gui, true);
this.wirelessTerminalGUIObject = gui; this.wirelessTerminalGUIObject = gui;
} }
@@ -25,10 +25,13 @@ import appeng.api.features.IWirelessTermHandler;
import appeng.api.features.IWirelessTermRegistry; import appeng.api.features.IWirelessTermRegistry;
import appeng.core.localization.PlayerMessages; import appeng.core.localization.PlayerMessages;
import appeng.core.sync.GuiBridge; import appeng.core.sync.GuiBridge;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.util.Platform; import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -80,6 +83,14 @@ public final class WirelessRegistry implements IWirelessTermRegistry {
} }
final IWirelessTermHandler handler = this.getWirelessTerminalHandler(item); final IWirelessTermHandler handler = this.getWirelessTerminalHandler(item);
WirelessTerminalGuiObject wtgo = new WirelessTerminalGuiObject(handler, item, player, w, (int) player.posX, (int) player.posY, (int) player.posZ);
IItemHandler upgrades = wtgo.getInventoryByName("upgrades");
if (upgrades.getSlots() > 0) {
player.sendMessage(new TextComponentString("ahhaah eheheh ihihih"));
}
final String unparsedKey = handler.getEncryptionKey(item); final String unparsedKey = handler.getEncryptionKey(item);
if (unparsedKey.isEmpty()) { if (unparsedKey.isEmpty()) {
player.sendMessage(PlayerMessages.DeviceNotLinked.get()); player.sendMessage(PlayerMessages.DeviceNotLinked.get());
@@ -2,6 +2,7 @@ package appeng.fluids.container;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.*; import appeng.api.config.*;
import appeng.api.implementations.IUpgradeableCellContainer;
import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.networking.IGridHost; import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNode;
@@ -24,6 +25,7 @@ import appeng.container.interfaces.IInventorySlotAware;
import appeng.container.slot.AppEngSlot; import appeng.container.slot.AppEngSlot;
import appeng.container.slot.SlotPlayerHotBar; import appeng.container.slot.SlotPlayerHotBar;
import appeng.container.slot.SlotPlayerInv; import appeng.container.slot.SlotPlayerInv;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AEConfig; import appeng.core.AEConfig;
import appeng.core.AELog; import appeng.core.AELog;
import appeng.core.localization.PlayerMessages; import appeng.core.localization.PlayerMessages;
@@ -45,12 +47,13 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandlerItem; import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.nio.BufferOverflowException; import java.nio.BufferOverflowException;
public class ContainerMEPortableFluidCell extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack> { public class ContainerMEPortableFluidCell extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack>, IUpgradeableCellContainer {
private final WirelessTerminalGuiObject wirelessTerminalGUIObject; private final WirelessTerminalGuiObject wirelessTerminalGUIObject;
@@ -66,8 +69,6 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo
// Holds the fluid the client wishes to extract, or null for insert // Holds the fluid the client wishes to extract, or null for insert
private IAEFluidStack clientRequestedTargetFluid = null; private IAEFluidStack clientRequestedTargetFluid = null;
private double powerMultiplier = 0.5; private double powerMultiplier = 0.5;
protected final IPortableCell civ;
private int ticks = 0; private int ticks = 0;
private final int slot; private final int slot;
@@ -98,24 +99,22 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo
this.monitor.addListener(this, null); this.monitor.addListener(this, null);
this.setPowerSource((IEnergySource) terminal); this.setPowerSource((IEnergySource) terminal);
if (terminal instanceof IGridHost || terminal instanceof IActionHost) { final IGridNode node;
final IGridNode node; if (terminal instanceof IGridHost) {
if (terminal instanceof IGridHost) { node = ((IGridHost) terminal).getGridNode(AEPartLocation.INTERNAL);
node = ((IGridHost) terminal).getGridNode(AEPartLocation.INTERNAL); } else {
} else { node = ((IActionHost) terminal).getActionableNode();
node = ((IActionHost) terminal).getActionableNode(); }
}
if (node != null) { if (node != null) {
this.networkNode = node; this.networkNode = node;
}
} }
} }
} else { } else {
this.monitor = null; this.monitor = null;
} }
if (monitorable instanceof IInventorySlotAware) { if (monitorable != null) {
final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot(); final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot();
this.lockPlayerInventorySlot(slotIndex); this.lockPlayerInventorySlot(slotIndex);
this.slot = slotIndex; this.slot = slotIndex;
@@ -123,11 +122,13 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo
this.slot = -1; this.slot = -1;
this.lockPlayerInventorySlot(ip.currentItem); this.lockPlayerInventorySlot(ip.currentItem);
} }
this.civ = monitorable;
if (bindInventory) { if (bindInventory) {
this.bindPlayerInventory(ip, 0, 140); this.bindPlayerInventory(ip, 0, 140);
} }
hasPower = this.civ.extractAEPower(this.getPowerMultiplier(), Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.001; hasPower = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier(), Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.001;
this.setupUpgrades();
} }
@@ -135,11 +136,11 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo
public void detectAndSendChanges() { public void detectAndSendChanges() {
final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot);
if (this.civ == null || currentItem.isEmpty()) { if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) {
this.setValidContainer(false); this.setValidContainer(false);
} else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) { } else if (this.wirelessTerminalGUIObject != null && !this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) {
if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) { if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) {
this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack());
} else { } else {
this.setValidContainer(false); this.setValidContainer(false);
} }
@@ -148,7 +149,7 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo
// drain 1 ae t // drain 1 ae t
this.ticks++; this.ticks++;
if (this.ticks > 10) { if (this.ticks > 10) {
double power = this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); double power = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG);
this.ticks = 0; this.ticks = 0;
this.hasPower = power > 0.001; this.hasPower = power > 0.001;
} }
@@ -515,4 +516,21 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo
public void setGui(@Nonnull final IConfigManagerHost gui) { public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui; this.gui = gui;
} }
@Override
public int availableUpgrades() {
return 2;
}
@Override
public void setupUpgrades() {
if (wirelessTerminalGUIObject instanceof WirelessTerminalGuiObject) {
final IItemHandler upgrades = ((WirelessTerminalGuiObject) wirelessTerminalGUIObject).getInventoryByName("upgrades");
for (int a = 0; a < availableUpgrades(); a++) {
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 139 + a * 18, this.getInventoryPlayer()))
.setNotDraggable());
}
}
}
} }
@@ -19,7 +19,6 @@
package appeng.fluids.container; package appeng.fluids.container;
import appeng.container.implementations.ContainerMEPortableCell;
import appeng.core.AEConfig; import appeng.core.AEConfig;
import appeng.core.localization.PlayerMessages; import appeng.core.localization.PlayerMessages;
import appeng.helpers.WirelessTerminalGuiObject; import appeng.helpers.WirelessTerminalGuiObject;
@@ -25,6 +25,7 @@ import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier; import appeng.api.config.PowerMultiplier;
import appeng.api.features.ILocatable; import appeng.api.features.ILocatable;
import appeng.api.features.IWirelessTermHandler; import appeng.api.features.IWirelessTermHandler;
import appeng.api.implementations.IUpgradeableCellHost;
import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IViewCellStorage; import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.implementations.tiles.IWirelessAccessPoint; import appeng.api.implementations.tiles.IWirelessAccessPoint;
@@ -44,6 +45,8 @@ import appeng.api.storage.data.IItemList;
import appeng.api.util.DimensionalCoord; import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager; import appeng.api.util.IConfigManager;
import appeng.container.interfaces.IInventorySlotAware; import appeng.container.interfaces.IInventorySlotAware;
import appeng.parts.automation.StackUpgradeInventory;
import appeng.parts.automation.UpgradeInventory;
import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.networking.TileWireless; import appeng.tile.networking.TileWireless;
import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.IAEAppEngInventory;
@@ -55,7 +58,7 @@ import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware, IViewCellStorage, IAEAppEngInventory { public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware, IViewCellStorage, IAEAppEngInventory, IUpgradeableCellHost {
private final ItemStack effectiveItem; private final ItemStack effectiveItem;
private final IWirelessTermHandler wth; private final IWirelessTermHandler wth;
@@ -70,6 +73,8 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II
private final int inventorySlot; private final int inventorySlot;
private final AppEngInternalInventory viewCell = new AppEngInternalInventory(this, 5); private final AppEngInternalInventory viewCell = new AppEngInternalInventory(this, 5);
private final UpgradeInventory upgrades;
public WirelessTerminalGuiObject(final IWirelessTermHandler wh, final ItemStack is, final EntityPlayer ep, final World w, final int x, final int y, final int z) { public WirelessTerminalGuiObject(final IWirelessTermHandler wh, final ItemStack is, final EntityPlayer ep, final World w, final int x, final int y, final int z) {
this.encryptionKey = wh.getEncryptionKey(is); this.encryptionKey = wh.getEncryptionKey(is);
@@ -100,6 +105,8 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II
} }
} }
upgrades = new StackUpgradeInventory(effectiveItem, this, 4);
this.loadFromNBT(); this.loadFromNBT();
} }
@@ -327,6 +334,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II
NBTTagCompound data = effectiveItem.getTagCompound(); NBTTagCompound data = effectiveItem.getTagCompound();
if (data != null) { if (data != null) {
viewCell.readFromNBT(data); viewCell.readFromNBT(data);
upgrades.readFromNBT(data);
} }
} }
@@ -334,4 +342,12 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II
public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) {
} }
@Override
public IItemHandler getInventoryByName(String name) {
if (name.equals("upgrades")) {
return upgrades;
}
return null;
}
} }