mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 10:55:17 +00:00
Fix flower bag gui
This commit is contained in:
1 parent
65f6148dcf
commit
eb0c2e6521
4 files changed
+21
-110
No files matched your search
@@ -19,6 +19,8 @@ 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 net.minecraftforge.registries.ObjectHolder;
|
||||
import vazkii.botania.client.gui.SlotLocked;
|
||||
@@ -36,14 +38,15 @@ public class ContainerFlowerBag extends Container {
|
||||
return new ContainerFlowerBag(windowId, inv, inv.player.getHeldItem(hand));
|
||||
}
|
||||
|
||||
private final InventoryFlowerBag flowerBagInv;
|
||||
private final ItemStack bag;
|
||||
|
||||
public ContainerFlowerBag(int windowId, PlayerInventory playerInv, ItemStack bag) {
|
||||
super(TYPE, windowId);
|
||||
int i;
|
||||
int j;
|
||||
|
||||
this.flowerBagInv = new InventoryFlowerBag(bag);
|
||||
this.bag = bag;
|
||||
IItemHandlerModifiable flowerBagInv = (IItemHandlerModifiable) bag.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
|
||||
|
||||
for(i = 0; i < 2; ++i)
|
||||
for(j = 0; j < 8; ++j) {
|
||||
@@ -56,17 +59,15 @@ public class ContainerFlowerBag extends Container {
|
||||
addSlot(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
|
||||
for(i = 0; i < 9; ++i) {
|
||||
if(playerInv.getStackInSlot(i) == flowerBagInv.bag)
|
||||
addSlot(new SlotLocked(playerInv, i, 8 + i * 18, 142));
|
||||
else addSlot(new Slot(playerInv, i, 8 + i * 18, 142));
|
||||
addSlot(new Slot(playerInv, i, 8 + i * 18, 142));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(@Nonnull PlayerEntity player) {
|
||||
return player.getHeldItemMainhand() == flowerBagInv.bag
|
||||
|| player.getHeldItemOffhand() == flowerBagInv.bag;
|
||||
return player.getHeldItemMainhand() == bag
|
||||
|| player.getHeldItemOffhand() == bag;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -58,18 +58,15 @@ public class GuiFlowerBag extends ContainerScreen<ContainerFlowerBag> {
|
||||
blit(k, l, 0, 0, xSize, ySize);
|
||||
|
||||
for(Slot slot : container.inventorySlots)
|
||||
if(slot instanceof SlotItemHandler) {
|
||||
SlotItemHandler slotf = (SlotItemHandler) slot;
|
||||
if(!slotf.getHasStack()) {
|
||||
DyeColor color = DyeColor.byId(slotf.getSlotIndex());
|
||||
ItemStack stack = new ItemStack(ModBlocks.getFlower(color));
|
||||
int x = guiLeft + slotf.xPos;
|
||||
int y = guiTop + slotf.yPos;
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
mc.getItemRenderer().renderItemIntoGUI(stack, x, y);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
mc.fontRenderer.drawStringWithShadow("0", x + 11, y + 9, 0xFF6666);
|
||||
}
|
||||
if(slot instanceof SlotItemHandler && !slot.getHasStack()) {
|
||||
DyeColor color = DyeColor.byId(slot.getSlotIndex());
|
||||
ItemStack stack = new ItemStack(ModBlocks.getFlower(color));
|
||||
int x = guiLeft + slot.xPos;
|
||||
int y = guiTop + slot.yPos;
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
mc.getItemRenderer().renderItemIntoGUI(stack, x, y);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
mc.fontRenderer.drawStringWithShadow("0", x + 11, y + 9, 0xFF6666);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,66 +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 @ [Mar 16, 2015, 6:42:56 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.client.gui.bag;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class InventoryFlowerBag implements IItemHandlerModifiable {
|
||||
|
||||
private final IItemHandlerModifiable bagInv;
|
||||
final ItemStack bag;
|
||||
|
||||
public InventoryFlowerBag(ItemStack bag) {
|
||||
this.bag = bag;
|
||||
bagInv = (IItemHandlerModifiable) bag.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
|
||||
bagInv.setStackInSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return bagInv.getSlots();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return bagInv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
return bagInv.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return bagInv.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return bagInv.getSlotLimit(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
|
||||
return bagInv.isItemValid(slot, stack);
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,10 @@ package vazkii.botania.common.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -30,7 +29,6 @@ import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
@@ -132,7 +130,9 @@ public class ItemFlowerBag extends ItemMod {
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, @Nonnull Hand hand) {
|
||||
if(!world.isRemote) {
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, new ContainerProvider(player.getHeldItem(hand)), buf -> {
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
INamedContainerProvider container = new SimpleNamedContainerProvider((w, p, pl) -> new ContainerFlowerBag(w, p, stack), stack.getDisplayName());
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, container, buf -> {
|
||||
buf.writeBoolean(hand == Hand.MAIN_HAND);
|
||||
});
|
||||
}
|
||||
@@ -169,25 +169,4 @@ public class ItemFlowerBag extends ItemMod {
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
|
||||
private static class ContainerProvider implements INamedContainerProvider {
|
||||
private final ItemStack stack;
|
||||
|
||||
private ContainerProvider(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int windowId, PlayerInventory playerInv, PlayerEntity player) {
|
||||
return new ContainerFlowerBag(windowId, playerInv, stack);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user