Java Code Examples for com.nukkitx.network.util.Preconditions#checkElementIndex()

The following examples show how to use com.nukkitx.network.util.Preconditions#checkElementIndex() . 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: PaddedBitArray.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void set(int index, int value) {
    Preconditions.checkElementIndex(index, this.size);
    Preconditions.checkArgument(value >= 0 && value <= this.version.maxEntryValue, "Invalid value");
    int arrayIndex = index / this.version.entriesPerWord;
    int offset = (index % this.version.entriesPerWord) * this.version.bits;

    this.words[arrayIndex] = this.words[arrayIndex] & ~(this.version.maxEntryValue << offset) | (value & this.version.maxEntryValue) << offset;
}
 
Example 2
Source File: PaddedBitArray.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public int get(int index) {
    Preconditions.checkElementIndex(index, this.size);
    int arrayIndex = index / this.version.entriesPerWord;
    int offset = (index % this.version.entriesPerWord) * this.version.bits;

    return (this.words[arrayIndex] >>> offset) & this.version.maxEntryValue;
}
 
Example 3
Source File: Pow2BitArray.java    From Geyser with MIT License 5 votes vote down vote up
/**
 * Sets the entry at the given location to the given value
 */
public void set(int index, int value) {
    Preconditions.checkElementIndex(index, this.size);
    Preconditions.checkArgument(value >= 0 && value <= this.version.maxEntryValue, "Invalid value %s", value);
    int bitIndex = index * this.version.bits;
    int arrayIndex = bitIndex >> 5;
    int offset = bitIndex & 31;
    this.words[arrayIndex] = this.words[arrayIndex] & ~(this.version.maxEntryValue << offset) | (value & this.version.maxEntryValue) << offset;
}
 
Example 4
Source File: Pow2BitArray.java    From Geyser with MIT License 5 votes vote down vote up
/**
 * Gets the entry at the given index
 */
public int get(int index) {
    Preconditions.checkElementIndex(index, this.size);
    int bitIndex = index * this.version.bits;
    int arrayIndex = bitIndex >> 5;
    int wordOffset = bitIndex & 31;
    return this.words[arrayIndex] >>> wordOffset & this.version.maxEntryValue;
}
 
Example 5
Source File: NibbleArray.java    From Geyser with MIT License 5 votes vote down vote up
public byte get(int index) {
    Preconditions.checkElementIndex(index, data.length * 2);
    byte val = data[index / 2];
    if ((index & 1) == 0) {
        return (byte) (val & 0x0f);
    } else {
        return (byte) ((val & 0xf0) >>> 4);
    }
}
 
Example 6
Source File: NibbleArray.java    From Geyser with MIT License 5 votes vote down vote up
public void set(int index, byte value) {
    Preconditions.checkArgument(value >= 0 && value < 16, "Nibbles must have a value between 0 and 15.");
    Preconditions.checkElementIndex(index, data.length * 2);
    value &= 0xf;
    int half = index / 2;
    byte previous = data[half];
    if ((index & 1) == 0) {
        data[half] = (byte) (previous & 0xf0 | value);
    } else {
        data[half] = (byte) (previous & 0x0f | value << 4);
    }
}
 
Example 7
Source File: ChunkSection.java    From Geyser with MIT License 4 votes vote down vote up
public int getFullBlock(int x, int y, int z, int layer) {
    checkBounds(x, y, z);
    Preconditions.checkElementIndex(layer, this.storage.length);
    return this.storage[layer].getFullBlock(blockPosition(x, y, z));
}
 
Example 8
Source File: ChunkSection.java    From Geyser with MIT License 4 votes vote down vote up
public void setFullBlock(int x, int y, int z, int layer, int fullBlock) {
    checkBounds(x, y, z);
    Preconditions.checkElementIndex(layer, this.storage.length);
    this.storage[layer].setFullBlock(blockPosition(x, y, z), fullBlock);
}