protected boolean shouldDoWorkThisTick(@Nonnull World world, @Nonnull BlockPos pos, int interval) { T te = getTileEntity(world, pos); if (te == null) { return world.getTotalWorldTime() % interval == 0; } else { return te.shouldDoWorkThisTick(interval); } }
/** * Tries to load this block's TileEntity if it exists. Will not create the TileEntity when used in a render thread with the correct IBlockAccess. * */ protected @Nullable T getTileEntitySafe(@Nonnull IBlockAccess world, @Nonnull BlockPos pos) { if (world instanceof ChunkCache) { final Class<? extends T> teClass2 = teClass; if (teClass2 != null) { TileEntity te = ((ChunkCache) world).getTileEntity(pos, EnumCreateEntityType.CHECK); if (teClass2.isInstance(te)) { return teClass2.cast(te); } } return null; } else { return getTileEntity(world, pos); } }
@Override public final void onBlockPlacedBy(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull EntityLivingBase placer, @Nonnull ItemStack stack) { onBlockPlaced(worldIn, pos, state, placer, stack); T te = getTileEntity(worldIn, pos); if (te != null) { te.readCustomNBT(stack); onBlockPlaced(worldIn, pos, state, placer, te); } }
protected boolean shouldDoWorkThisTick(@Nonnull World world, @Nonnull BlockPos pos, int interval, int offset) { T te = getTileEntity(world, pos); if (te == null) { return (world.getTotalWorldTime() + offset) % interval == 0; } else { return te.shouldDoWorkThisTick(interval, offset); } }
@Override public final void getDrops(@Nonnull NonNullList<ItemStack> drops, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull IBlockState state, int fortune) { final T te = getTileEntity(world, pos); final ItemStack drop = getNBTDrop(world, pos, state, fortune, te); if (drop != null) { drops.add(drop); } getExtraDrops(drops, world, pos, state, fortune, te); }
/** * @deprecated override {@link #processPickBlock(IBlockState, RayTraceResult, World, BlockPos, EntityPlayer, ItemStack)} instead if possible */ @Override @Deprecated public @Nonnull ItemStack getPickBlock(@Nonnull IBlockState state, @Nonnull RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player) { if (player.capabilities.isCreativeMode && GuiScreen.isCtrlKeyDown()) { ItemStack nbtDrop = getNBTDrop(world, pos, state, 0, getTileEntity(world, pos)); if (nbtDrop != null) { return nbtDrop; } } return processPickBlock(state, target, world, pos, player, super.getPickBlock(state, target, world, pos, player)); }
@Override public boolean onBlockActivated(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull EntityPlayer playerIn, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ) { if (playerIn.isSneaking()) { return false; } TileEntity te = getTileEntity(worldIn, pos); if (te instanceof ITankAccess) { if (FluidUtil.fillInternalTankFromPlayerHandItem(worldIn, pos, playerIn, hand, (ITankAccess) te)) { return true; } if (FluidUtil.fillPlayerHandItemFromInternalTank(worldIn, pos, playerIn, hand, (ITankAccess) te)) { return true; } } return openGui(worldIn, pos, playerIn, side); }