Search in sources :

Example 1 with ItemSeedBag

use of com.infinityraider.agricraft.content.tools.ItemSeedBag in project AgriCraft by AgriCraft.

the class ItemToolTipHandler method addSeedBagTooltip.

/**
 * Adds tooltips to the seed bag (we must do this here to avoid the enchantment tool tip)
 */
@SubscribeEvent
@SuppressWarnings("unused")
public void addSeedBagTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.getItemStack();
    if (stack.getItem() instanceof ItemSeedBag) {
        ItemSeedBag bag = (ItemSeedBag) stack.getItem();
        ItemSeedBag.Contents contents = bag.getContents(stack);
        if (bag.isActivated(stack)) {
            // Remove previous tooltip
            if (event.getToolTip().size() > 0) {
                ITextComponent name = event.getToolTip().get(0);
                event.getToolTip().clear();
                event.getToolTip().add(name);
            }
            // Description
            event.getToolTip().add(AgriToolTips.SEED_BAG_ACTIVE);
            event.getToolTip().add(AgriToolTips.EMPTY_LINE);
            // Contents
            if (contents.getPlant().isPlant()) {
                event.getToolTip().add(new StringTextComponent("").appendSibling(AgriToolTips.SEED_BAG_CONTENTS).appendSibling(new StringTextComponent(" " + contents.getCount() + " ")).appendSibling(contents.getPlant().getSeedName()));
            } else {
                event.getToolTip().add(AgriToolTips.SEED_BAG_EMPTY);
            }
            // Sorter
            event.getToolTip().add(new StringTextComponent("").appendSibling(AgriToolTips.SEED_BAG_SORTER).appendSibling(new StringTextComponent(" ")).appendSibling(contents.getSorter().getName()));
            event.getToolTip().add(AgriToolTips.EMPTY_LINE);
            // Usage
            if (ModuleKeyboard.getInstance().isKeyPressed(Minecraft.getInstance().gameSettings.keyBindSneak)) {
                event.getToolTip().add(new StringTextComponent("").mergeStyle(TextFormatting.DARK_GRAY).appendSibling(AgriToolTips.SEED_BAG_MAIN_HAND));
                event.getToolTip().add(new StringTextComponent("").mergeStyle(TextFormatting.DARK_GRAY).appendSibling(AgriToolTips.SEED_BAG_OFF_HAND));
                event.getToolTip().add(new StringTextComponent("").mergeStyle(TextFormatting.DARK_GRAY).appendSibling(AgriToolTips.SEED_BAG_SCROLLING));
            } else {
                event.getToolTip().add(new StringTextComponent("").mergeStyle(TextFormatting.DARK_GRAY).appendSibling(AgriToolTips.SNEAK_INFO));
            }
        } else {
            event.getToolTip().add(AgriToolTips.SEED_BAG_INACTIVE_1);
            event.getToolTip().add(AgriToolTips.SEED_BAG_INACTIVE_2);
        }
    }
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) ItemSeedBag(com.infinityraider.agricraft.content.tools.ItemSeedBag) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with ItemSeedBag

use of com.infinityraider.agricraft.content.tools.ItemSeedBag in project AgriCraft by AgriCraft.

the class SeedBagScrollHandler method tryCycleSortMode.

public boolean tryCycleSortMode(Hand hand, int delta) {
    ItemStack stack = this.getPlayer().getHeldItem(hand);
    if (stack.getItem() instanceof ItemSeedBag) {
        ItemSeedBag bag = (ItemSeedBag) stack.getItem();
        if (bag.incrementSorter(stack, delta)) {
            new MessageSyncSeedBagSortMode(hand, bag.getContents(stack).getSorterIndex()).sendToServer();
            SeedBagShakeHandler.getInstance().shake(hand);
            ItemSeedBag.Contents contents = bag.getContents(stack);
            IFormattableTextComponent message = new StringTextComponent("").appendSibling(contents.getSorter().describe()).appendSibling(new StringTextComponent(", ")).appendSibling(AgriToolTips.MSG_SEED_BAG_SHAKE);
            if (contents.getCount() <= 0) {
                message.appendSibling(new StringTextComponent(" ")).appendSibling(AgriToolTips.MSG_SEED_BAG_EMPTY);
            }
            AgriCraft.instance.getClientPlayer().sendMessage(message, Util.DUMMY_UUID);
            return true;
        }
    }
    return false;
}
Also used : MessageSyncSeedBagSortMode(com.infinityraider.agricraft.network.MessageSyncSeedBagSortMode) StringTextComponent(net.minecraft.util.text.StringTextComponent) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) ItemStack(net.minecraft.item.ItemStack) ItemSeedBag(com.infinityraider.agricraft.content.tools.ItemSeedBag)

Aggregations

ItemSeedBag (com.infinityraider.agricraft.content.tools.ItemSeedBag)2 ItemStack (net.minecraft.item.ItemStack)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 MessageSyncSeedBagSortMode (com.infinityraider.agricraft.network.MessageSyncSeedBagSortMode)1 IFormattableTextComponent (net.minecraft.util.text.IFormattableTextComponent)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1