Toggle magnet on/off from container/gui

This commit is contained in:
PrototypeTrousers
2023-02-02 21:45:31 -03:00
parent fb2aa21337
commit 9d7dacdc29
6 changed files with 93 additions and 13 deletions
@@ -90,9 +90,9 @@ public interface IMaterials {
IItemDefinition cardPatternExpansion(); IItemDefinition cardPatternExpansion();
public IItemDefinition cardQuantumLink(); IItemDefinition cardQuantumLink();
public IItemDefinition cardMagnet(); IItemDefinition cardMagnet();
IItemDefinition cardFuzzy(); IItemDefinition cardFuzzy();
@@ -34,7 +34,9 @@ import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation; import appeng.util.inv.InvOperation;
import baubles.api.BaublesApi; import baubles.api.BaublesApi;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Slot; 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;
@@ -49,6 +51,7 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I
private int ticks = 0; private int ticks = 0;
protected AppEngInternalInventory upgrades; protected AppEngInternalInventory upgrades;
protected SlotRestrictedInput magnetSlot;
public ContainerMEPortableCell(InventoryPlayer ip, WirelessTerminalGuiObject monitorable, boolean bindInventory) { public ContainerMEPortableCell(InventoryPlayer ip, WirelessTerminalGuiObject monitorable, boolean bindInventory) {
super(ip, monitorable, bindInventory); super(ip, monitorable, bindInventory);
@@ -110,6 +113,31 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I
} }
} }
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
if (clickTypeIn == ClickType.PICKUP && dragType == 1) {
if (this.inventorySlots.get(slotId) == magnetSlot) {
ItemStack itemStack = magnetSlot.getStack();
if (!magnetSlot.getStack().isEmpty()) {
NBTTagCompound tag = itemStack.getTagCompound();
if (tag == null) {
tag = new NBTTagCompound();
}
if (tag.hasKey("enabled")) {
boolean e = tag.getBoolean("enabled");
tag.setBoolean("enabled", !e);
} else {
tag.setBoolean("enabled", false);
}
magnetSlot.getStack().setTagCompound(tag);
magnetSlot.onSlotChanged();
return ItemStack.EMPTY;
}
}
}
return super.slotClick(slotId, dragType, clickTypeIn, player);
}
@Override @Override
protected IActionHost getActionHost() { protected IActionHost getActionHost() {
return this.wirelessTerminalGUIObject; return this.wirelessTerminalGUIObject;
@@ -132,9 +160,9 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I
public void setupUpgrades() { public void setupUpgrades() {
if (wirelessTerminalGUIObject != null) { if (wirelessTerminalGUIObject != null) {
for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) {
this.addSlotToContainer( this.magnetSlot = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer());
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer())) this.magnetSlot.setNotDraggable();
.setNotDraggable()); this.addSlotToContainer(magnetSlot);
} }
} }
} }
@@ -40,7 +40,9 @@ 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 baubles.api.BaublesApi; import baubles.api.BaublesApi;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@@ -56,6 +58,8 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im
protected AppEngInternalInventory pattern; protected AppEngInternalInventory pattern;
protected AppEngInternalInventory upgrades; protected AppEngInternalInventory upgrades;
protected SlotRestrictedInput magnetSlot;
private double powerMultiplier = 0.5; private double powerMultiplier = 0.5;
private int ticks = 0; private int ticks = 0;
@@ -158,6 +162,31 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im
} }
} }
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
if (clickTypeIn == ClickType.PICKUP && dragType == 1) {
if (this.inventorySlots.get(slotId) == magnetSlot) {
ItemStack itemStack = magnetSlot.getStack();
if (!magnetSlot.getStack().isEmpty()) {
NBTTagCompound tag = itemStack.getTagCompound();
if (tag == null) {
tag = new NBTTagCompound();
}
if (tag.hasKey("enabled")) {
boolean e = tag.getBoolean("enabled");
tag.setBoolean("enabled", !e);
} else {
tag.setBoolean("enabled", false);
}
magnetSlot.getStack().setTagCompound(tag);
magnetSlot.onSlotChanged();
return ItemStack.EMPTY;
}
}
}
return super.slotClick(slotId, dragType, clickTypeIn, player);
}
private double getPowerMultiplier() { private double getPowerMultiplier() {
return this.powerMultiplier; return this.powerMultiplier;
} }
@@ -258,9 +287,9 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im
public void setupUpgrades() { public void setupUpgrades() {
if (wirelessTerminalGUIObject != null) { if (wirelessTerminalGUIObject != null) {
for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) {
this.addSlotToContainer( this.magnetSlot = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer());
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer())) this.magnetSlot.setNotDraggable();
.setNotDraggable()); this.addSlotToContainer(magnetSlot);
} }
} }
} }
@@ -95,6 +95,17 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
lines.add(c.getString("InscribeName")); lines.add(c.getString("InscribeName"));
} }
if (mt == MaterialType.CARD_MAGNET) {
final NBTTagCompound c = Platform.openNbtData(stack);
if (!c.hasKey("enabled") || c.getBoolean("enabled")) {
lines.add(I18n.translateToLocal("gui.tooltips.appliedenergistics2.Enable"));
} else {
lines.add(I18n.translateToLocal("gui.tooltips.appliedenergistics2.Disabled"));
}
lines.add(I18n.translateToLocal("item.appliedenergistics2.material.card_magnet.usage"));
lines.add(I18n.translateToLocal("item.appliedenergistics2.material.card_magnet.partition"));
}
final Upgrades u = this.getType(stack); final Upgrades u = this.getType(stack);
if (u != null) { if (u != null) {
final List<String> textList = new ArrayList<>(); final List<String> textList = new ArrayList<>();
@@ -20,7 +20,13 @@ package appeng.items.tools.powered;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.*; import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.Upgrades;
import appeng.api.config.ViewItems;
import appeng.api.features.IWirelessTermHandler; import appeng.api.features.IWirelessTermHandler;
import appeng.api.util.IConfigManager; import appeng.api.util.IConfigManager;
import appeng.core.AEConfig; import appeng.core.AEConfig;
@@ -189,6 +195,10 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless
for (int s = 0; s < siu.getSlots(); s++) { for (int s = 0; s < siu.getSlots(); s++) {
ItemStack is = siu.getStackInSlot(s); ItemStack is = siu.getStackInSlot(s);
if (AEApi.instance().definitions().materials().cardMagnet().isSameAs(is)) { if (AEApi.instance().definitions().materials().cardMagnet().isSameAs(is)) {
NBTTagCompound tag = is.getTagCompound();
if (tag != null && !tag.getBoolean("enabled")) {
return;
}
ItemMaterial im = (ItemMaterial) is.getItem(); ItemMaterial im = (ItemMaterial) is.getItem();
CellConfig c = (CellConfig) im.getConfigInventory(is); CellConfig c = (CellConfig) im.getConfigInventory(is);
CellUpgrades u = (CellUpgrades) im.getUpgradesInventory(is); CellUpgrades u = (CellUpgrades) im.getUpgradesInventory(is);
@@ -235,11 +245,11 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless
} }
} }
if (emptyFilter) { if (emptyFilter) {
teleportItem(i,entityIn); teleportItem(i, entityIn);
} else if (matched && !inverted) { } else if (matched && !inverted) {
teleportItem(i,entityIn); teleportItem(i, entityIn);
} else if (!matched && inverted) { } else if (!matched && inverted) {
teleportItem(i,entityIn); teleportItem(i, entityIn);
} }
} }
} }
@@ -248,7 +258,7 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless
} }
} }
private void teleportItem(EntityItem i, Entity entityIn){ private void teleportItem(EntityItem i, Entity entityIn) {
i.motionX = i.motionY = i.motionZ = 0; i.motionX = i.motionY = i.motionZ = 0;
i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ);
} }
@@ -463,6 +463,8 @@ item.appliedenergistics2.material.calculation_processor.name=Calculation Process
item.appliedenergistics2.material.card_capacity.name=Capacity Card item.appliedenergistics2.material.card_capacity.name=Capacity Card
item.appliedenergistics2.material.card_pattern_expansion.name=Pattern Expansion Card item.appliedenergistics2.material.card_pattern_expansion.name=Pattern Expansion Card
item.appliedenergistics2.material.card_magnet.name=Magnet Card item.appliedenergistics2.material.card_magnet.name=Magnet Card
item.appliedenergistics2.material.card_magnet.usage=Right click with an empty hand while equipped on a terminal to toggle ON or OFF
item.appliedenergistics2.material.card_magnet.partition=Can be configured in a Cell Workbench
item.appliedenergistics2.material.card_quantum_link.name=Quantum Link Card item.appliedenergistics2.material.card_quantum_link.name=Quantum Link Card
item.appliedenergistics2.material.card_fuzzy.name=Fuzzy Card item.appliedenergistics2.material.card_fuzzy.name=Fuzzy Card
item.appliedenergistics2.material.card_inverter.name=Inverter Card item.appliedenergistics2.material.card_inverter.name=Inverter Card