Java Code Examples for net.minecraft.item.ItemStack#equals()
The following examples show how to use
net.minecraft.item.ItemStack#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockOben.java From Sakura_mod with MIT License | 5 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) return true; ItemStack stack = playerIn.getHeldItem(hand); TileEntity tile = worldIn.getTileEntity(pos); if (hand == EnumHand.MAIN_HAND) { if (tile instanceof TileEntityOben) { TileEntityOben tileEntity = (TileEntityOben) tile; if(!(tileEntity.getInventory().getStackInSlot(0)).isEmpty()&&!(stack.equals(tileEntity.getInventory().getStackInSlot(0)))){ Block.spawnAsEntity(worldIn, pos, tileEntity.getInventory().getStackInSlot(0)); tileEntity.getInventory().setStackInSlot(0, ItemStack.EMPTY); tileEntity.markDirty(); return true; } ItemStack campfireStack=stack.copy(); campfireStack.setCount(1); stack.shrink(1); tileEntity.getInventory().insertItem(0,campfireStack,false); tileEntity.markDirty(); return true; } } return true; }
Example 2
Source File: BookBot.java From ForgeHax with MIT License | 4 votes |
@Override public void run() { try { while (!stopped) { // check to see if we've finished the book if (!parser.hasNext()) { this.status = Status.FINISHED; break; } sleep(); // wait for screen if (MC.currentScreen != null) { this.status = Status.AWAITING_GUI_CLOSE; continue; } // search for empty book int slot = -1; ItemStack selected = null; for (int i = 0; i < InventoryPlayer.getHotbarSize(); i++) { ItemStack stack = getLocalPlayer().inventory.getStackInSlot(i); if (stack != null && !stack.equals(ItemStack.EMPTY) && stack.getItem() instanceof ItemWritableBook) { slot = i; selected = stack; break; } } // make sure we found a book if (slot == -1) { this.status = Status.NEED_EMPTY_BOOKS_IN_HOTBAR; continue; } // set selected item to that slot while (getLocalPlayer().inventory.currentItem != slot) { getLocalPlayer().inventory.currentItem = slot; this.status = Status.CHANGING_HELD_ITEM; sleep(); } final ItemStack item = selected; // open the book gui screen this.status = Status.OPENING_BOOK; MC.addScheduledTask(() -> getLocalPlayer().openBook(item, EnumHand.MAIN_HAND)); // wait for gui to open while (!(MC.currentScreen instanceof GuiScreenBook)) { sleep(); } // send book to server this.status = Status.WRITING_BOOK; MC.addScheduledTask( () -> { sendBook(item); MC.displayGuiScreen(null); }); // wait for screen to close while (MC.currentScreen != null) { sleep(); } } } catch (Throwable t) { this.status = Status.ERROR; } finally { if (finalListener != null) { finalListener.accept(this); finalListener = null; } // set stopped to true this.stopped = true; if (!this.status.equals(Status.FINISHED) && !this.status.equals(Status.ERROR)) { this.status = Status.STOPPED; } } }
Example 3
Source File: IForgeItem.java From patchwork-api with GNU Lesser General Public License v2.1 | 2 votes |
/** * Determine if the player switching between these two item stacks. * * @param oldStack The old stack that was equipped * @param newStack The new stack * @param slotChanged If the current equipped slot was changed, Vanilla does not * play the animation if you switch between two slots that * hold the exact same item. * @return True to play the item change animation */ default boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { return !oldStack.equals(newStack); }
Example 4
Source File: IForgeItem.java From patchwork-api with GNU Lesser General Public License v2.1 | 2 votes |
/** * Called while an item is in 'active' use to determine if usage should * continue. Allows items to continue being used while sustaining damage, for * example. * * @param oldStack the previous 'active' stack * @param newStack the stack currently in the active hand * @return true to set the new stack to active and continue using it */ default boolean canContinueUsing(ItemStack oldStack, ItemStack newStack) { return oldStack.equals(newStack); }