mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Move flower pouch to caps
This commit is contained in:
8 files changed
+145
-271
No files matched your search
@@ -11,6 +11,8 @@
|
||||
package vazkii.botania.client.gui.bag;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ClickType;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
@@ -21,15 +23,13 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class ContainerFlowerBag extends Container {
|
||||
|
||||
final InventoryFlowerBag flowerBagInv;
|
||||
private final InventoryFlowerBag flowerBagInv;
|
||||
|
||||
public ContainerFlowerBag(EntityPlayer player) {
|
||||
public ContainerFlowerBag(InventoryPlayer playerInv, InventoryFlowerBag flowerBagInv) {
|
||||
int i;
|
||||
int j;
|
||||
|
||||
int slot = player.inventory.currentItem;
|
||||
IInventory playerInv = player.inventory;
|
||||
flowerBagInv = new InventoryFlowerBag(player, slot);
|
||||
this.flowerBagInv = flowerBagInv;
|
||||
|
||||
for(i = 0; i < 2; ++i)
|
||||
for(j = 0; j < 8; ++j) {
|
||||
@@ -42,26 +42,25 @@ public class ContainerFlowerBag 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)
|
||||
addSlotToContainer(new SlotLocked(playerInv, i, 8 + i * 18, 142));
|
||||
else addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 142));
|
||||
/*if(player.inventory.currentItem == i)
|
||||
addSlotToContainer(new SlotLocked(player.inventory, i, 8 + i * 18, 142));
|
||||
else*/ addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 142));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(@Nonnull EntityPlayer player) {
|
||||
boolean can = flowerBagInv.isUseableByPlayer(player);
|
||||
if(!can)
|
||||
onContainerClosed(player);
|
||||
|
||||
return can;
|
||||
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 void onContainerClosed(EntityPlayer player) {
|
||||
super.onContainerClosed(player);
|
||||
flowerBagInv.pushInventory();
|
||||
public boolean canInteractWith(@Nonnull EntityPlayer player) {
|
||||
return player.getHeldItemMainhand() == flowerBagInv.bag
|
||||
|| player.getHeldItemOffhand() == flowerBagInv.bag;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -27,8 +28,8 @@ public class GuiFlowerBag extends GuiContainer {
|
||||
|
||||
private static final ResourceLocation texture = new ResourceLocation(LibResources.GUI_FLOWER_BAG);
|
||||
|
||||
public GuiFlowerBag(EntityPlayer player) {
|
||||
super(new ContainerFlowerBag(player));
|
||||
public GuiFlowerBag(InventoryPlayer playerInv, InventoryFlowerBag flowerBagInv) {
|
||||
super(new ContainerFlowerBag(playerInv, flowerBagInv));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,183 +10,42 @@
|
||||
*/
|
||||
package vazkii.botania.client.gui.bag;
|
||||
|
||||
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.ItemFlowerBag;
|
||||
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 InventoryFlowerBag implements IItemHandlerModifiable {
|
||||
|
||||
public class InventoryFlowerBag implements IInventory {
|
||||
private final IItemHandlerModifiable bagInv;
|
||||
final ItemStack bag;
|
||||
|
||||
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 InventoryFlowerBag(EntityPlayer player, int slot) {
|
||||
this.player = player;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public static boolean isFlowerBag(ItemStack stack) {
|
||||
return stack != null && stack.getItem() == ModItems.flowerBag;
|
||||
}
|
||||
|
||||
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(isFlowerBag(getStack())) {
|
||||
stacks = ItemFlowerBag.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();
|
||||
ItemFlowerBag.setStacks(stack, inv);
|
||||
}
|
||||
|
||||
invPushed = true;
|
||||
public InventoryFlowerBag(ItemStack bag) {
|
||||
this.bag = bag;
|
||||
this.bagInv = (IItemHandlerModifiable) bag.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 16;
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
bagInv.setStackInSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return getInventory()[i];
|
||||
public int getSlots() {
|
||||
return bagInv.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 bagInv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int i) {
|
||||
return getStackInSlot(i);
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
return bagInv.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
ItemStack[] inventorySlots = getInventory();
|
||||
inventorySlots[i] = itemstack;
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return bagInv.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return isFlowerBag(getStack()) ? 64 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(@Nonnull EntityPlayer entityplayer) {
|
||||
return isFlowerBag(getStack());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, @Nonnull ItemStack itemstack) {
|
||||
return isFlowerBag(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.FLOWER_BAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,14 +10,14 @@
|
||||
*/
|
||||
package vazkii.botania.client.gui.bag;
|
||||
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
|
||||
public class SlotFlower extends Slot {
|
||||
public class SlotFlower extends SlotItemHandler {
|
||||
|
||||
final InventoryFlowerBag inv;
|
||||
private final InventoryFlowerBag inv;
|
||||
final int color;
|
||||
|
||||
public SlotFlower(InventoryFlowerBag p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_, int color) {
|
||||
@@ -26,11 +26,6 @@ public class SlotFlower extends Slot {
|
||||
inv = p_i1824_1_;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChange(ItemStack oldStack, ItemStack newStack) {
|
||||
inv.setInventorySlotContents(color, newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return stack.getItem() == Item.getItemFromBlock(ModBlocks.flower) && stack.getItemDamage() == color;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ItemBaubleBox extends ItemMod {
|
||||
@Nonnull
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
|
||||
player.openGui(Botania.instance, LibGuiIDs.BAUBLE_BOX, world, 0, 0, 0);
|
||||
player.openGui(Botania.instance, LibGuiIDs.BAUBLE_BOX, world, hand == EnumHand.OFF_HAND ? 1 : 0, 0, 0);
|
||||
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ public class ItemCraftingHalo extends ItemMod implements ICraftAchievement {
|
||||
ItemStack itemForPos = getItemForSlot(stack, segment);
|
||||
|
||||
if(segment == 0)
|
||||
player.openGui(Botania.instance, LibGuiIDs.CRAFTING_HALO, world, 0, 0, 0);
|
||||
player.openGui(Botania.instance, LibGuiIDs.CRAFTING_HALO, world, hand == EnumHand.OFF_HAND ? 1 : 0, 0, 0);
|
||||
else {
|
||||
if(itemForPos == null)
|
||||
assignRecipe(stack, itemForPos, segment);
|
||||
|
||||
@@ -10,12 +10,14 @@
|
||||
*/
|
||||
package vazkii.botania.common.item;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
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.network.play.server.SPacketCollectItem;
|
||||
@@ -29,11 +31,17 @@ import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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.Constants;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
@@ -42,6 +50,7 @@ import vazkii.botania.common.lib.LibGuiIDs;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ItemFlowerBag extends ItemMod {
|
||||
|
||||
@@ -54,11 +63,66 @@ public class ItemFlowerBag extends ItemMod {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@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(16) {
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack toInsert, boolean simulate) {
|
||||
if(toInsert != null && toInsert.getItem() == Item.getItemFromBlock(ModBlocks.flower))
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPickupItem(EntityItemPickupEvent event) {
|
||||
ItemStack stack = event.getItem().getEntityItem();
|
||||
if(stack.getItem() == Item.getItemFromBlock(ModBlocks.flower) && stack.stackSize > 0) {
|
||||
int color = stack.getItemDamage();
|
||||
ItemStack entityStack = event.getItem().getEntityItem();
|
||||
if(entityStack.getItem() == Item.getItemFromBlock(ModBlocks.flower) && entityStack.stackSize > 0) {
|
||||
int color = entityStack.getItemDamage();
|
||||
if(color > 15)
|
||||
return;
|
||||
|
||||
@@ -66,40 +130,31 @@ public class ItemFlowerBag extends ItemMod {
|
||||
if(i == event.getEntityPlayer().inventory.currentItem)
|
||||
continue; // prevent item deletion
|
||||
|
||||
ItemStack invStack = event.getEntityPlayer().inventory.getStackInSlot(i);
|
||||
if(invStack != null && invStack.getItem() == this) {
|
||||
ItemStack[] bagInv = loadStacks(invStack);
|
||||
ItemStack stackAt = bagInv[color];
|
||||
boolean didChange = false;
|
||||
if(stackAt == null) {
|
||||
bagInv[color] = stack.copy();
|
||||
stack.stackSize = 0;
|
||||
didChange = true;
|
||||
} else {
|
||||
int stackAtSize = stackAt.stackSize;
|
||||
int stackSize = stack.stackSize;
|
||||
int spare = 64 - stackAtSize;
|
||||
int pass = Math.min(spare, stackSize);
|
||||
if(pass > 0) {
|
||||
stackAt.stackSize += pass;
|
||||
stack.stackSize -= pass;
|
||||
didChange = true;
|
||||
}
|
||||
ItemStack bag = event.getEntityPlayer().inventory.getStackInSlot(i);
|
||||
if(bag != null && bag.getItem() == this) {
|
||||
event.setCanceled(true);
|
||||
|
||||
IItemHandler bagInv = bag.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
|
||||
ItemStack result = bagInv.insertItem(color, entityStack, false);
|
||||
|
||||
if(result == null)
|
||||
event.getItem().setDead();
|
||||
else {
|
||||
event.getItem().setEntityItemStack(result);
|
||||
event.getItem().setDefaultPickupDelay();
|
||||
}
|
||||
|
||||
if(didChange) {
|
||||
setStacks(invStack, bagInv);
|
||||
if(result != entityStack) {
|
||||
if (!event.getItem().isSilent()) {
|
||||
event.getItem().worldObj.playSound(null, event.getEntityPlayer().posX, event.getEntityPlayer().posY, event.getEntityPlayer().posZ,
|
||||
SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F,
|
||||
((event.getItem().worldObj.rand.nextFloat() - event.getItem().worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
|
||||
}
|
||||
((EntityPlayerMP) event.getEntityPlayer()).connection.sendPacket(new SPacketCollectItem(event.getItem().getEntityId(), event.getEntityPlayer().getEntityId()));
|
||||
event.getEntityPlayer().openContainer.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
|
||||
if(stack.stackSize == 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,7 +162,7 @@ public class ItemFlowerBag extends ItemMod {
|
||||
@Nonnull
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
|
||||
player.openGui(Botania.instance, LibGuiIDs.FLOWER_BAG, world, 0, 0, 0);
|
||||
player.openGui(Botania.instance, LibGuiIDs.FLOWER_BAG, world, hand == EnumHand.OFF_HAND ? 1 : 0, 0, 0);
|
||||
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
|
||||
}
|
||||
|
||||
@@ -117,35 +172,20 @@ public class ItemFlowerBag extends ItemMod {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile != null) {
|
||||
if(!world.isRemote) {
|
||||
IItemHandler inv = null;
|
||||
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
|
||||
inv = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
IItemHandler tileInv = null;
|
||||
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
|
||||
tileInv = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
|
||||
else if(tile instanceof IInventory)
|
||||
inv = new InvWrapper(((IInventory) tile));
|
||||
tileInv = new InvWrapper(((IInventory) tile));
|
||||
|
||||
if(inv == null)
|
||||
return EnumActionResult.SUCCESS;
|
||||
if(tileInv == null)
|
||||
return EnumActionResult.FAIL;
|
||||
|
||||
ItemStack[] stacks = loadStacks(stack);
|
||||
ItemStack[] newStacks = new ItemStack[stacks.length];
|
||||
boolean putAny = false;
|
||||
IItemHandlerModifiable bagInv = (IItemHandlerModifiable) stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
|
||||
int i = 0;
|
||||
for(ItemStack petal : stacks) {
|
||||
if(petal != null) {
|
||||
newStacks[i] = ItemHandlerHelper.insertItemStacked(inv, petal, false);
|
||||
int count = petal.stackSize;
|
||||
if(newStacks[i] != null)
|
||||
count = petal.stackSize - newStacks[i].stackSize;
|
||||
putAny |= count > 0;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
setStacks(stack, newStacks);
|
||||
if(putAny && tile instanceof TileEntityChest) {
|
||||
player.displayGUIChest(((TileEntityChest) tile));
|
||||
for(int i = 0; i < bagInv.getSlots(); i++) {
|
||||
ItemStack flower = bagInv.getStackInSlot(i);
|
||||
bagInv.setStackInSlot(i, ItemHandlerHelper.insertItemStacked(tileInv, flower, false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,30 +194,4 @@ public class ItemFlowerBag extends ItemMod {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
public static ItemStack[] loadStacks(ItemStack stack) {
|
||||
NBTTagList var2 = ItemNBTHelper.getList(stack, TAG_ITEMS, 10, false);
|
||||
ItemStack[] inventorySlots = new ItemStack[16];
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,10 +11,12 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import vazkii.botania.client.gui.bag.ContainerFlowerBag;
|
||||
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.crafting.ContainerCraftingHalo;
|
||||
@@ -25,12 +27,14 @@ import vazkii.botania.common.lib.LibGuiIDs;
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int handId, int unused1, int unused2) {
|
||||
EnumHand hand = handId == 1 ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
|
||||
|
||||
switch(ID) {
|
||||
case LibGuiIDs.CRAFTING_HALO :
|
||||
return new ContainerCraftingHalo(player.inventory, world);
|
||||
case LibGuiIDs.FLOWER_BAG :
|
||||
return new ContainerFlowerBag(player);
|
||||
return new ContainerFlowerBag(player.inventory, new InventoryFlowerBag(player.getHeldItem(hand)));
|
||||
case LibGuiIDs.BAUBLE_BOX :
|
||||
return new ContainerBaubleBox(player);
|
||||
}
|
||||
@@ -39,14 +43,16 @@ public class GuiHandler implements IGuiHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int handId, int unused1, int unused2) {
|
||||
EnumHand hand = handId == 1 ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
|
||||
|
||||
switch(ID) {
|
||||
case LibGuiIDs.LEXICON :
|
||||
return GuiLexicon.currentOpenLexicon;
|
||||
case LibGuiIDs.CRAFTING_HALO :
|
||||
return new GuiCraftingHalo(player.inventory, world);
|
||||
case LibGuiIDs.FLOWER_BAG :
|
||||
return new GuiFlowerBag(player);
|
||||
return new GuiFlowerBag(player.inventory, new InventoryFlowerBag(player.getHeldItem(hand)));
|
||||
case LibGuiIDs.BAUBLE_BOX :
|
||||
return new GuiBaubleBox(player);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user