Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Code cleanup and implement index fix by @Matsv
Dieser Commit ist enthalten in:
Ursprung
abe3c4b0c9
Commit
8edb7048a1
@ -2,9 +2,6 @@ package us.myles.ViaVersion.api.minecraft.chunks;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Lennart on 6/23/2016.
|
|
||||||
*/
|
|
||||||
public interface ChunkSection {
|
public interface ChunkSection {
|
||||||
int getBlockId(int x, int y, int z);
|
int getBlockId(int x, int y, int z);
|
||||||
|
|
||||||
|
@ -3,9 +3,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Lennart on 6/23/2016.
|
|
||||||
*/
|
|
||||||
public class ChunkSection1_9_3_4 implements ChunkSection {
|
public class ChunkSection1_9_3_4 implements ChunkSection {
|
||||||
private final byte[] data;
|
private final byte[] data;
|
||||||
|
|
||||||
|
@ -61,9 +61,6 @@ public class Chunk1_9_1_2Type extends BaseChunkType {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuf output, Chunk input) throws Exception {
|
public void write(ByteBuf output, Chunk input) throws Exception {
|
||||||
// if (!(input instanceof Chunk1_9_1_2))
|
|
||||||
// throw new Exception("Tried to send the wrong chunk type from 1.9.3-4 chunk: " + input.getClass());
|
|
||||||
// Chunk1_9_1_2 chunk = (Chunk1_9_1_2) input;
|
|
||||||
Chunk chunk = input;
|
Chunk chunk = input;
|
||||||
|
|
||||||
output.writeInt(chunk.getX());
|
output.writeInt(chunk.getX());
|
||||||
@ -92,7 +89,5 @@ public class Chunk1_9_1_2Type extends BaseChunkType {
|
|||||||
if (chunk.isBiomeData()) {
|
if (chunk.isBiomeData()) {
|
||||||
output.writeBytes(chunk.getBiomeData());
|
output.writeBytes(chunk.getBiomeData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type.NBT_ARRAY.write(output, tags.toArray(new CompoundTag[0])); Written by the handler
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int index(int x, int y, int z) {
|
private int index(int x, int y, int z) {
|
||||||
return z << 8 | y << 4 | x;
|
return y << 8 | z << 4 | x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,12 +76,7 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
|||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||||
|
|
||||||
Chunk1_9_1_2Type type = new Chunk1_9_1_2Type(clientWorld);
|
Chunk1_9_1_2Type type = new Chunk1_9_1_2Type(clientWorld);
|
||||||
// if (wrapper.isReadable(type, 0)) {
|
Chunk chunk = wrapper.passthrough(type);
|
||||||
Chunk chunk = wrapper.read(type);
|
|
||||||
// if(rawChunk instanceof Chunk1_9to1_8) {
|
|
||||||
// throw new RuntimeException("Sweet berry candies");
|
|
||||||
// }
|
|
||||||
// Chunk1_9_1_2 chunk = (Chunk1_9_1_2) rawChunk;
|
|
||||||
|
|
||||||
List<CompoundTag> tags = new ArrayList<>();
|
List<CompoundTag> tags = new ArrayList<>();
|
||||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||||
@ -89,21 +84,20 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
|||||||
if (section == null)
|
if (section == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int x = 0; x < 16; x++)
|
for (int x = 0; x < 16; x++) {
|
||||||
for (int y = 0; y < 16; y++)
|
for (int y = 0; y < 16; y++) {
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
int block = section.getBlockId(x, y, z);
|
int block = section.getBlockId(x, y, z);
|
||||||
if (FakeTileEntity.hasBlock(block)) {
|
if (FakeTileEntity.hasBlock(block)) {
|
||||||
// NOT SURE WHY Y AND Z WORK THIS WAY, TODO: WORK OUT WHY THIS IS OR FIX W/E BROKE IT
|
tags.add(FakeTileEntity.getFromBlock(x + (chunk.getX() << 4), y + (i << 4), z + (chunk.getZ() << 4), block));
|
||||||
tags.add(FakeTileEntity.getFromBlock(x + (chunk.getX() << 4), z + (i << 4), y + (chunk.getZ() << 4), block));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper.write(type, chunk);
|
|
||||||
wrapper.write(Type.NBT_ARRAY, tags.toArray(new CompoundTag[0]));
|
wrapper.write(Type.NBT_ARRAY, tags.toArray(new CompoundTag[0]));
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -112,15 +106,17 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
|||||||
registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() {
|
registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
|
map(Type.INT); // 0 - Entity ID
|
||||||
|
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||||
|
map(Type.INT); // 2 - Dimension
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||||
wrapper.passthrough(Type.INT);
|
int dimensionId = wrapper.get(Type.INT, 1);
|
||||||
wrapper.passthrough(Type.UNSIGNED_BYTE);
|
|
||||||
int dimensionId = wrapper.passthrough(Type.INT);
|
|
||||||
clientChunks.setEnvironment(dimensionId);
|
clientChunks.setEnvironment(dimensionId);
|
||||||
wrapper.passthroughAll();
|
wrapper.passthroughAll(); // Todo: Fix this
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -130,13 +126,14 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
|||||||
registerOutgoing(State.PLAY, 0x33, 0x33, new PacketRemapper() {
|
registerOutgoing(State.PLAY, 0x33, 0x33, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
|
map(Type.INT); // 0 - Dimension ID
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||||
int dimensionId = wrapper.passthrough(Type.INT);
|
int dimensionId = wrapper.get(Type.INT, 0);
|
||||||
clientWorld.setEnvironment(dimensionId);
|
clientWorld.setEnvironment(dimensionId);
|
||||||
wrapper.passthroughAll();
|
wrapper.passthroughAll(); // Todo: Fix this
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class ChunkSection1_9to1_8 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int index(int x, int y, int z) {
|
private int index(int x, int y, int z) {
|
||||||
return z << 8 | y << 4 | x;
|
return y << 8 | z << 4 | x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren