/** * This gets called every tick, please be careful with your checks. */ public boolean matches(World world, BlockPos pos, SubTileEntity pureDaisy, IBlockState state) { if(input instanceof Block) return state.getBlock() == input; if(input instanceof IBlockState) return state == input; ItemStack stack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); String oredict = (String) input; return isOreDict(stack, oredict); }
@Override public String getBlockName(World world, RayTraceResult pos, EntityPlayer player) { BlockPos bPos = pos.getBlockPos(); IBlockState state = world.getBlockState(bPos); ItemStack stack = state.getBlock().getPickBlock(state, pos, world, bPos, player); if(stack.isEmpty()) stack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); if(stack.isEmpty()) return null; String name = stack.getDisplayName(); if(name == null || name.isEmpty()) return null; return name; }
/** * Uses the hooks from Block.getPickBlock() to check if the first and * second blocks give different metadata. * @param first BlockID of the first block. * @param second BlockID of the secound block. * @return If pick block on both blocks are the same. */ public static boolean arePickBlockEqual(BlockID first, BlockID second) { if(first == null || second == null) { return false; } int firstResultMeta = first.state.getBlock().damageDropped(first.state); int secondResultMeta = second.state.getBlock().damageDropped(second.state); return first.name.equals(second.name) && firstResultMeta == secondResultMeta; }
default Iterable<ItemStack> getDropsFromFall(World world, BlockPos pos, IBlockState state, @Nullable NBTTagCompound teData, int fallTime, float fallDistance) { return ImmutableList.of(new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state))); }
@Override public ItemStack getStack() { return new ItemStack(item, 1, state.getBlock().damageDropped(state)); }
/** * Creates an ItemStack representation of an IBlockState. * * @param state The state to use. * @param size The stack size to create. * @return An ItemStack which represents the passed state. */ @Deprecated public static ItemStack getStackFromState (IBlockState state, int size) { return new ItemStack(state.getBlock(), size, state.getBlock().damageDropped(state)); }
@Override public ItemStack getStack() { return new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); } }
public static ItemStack stateToDroppedStack(IBlockState state, int stackSize) { return new ItemStack(state.getBlock(), stackSize, state.getBlock().damageDropped(state)); } }
public void addItemBlockState(IBlockState state, @Nonnull ItemStack stack) { if (state != null) { if (Prep.isInvalid(stack)) { stack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); } addItemModel(stack); } }
public void addItemBlockStates(List<Pair<IBlockState, ItemStack>> states, @Nonnull ItemStack parent, Block parentBlock) { if (states == null || states.isEmpty()) { return; } for (Pair<IBlockState, ItemStack> pair : states) { IBlockState state = pair.getLeft(); if (state != null) { ItemStack stack = pair.getRight(); if (stack == null || Prep.isInvalid(stack)) { if (state.getBlock() == parentBlock) { stack = parent; } else { stack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); } } addItemModel(NullHelper.notnullJ(stack, "If you see this, the world will be ending yesterday half past yellow!")); } } }
@Override protected ItemStack getStack() { return new ItemStack(Item.getItemFromBlock(state.getBlock()), 1, state.getBlock().damageDropped(state)); }
public static ItemStack getSilkTouchDrop(IBlockState state) { Item item = Item.getItemFromBlock(state.getBlock()); int i = 0; if (item.getHasSubtypes()) { i = state.getBlock().damageDropped(state); } return new ItemStack(item, 1, i); }
@Override public String getLocalizedName() { return item != null ? item.getItemStackDisplayName(new ItemStack(item, 1, state.getBlock().damageDropped(state))) : state.getBlock().getLocalizedName(); }
public void addBlockStates(List<Pair<IBlockState, ItemStack>> states, @Nonnull ItemStack parent, Block parentBlock) { if (states == null || states.isEmpty()) { return; } BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes(); for (Pair<IBlockState, ItemStack> pair : states) { IBlockState state = pair.getLeft(); if (state != null) { ItemStack stack = pair.getRight(); if (stack == null || Prep.isInvalid(stack)) { if (state.getBlock() == parentBlock) { stack = parent; } else { stack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); } } IBakedModel model = modelShapes.getModelForState(state); addBakedModel(model, NullHelper.notnullJ(stack, "If you see this, the world will be ending yesterday half past yellow!")); } } }
public void addBlockState(IBlockState state, @Nonnull ItemStack stack, boolean allFacesToGeneral) { if (state != null) { if (Prep.isInvalid(stack)) { stack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); } BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes(); IBakedModel model = modelShapes.getModelForState(state); addBakedModel(model, stack, allFacesToGeneral); } }
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing face, float hitX, float hitY, float hitZ){ if(player.isSneaking()){ IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); ItemStack blockStack = new ItemStack(block, 1, block.damageDropped(state)); IBookletPage page = BookletUtils.findFirstPageForStack(blockStack); if(page != null){ if(world.isRemote){ forcedPage = page; } this.onItemRightClick(world, player, hand); return EnumActionResult.SUCCESS; } } return EnumActionResult.FAIL; }
protected void findBlockDataForDirection(EnumFacing direction) { World world = cb.getBundleworld(); BlockPos blockPos = cb.getLocation().offset(direction); if (!world.isAirBlock(blockPos)) { IBlockState bs = world.getBlockState(blockPos); Block b = bs.getBlock(); if (b != null && b != ConduitRegistry.getConduitModObjectNN().getBlock()) { try {// TODO: This seems wrong. pickBlock? Item item = b.getItemDropped(bs.getActualState(world, blockPos), world.rand, 0); if (item != null) { stacks.put(direction, new ItemStack(item, 1, b.damageDropped(bs))); } } catch (Throwable t) { } } } }
private void dropBlock() { final Block block = blockState.getBlock(); Random rand = world.rand; final int count = block.quantityDropped(blockState, 0, rand); for (int i = 0; i < count; i++) { final Item item = block.getItemDropped(blockState, rand, 0); if (item != null) { ItemStack toDrop = new ItemStack(item, 1, block.damageDropped(blockState)); entityDropItem(toDrop, 0.1f); } } if (tileEntity instanceof IInventory) { IInventory inv = (IInventory)tileEntity; for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack is = inv.getStackInSlot(i); if (is != null) entityDropItem(is, 0.1f); } } }
private static boolean removeFittingItem(IBlockState state, EntityPlayer player) { Block block = state.getBlock(); ItemStack stack = new ItemStack(block, 1, block.damageDropped(state)); if (StackUtil.isValid(stack)) { for (int i = 0; i < player.inventory.getSizeInventory(); i++) { ItemStack slot = player.inventory.getStackInSlot(i); if (StackUtil.isValid(slot) && slot.isItemEqual(stack)) { slot.shrink(1); if (!StackUtil.isValid(slot)) { player.inventory.setInventorySlotContents(i, StackUtil.getEmpty()); } return true; } } } return false; }
private boolean consumeFallingBlock(EntityFallingBlock fallingBlock) { ItemStack itemStack = new ItemStack(fallingBlock.getBlock().getBlock(), 1, fallingBlock.getBlock().getBlock().damageDropped(fallingBlock.getBlock())); if (!itemStack.isEmpty()) { try { mass = Math.addExact(mass, (long) MatterHelper.getMatterAmountFromItem(itemStack) * (long) itemStack.getCount()); markDirty(); } catch (ArithmeticException e) { return false; } fallingBlock.setDead(); world.removeEntity(fallingBlock); return true; } return false; }