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

@@ -31,15 +31,7 @@ public class AnvilBlock implements Block {
public BlockType getType() { public BlockType getType() {
final byte id = chunkSection.getBlocks().get((location.getY() << 8) + (location.getZ() << 4) + location.getX()); final byte id = chunkSection.getBlocks().get((location.getY() << 8) + (location.getZ() << 4) + location.getX());
final int meta = chunkSection.getBlocksMeta().get(location); final int meta = chunkSection.getBlocksMeta().get(location);
BlockType type = BlockType.getByIdMeta(id & 0xFF, meta); return BlockType.getByIdMeta(id & 0xFF, meta);
if (type.equals(BlockType.BEDROCK) && id != 7) {
log.warn("ChunkSection: {},{},{} | Block: {}",
chunkSection.getParent().getX(),
chunkSection.getY(),
chunkSection.getParent().getZ(),
location.toString());
}
return type;
} }
@Override @Override

View File

@@ -1,6 +1,7 @@
package mc.world.anvil; package mc.world.anvil;
import gnu.trove.list.TByteList; import gnu.trove.list.TByteList;
import gnu.trove.list.array.TByteArrayList;
import gnu.trove.list.linked.TByteLinkedList; import gnu.trove.list.linked.TByteLinkedList;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@@ -17,7 +18,7 @@ public class AnvilChunkSection implements ChunkSection {
@Setter @Setter
private int y; private int y;
private TByteList blocks = new TByteLinkedList(); private TByteList blocks = new TByteArrayList();
@Setter @Setter
private NibbleArray blocksMeta; private NibbleArray blocksMeta;
@Setter @Setter

View File

@@ -41,10 +41,6 @@ public class NibbleArray {
return isLowerNibble(idx) ? this.data[ni] & 0x0F : this.data[ni] >> 4 & 0x0F; 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) { public void set(int x, int y, int z, int value) {
if (value < 0) value = 0; if (value < 0) value = 0;
else if (value > 15) value = 15; else if (value > 15) value = 15;

View File

@@ -1,10 +1,13 @@
package mc.core.world.block; package mc.core.world.block;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
@Slf4j @Slf4j
@@ -491,25 +494,29 @@ public enum BlockType {
this.namedId = null; 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 @Getter
private final int id; private final int id;
@Getter @Getter
private final int meta; private final int meta;
@Getter @Getter
private final String namedId; 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;
});
}
} }

View File

@@ -6,5 +6,4 @@ dependencies {
/* Components */ /* Components */
compile (group: 'com.google.code.gson', name: 'gson', version: '2.8.5') compile (group: 'com.google.code.gson', name: 'gson', version: '2.8.5')
compile (group: 'net.sf.trove4j', name: 'trove4j', version: '3.0.3')
} }

View File

@@ -1,8 +1,6 @@
package mc.core.network.proto_1_12_2.packets; package mc.core.network.proto_1_12_2.packets;
import com.flowpowered.nbt.CompoundTag; import com.flowpowered.nbt.CompoundTag;
import gnu.trove.list.TIntList;
import gnu.trove.list.array.TIntArrayList;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -11,7 +9,6 @@ import mc.core.network.SCPacket;
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream; import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
import mc.core.utils.NibbleArray; import mc.core.utils.NibbleArray;
import mc.core.world.block.Block; import mc.core.world.block.Block;
import mc.core.world.block.BlockLocation;
import mc.core.world.block.BlockType; import mc.core.world.block.BlockType;
import mc.core.world.chunk.Chunk; import mc.core.world.chunk.Chunk;
import mc.core.world.chunk.ChunkSection; import mc.core.world.chunk.ChunkSection;
@@ -208,15 +205,11 @@ public class ChunkDataPacket implements SCPacket {
} }
private class PalettedChunkSection { private class PalettedChunkSection {
private TIntList palette = new TIntArrayList(); private List<Integer> palette = new ArrayList<>();
private byte[] blocks = new byte[4096]; private byte[] blocks = new byte[4096];
private NibbleArray blockLight = new NibbleArray(); private NibbleArray blockLight = new NibbleArray();
private NibbleArray skyLight = new NibbleArray(); private NibbleArray skyLight = new NibbleArray();
private int coordsToIndex(BlockLocation location) {
return coordsToIndex(location.getX(), location.getY(), location.getZ());
}
private int coordsToIndex(int x, int y, int z) { private int coordsToIndex(int x, int y, int z) {
return y << 8 | z << 4 | x; return y << 8 | z << 4 | x;
} }
@@ -238,14 +231,13 @@ public class ChunkDataPacket implements SCPacket {
} }
void addBlock(Block block, int skyLight) { void addBlock(Block block, int skyLight) {
BlockLocation location = new BlockLocation( final int bx = block.getLocation().getX() - ((block.getLocation().getX() >> 4) << 4);
block.getLocation().getX() - ((block.getLocation().getX() >> 4) << 4), final int by = block.getLocation().getY() - ((block.getLocation().getY() >> 4) << 4);
block.getLocation().getY() - ((block.getLocation().getY() >> 4) << 4), final int bz = block.getLocation().getZ() - ((block.getLocation().getZ() >> 4) << 4);
block.getLocation().getZ() - ((block.getLocation().getZ() >> 4) << 4)
); blocks[coordsToIndex(bx, by, bz)] = addBlockType(block.getType());
blocks[coordsToIndex(location)] = addBlockType(block.getType()); blockLight.set(bx, by, bz, block.getLight());
blockLight.set(location, block.getLight()); this.skyLight.set(bx, by, bz, skyLight);
this.skyLight.set(location, skyLight);
} }
void writeToNetStream(final NetOutputStream netOutputStream) { void writeToNetStream(final NetOutputStream netOutputStream) {
@@ -264,7 +256,7 @@ public class ChunkDataPacket implements SCPacket {
// <Palette> // <Palette>
netOutputStream.writeUnsignedByte(bitsPerBlock); // Bits Per Block netOutputStream.writeUnsignedByte(bitsPerBlock); // Bits Per Block
netOutputStream.writeVarInt(palette.size()); // Size of palette netOutputStream.writeVarInt(palette.size()); // Size of palette
palette.forEach(value -> { netOutputStream.writeVarInt(value); return true; }); // Palette palette.forEach(netOutputStream::writeVarInt); // Palette
// </Palette> // </Palette>
// <Data Array> // <Data Array>
final int dataLength = (4096/*16*16*16*/ * bitsPerBlock) / 64/*size of long in bits*/; final int dataLength = (4096/*16*16*16*/ * bitsPerBlock) / 64/*size of long in bits*/;