Java Code Examples for cn.nukkit.block.Block#getDamage()

The following examples show how to use cn.nukkit.block.Block#getDamage() . 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: PopulatorGroundCover.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    FullChunk chunk = level.getChunk(chunkX, chunkZ);
    for (int x = 0; x < 16; ++x) {
        for (int z = 0; z < 16; ++z) {
            Biome biome = Biome.getBiome(chunk.getBiomeId(x, z));
            Block[] cover = biome.getGroundCover();
            if (cover != null && cover.length > 0) {
                int diffY = 0;
                if (!cover[0].isSolid()) {
                    diffY = 1;
                }

                byte[] column = chunk.getBlockIdColumn(x, z);
                int y;
                for (y = 127; y > 0; --y) {
                    if (column[y] != 0x00 && !Block.get(column[y] & 0xff).isTransparent()) {
                        break;
                    }
                }
                int startY = Math.min(127, y + diffY);
                int endY = startY - cover.length;
                for (y = startY; y > endY && y >= 0; --y) {
                    Block b = cover[startY - y];
                    if (column[y] == 0x00 && b.isSolid()) {
                        break;
                    }
                    if (b.getDamage() == 0) {
                        chunk.setBlockId(x, y, z, b.getId());
                    } else {
                        chunk.setBlock(x, y, z, b.getId(), b.getDamage());
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: BlockEntityCommandBlock.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void useCommand() {
	if (this.getServer().dispatchCommand(this, getCommand())) {
		Block block = getBlock();
		Block commandBlock = block.getSide(BlockFace.fromIndex(block.getDamage()));
		if (commandBlock instanceof BlockCommandChain) {
			if (block.getDamage() == commandBlock.getDamage()) {
				BlockEntityCommandBlock blockEntity = ((BlockCommandChain) commandBlock).getBlockEntity();
				if (blockEntity != null) {
					blockEntity.chainUpdate();
				}
			}
		}
	}
}
 
Example 3
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getAndSetBlock(int x, int y, int z, Block block) {
    int i = (x << 11) | (z << 7) | y;
    boolean changed = false;
    byte id = (byte) block.getId();

    byte previousId = this.blocks[i];

    if (previousId != id) {
        this.blocks[i] = id;
        changed = true;
    }

    int previousData;
    i >>= 1;
    int old = this.data[i] & 0xff;
    if ((y & 1) == 0) {
        previousData = old & 0x0f;
        if (Block.hasMeta[block.getId()]) {
            this.data[i] = (byte) ((old & 0xf0) | (block.getDamage() & 0x0f));
            if (block.getDamage() != previousData) {
                changed = true;
            }
        }
    } else {
        previousData = old >> 4;
        if (Block.hasMeta[block.getId()]) {
            this.data[i] = (byte) (((block.getDamage() & 0x0f) << 4) | (old & 0x0f));
            if (block.getDamage() != previousData) {
                changed = true;
            }
        }
    }

    if (changed) {
        setChanged();
    }
    return Block.get(previousId, previousData);
}
 
Example 4
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getAndSetBlock(int x, int y, int z, Block block) {
    int i = (x << 11) | (z << 7) | y;
    boolean changed = false;
    byte id = (byte) block.getId();

    byte previousId = this.blocks[i];

    if (previousId != id) {
        this.blocks[i] = id;
        changed = true;
    }

    int previousData;
    i >>= 1;
    int old = this.data[i] & 0xff;
    if ((y & 1) == 0) {
        previousData = old & 0x0f;
        if (Block.hasMeta[block.getId()]) {
            this.data[i] = (byte) ((old & 0xf0) | (block.getDamage() & 0x0f));
            if (block.getDamage() != previousData) {
                changed = true;
            }
        }
    } else {
        previousData = old >> 4;
        if (Block.hasMeta[block.getId()]) {
            this.data[i] = (byte) (((block.getDamage() & 0x0f) << 4) | (old & 0x0f));
            if (block.getDamage() != previousData) {
                changed = true;
            }
        }
    }

    if (changed) {
        setChanged();
    }
    return Block.get(previousId, previousData);
}
 
Example 5
Source File: NukkitUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public static BaseBlock getBlock(Level level, Vector position) {
    Vector3 pos = new Vector3(position.getX(), position.getY(), position.getZ());
    Block block = level.getBlock(pos);
    int id = block.getId();
    int data = block.getDamage();
    return new BaseBlock(id, data);
}
 
Example 6
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getAndSetBlock(int x, int y, int z, Block block) {
    int i = (x << 11) | (z << 7) | y;
    boolean changed = false;
    byte id = (byte) block.getId();

    byte previousId = this.blocks[i];

    if (previousId != id) {
        this.blocks[i] = id;
        changed = true;
    }

    int previousData;
    i >>= 1;
    int old = this.data[i] & 0xff;
    if ((y & 1) == 0) {
        previousData = old & 0x0f;
        if (Block.hasMeta[block.getId()]) {
            this.data[i] = (byte) ((old & 0xf0) | (block.getDamage() & 0x0f));
            if (block.getDamage() != previousData) {
                changed = true;
            }
        }
    } else {
        previousData = old >> 4;
        if (Block.hasMeta[block.getId()]) {
            this.data[i] = (byte) (((block.getDamage() & 0x0f) << 4) | (old & 0x0f));
            if (block.getDamage() != previousData) {
                changed = true;
            }
        }
    }

    if (changed) {
        setChanged();
    }
    return Block.get(previousId, previousData);
}
 
Example 7
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getAndSetBlock(int x, int y, int z, Block block) {
    int i = (x << 11) | (z << 7) | y;
    boolean changed = false;
    byte id = (byte) block.getId();

    byte previousId = this.blocks[i];

    if (previousId != id) {
        this.blocks[i] = id;
        changed = true;
    }

    int previousData;
    i >>= 1;
    int old = this.data[i] & 0xff;
    if ((y & 1) == 0) {
        previousData = old & 0x0f;
        if (Block.hasMeta[block.getId()]) {
            this.data[i] = (byte) ((old & 0xf0) | (block.getDamage() & 0x0f));
            if (block.getDamage() != previousData) {
                changed = true;
            }
        }
    } else {
        previousData = old >> 4;
        if (Block.hasMeta[block.getId()]) {
            this.data[i] = (byte) (((block.getDamage() & 0x0f) << 4) | (old & 0x0f));
            if (block.getDamage() != previousData) {
                changed = true;
            }
        }
    }

    if (changed) {
        setChanged();
    }
    return Block.get(previousId, previousData);
}
 
Example 8
Source File: TerrainParticle.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public TerrainParticle(Vector3 pos, Block block) {
    super(pos, Particle.TYPE_TERRAIN, (block.getDamage() << 8) | block.getId());
}
 
Example 9
Source File: DestroyBlockParticle.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public DestroyBlockParticle(Vector3 pos, Block block) {
    super(pos.x, pos.y, pos.z);
    this.data = block.getId() | (block.getDamage() << 8);
}
 
Example 10
Source File: PunchBlockParticle.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public PunchBlockParticle(Vector3 pos, Block block, BlockFace face) {
    this(pos, block.getId(), block.getDamage(), face);
}
 
Example 11
Source File: PunchBlockParticle.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PunchBlockParticle(Vector3 pos, Block block, BlockFace face) {
    this(pos, block.getId(), block.getDamage(), face);
}
 
Example 12
Source File: PopulatorGroundCover.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    FullChunk chunk = level.getChunk(chunkX, chunkZ);
    for (int x = 0; x < 16; ++x) {
        for (int z = 0; z < 16; ++z) {
            Biome biome = Biome.getBiome(chunk.getBiomeId(x, z));
            Block[] cover = biome.getGroundCover();
            if (cover != null && cover.length > 0) {
                int diffY = 0;
                if (!cover[0].isSolid()) {
                    diffY = 1;
                }

                int height = chunk.getHeightMap(x, z);
                if (height == 0 || height == 255) height = 126;

                int y;
                for (y = height + 1; y > 0; --y) {
                    int fullId = chunk.getFullBlock(x, y, z);
                    if (fullId != 0 && !Block.get(fullId >> 4).isTransparent()) {
                        break;
                    }
                }
                int startY = Math.min(127, y + diffY);
                int endY = startY - cover.length;
                for (y = startY; y > endY && y >= 0; --y) {
                    Block b = cover[startY - y];
                    int blockId = chunk.getBlockId(x, y, z);
                    if (blockId == 0 && b.isSolid()) {
                        break;
                    }
                    if (b.getDamage() == 0) {
                        chunk.setBlockId(x, y, z, b.getId());
                    } else {
                        chunk.setBlock(x, y, z, b.getId(), b.getDamage());
                    }
                }
            }
        }
    }
}
 
Example 13
Source File: TerrainParticle.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public TerrainParticle(Vector3 pos, Block block) {
    super(pos, Particle.TYPE_TERRAIN, (block.getDamage() << 8) | block.getId());
}
 
Example 14
Source File: DestroyBlockParticle.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public DestroyBlockParticle(Vector3 pos, Block block) {
    super(pos.x, pos.y, pos.z);
    this.data = block.getId() | (block.getDamage() << 8);
}
 
Example 15
Source File: PunchBlockParticle.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PunchBlockParticle(Vector3 pos, Block block, BlockFace face) {
    this(pos, block.getId(), block.getDamage(), face);
}