Search in sources :

Example 1 with IQuiver

use of net.silentchaos512.gems.item.quiver.IQuiver in project SilentGems by SilentChaos512.

the class ContainerQuiver method canTake.

public boolean canTake(int slotId, Slot slot, int button, EntityPlayer player, ClickType clickType) {
    if (slotId == blocked)
        return false;
    if (slotId <= ItemQuiver.MAX_STACKS - 1) {
        if (player.inventory.getItemStack().getItem() instanceof IQuiver)
            return false;
    }
    // Hotbar swapping via number keys
    if (clickType == ClickType.SWAP) {
        int hotbarId = ItemQuiver.MAX_STACKS + 27 + button;
        // Block swapping with quiver
        if (blocked == hotbarId)
            return false;
        Slot hotbarSlot = getSlot(hotbarId);
        if (slotId <= ItemQuiver.MAX_STACKS - 1) {
            if (slot.getStack().getItem() instanceof IQuiver || hotbarSlot.getStack().getItem() instanceof IQuiver)
                return false;
        }
    }
    return true;
}
Also used : IQuiver(net.silentchaos512.gems.item.quiver.IQuiver) Slot(net.minecraft.inventory.Slot)

Example 2 with IQuiver

use of net.silentchaos512.gems.item.quiver.IQuiver in project SilentGems by SilentChaos512.

the class GuiQuiverArrowOverlay method onRenderGameOverlay.

@SubscribeEvent
public void onRenderGameOverlay(RenderGameOverlayEvent event) {
    if (!GemsConfig.SHOW_ARROW_COUNT || event.getType() != ElementType.HOTBAR) {
        return;
    }
    // Player holding a bow?
    EntityPlayer player = SilentGems.proxy.getClientPlayer();
    ItemStack bow = getActiveBow(player);
    if (StackHelper.isValid(bow)) {
        // Get the "arrow" the bow would fire.
        ItemStack arrow = StackHelper.empty();
        int arrowCount = 0;
        ItemStack stack = findAmmo(player);
        if (StackHelper.isValid(stack)) {
            // Is it a quiver?
            if (stack.getItem() instanceof IQuiver) {
                // Find first arrow.
                IItemHandler itemHandler = ((IQuiver) stack.getItem()).getInventory(stack);
                for (int i = 0; i < itemHandler.getSlots(); ++i) {
                    ItemStack itemstack = itemHandler.getStackInSlot(i);
                    if (StackHelper.isValid(itemstack) && itemstack.getItem() instanceof ItemArrow) {
                        if (StackHelper.isEmpty(arrow)) {
                            arrow = itemstack;
                            arrowCount = arrow.getCount();
                        } else if (arrow.isItemEqual(itemstack) && ((!arrow.hasTagCompound() && !itemstack.hasTagCompound()) || itemstack.getTagCompound().equals(arrow.getTagCompound()))) {
                            arrowCount += itemstack.getCount();
                        }
                    }
                }
            } else {
                // It's just an arrow.
                arrow = stack;
                arrowCount = arrow.getCount();
            }
        }
        if (StackHelper.isValid(arrow)) {
            renderArrow(arrow, arrowCount, player);
        }
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IQuiver(net.silentchaos512.gems.item.quiver.IQuiver) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IQuiver (net.silentchaos512.gems.item.quiver.IQuiver)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Slot (net.minecraft.inventory.Slot)1 ItemArrow (net.minecraft.item.ItemArrow)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 IItemHandler (net.minecraftforge.items.IItemHandler)1