mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 03:15:07 +00:00
Move bauble box to caps as well. Closes #297
This commit is contained in:
9 files changed
+103
-259
No files matched your search
@@ -50,14 +50,6 @@ public class ContainerFlowerBag extends Container {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
|
||||
if (slotId >= 0 && slotId < inventorySlots.size()
|
||||
&& getSlot(slotId).getStack() == flowerBagInv.bag)
|
||||
return null;
|
||||
else return super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(@Nonnull EntityPlayer player) {
|
||||
return player.getHeldItemMainhand() == flowerBagInv.bag
|
||||
|
||||
@@ -64,9 +64,4 @@ public class GuiFlowerBag extends GuiContainer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkHotbarKeys(int p_146983_1_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import vazkii.botania.api.mana.IManaItem;
|
||||
import vazkii.botania.client.gui.SlotLocked;
|
||||
|
||||
@@ -27,16 +28,15 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class ContainerBaubleBox extends Container {
|
||||
|
||||
final InventoryBaubleBox baubleBoxInv;
|
||||
final InventoryBaubles baubles;
|
||||
private final InventoryBaubleBox baubleBoxInv;
|
||||
private final InventoryBaubles baubles;
|
||||
|
||||
public ContainerBaubleBox(EntityPlayer player) {
|
||||
public ContainerBaubleBox(EntityPlayer player, InventoryBaubleBox boxInv) {
|
||||
int i;
|
||||
int j;
|
||||
|
||||
int slot = player.inventory.currentItem;
|
||||
IInventory playerInv = player.inventory;
|
||||
baubleBoxInv = new InventoryBaubleBox(player, slot);
|
||||
baubleBoxInv = boxInv;
|
||||
|
||||
baubles = new InventoryBaubles(player);
|
||||
baubles.setEventHandler(this);
|
||||
@@ -51,7 +51,7 @@ public class ContainerBaubleBox extends Container {
|
||||
for(i = 0; i < 4; ++i)
|
||||
for(j = 0; j < 6; ++j) {
|
||||
int k = j + i * 6;
|
||||
addSlotToContainer(new SlotAnyBauble(baubleBoxInv, k, 62 + j * 18, 8 + i * 18));
|
||||
addSlotToContainer(new SlotItemHandler(baubleBoxInv, k, 62 + j * 18, 8 + i * 18));
|
||||
}
|
||||
|
||||
for(i = 0; i < 3; ++i)
|
||||
@@ -59,7 +59,7 @@ public class ContainerBaubleBox extends Container {
|
||||
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
|
||||
for(i = 0; i < 9; ++i) {
|
||||
if(player.inventory.currentItem == i)
|
||||
if(playerInv.getStackInSlot(i) == baubleBoxInv.box)
|
||||
addSlotToContainer(new SlotLocked(playerInv, i, 8 + i * 18, 142));
|
||||
else addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 142));
|
||||
}
|
||||
@@ -68,17 +68,13 @@ public class ContainerBaubleBox extends Container {
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(@Nonnull EntityPlayer player) {
|
||||
boolean can = baubleBoxInv.isUseableByPlayer(player);
|
||||
if(!can)
|
||||
onContainerClosed(player);
|
||||
|
||||
return can;
|
||||
return player.getHeldItemMainhand() == baubleBoxInv.box
|
||||
|| player.getHeldItemOffhand() == baubleBoxInv.box;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer player) {
|
||||
super.onContainerClosed(player);
|
||||
baubleBoxInv.pushInventory();
|
||||
|
||||
if(!player.worldObj.isRemote)
|
||||
PlayerHandler.setPlayerBaubles(player, baubles);
|
||||
@@ -99,7 +95,6 @@ public class ContainerBaubleBox extends Container {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
System.out.println(p_82846_2_ + " " + itemstack);
|
||||
if(p_82846_2_ < 28) {
|
||||
if(!mergeItemStack(itemstack1, 28, 64, true))
|
||||
return null;
|
||||
|
||||
@@ -22,13 +22,8 @@ public class GuiBaubleBox extends InventoryEffectRenderer {
|
||||
|
||||
private static final ResourceLocation texture = new ResourceLocation(LibResources.GUI_BAUBLE_BOX);
|
||||
|
||||
public GuiBaubleBox(EntityPlayer player) {
|
||||
super(new ContainerBaubleBox(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkHotbarKeys(int p_146983_1_) {
|
||||
return false;
|
||||
public GuiBaubleBox(EntityPlayer player, InventoryBaubleBox box) {
|
||||
super(new ContainerBaubleBox(player, box));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,182 +10,43 @@
|
||||
*/
|
||||
package vazkii.botania.client.gui.box;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import vazkii.botania.common.item.ItemBaubleBox;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
public class InventoryBaubleBox implements IItemHandlerModifiable {
|
||||
|
||||
public class InventoryBaubleBox implements IInventory {
|
||||
private final IItemHandlerModifiable boxInv;
|
||||
final ItemStack box;
|
||||
|
||||
private static final ItemStack[] FALLBACK_INVENTORY = new ItemStack[16];
|
||||
|
||||
final EntityPlayer player;
|
||||
final int slot;
|
||||
ItemStack[] stacks = null;
|
||||
|
||||
boolean invPushed = false;
|
||||
ItemStack storedInv = null;
|
||||
|
||||
public InventoryBaubleBox(EntityPlayer player, int slot) {
|
||||
this.player = player;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public static boolean isBaubleBox(ItemStack stack) {
|
||||
return stack != null && stack.getItem() == ModItems.baubleBox;
|
||||
}
|
||||
|
||||
ItemStack getStack() {
|
||||
ItemStack stack = player.inventory.getStackInSlot(slot);
|
||||
if(stack != null)
|
||||
storedInv = stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
ItemStack[] getInventory() {
|
||||
if(stacks != null)
|
||||
return stacks;
|
||||
|
||||
ItemStack stack = getStack();
|
||||
if(isBaubleBox(getStack())) {
|
||||
stacks = ItemBaubleBox.loadStacks(stack);
|
||||
return stacks;
|
||||
}
|
||||
|
||||
return FALLBACK_INVENTORY;
|
||||
}
|
||||
|
||||
public void pushInventory() {
|
||||
if(invPushed)
|
||||
return;
|
||||
|
||||
ItemStack stack = getStack();
|
||||
if(stack == null)
|
||||
stack = storedInv;
|
||||
|
||||
if(stack != null) {
|
||||
ItemStack[] inv = getInventory();
|
||||
ItemBaubleBox.setStacks(stack, inv);
|
||||
}
|
||||
|
||||
invPushed = true;
|
||||
public InventoryBaubleBox(ItemStack box) {
|
||||
this.box = box;
|
||||
this.boxInv = (IItemHandlerModifiable) box.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 16;
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
boxInv.setStackInSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return getInventory()[i];
|
||||
public int getSlots() {
|
||||
return boxInv.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
ItemStack[] inventorySlots = getInventory();
|
||||
if (inventorySlots[i] != null) {
|
||||
ItemStack stackAt;
|
||||
|
||||
if (inventorySlots[i].stackSize <= j) {
|
||||
stackAt = inventorySlots[i];
|
||||
inventorySlots[i] = null;
|
||||
return stackAt;
|
||||
} else {
|
||||
stackAt = inventorySlots[i].splitStack(j);
|
||||
|
||||
if (inventorySlots[i].stackSize == 0)
|
||||
inventorySlots[i] = null;
|
||||
|
||||
return stackAt;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return boxInv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int i) {
|
||||
return getStackInSlot(i);
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
return boxInv.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
ItemStack[] inventorySlots = getInventory();
|
||||
inventorySlots[slot] = itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return isBaubleBox(getStack()) ? 64 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(@Nonnull EntityPlayer entityplayer) {
|
||||
return isBaubleBox(getStack());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, @Nonnull ItemStack itemstack) {
|
||||
return isBaubleBox(getStack());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {}
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if (stacks != null)
|
||||
Arrays.fill(stacks, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TextComponentString(getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(@Nonnull EntityPlayer player) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(@Nonnull EntityPlayer player) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return LibItemNames.BAUBLE_BOX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
// NO-OP
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return boxInv.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [25/11/2015, 19:59:22 (GMT)]
|
||||
*/
|
||||
package vazkii.botania.client.gui.box;
|
||||
|
||||
import baubles.api.IBauble;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.mana.IManaItem;
|
||||
|
||||
public class SlotAnyBauble extends Slot {
|
||||
|
||||
final InventoryBaubleBox inv;
|
||||
|
||||
public SlotAnyBauble(InventoryBaubleBox p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_) {
|
||||
super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_);
|
||||
inv = p_i1824_1_;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChange(ItemStack oldStack, ItemStack newStack) {
|
||||
inv.setInventorySlotContents(slotNumber, newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return stack.getItem() instanceof IBauble || stack.getItem() instanceof IManaItem;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,31 +10,101 @@
|
||||
*/
|
||||
package vazkii.botania.common.item;
|
||||
|
||||
import baubles.api.IBauble;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
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.Constants;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import vazkii.botania.api.mana.IManaItem;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.lib.LibGuiIDs;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ItemBaubleBox extends ItemMod {
|
||||
|
||||
private static final String TAG_ITEMS = "InvItems";
|
||||
private static final String TAG_SLOT = "Slot";
|
||||
|
||||
public ItemBaubleBox() {
|
||||
super(LibItemNames.BAUBLE_BOX);
|
||||
setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound oldCapNbt) {
|
||||
return new InvProvider();
|
||||
}
|
||||
|
||||
private static class InvProvider implements ICapabilitySerializable<NBTBase> {
|
||||
|
||||
private final IItemHandler inv = new ItemStackHandler(24) {
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack toInsert, boolean simulate) {
|
||||
if(toInsert != null &&
|
||||
(toInsert.getItem() instanceof IManaItem
|
||||
|| toInsert.getItem() instanceof IBauble))
|
||||
return super.insertItem(slot, toInsert, simulate);
|
||||
else return toInsert;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inv);
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase serializeNBT() {
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inv, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(NBTBase nbt) {
|
||||
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inv, null, nbt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
||||
if(stack.getTagCompound() != null && stack.getTagCompound().hasKey(TAG_ITEMS)) {
|
||||
NBTTagList oldData = stack.getTagCompound().getTagList(TAG_ITEMS, Constants.NBT.TAG_COMPOUND);
|
||||
IItemHandler newInv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
|
||||
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(newInv, null, oldData);
|
||||
|
||||
stack.getTagCompound().removeTag(TAG_ITEMS);
|
||||
|
||||
if(stack.getTagCompound().getSize() == 0)
|
||||
stack.setTagCompound(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
|
||||
@@ -42,31 +112,4 @@ public class ItemBaubleBox extends ItemMod {
|
||||
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
|
||||
}
|
||||
|
||||
|
||||
public static ItemStack[] loadStacks(ItemStack stack) {
|
||||
NBTTagList var2 = ItemNBTHelper.getList(stack, TAG_ITEMS, 10, false);
|
||||
ItemStack[] inventorySlots = new ItemStack[36];
|
||||
for(int var3 = 0; var3 < var2.tagCount(); ++var3) {
|
||||
NBTTagCompound var4 = var2.getCompoundTagAt(var3);
|
||||
byte var5 = var4.getByte(TAG_SLOT);
|
||||
if(var5 >= 0 && var5 < inventorySlots.length)
|
||||
inventorySlots[var5] = ItemStack.loadItemStackFromNBT(var4);
|
||||
}
|
||||
|
||||
return inventorySlots;
|
||||
}
|
||||
|
||||
public static void setStacks(ItemStack stack, ItemStack[] inventorySlots) {
|
||||
NBTTagList var2 = new NBTTagList();
|
||||
for(int var3 = 0; var3 < inventorySlots.length; ++var3)
|
||||
if(inventorySlots[var3] != null) {
|
||||
NBTTagCompound var4 = new NBTTagCompound();
|
||||
var4.setByte(TAG_SLOT, (byte)var3);
|
||||
inventorySlots[var3].writeToNBT(var4);
|
||||
var2.appendTag(var4);
|
||||
}
|
||||
|
||||
ItemNBTHelper.setList(stack, TAG_ITEMS, var2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,7 +55,6 @@ import javax.annotation.Nullable;
|
||||
public class ItemFlowerBag extends ItemMod {
|
||||
|
||||
private static final String TAG_ITEMS = "InvItems";
|
||||
private static final String TAG_SLOT = "Slot";
|
||||
|
||||
public ItemFlowerBag() {
|
||||
super(LibItemNames.FLOWER_BAG);
|
||||
|
||||
@@ -19,6 +19,7 @@ import vazkii.botania.client.gui.bag.GuiFlowerBag;
|
||||
import vazkii.botania.client.gui.bag.InventoryFlowerBag;
|
||||
import vazkii.botania.client.gui.box.ContainerBaubleBox;
|
||||
import vazkii.botania.client.gui.box.GuiBaubleBox;
|
||||
import vazkii.botania.client.gui.box.InventoryBaubleBox;
|
||||
import vazkii.botania.client.gui.crafting.ContainerCraftingHalo;
|
||||
import vazkii.botania.client.gui.crafting.GuiCraftingHalo;
|
||||
import vazkii.botania.client.gui.lexicon.GuiLexicon;
|
||||
@@ -36,7 +37,7 @@ public class GuiHandler implements IGuiHandler {
|
||||
case LibGuiIDs.FLOWER_BAG :
|
||||
return new ContainerFlowerBag(player.inventory, new InventoryFlowerBag(player.getHeldItem(hand)));
|
||||
case LibGuiIDs.BAUBLE_BOX :
|
||||
return new ContainerBaubleBox(player);
|
||||
return new ContainerBaubleBox(player, new InventoryBaubleBox(player.getHeldItem(hand)));
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -54,7 +55,7 @@ public class GuiHandler implements IGuiHandler {
|
||||
case LibGuiIDs.FLOWER_BAG :
|
||||
return new GuiFlowerBag(player.inventory, new InventoryFlowerBag(player.getHeldItem(hand)));
|
||||
case LibGuiIDs.BAUBLE_BOX :
|
||||
return new GuiBaubleBox(player);
|
||||
return new GuiBaubleBox(player, new InventoryBaubleBox(player.getHeldItem(hand)));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user