mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-23 21:49:50 +00:00
De-capify bauble box, pull inv sizes to constants
This commit is contained in:
1 parent
66bd3ae399
commit
4bbf5fe08d
4 files changed
+37
-39
No files matched your search
@@ -43,7 +43,7 @@ public class ContainerFlowerBag extends Container {
|
||||
if (!playerInv.player.world.isRemote) {
|
||||
flowerBagInv = ItemFlowerBag.getInventory(bag);
|
||||
} else {
|
||||
flowerBagInv = new Inventory(16);
|
||||
flowerBagInv = new Inventory(ItemFlowerBag.SIZE);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; ++i) {
|
||||
|
||||
@@ -10,16 +10,16 @@ package vazkii.botania.client.gui.box;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
import vazkii.botania.common.core.handler.EquipmentHandler;
|
||||
import vazkii.botania.common.item.ItemBaubleBox;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -31,7 +31,6 @@ public class ContainerBaubleBox extends Container {
|
||||
}
|
||||
|
||||
private final ItemStack box;
|
||||
public IItemHandlerModifiable baubles;
|
||||
|
||||
public ContainerBaubleBox(int windowId, PlayerInventory playerInv, ItemStack box) {
|
||||
super(ModItems.BAUBLE_BOX_CONTAINER, windowId);
|
||||
@@ -39,12 +38,22 @@ public class ContainerBaubleBox extends Container {
|
||||
int j;
|
||||
|
||||
this.box = box;
|
||||
IItemHandlerModifiable baubleBoxInv = (IItemHandlerModifiable) box.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
|
||||
IInventory baubleBoxInv;
|
||||
if (!playerInv.player.world.isRemote) {
|
||||
baubleBoxInv = ItemBaubleBox.getInventory(box);
|
||||
} else {
|
||||
baubleBoxInv = new Inventory(ItemBaubleBox.SIZE);
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
for (j = 0; j < 6; ++j) {
|
||||
int k = j + i * 6;
|
||||
addSlot(new SlotItemHandler(baubleBoxInv, k, 62 + j * 18, 8 + i * 18));
|
||||
addSlot(new Slot(baubleBoxInv, k, 62 + j * 18, 8 + i * 18) {
|
||||
@Override
|
||||
public boolean isItemValid(@Nonnull ItemStack stack) {
|
||||
return EquipmentHandler.instance.isAccessory(stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,25 +10,24 @@ package vazkii.botania.common.item;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import vazkii.botania.client.gui.box.ContainerBaubleBox;
|
||||
import vazkii.botania.common.core.handler.EquipmentHandler;
|
||||
|
||||
@@ -36,48 +35,39 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ItemBaubleBox extends Item {
|
||||
public static final int SIZE = 24;
|
||||
|
||||
public ItemBaubleBox(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
public static Inventory getInventory(ItemStack stack) {
|
||||
return new ItemBackedInventory(stack, SIZE) {
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int index, @Nonnull ItemStack stack) {
|
||||
return EquipmentHandler.instance.isAccessory(stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT oldCapNbt) {
|
||||
return new InvProvider();
|
||||
return new InvProvider(stack);
|
||||
}
|
||||
|
||||
private static class InvProvider implements ICapabilitySerializable<INBT> {
|
||||
private static class InvProvider implements ICapabilityProvider {
|
||||
private final LazyOptional<IItemHandler> opt;
|
||||
|
||||
private final IItemHandler inv = new ItemStackHandler(24) {
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack toInsert, boolean simulate) {
|
||||
if (!toInsert.isEmpty()) {
|
||||
if (EquipmentHandler.instance.isAccessory(toInsert)) {
|
||||
return super.insertItem(slot, toInsert, simulate);
|
||||
}
|
||||
}
|
||||
return toInsert;
|
||||
}
|
||||
};
|
||||
private final LazyOptional<IItemHandler> opt = LazyOptional.of(() -> inv);
|
||||
public InvProvider(ItemStack stack) {
|
||||
opt = LazyOptional.of(() -> new InvWrapper(getInventory(stack)));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) {
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.orEmpty(capability, opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBT serializeNBT() {
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inv, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(INBT nbt) {
|
||||
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inv, null, nbt);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -19,7 +19,6 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.network.play.server.SCollectItemPacket;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
@@ -28,7 +27,6 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
@@ -36,13 +34,14 @@ import net.minecraftforge.items.*;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
|
||||
import vazkii.botania.client.gui.bag.ContainerFlowerBag;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.BlockModFlower;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ItemFlowerBag extends Item {
|
||||
public static final int SIZE = 16;
|
||||
|
||||
public ItemFlowerBag(Properties props) {
|
||||
super(props);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::onPickupItem);
|
||||
@@ -56,7 +55,7 @@ public class ItemFlowerBag extends Item {
|
||||
}
|
||||
|
||||
public static Inventory getInventory(ItemStack stack) {
|
||||
return new ItemBackedInventory(stack, 16) {
|
||||
return new ItemBackedInventory(stack, SIZE) {
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, @Nonnull ItemStack stack) {
|
||||
return isValid(slot, stack);
|
||||
|
||||
Reference in new issue
Block a user