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

The following examples show how to use net.minecraft.tileentity.TileEntity#invalidate() . 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: MovingBlock.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void startMoving(boolean invalidate, boolean validate) {

    TileEntity te = getTileEntity();
    if (te != null) {
        if (invalidate)
            te.invalidate();
    }

    if (!getWorld().isRemote) {
        BlockUtils.setBlockSneaky(getWorld(), getX(), getY(), getZ(), Blocks.air);
        getWorld().setBlockMetadataWithNotify(getX(), getY(), getZ(), 0, 2);
    }

    if (te != null)
        BlockUtils.removeTileEntity(getWorld(), getX(), getY(), getZ());

    if (te != null && validate) {
        te.setWorldObj(FakeWorld.getFakeWorld(this));
        te.validate();
    }
}
 
Example 2
Source File: MobileChunk.java    From archimedes-ships with MIT License 6 votes vote down vote up
/**
 * Sets the TileEntity for a given block in this chunk
 */
private void setChunkBlockTileEntity(int x, int y, int z, TileEntity tileentity)
{
	ChunkPosition chunkposition = new ChunkPosition(x, y, z);
	tileentity.setWorldObj(worldObj);
	int ox = tileentity.xCoord;
	int oy = tileentity.yCoord;
	int oz = tileentity.zCoord;
	tileentity.xCoord = x;
	tileentity.yCoord = y;
	tileentity.zCoord = z;
	
	Block block = getBlock(x, y, z);
	if (block != null && block.hasTileEntity(getBlockMetadata(x, y, z)))
	{
		tileentity.blockMetadata = getBlockMetadata(x, y, z);
		tileentity.invalidate();
		chunkTileEntityMap.put(chunkposition, tileentity);
		
		if (tileentity instanceof IShipTileEntity)
		{
			((IShipTileEntity) tileentity).setParentShip(entityShip, ox, oy, oz);
		}
	}
}
 
Example 3
Source File: MobileChunk.java    From archimedes-ships with MIT License 6 votes vote down vote up
/**
 * Removes the TileEntity for a given block in this chunk
 */
public void removeChunkBlockTileEntity(int x, int y, int z)
{
	ChunkPosition chunkposition = new ChunkPosition(x, y, z);
	if (isChunkLoaded)
	{
		TileEntity tileentity = chunkTileEntityMap.remove(chunkposition);
		if (tileentity != null)
		{
			if (tileentity instanceof IShipTileEntity)
			{
				((IShipTileEntity) tileentity).setParentShip(null, x, y, z);
			}
			tileentity.invalidate();
		}
	}
}
 
Example 4
Source File: BlockRotationAxle.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    super.breakBlock(worldIn, pos, state);
    TileEntity tile = worldIn.getTileEntity(pos);
    if (tile != null) {
        tile.invalidate();
    }
}
 
Example 5
Source File: MovingBlock.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void finishMoving(boolean invalidate, boolean validate) {

    Vec3i newLocation = getStructure().getMovement().transform(new Vec3i(this));
    TileEntity te = getTileEntity();

    if (te != null && invalidate)
        te.invalidate();

    // if (!newLocation.getWorld().isRemote) {
    if (getWorld().isRemote) {
        newLocation.getWorld().setBlock(newLocation.getX(), newLocation.getY(), newLocation.getZ(), getBlock(), 0, 0);
    } else {
        BlockUtils.setBlockSneaky(newLocation.getWorld(), newLocation.getX(), newLocation.getY(), newLocation.getZ(), getBlock());
    }
    newLocation.getWorld().setBlockMetadataWithNotify(newLocation.getX(), newLocation.getY(), newLocation.getZ(), getMetadata(), 2);
    // }

    if (te != null) {
        te.setWorldObj(newLocation.getWorld());
        te.xCoord = newLocation.getX();
        te.yCoord = newLocation.getY();
        te.zCoord = newLocation.getZ();

        if (validate)
            te.validate();
        BlockUtils.setTileEntity(newLocation.getWorld(), newLocation.getX(), newLocation.getY(), newLocation.getZ(), te);
    }
}
 
Example 6
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void check(TileEntity te) {
    for (SegmentTileEntity segment : segmentsTile.get(te.getClass())) {
        if (!segment.shouldExist(te)) {
            ItemStack itemStack = new ItemStack(te.getBlockType(), 1, te.getBlockMetadata());
            NBTTagCompound nbt = new NBTTagCompound();
            te.writeToNBT(nbt);
            itemStack.setTagCompound(nbt);
            WorldUtils.dropAsEntity(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, itemStack);
            te.getWorldObj().setBlock(te.xCoord, te.yCoord, te.zCoord, Blocks.air);
            te.invalidate();
            MyTown.instance.LOG.info("TileEntity {} was ATOMICALLY DISINTEGRATED!", te.toString());
            return;
        }
    }
}