use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSection in project ViaVersion by ViaVersion.
the class Protocol1_12To1_11_1 method registerPackets.
@Override
protected void registerPackets() {
metadataRewriter.register();
itemRewriter.register();
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - UUID
map(Type.UUID);
// 2 - Type
map(Type.BYTE);
// Track Entity
handler(metadataRewriter.objectTrackerHandler());
}
});
registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Entity UUID
map(Type.UUID);
// 2 - Entity Type
map(Type.VAR_INT);
// 3 - X
map(Type.DOUBLE);
// 4 - Y
map(Type.DOUBLE);
// 5 - Z
map(Type.DOUBLE);
// 6 - Yaw
map(Type.BYTE);
// 7 - Pitch
map(Type.BYTE);
// 8 - Head Pitch
map(Type.BYTE);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
// 12 - Metadata
map(Types1_12.METADATA_LIST);
// Track mob and rewrite metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_12.METADATA_LIST));
}
});
registerClientbound(ClientboundPackets1_9_3.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if (!Via.getConfig().is1_12NBTArrayFix())
return;
try {
JsonElement obj = Protocol1_9To1_8.FIX_JSON.transform(null, wrapper.passthrough(Type.COMPONENT).toString());
TranslateRewriter.toClient(obj, wrapper.user());
ChatItemRewriter.toClient(obj, wrapper.user());
wrapper.set(Type.COMPONENT, 0, obj);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
});
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
Chunk chunk = wrapper.passthrough(type);
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int block = section.getBlockWithoutData(x, y, z);
// Is this a bed?
if (block == 26) {
// NBT -> { color:14, x:132, y:64, z:222, id:"minecraft:bed" } (Debug output)
CompoundTag tag = new CompoundTag();
// Set color to red (Default in previous versions)
tag.put("color", new IntTag(14));
tag.put("x", new IntTag(x + (chunk.getX() << 4)));
tag.put("y", new IntTag(y + (i << 4)));
tag.put("z", new IntTag(z + (chunk.getZ() << 4)));
tag.put("id", new StringTag("minecraft:bed"));
// Add a fake block entity
chunk.getBlockEntities().add(tag);
}
}
}
}
}
}
});
}
});
metadataRewriter.registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_12.METADATA_LIST);
registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
map(Type.UNSIGNED_BYTE);
map(Type.INT);
handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
});
}
});
registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
});
}
});
new SoundRewriter(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND);
// New packet at 0x01
cancelServerbound(ServerboundPackets1_12.PREPARE_CRAFTING_GRID);
// Client Settings (max length changed)
registerServerbound(ServerboundPackets1_12.CLIENT_SETTINGS, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Locale
map(Type.STRING);
// 1 - view distance
map(Type.BYTE);
// 2 - chat mode
map(Type.VAR_INT);
// 3 - chat colors
map(Type.BOOLEAN);
// 4 - chat flags
map(Type.UNSIGNED_BYTE);
// 5 - main hand
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// As part of the fix for MC-111054, the max length of
// the locale was raised to 16 (from 7), and the client
// now makes sure that resource packs have names in that
// length. However, for older servers, it is still 7,
// and thus the server will reject it (and the client
// won't know that the pack's invalid).
// The fix is to just silently lower the length. The
// server doesn't actually use the locale anywhere, so
// this is fine.
String locale = wrapper.get(Type.STRING, 0);
if (locale.length() > 7) {
wrapper.set(Type.STRING, 0, locale.substring(0, 7));
}
}
});
}
});
// New packet at 0x17
cancelServerbound(ServerboundPackets1_12.RECIPE_BOOK_DATA);
// New packet 0x19
cancelServerbound(ServerboundPackets1_12.ADVANCEMENT_TAB);
}
use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSection in project ViaVersion by ViaVersion.
the class WorldPackets method register.
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION);
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld));
for (ChunkSection section : chunk.getSections()) {
if (section == null)
continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(section.getPaletteEntry(i)));
}
}
}
});
}
});
blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_13.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Effect Id
map(Type.INT);
// Location
map(Type.POSITION);
// Data
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
if (id == 2000) {
// Smoke
int data = wrapper.get(Type.INT, 1);
switch(data) {
case // North
1:
// North
wrapper.set(Type.INT, 1, 2);
break;
// North-West
case 0:
// West
case 3:
case // South-West
6:
// West
wrapper.set(Type.INT, 1, 4);
break;
// North-East
case 2:
// East
case 5:
case // South-East
8:
// East
wrapper.set(Type.INT, 1, 5);
break;
case // South
7:
// South
wrapper.set(Type.INT, 1, 3);
break;
default:
// Self and other directions
// Down
wrapper.set(Type.INT, 1, 0);
break;
}
} else if (id == 1010) {
// Play record
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(wrapper.get(Type.INT, 1)));
} else if (id == 2001) {
// Block break + block break sound
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewBlockStateId(wrapper.get(Type.INT, 1)));
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Store the player
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Dimension ID
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
}
use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSection in project ViaVersion by ViaVersion.
the class Protocol1_10To1_9_3_4 method registerPackets.
@Override
protected void registerPackets() {
itemRewriter.register();
// Named sound effect
registerClientbound(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sound name
map(Type.STRING);
// 1 - Sound Category
map(Type.VAR_INT);
// 2 - x
map(Type.INT);
// 3 - y
map(Type.INT);
// 4 - z
map(Type.INT);
// 5 - Volume
map(Type.FLOAT);
// 6 - Pitch
map(Type.UNSIGNED_BYTE, TO_NEW_PITCH);
}
});
// Sound effect
registerClientbound(ClientboundPackets1_9_3.SOUND, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sound name
map(Type.VAR_INT);
// 1 - Sound Category
map(Type.VAR_INT);
// 2 - x
map(Type.INT);
// 3 - y
map(Type.INT);
// 4 - z
map(Type.INT);
// 5 - Volume
map(Type.FLOAT);
// 6 - Pitch
map(Type.UNSIGNED_BYTE, TO_NEW_PITCH);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, getNewSoundId(id));
}
});
}
});
// Metadata packet
registerClientbound(ClientboundPackets1_9_3.ENTITY_METADATA, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Metadata list
map(Types1_9.METADATA_LIST, TRANSFORM_METADATA);
}
});
// Spawn Mob
registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - UUID
map(Type.UUID);
// 2 - Entity Type
map(Type.UNSIGNED_BYTE);
// 3 - X
map(Type.DOUBLE);
// 4 - Y
map(Type.DOUBLE);
// 5 - Z
map(Type.DOUBLE);
// 6 - Yaw
map(Type.BYTE);
// 7 - Pitch
map(Type.BYTE);
// 8 - Head Pitch
map(Type.BYTE);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
// 12 - Metadata
map(Types1_9.METADATA_LIST, TRANSFORM_METADATA);
}
});
// Spawn Player
registerClientbound(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Player UUID
map(Type.UUID);
// 2 - X
map(Type.DOUBLE);
// 3 - Y
map(Type.DOUBLE);
// 4 - Z
map(Type.DOUBLE);
// 5 - Yaw
map(Type.BYTE);
// 6 - Pitch
map(Type.BYTE);
// 7 - Metadata list
map(Types1_9.METADATA_LIST, TRANSFORM_METADATA);
}
});
// Join Game
registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
// Respawn
registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Dimension ID
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
// Chunk Data
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new Chunk1_9_3_4Type(clientWorld));
if (Via.getConfig().isReplacePistons()) {
int replacementId = Via.getConfig().getPistonReplacementId();
for (ChunkSection section : chunk.getSections()) {
if (section == null)
continue;
section.replacePaletteEntry(36, replacementId);
}
}
}
});
}
});
// Packet Send ResourcePack
registerClientbound(ClientboundPackets1_9_3.RESOURCE_PACK, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - URL
map(Type.STRING);
// 1 - Hash
map(Type.STRING);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ResourcePackTracker tracker = wrapper.user().get(ResourcePackTracker.class);
// Store the hash for resourcepack status
tracker.setLastHash(wrapper.get(Type.STRING, 1));
}
});
}
});
// Packet ResourcePack status
registerServerbound(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ResourcePackTracker tracker = wrapper.user().get(ResourcePackTracker.class);
wrapper.write(Type.STRING, tracker.getLastHash());
wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT));
}
});
}
});
}
use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSection in project ViaVersion by ViaVersion.
the class Chunk1_16Type method write.
@Override
public void write(ByteBuf output, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk());
output.writeBoolean(chunk.isIgnoreOldLightData());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NBT.write(output, chunk.getHeightMap());
// Write biome data
if (chunk.isBiomeData()) {
for (int value : chunk.getBiomeData()) {
output.writeInt(value);
}
}
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
// Section not set
if (section == null)
continue;
buf.writeShort(section.getNonAirBlocksCount());
Types1_16.CHUNK_SECTION.write(buf, section);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes());
output.writeBytes(buf);
} finally {
// release buffer
buf.release();
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSection in project ViaVersion by ViaVersion.
the class Chunk1_9_1_2Type method write.
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
// Section not set
if (section == null)
continue;
Types1_9.CHUNK_SECTION.write(buf, section);
section.getLight().writeBlockLight(buf);
// No sky light, we're done here.
if (!section.getLight().hasSkyLight())
continue;
section.getLight().writeSkyLight(buf);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
output.writeBytes(buf);
} finally {
// release buffer
buf.release();
}
// Write biome data
if (chunk.isBiomeData()) {
for (int biome : chunk.getBiomeData()) {
output.writeByte((byte) biome);
}
}
}
Aggregations