Search in sources :

Example 1 with IAgriJournalItem

use of com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem in project AgriCraft by AgriCraft.

the class ItemToolTipHandler method addJournalTooltip.

/**
 * Adds tooltips to items that are journals (implementing ITrowel).
 */
@SubscribeEvent
@SuppressWarnings("unused")
public void addJournalTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.getItemStack();
    if (!stack.isEmpty() && stack.getItem() instanceof IAgriJournalItem) {
        IAgriJournalItem journal = (IAgriJournalItem) stack.getItem();
        int count = journal.getDiscoveredSeeds(stack).size();
        event.getToolTip().add(new StringTextComponent("" + count + " ").appendSibling(AgriToolTips.JOURNAL_SEEDS));
        event.getToolTip().add(AgriToolTips.JOURNAL_USE_1);
        event.getToolTip().add(AgriToolTips.JOURNAL_USE_2);
    }
}
Also used : StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) IAgriJournalItem(com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with IAgriJournalItem

use of com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem in project AgriCraft by AgriCraft.

the class SeedAnalyzerContainer method transferStackInSlot.

@Nonnull
@Override
public ItemStack transferStackInSlot(@Nonnull PlayerEntity playerIn, int index) {
    ItemStack itemStack = ItemStack.EMPTY;
    Slot slot = this.inventorySlots.get(index);
    if (slot != null && slot.getHasStack()) {
        ItemStack slotStack = slot.getStack();
        itemStack = slotStack.copy();
        if (index <= 1) {
            // shift-click in seed/journal slot
            if (!this.mergeItemStack(slotStack, 2, 38, true)) {
                return ItemStack.EMPTY;
            }
        } else if (index <= 38) {
            // shift-click in inventory slots
            if (slotStack.getItem() instanceof IAgriSeedItem) {
                if (!this.mergeItemStack(slotStack, 0, 1, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (slotStack.getItem() instanceof IAgriJournalItem) {
                if (!this.mergeItemStack(slotStack, 1, 2, false)) {
                    return ItemStack.EMPTY;
                }
            }
        }
        if (slotStack.isEmpty()) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }
        if (slotStack.getCount() == itemStack.getCount()) {
            return ItemStack.EMPTY;
        }
        slot.onTake(playerIn, slotStack);
    }
    return itemStack;
}
Also used : Slot(net.minecraft.inventory.container.Slot) ItemStack(net.minecraft.item.ItemStack) IAgriSeedItem(com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem) IAgriJournalItem(com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem) Nonnull(javax.annotation.Nonnull)

Example 3 with IAgriJournalItem

use of com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem in project AgriCraft by AgriCraft.

the class MessageFlipJournalPage method processMessage.

@Override
protected void processMessage(NetworkEvent.Context ctx) {
    if (ctx.getSender() == null) {
        return;
    }
    ItemStack journalStack = ctx.getSender().getHeldItem(this.getHand());
    if (journalStack.getItem() instanceof IAgriJournalItem) {
        IAgriJournalItem journalItem = (IAgriJournalItem) journalStack.getItem();
        int currentPage = journalItem.getCurrentPageIndex(journalStack);
        journalItem.setCurrentPageIndex(journalStack, this.getPage());
        int newPage = journalItem.getCurrentPageIndex(journalStack);
        if (newPage != currentPage) {
            journalItem.getPages(journalStack).get(newPage).onPageOpened(ctx.getSender(), journalStack, journalItem);
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) IAgriJournalItem(com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem)

Example 4 with IAgriJournalItem

use of com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem in project AgriCraft by AgriCraft.

the class BlockSeedAnalyzer method onBlockActivated.

@Override
@Deprecated
@SuppressWarnings("deprecation")
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
    if (hand == Hand.OFF_HAND) {
        return ActionResultType.FAIL;
    }
    TileEntity tile = world.getTileEntity(pos);
    if (!(tile instanceof TileEntitySeedAnalyzer)) {
        return ActionResultType.FAIL;
    }
    TileEntitySeedAnalyzer analyzer = (TileEntitySeedAnalyzer) tile;
    ItemStack heldItem = player.getHeldItem(hand);
    // debugging
    if (heldItem.getItem() instanceof ItemDebugger) {
        return ActionResultType.PASS;
    }
    // Player is sneaking: insertion / extraction logic
    if (player.isSneaking()) {
        // No sneak-action on the client
        if (world.isRemote()) {
            return ActionResultType.PASS;
        }
        // Try extracting the seed
        if (analyzer.hasSeed()) {
            this.extractSeed(analyzer, player);
            return ActionResultType.CONSUME;
        }
        // Try inserting a seed
        if (heldItem.getItem() instanceof IAgriSeedItem) {
            player.getHeldItem(hand).setCount(analyzer.insertSeed(heldItem).getCount());
            return ActionResultType.CONSUME;
        }
        // Try extracting the journal
        if (analyzer.hasJournal()) {
            // Only allow extraction of journal with empty hand
            if (heldItem.isEmpty()) {
                this.extractJournal(analyzer, player);
                return ActionResultType.CONSUME;
            }
            return ActionResultType.FAIL;
        }
        // Try inserting a journal
        if (heldItem.getItem() instanceof IAgriJournalItem) {
            if (analyzer.insertJournal(heldItem).isEmpty()) {
                heldItem.shrink(1);
            }
            return ActionResultType.CONSUME;
        }
        return ActionResultType.FAIL;
    } else {
        // On the client, inspect the genome
        if (world.isRemote()) {
            if (!analyzer.isObserved()) {
                if (this.isViewBlocked(world, pos, ORIENTATION.fetch(state))) {
                    player.sendMessage(AgriToolTips.MSG_ANALYZER_VIEW_BLOCKED, Util.DUMMY_UUID);
                } else {
                    analyzer.setObserving(true);
                }
            }
        }
        return ActionResultType.CONSUME;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack) IAgriSeedItem(com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem) IAgriJournalItem(com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem)

Example 5 with IAgriJournalItem

use of com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem in project AgriCraft by AgriCraft.

the class TileEntitySeedAnalyzer method addSeedToJournal.

public static Optional<ItemStack> addSeedToJournal(ItemStack seed, ItemStack journal) {
    // Check if the items are a seed and a journal respectively
    if (!seed.isEmpty() && !journal.isEmpty() && seed.getItem() instanceof IAgriGeneCarrierItem && journal.getItem() instanceof IAgriJournalItem) {
        // Fetch plant from seed
        IAgriJournalItem journalItem = (IAgriJournalItem) journal.getItem();
        IAgriPlant plant = ((IAgriGeneCarrierItem) seed.getItem()).getPlant(seed);
        // If the plant is not yet discovered, add it to the journal
        if (!journalItem.isPlantDiscovered(journal, plant)) {
            ItemStack newJournal = journal.copy();
            journalItem.addEntry(newJournal, plant);
            return Optional.of(newJournal);
        }
    }
    return Optional.empty();
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriJournalItem(com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IAgriJournalItem (com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem)6 ItemStack (net.minecraft.item.ItemStack)6 IAgriSeedItem (com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem)2 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)2 Nonnull (javax.annotation.Nonnull)1 Slot (net.minecraft.inventory.container.Slot)1 TileEntity (net.minecraft.tileentity.TileEntity)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1