public default IMultipartTile createMultipartTile(World world, IPartSlot slot, IBlockState state) { TileEntity tileEntity = state.getBlock().createTileEntity(world, state); return tileEntity != null ? convertToMultipartTile(tileEntity) : null; }
@SuppressWarnings("null") private TileEntity createTileEntity(IBlockState state, @Nonnull BlockPos pos) { Block block = state.getBlock(); if (!block.hasTileEntity(state) || teBlackList.containsKey(block)) { return null; } if (teCache.containsKey(block)) { try { TileEntity tileEntity = teCache.get(block); tileEntity.setPos(pos); return tileEntity; } catch (Throwable t) { teCache.remove(block); } } try { TileEntity tileEntity = block.createTileEntity(null, state); tileEntity.setPos(pos); teCache.put(block, tileEntity); return tileEntity; } catch (Throwable t) { teBlackList.put(block, true); } return null; }
@Override @Nullable public TileEntity getTileEntity(BlockPos pos) { IBlockState state = getBlockState(pos); if (state.getBlock().hasTileEntity(state)) { return teCache.computeIfAbsent(pos.toImmutable(), p -> state.getBlock().createTileEntity(world, state)); } return null; }
TileEntity newTile = block.createTileEntity(world, state); world.setTileEntity(pos_, newTile);
IBlockState state = replacementState; if (block.hasTileEntity(state)) { TileEntity tile = block.createTileEntity(world, state);
@Nullable @Override public TileEntity getTileEntity(BlockPos pos) { IBlockState state = getBlockState(pos); if(state.getBlock().hasTileEntity(state)) { TileEntity tileentity = state.getBlock().createTileEntity(proxyWorld, state); tileentity.setWorld(proxyWorld); if (tileentity != null) { NBTTagCompound nbt = getVariantAtBlockPos(pos); if(nbt != null) { tileentity.readFromNBT(nbt); for (AbstractExtraTileDataProvider provider : ExtraTileDataProviderRegistry.getDataProviders(tileentity)) { String tagName = String.format("cm3_extra:%s", provider.getName()); if (nbt.hasKey(tagName)) { provider.readExtraData(tileentity, (NBTTagCompound) nbt.getTag(tagName)); } } } } return tileentity; } return null; }
final TileEntity nte = blk.createTileEntity( world, state ); final NBTTagCompound data = new NBTTagCompound(); ote.writeToNBT( data );
TileEntity restoredTe = machineWorld.getTileEntity(absolutePos); if (restoredTe == null) { restoredTe = bi.block.createTileEntity(machineWorld, state);