mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-24 05:44:24 +00:00
Add support for InventoryTweaks
This commit is contained in:
1 parent
a49eb1c5f9
commit
27daa8e1ac
18 files changed
+596
-15
No files matched your search
@@ -10,18 +10,28 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gui.slots.SlotFilteredInventory;
|
||||
import forestry.core.gui.slots.SlotForestry;
|
||||
import forestry.core.gui.slots.SlotLocked;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
|
||||
import invtweaks.api.container.ContainerSection;
|
||||
import invtweaks.api.container.ContainerSectionCallback;
|
||||
|
||||
@invtweaks.api.container.ChestContainer
|
||||
public abstract class ContainerForestry extends Container {
|
||||
protected final void addPlayerInventory(InventoryPlayer playerInventory, int xInv, int yInv) {
|
||||
// Player inventory
|
||||
@@ -89,4 +99,34 @@ public abstract class ContainerForestry extends Container {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ContainerSectionCallback
|
||||
public Map<ContainerSection, List<Slot>> getContainerSections() {
|
||||
ArrayListMultimap<ContainerSection, Slot> map = ArrayListMultimap.create();
|
||||
|
||||
for (Object object : inventorySlots) {
|
||||
if (!(object instanceof Slot)) {
|
||||
continue;
|
||||
}
|
||||
Slot slot = (Slot) object;
|
||||
|
||||
if (slot.inventory instanceof InventoryPlayer) {
|
||||
map.put(ContainerSection.INVENTORY, slot);
|
||||
if (slot.slotNumber < 9) {
|
||||
map.put(ContainerSection.INVENTORY_HOTBAR, slot);
|
||||
} else if (slot.slotNumber < 36) {
|
||||
map.put(ContainerSection.INVENTORY_NOT_HOTBAR, slot);
|
||||
} else {
|
||||
map.put(ContainerSection.ARMOR, slot);
|
||||
}
|
||||
} else {
|
||||
if (!(slot instanceof SlotForestry) || slot instanceof SlotFilteredInventory) {
|
||||
map.put(ContainerSection.CHEST, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return (Map<ContainerSection, List<Slot>>) (Object) map.asMap();
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,11 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotFilteredInventory;
|
||||
import forestry.core.network.packets.PacketGuiSelectRequest;
|
||||
import forestry.core.tiles.IFilterSlotDelegate;
|
||||
import forestry.core.tiles.TileNaturalistChest;
|
||||
|
||||
public class ContainerNaturalistInventory extends ContainerTile<TileNaturalistChest> implements IGuiSelectable {
|
||||
@@ -24,10 +26,20 @@ public class ContainerNaturalistInventory extends ContainerTile<TileNaturalistCh
|
||||
public ContainerNaturalistInventory(InventoryPlayer player, TileNaturalistChest tile, int page) {
|
||||
super(tile, player, 18, 120);
|
||||
|
||||
// Inventory
|
||||
for (int x = 0; x < 5; x++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
addSlotToContainer(new SlotFiltered(tile, y + page * 25 + x * 5, 100 + y * 18, 21 + x * 18));
|
||||
addInventory(this, tile, page);
|
||||
}
|
||||
|
||||
public static <T extends IInventory & IFilterSlotDelegate> void addInventory(ContainerForestry container, T inventory, int selectedPage) {
|
||||
for (int page = 0; page < 5; page++) {
|
||||
for (int x = 0; x < 5; x++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
int slot = y + page * 25 + x * 5;
|
||||
if (page == selectedPage) {
|
||||
container.addSlotToContainer(new SlotFilteredInventory(inventory, slot, 100 + y * 18, 21 + x * 18));
|
||||
} else {
|
||||
container.addSlotToContainer(new SlotFilteredInventory(inventory, slot, -10000, -10000));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +55,7 @@ public class ContainerNaturalistInventory extends ContainerTile<TileNaturalistCh
|
||||
tile.increaseNumPlayersUsing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer player) {
|
||||
super.onContainerClosed(player);
|
||||
tile.decreaseNumPlayersUsing();
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.gui.slots;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
||||
import forestry.core.tiles.IFilterSlotDelegate;
|
||||
|
||||
/**
|
||||
* Useful for InventoryTweaks. Works like SlotFiltered but allows InventoryTweaks to sort it.
|
||||
*/
|
||||
public class SlotFilteredInventory extends SlotFiltered {
|
||||
public <T extends IInventory & IFilterSlotDelegate> SlotFilteredInventory(T inventory, int slotIndex, int xPos, int yPos) {
|
||||
super(inventory, slotIndex, xPos, yPos);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotFilteredInventory;
|
||||
import forestry.storage.inventory.ItemInventoryBackpack;
|
||||
|
||||
public class ContainerBackpack extends ContainerItemInventory<ItemInventoryBackpack> {
|
||||
@@ -47,7 +47,7 @@ public class ContainerBackpack extends ContainerItemInventory<ItemInventoryBackp
|
||||
for (int j = 0; j < size.rows; j++) {
|
||||
for (int k = 0; k < size.columns; k++) {
|
||||
int slot = k + j * size.columns;
|
||||
addSlotToContainer(new SlotFiltered(inventory, slot, size.startX + k * 18, size.startY + j * 18));
|
||||
addSlotToContainer(new SlotFilteredInventory(inventory, slot, size.startX + k * 18, size.startY + j * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,22 +14,17 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.ContainerNaturalistInventory;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.network.packets.PacketGuiSelectRequest;
|
||||
import forestry.storage.inventory.ItemInventoryBackpackPaged;
|
||||
|
||||
public class ContainerNaturalistBackpack extends ContainerItemInventory<ItemInventoryBackpackPaged> implements IGuiSelectable {
|
||||
|
||||
public ContainerNaturalistBackpack(EntityPlayer player, ItemInventoryBackpackPaged inventory, int page) {
|
||||
public ContainerNaturalistBackpack(EntityPlayer player, ItemInventoryBackpackPaged inventory, int selectedPage) {
|
||||
super(inventory, player.inventory, 18, 120);
|
||||
|
||||
// Inventory
|
||||
for (int x = 0; x < 5; x++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
addSlotToContainer(new SlotFiltered(inventory, y + page * 25 + x * 5, 100 + y * 18, 21 + x * 18));
|
||||
}
|
||||
}
|
||||
ContainerNaturalistInventory.addInventory(this, inventory, selectedPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user