Java Code Examples for net.minecraft.tileentity.TileEntity#createAndLoadEntity()

The following examples show how to use net.minecraft.tileentity.TileEntity#createAndLoadEntity() . 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: PacketTileEntityNBT.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handle(ByteBuf data, EntityPlayer player) {
	int dimension = data.readInt();
	int xPos = data.readInt();
	int yPos = data.readInt();
	int zPos = data.readInt();
	NBTTagCompound nbt = ByteBufUtils.readTag(data);

	WorldClient proxyworld = ProxyWorldManager.getProxyworld(dimension);
	if (proxyworld == null) return;
	if (proxyworld.provider.dimensionId != dimension) return;
	if (proxyworld.blockExists(xPos, yPos, zPos)) {
		TileEntity tileentity = proxyworld.getTileEntity(xPos, yPos, zPos);

		if (tileentity != null) {
			tileentity.readFromNBT(nbt);
		} else {
			//Create tile entity from data
			tileentity = TileEntity.createAndLoadEntity(nbt);
			if (tileentity != null) {
				proxyworld.addTileEntity(tileentity);
			}
		}
		proxyworld.markTileEntityChunkModified(xPos, yPos, zPos, tileentity);
		proxyworld.setTileEntity(xPos, yPos, zPos, tileentity);
		proxyworld.markBlockForUpdate(xPos, yPos, zPos);
	}
}
 
Example 2
Source File: CraftBlockState.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public TileEntity getTileEntity() {
    if (nbt != null)
        return TileEntity.createAndLoadEntity(nbt);
    else return null;
}
 
Example 3
Source File: EntityShip.java    From archimedes-ships with MIT License 4 votes vote down vote up
@Override
protected void readEntityFromNBT(NBTTagCompound compound)
{
	super.readEntityFromNBT(compound);
	byte[] ab = compound.getByteArray("chunk");
	ByteArrayInputStream bais = new ByteArrayInputStream(ab);
	DataInputStream in = new DataInputStream(bais);
	try
	{
		ChunkIO.read(in, shipChunk);
		in.close();
	} catch (IOException e)
	{
		e.printStackTrace();
	}
	if (compound.hasKey("seat"))
	{
		short s = compound.getShort("seat");
		seatX = s & 0xF;
		seatY = s >>> 4 & 0xF;
		seatZ = s >>> 8 & 0xF;
		frontDirection = s >>> 12 & 3;
	} else
	{
		seatX = compound.getByte("seatX") & 0xFF;
		seatY = compound.getByte("seatY") & 0xFF;
		seatZ = compound.getByte("seatZ") & 0xFF;
		frontDirection = compound.getByte("front") & 3;
	}
	
	NBTTagList tileentities = compound.getTagList("tileent", 10);
	if (tileentities != null)
	{
		for (int i = 0; i < tileentities.tagCount(); i++)
		{
			NBTTagCompound comp = tileentities.getCompoundTagAt(i);
			TileEntity tileentity = TileEntity.createAndLoadEntity(comp);
			shipChunk.setTileEntity(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord, tileentity);
		}
	}
	
	info = new ShipInfo();
	info.shipName = compound.getString("name");
	if (compound.hasKey("owner"))
	{
		info.shipName = compound.getString("owner");
	}
}