Java Code Examples for us.myles.ViaVersion.api.Pair#getValue()

The following examples show how to use us.myles.ViaVersion.api.Pair#getValue() . 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: BlockConnectionStorage.java    From ViaVersion with MIT License 6 votes vote down vote up
public void remove(int x, int y, int z) {
    long pair = getChunkSectionIndex(x, y, z);
    Pair<byte[], NibbleArray> map = blockStorage.get(pair);
    if (map == null) return;
    int blockIndex = encodeBlockPos(x, y, z);
    NibbleArray nibbleArray = map.getValue();
    if (nibbleArray != null) {
        nibbleArray.set(blockIndex, 0);
        boolean allZero = true;
        for (int i = 0; i < 4096; i++) {
            if (nibbleArray.get(i) != 0) {
                allZero = false;
                break;
            }
        }
        if (allZero) map.setValue(null);
    }
    map.getKey()[blockIndex] = 0;
    for (short entry : map.getKey()) {
        if (entry != 0) return;
    }
    blockStorage.remove(pair);
}
 
Example 2
Source File: ProtocolRegistry.java    From ViaVersion with MIT License 5 votes vote down vote up
public static Protocol getBaseProtocol(int serverVersion) {
    for (Pair<Range<Integer>, Protocol> rangeProtocol : Lists.reverse(baseProtocols)) {
        if (rangeProtocol.getKey().contains(serverVersion)) {
            return rangeProtocol.getValue();
        }
    }
    throw new IllegalStateException("No Base Protocol for " + serverVersion);
}
 
Example 3
Source File: ProtocolRegistry.java    From ViaVersion with MIT License 5 votes vote down vote up
public static boolean isBaseProtocol(Protocol protocol) {
    for (Pair<Range<Integer>, Protocol> p : baseProtocols) {
        if (p.getValue() == protocol) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: BlockConnectionStorage.java    From ViaVersion with MIT License 5 votes vote down vote up
public void store(int x, int y, int z, int blockState) {
    short mapping = REVERSE_BLOCK_MAPPINGS[blockState];
    if (mapping == -1) return;

    blockState = mapping;
    long pair = getChunkSectionIndex(x, y, z);
    Pair<byte[], NibbleArray> map = getChunkSection(pair, (blockState & 0xF) != 0);
    int blockIndex = encodeBlockPos(x, y, z);
    map.getKey()[blockIndex] = (byte) (blockState >> 4);
    NibbleArray nibbleArray = map.getValue();
    if (nibbleArray != null) {
        nibbleArray.set(blockIndex, blockState);
    }
}
 
Example 5
Source File: BlockConnectionStorage.java    From ViaVersion with MIT License 5 votes vote down vote up
public int get(int x, int y, int z) {
    long pair = getChunkSectionIndex(x, y, z);
    Pair<byte[], NibbleArray> map = blockStorage.get(pair);
    if (map == null) return 0;
    short blockPosition = encodeBlockPos(x, y, z);
    NibbleArray nibbleArray = map.getValue();
    return WorldPackets.toNewId(
            ((map.getKey()[blockPosition] & 0xFF) << 4)
                    | (nibbleArray == null ? 0 : nibbleArray.get(blockPosition))
    );
}
 
Example 6
Source File: BlockConnectionStorage.java    From ViaVersion with MIT License 5 votes vote down vote up
private Pair<byte[], NibbleArray> getChunkSection(long index, boolean requireNibbleArray) {
    Pair<byte[], NibbleArray> map = blockStorage.get(index);
    if (map == null) {
        map = new Pair<>(new byte[4096], null);
        blockStorage.put(index, map);
    }
    if (map.getValue() == null && requireNibbleArray) {
        map.setValue(new NibbleArray(4096));
    }
    return map;
}