mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-26 23:03:18 +00:00
Tidy up item inventory code
This commit is contained in:
1 parent
cd7d5f10e6
commit
e73e703f8c
11 files changed
+41
-73
No files matched your search
@@ -17,10 +17,10 @@ import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
|
||||
public class ContainerHabitatLocator extends ContainerItemInventory {
|
||||
public class ContainerHabitatLocator extends ContainerItemInventory<HabitatLocatorInventory> {
|
||||
|
||||
public ContainerHabitatLocator(InventoryPlayer inventoryplayer, HabitatLocatorInventory inventory) {
|
||||
super(inventory, inventoryplayer.player);
|
||||
super(inventory);
|
||||
|
||||
// Energy
|
||||
this.addSlotToContainer(new SlotFiltered(inventory, 2, 152, 8));
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.core.circuits;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.circuits.ICircuitLayout;
|
||||
import forestry.core.circuits.ItemSolderingIron.SolderingInventory;
|
||||
@@ -25,13 +24,10 @@ import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class ContainerSolderingIron extends ContainerItemInventory implements IGuiSelectable {
|
||||
|
||||
private final SolderingInventory inventory;
|
||||
public class ContainerSolderingIron extends ContainerItemInventory<SolderingInventory> implements IGuiSelectable {
|
||||
|
||||
public ContainerSolderingIron(InventoryPlayer inventoryplayer, SolderingInventory inventory) {
|
||||
super(inventory, inventoryplayer.player);
|
||||
this.inventory = inventory;
|
||||
super(inventory);
|
||||
|
||||
// Input
|
||||
this.addSlotToContainer(new SlotFiltered(inventory, 0, 152, 12));
|
||||
@@ -62,21 +58,21 @@ public class ContainerSolderingIron extends ContainerItemInventory implements IG
|
||||
return inventory.getLayout();
|
||||
}
|
||||
|
||||
public void advanceSelection(int index, World world) {
|
||||
public static void advanceSelection(int index) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = index;
|
||||
payload.intPayload[1] = 0;
|
||||
sendSelectionChange(payload);
|
||||
}
|
||||
|
||||
public void regressSelection(int index, World world) {
|
||||
public static void regressSelection(int index) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = index;
|
||||
payload.intPayload[1] = 1;
|
||||
sendSelectionChange(payload);
|
||||
}
|
||||
|
||||
private void sendSelectionChange(PacketPayload payload) {
|
||||
private static void sendSelectionChange(PacketPayload payload) {
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
@@ -67,9 +67,9 @@ public class GuiSolderingIron extends GuiForestry<ContainerSolderingIron, Solder
|
||||
super.actionPerformed(guibutton);
|
||||
|
||||
if (guibutton.id == 1) {
|
||||
((ContainerSolderingIron) inventorySlots).regressSelection(0, Proxies.common.getRenderWorld());
|
||||
ContainerSolderingIron.regressSelection(0);
|
||||
} else if (guibutton.id == 2) {
|
||||
((ContainerSolderingIron) inventorySlots).advanceSelection(0, Proxies.common.getRenderWorld());
|
||||
ContainerSolderingIron.advanceSelection(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,15 +8,10 @@ import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.inventory.AlyzerInventory;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class ContainerAlyzer extends ContainerItemInventory {
|
||||
|
||||
private final AlyzerInventory inventory;
|
||||
public class ContainerAlyzer extends ContainerItemInventory<AlyzerInventory> {
|
||||
|
||||
public ContainerAlyzer(AlyzerInventory inventory, EntityPlayer player) {
|
||||
super(inventory, player);
|
||||
|
||||
InventoryPlayer inventoryplayer = player.inventory;
|
||||
this.inventory = inventory;
|
||||
super(inventory);
|
||||
|
||||
final int xPosLeftSlots = 223;
|
||||
|
||||
@@ -39,6 +34,8 @@ public class ContainerAlyzer extends ContainerItemInventory {
|
||||
final int ySpacePlayerInv = 18;
|
||||
|
||||
// Player inventory
|
||||
InventoryPlayer inventoryplayer = player.inventory;
|
||||
|
||||
for (int i1 = 0; i1 < 3; i1++) {
|
||||
for (int l1 = 0; l1 < 9; l1++) {
|
||||
int slot = l1 + i1 * 9 + 9;
|
||||
|
||||
@@ -24,8 +24,8 @@ import forestry.core.utils.SlotHelper;
|
||||
|
||||
public class ContainerForestry extends Container {
|
||||
|
||||
protected final IInventory inventoryAccess;
|
||||
protected final IRestrictedAccess restrictedAccess;
|
||||
private final IInventory inventoryAccess;
|
||||
private final IRestrictedAccess restrictedAccess;
|
||||
|
||||
public ContainerForestry(TileForestry tileForestry) {
|
||||
this.inventoryAccess = tileForestry;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
package forestry.core.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -20,29 +20,21 @@ import forestry.core.inventory.ItemInventory;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StackUtils;
|
||||
|
||||
public abstract class ContainerItemInventory extends ContainerForestry {
|
||||
public abstract class ContainerItemInventory<I extends ItemInventory> extends ContainerForestry {
|
||||
|
||||
protected final EntityPlayer player;
|
||||
protected final ItemInventory inventory;
|
||||
protected final I inventory;
|
||||
|
||||
public ContainerItemInventory(ItemInventory inventory, EntityPlayer player) {
|
||||
public ContainerItemInventory(I inventory) {
|
||||
super(inventory);
|
||||
this.inventory = inventory;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
protected void addSecuredSlot(IInventory other, int slot, int x, int y) {
|
||||
ItemStack stackInSlot = other.getStackInSlot(slot);
|
||||
protected void addSecuredSlot(InventoryPlayer playerInventory, int slot, int x, int y) {
|
||||
ItemStack stackInSlot = playerInventory.getStackInSlot(slot);
|
||||
if (StackUtils.isIdenticalItem(inventory.parent, stackInSlot)) {
|
||||
addSlotToContainer(new SlotLocked(other, slot, x, y));
|
||||
addSlotToContainer(new SlotLocked(playerInventory, slot, x, y));
|
||||
} else {
|
||||
addSlotToContainer(new Slot(other, slot, x, y));
|
||||
}
|
||||
}
|
||||
|
||||
public void saveInventory(EntityPlayer entityplayer) {
|
||||
if (inventory.isItemInventory) {
|
||||
inventory.onGuiSaved(entityplayer);
|
||||
addSlotToContainer(new Slot(playerInventory, slot, x, y));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +45,6 @@ public abstract class ContainerItemInventory extends ContainerForestry {
|
||||
return;
|
||||
}
|
||||
|
||||
saveInventory(player);
|
||||
inventory.onGuiSaved(player);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import forestry.core.utils.Utils;
|
||||
public class ItemInventory implements IInventory, IFilterSlotDelegate, INBTTagable {
|
||||
|
||||
public final Class<? extends Item> itemClass;
|
||||
public final boolean isItemInventory;
|
||||
public ItemStack parent;
|
||||
protected ItemStack[] inventoryStacks;
|
||||
|
||||
@@ -35,7 +34,6 @@ public class ItemInventory implements IInventory, IFilterSlotDelegate, INBTTagab
|
||||
inventoryStacks = new ItemStack[size];
|
||||
|
||||
parent = itemstack;
|
||||
isItemInventory = true;
|
||||
|
||||
// Set an uid to identify the itemstack on SMP
|
||||
setUID(false);
|
||||
|
||||
@@ -39,19 +39,16 @@ import forestry.mail.items.ItemLetter;
|
||||
import forestry.mail.items.ItemLetter.LetterInventory;
|
||||
import forestry.mail.network.PacketLetterInfo;
|
||||
|
||||
public class ContainerLetter extends ContainerItemInventory {
|
||||
public class ContainerLetter extends ContainerItemInventory<LetterInventory> {
|
||||
|
||||
private final LetterInventory letterInventory;
|
||||
private EnumAddressee carrierType = EnumAddressee.PLAYER;
|
||||
private TradeStationInfo tradeInfo = null;
|
||||
|
||||
public ContainerLetter(EntityPlayer player, LetterInventory inventory) {
|
||||
super(inventory, player);
|
||||
|
||||
letterInventory = inventory;
|
||||
super(inventory);
|
||||
|
||||
// Rip open delivered mails
|
||||
if (Proxies.common.isSimulating(player.worldObj) && letterInventory.getLetter().isProcessed() && inventory.parent != null
|
||||
if (Proxies.common.isSimulating(player.worldObj) && inventory.getLetter().isProcessed() && inventory.parent != null
|
||||
&& ItemLetter.getState(inventory.parent.getItemDamage()) < 2) {
|
||||
inventory.parent.setItemDamage(ItemLetter.encodeMeta(2, ItemLetter.getSize(inventory.parent.getItemDamage())));
|
||||
}
|
||||
@@ -82,11 +79,11 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
}
|
||||
|
||||
// Set recipient type
|
||||
if (letterInventory.getLetter() != null) {
|
||||
if (letterInventory.getLetter().getRecipients() != null) {
|
||||
if (letterInventory.getLetter().getRecipients().length > 0) {
|
||||
this.carrierType = letterInventory.getLetter().getRecipients()[0].getType();
|
||||
}
|
||||
ILetter letter = inventory.getLetter();
|
||||
if (letter != null) {
|
||||
IMailAddress[] recipients = letter.getRecipients();
|
||||
if (recipients != null && recipients.length > 0) {
|
||||
this.carrierType = recipients[0].getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +92,7 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
public void onContainerClosed(EntityPlayer entityplayer) {
|
||||
|
||||
if (Proxies.common.isSimulating(entityplayer.worldObj)) {
|
||||
ILetter letter = letterInventory.getLetter();
|
||||
ILetter letter = inventory.getLetter();
|
||||
if (!letter.isProcessed()) {
|
||||
IMailAddress sender = PostManager.postRegistry.getMailAddress(entityplayer.getGameProfile());
|
||||
letter.setSender(sender);
|
||||
@@ -106,7 +103,7 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
}
|
||||
|
||||
public ILetter getLetter() {
|
||||
return letterInventory.getLetter();
|
||||
return inventory.getLetter();
|
||||
}
|
||||
|
||||
public void setCarrierType(EnumAddressee type) {
|
||||
@@ -135,7 +132,7 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
setCarrierType(postal.getType());
|
||||
}
|
||||
|
||||
public void setRecipient(String recipientName, EnumAddressee type) {
|
||||
public static void setRecipient(String recipientName, EnumAddressee type) {
|
||||
if (StringUtils.isBlank(recipientName) || type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.inventory.ItemInventoryBackpack;
|
||||
|
||||
public class ContainerBackpack extends ContainerItemInventory {
|
||||
public class ContainerBackpack extends ContainerItemInventory<ItemInventoryBackpack> {
|
||||
|
||||
public ContainerBackpack(final EntityPlayer player, ItemInventoryBackpack inventory) {
|
||||
super(inventory, player);
|
||||
public ContainerBackpack(EntityPlayer player, ItemInventoryBackpack inventory) {
|
||||
super(inventory);
|
||||
|
||||
int lines = 0;
|
||||
int columns = 0;
|
||||
|
||||
@@ -19,14 +19,10 @@ import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.storage.GuiHandlerStorage.PagedBackpackInventory;
|
||||
|
||||
public class ContainerNaturalistBackpack extends ContainerItemInventory implements IGuiSelectable {
|
||||
|
||||
private final PagedBackpackInventory inv;
|
||||
public class ContainerNaturalistBackpack extends ContainerItemInventory<PagedBackpackInventory> implements IGuiSelectable {
|
||||
|
||||
public ContainerNaturalistBackpack(InventoryPlayer player, PagedBackpackInventory inventory, int page, int pageSize) {
|
||||
super(inventory, player.player);
|
||||
|
||||
this.inv = inventory;
|
||||
super(inventory);
|
||||
|
||||
// Inventory
|
||||
for (int x = 0; x < 5; x++) {
|
||||
@@ -49,7 +45,7 @@ public class ContainerNaturalistBackpack extends ContainerItemInventory implemen
|
||||
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
|
||||
inv.flipPage(player, packet.payload.intPayload[0]);
|
||||
inventory.flipPage(player, packet.payload.intPayload[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -218,14 +218,6 @@ public class ItemBackpack extends ItemInventoried {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBackpack(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return stack.getItem() == this;
|
||||
}
|
||||
|
||||
public int getBackpackSize() {
|
||||
return getSlotsForType(type);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user