Archived
0
This commit is contained in:
2019-01-29 18:16:20 +03:00
parent 5c91122b08
commit 00d536710a
6 changed files with 34 additions and 47 deletions

View File

@@ -41,10 +41,6 @@ public class NibbleArray {
return isLowerNibble(idx) ? this.data[ni] & 0x0F : this.data[ni] >> 4 & 0x0F;
}
public void set(BlockLocation location, int value) {
set(location.getX(), location.getY(), location.getZ(), value);
}
public void set(int x, int y, int z, int value) {
if (value < 0) value = 0;
else if (value > 15) value = 15;

View File

@@ -1,10 +1,13 @@
package mc.core.world.block;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;
@Slf4j
@@ -491,25 +494,29 @@ public enum BlockType {
this.namedId = null;
}
public static BlockType getByIdMeta(int id, int meta) {
if (id < 0) {
log.warn("Incorrect id \"{}\"", id);
return BEDROCK;
}
Stream<BlockType> stream = Arrays.stream(BlockType.values());
return stream.filter(blockType -> blockType.id == id && blockType.meta == meta)
.findFirst()
.orElseGet(() -> {
log.warn("Unknow block type: {}:{}", id, meta);
return BEDROCK;
});
}
@Getter
private final int id;
@Getter
private final int meta;
@Getter
private final String namedId;
private static final Table<Integer, Integer, BlockType> typeTable = HashBasedTable.create();
static {
Arrays.stream(BlockType.values())
.forEach(blockType -> typeTable.put(blockType.id, blockType.meta, blockType));
}
public static BlockType getByIdMeta(int id, int meta) {
if (id < 0) {
log.warn("Incorrect id \"{}\"", id);
return BEDROCK;
}
return Optional.ofNullable(typeTable.get(id, meta)).orElseGet(() -> {
log.warn("Unknow block type: {}:{}", id, meta);
return BEDROCK;
});
}
}