Java Code Examples for net.minecraft.block.Block#createTileEntity()

The following examples show how to use net.minecraft.block.Block#createTileEntity() . 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: TileStickyJar.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void readCustomNBT(NBTTagCompound compound) {
    String parentType = compound.getString("parentType");
    if(parentType.length() > 0) {
        Block block = GameData.getBlockRegistry().getObject(parentType);
        if(block != null && compound.hasKey("parent") && compound.hasKey("parentMetadata")) {
            NBTTagCompound data = compound.getCompoundTag("parent");
            int metadata = compound.getInteger("parentMetadata");
            TileEntity tile = block.createTileEntity(getWorldObj(), metadata);
            if(tile instanceof TileJarFillable) {
                placedOn = ForgeDirection.getOrientation(compound.getInteger("placedOn"));
                tile.readFromNBT(data);
                init((TileJarFillable) tile, block, metadata, placedOn);
            }
        }
    }

    if(!isValid() && !getWorldObj().isRemote) {
        getWorldObj().setBlockToAir(xCoord, yCoord, zCoord);
    }
}
 
Example 2
Source File: MobileChunk.java    From archimedes-ships with MIT License 6 votes vote down vote up
/**
 * Gets the TileEntity for a given block in this chunk
 */
@Override
public TileEntity getTileEntity(int x, int y, int z)
{
	ChunkPosition chunkposition = new ChunkPosition(x, y, z);
	TileEntity tileentity = chunkTileEntityMap.get(chunkposition);
			
	if (tileentity == null)
	{
		Block block = getBlock(x, y, z);
		int meta = getBlockMetadata(x, y, z);
		
		if (block == null || !block.hasTileEntity(meta))
		{
			return null;
		}
		
		tileentity = block.createTileEntity(worldObj, meta);
		setTileEntity(x, y, z, tileentity);
		
		tileentity = chunkTileEntityMap.get(chunkposition);
	}
	
	return tileentity;
}
 
Example 3
Source File: EntityGroup.java    From TickDynamic with MIT License 5 votes vote down vote up
private List<Class> loadTilesByName(String name) {
	FMLControlledNamespacedRegistry<Block> blockRegistry = GameData.getBlockRegistry();
	Block block = blockRegistry.getRaw(name);
	if(block == null)
		return null;

	//Get TileEntities for every metadata
	TileEntity currentTile;
	Class prevTile = null;
	List<Class> tileClassList = new ArrayList<Class>(16);
	for(byte b = 0; b < 16; b++)
	{
		if(block.hasTileEntity(b))
		{
			//Might throw an exception while creating TileEntity, especially at initial load of global groups
			try {
				currentTile = block.createTileEntity(world, b);
			} catch(Exception e)
			{
				if(mod.debug)
					System.out.println("Exception while loading Tile for " + name + ":\n" + e.getMessage());
				currentTile = null;
			}
			
			Class cls = currentTile.getClass();
			if(currentTile != null && cls != prevTile)
			{
				
				if(!tileClassList.contains(cls))
					tileClassList.add(currentTile.getClass());
			}
			prevTile = cls;
		}
	}
	
	return tileClassList;
}