/** * Tries to load any block's TileEntity if it exists. Will not create the TileEntity when used in a render thread with the correct IBlockAccess. Will not * cause chunk loads. * */ public static @Nullable TileEntity getAnyTileEntitySafe(@Nonnull IBlockAccess world, @Nonnull BlockPos pos) { return getAnyTileEntitySafe(world, pos, TileEntity.class); }
public @Nullable ItemStack getNBTDrop(@Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull IBlockState state, int fortune, @Nullable T te) { ItemStack itemStack = new ItemStack(this, 1, damageDropped(state)); processDrop(world, pos, te, itemStack); return itemStack; }
/** * (Re-)Paints a block that exists in the world. It's the caller's responsibility to check that the paint source is valid and appropriate, and to trigger a * world re-render. */ default void setPaintSource(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nullable IBlockState paintSource) { IPaintable.IPaintableTileEntity te = BlockEnder.getAnyTileEntity(world, pos, IPaintable.IPaintableTileEntity.class); if (te != null) { te.setPaintSource(paintSource); } }
@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); }
@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); } }
/** * @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); }
/** * 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 @Nonnull TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) { if (teClass != null) { try { T te = teClass.newInstance(); te.setWorldCreate(world); te.init(); return te; } catch (Exception e) { throw new RuntimeException("Could not create tile entity for block " + getLocalizedName() + " for class " + teClass, e); } } throw new RuntimeException( "Cannot create a TileEntity for a block that doesn't have a TileEntity. This is not a problem with EnderCore, this is caused by the caller."); }
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); } }
protected boolean isSilent(@Nonnull IBlockAccess worldIn, @Nonnull BlockPos pos) { TileEntity te = BlockEnder.getAnyTileEntitySafe(worldIn, pos); if (te instanceof TilePaintedPressurePlate) { return ((TilePaintedPressurePlate) te).isSilent(); } return false; }
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); } }
@Override public int getFlammability(@Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull EnumFacing face) { TileEntity te = BlockEnder.getAnyTileEntitySafe(world, pos); if (te instanceof TilePaintedPressurePlate) { return EnumPressurePlateType.WOOD == ((TilePaintedPressurePlate) te).getType() ? 20 : 0; } return 0; }
@Override public int getFireSpreadSpeed(@Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull EnumFacing face) { TileEntity te = BlockEnder.getAnyTileEntitySafe(world, pos); if (te instanceof TilePaintedPressurePlate) { return EnumPressurePlateType.WOOD == ((TilePaintedPressurePlate) te).getType() ? 5 : 0; } return 0; }
protected EnumFacing getRotation(@Nonnull IBlockAccess world, @Nonnull BlockPos pos) { TileEntity te = BlockEnder.getAnyTileEntitySafe(world, pos); if (te instanceof TilePaintedPressurePlate) { return ((TilePaintedPressurePlate) te).getRotation(); } return EnumFacing.NORTH; }
protected EnumPressurePlateType getType(@Nonnull IBlockAccess worldIn, @Nonnull BlockPos pos) { TileEntity te = BlockEnder.getAnyTileEntitySafe(worldIn, pos); if (te instanceof TilePaintedPressurePlate) { return ((TilePaintedPressurePlate) te).getType(); } return EnumPressurePlateType.WOOD; }
/** * Gets the paint source from a block that exists in the world. Will return null if the block is not painted. */ default @Nullable IBlockState getPaintSource(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos) { IPaintable.IPaintableTileEntity te = BlockEnder.getAnyTileEntitySafe(world, pos, IPaintable.IPaintableTileEntity.class); if (te != null) { return te.getPaintSource(); } return null; }
protected CapturedMob getMobType(@Nonnull IBlockAccess worldIn, @Nonnull BlockPos pos) { TileEntity te = BlockEnder.getAnyTileEntitySafe(worldIn, pos); if (te instanceof TilePaintedPressurePlate) { return ((TilePaintedPressurePlate) te).getMobType(); } return null; }
public void getChargers(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull Collection<IWirelessCharger> res) { final Collection<BlockPos> chargers = getChargersForWorld(world); for (Iterator<BlockPos> iterator = chargers.iterator(); iterator.hasNext();) { BlockPos chargerPos = iterator.next(); IWirelessCharger charger = chargerPos != null ? BlockEnder.getAnyTileEntitySafe(world, chargerPos, IWirelessCharger.class) : null; if (charger != null) { if (charger.getRange().contains(pos)) { res.add(charger); } } else { iterator.remove(); changeCount++; } } }
public IBlockState getPaintSource2(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos) { if (isDouble()) { TileEntity te = BlockEnder.getAnyTileEntitySafe(world, pos); if (te instanceof TileEntityTwicePaintedBlock) { return ((TileEntityTwicePaintedBlock) te).getPaintSource2(); } return null; } else { return getPaintSource(state, world, pos); } }