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
@@ -21,33 +21,29 @@ package appeng.container.implementations;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.IUpgradeableCellContainer;
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.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
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 IPortableCell civ;
private int ticks = 0;
protected final WirelessTerminalGuiObject wirelessTerminalGUIObject;
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) {
this(ip, monitorable, iGuiItemObject, true);
}
public ContainerMEPortableCell(InventoryPlayer ip, IPortableCell monitorable, IGuiItemObject iGuiItemObject, boolean bindInventory) {
super(ip, monitorable, iGuiItemObject, bindInventory);
if (monitorable instanceof IInventorySlotAware) {
public ContainerMEPortableCell(InventoryPlayer ip, WirelessTerminalGuiObject monitorable, boolean bindInventory) {
super(ip, monitorable, bindInventory);
if (monitorable != null) {
final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot();
this.lockPlayerInventorySlot(slotIndex);
this.slot = slotIndex;
@@ -55,21 +51,22 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable {
this.slot = -1;
this.lockPlayerInventorySlot(ip.currentItem);
}
this.civ = monitorable;
this.wirelessTerminalGUIObject = monitorable;
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 (this.civ == null || currentItem.isEmpty()) {
if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) {
this.setValidContainer(false);
} else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) {
if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) {
this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack());
} 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);
}
@@ -78,9 +75,20 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable {
// drain 1 ae t
this.ticks++;
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;
}
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();
}
@@ -91,4 +99,21 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable {
void setPowerMultiplier(final double 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());
}
}
}
}