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

The following examples show how to use cn.nukkit.block.Block#hasMeta() . 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: 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 2
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setBlock(int x, int y, int z, int blockId, int meta) {
    int i = (x << 11) | (z << 7) | y;
    boolean changed = false;
    byte id = (byte) blockId;
    if (this.blocks[i] != id) {
        this.blocks[i] = id;
        changed = true;
    }

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

    if (changed) {
        setChanged();
    }
    return changed;
}
 
Example 3
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setBlock(int x, int y, int z, int blockId, int meta) {
    int i = (x << 11) | (z << 7) | y;
    boolean changed = false;
    byte id = (byte) blockId;
    if (this.blocks[i] != id) {
        this.blocks[i] = id;
        changed = true;
    }

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

    if (changed) {
        setChanged();
    }
    return changed;
}
 
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: 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 6
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setBlock(int x, int y, int z, int blockId, int meta) {
    int i = (x << 11) | (z << 7) | y;
    boolean changed = false;
    byte id = (byte) blockId;
    if (this.blocks[i] != id) {
        this.blocks[i] = id;
        changed = true;
    }

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

    if (changed) {
        setChanged();
    }
    return changed;
}
 
Example 7
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setBlock(int x, int y, int z, int blockId, int meta) {
    int i = (x << 11) | (z << 7) | y;
    boolean changed = false;
    byte id = (byte) blockId;
    if (this.blocks[i] != id) {
        this.blocks[i] = id;
        changed = true;
    }

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

    if (changed) {
        setChanged();
    }
    return changed;
}
 
Example 8
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);
}