Skip to content

Commit

Permalink
Cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Dec 10, 2023
1 parent b517a95 commit 7ad946c
Show file tree
Hide file tree
Showing 73 changed files with 2,549 additions and 5,395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public class BlockList1_6 {

public static Block1_6 getByID(final int id) {
for (Block1_6 block : blockList) {
if(block.blockID == id) {
if (block.blockID == id) {
return block;
}
}
Expand All @@ -200,7 +200,7 @@ public static Block1_6 getByID(final int id) {

public static Block1_6 getByName(final String name) {
for (Block1_6 block : blockList) {
if(block.name.equalsIgnoreCase(name)) {
if (block.name.equalsIgnoreCase(name)) {
return block;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.base.ServerboundHandshakePackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
Expand All @@ -38,17 +37,12 @@ private PreNettyBaseProtocol() {

@Override
protected void registerPackets() {
this.registerServerbound(State.HANDSHAKE, ServerboundHandshakePackets.CLIENT_INTENTION.getId(), ServerboundHandshakePackets.CLIENT_INTENTION.getId(), new PacketHandlers() {
@Override
public void register() {
handler(wrapper -> {
wrapper.cancel();
wrapper.read(Type.VAR_INT); // protocolVersion
final String hostname = wrapper.read(Type.STRING); // hostName
final int port = wrapper.read(Type.UNSIGNED_SHORT); // port
wrapper.user().put(new HandshakeStorage(hostname, port));
});
}
this.registerServerbound(State.HANDSHAKE, ServerboundHandshakePackets.CLIENT_INTENTION.getId(), ServerboundHandshakePackets.CLIENT_INTENTION.getId(), wrapper -> {
wrapper.cancel();
wrapper.read(Type.VAR_INT); // protocolVersion
final String hostname = wrapper.read(Type.STRING); // hostName
final int port = wrapper.read(Type.UNSIGNED_SHORT); // port
wrapper.user().put(new HandshakeStorage(hostname, port));
});

// Copied from BaseProtocol1_7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,65 +34,29 @@ public enum ClientboundPacketsa1_0_15 implements ClientboundPacketType, PreNetty
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.skipBytes(1);
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.skipBytes(33);
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.skipBytes(9);
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.skipBytes(41);
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.skipBytes(6);
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.skipBytes(5);
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.skipBytes(5);
}),
CHAT_MESSAGE(3, (user, buf) -> PreNettyTypes.readUTF(buf)),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> buf.skipBytes(1)),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> buf.skipBytes(33)),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> buf.skipBytes(9)),
PLAYER_POSITION(13, (user, buf) -> buf.skipBytes(41)),
HELD_ITEM_CHANGE(16, (user, buf) -> buf.skipBytes(6)),
ADD_TO_INVENTORY(17, (user, buf) -> buf.skipBytes(5)),
ENTITY_ANIMATION(18, (user, buf) -> buf.skipBytes(5)),
SPAWN_PLAYER(20, (user, buf) -> {
buf.skipBytes(4);
PreNettyTypes.readUTF(buf);
buf.skipBytes(16);
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.skipBytes(22);
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.skipBytes(8);
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.skipBytes(17);
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.skipBytes(4);
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.skipBytes(4);
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.skipBytes(7);
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.skipBytes(6);
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.skipBytes(9);
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.skipBytes(18);
}),
PRE_CHUNK(50, (user, buf) -> {
buf.skipBytes(9);
}),
SPAWN_ITEM(21, (user, buf) -> buf.skipBytes(22)),
COLLECT_ITEM(22, (user, buf) -> buf.skipBytes(8)),
SPAWN_ENTITY(23, (user, buf) -> buf.skipBytes(17)),
DESTROY_ENTITIES(29, (user, buf) -> buf.skipBytes(4)),
ENTITY_MOVEMENT(30, (user, buf) -> buf.skipBytes(4)),
ENTITY_POSITION(31, (user, buf) -> buf.skipBytes(7)),
ENTITY_ROTATION(32, (user, buf) -> buf.skipBytes(6)),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> buf.skipBytes(9)),
ENTITY_TELEPORT(34, (user, buf) -> buf.skipBytes(18)),
PRE_CHUNK(50, (user, buf) -> buf.skipBytes(9)),
CHUNK_DATA(51, (user, buf) -> {
buf.skipBytes(13);
int x = buf.readInt();
Expand All @@ -105,12 +69,8 @@ public enum ClientboundPacketsa1_0_15 implements ClientboundPacketType, PreNetty
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.skipBytes(11);
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
BLOCK_CHANGE(53, (user, buf) -> buf.skipBytes(11)),
DISCONNECT(255, (user, buf) -> PreNettyTypes.readUTF(buf));

private static final ClientboundPacketsa1_0_15[] REGISTRY = new ClientboundPacketsa1_0_15[256];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import net.raphimc.vialegacy.api.protocol.StatelessProtocol;
import net.raphimc.vialegacy.api.splitter.PreNettySplitter;
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.ClientboundPacketsa1_0_16;
Expand All @@ -34,16 +33,11 @@ public Protocola1_0_16_2toa1_0_15() {

@Override
protected void registerPackets() {
this.registerServerbound(ServerboundPacketsa1_0_17.HANDSHAKE, null, new PacketHandlers() {
@Override
public void register() {
handler(wrapper -> {
wrapper.cancel();
final PacketWrapper handshake = PacketWrapper.create(ClientboundPacketsa1_0_16.HANDSHAKE, wrapper.user());
handshake.write(Typesb1_7_0_3.STRING, "-"); // server hash
handshake.send(Protocola1_0_16_2toa1_0_15.class);
});
}
this.registerServerbound(ServerboundPacketsa1_0_17.HANDSHAKE, null, wrapper -> {
wrapper.cancel();
final PacketWrapper handshake = PacketWrapper.create(ClientboundPacketsa1_0_16.HANDSHAKE, wrapper.user());
handshake.write(Typesb1_7_0_3.STRING, "-"); // server hash
handshake.send(Protocola1_0_16_2toa1_0_15.class);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,17 @@ public enum ServerboundPacketsa1_0_15 implements ServerboundPacketType, PreNetty
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.skipBytes(1);
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.skipBytes(33);
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.skipBytes(9);
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.skipBytes(41);
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.skipBytes(11);
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.skipBytes(12);
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.skipBytes(6);
}),
ANIMATION(18, (user, buf) -> {
buf.skipBytes(5);
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.skipBytes(22);
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
CHAT_MESSAGE(3, (user, buf) -> PreNettyTypes.readUTF(buf)),
PLAYER_MOVEMENT(10, (user, buf) -> buf.skipBytes(1)),
PLAYER_POSITION(11, (user, buf) -> buf.skipBytes(33)),
PLAYER_ROTATION(12, (user, buf) -> buf.skipBytes(9)),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> buf.skipBytes(41)),
PLAYER_DIGGING(14, (user, buf) -> buf.skipBytes(11)),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> buf.skipBytes(12)),
HELD_ITEM_CHANGE(16, (user, buf) -> buf.skipBytes(6)),
ANIMATION(18, (user, buf) -> buf.skipBytes(5)),
SPAWN_ITEM(21, (user, buf) -> buf.skipBytes(22)),
DISCONNECT(255, (user, buf) -> PreNettyTypes.readUTF(buf));

private static final ServerboundPacketsa1_0_15[] REGISTRY = new ServerboundPacketsa1_0_15[256];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,68 +35,30 @@ public enum ClientboundPacketsa1_0_16 implements ClientboundPacketType, PreNetty
readUTF(buf);
readUTF(buf);
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.skipBytes(1);
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.skipBytes(33);
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.skipBytes(9);
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.skipBytes(41);
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.skipBytes(6);
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.skipBytes(5);
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.skipBytes(5);
}),
HANDSHAKE(2, (user, buf) -> readUTF(buf)),
CHAT_MESSAGE(3, (user, buf) -> readUTF(buf)),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> buf.skipBytes(1)),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> buf.skipBytes(33)),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> buf.skipBytes(9)),
PLAYER_POSITION(13, (user, buf) -> buf.skipBytes(41)),
HELD_ITEM_CHANGE(16, (user, buf) -> buf.skipBytes(6)),
ADD_TO_INVENTORY(17, (user, buf) -> buf.skipBytes(5)),
ENTITY_ANIMATION(18, (user, buf) -> buf.skipBytes(5)),
SPAWN_PLAYER(20, (user, buf) -> {
buf.skipBytes(4);
readUTF(buf);
buf.skipBytes(16);
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.skipBytes(22);
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.skipBytes(8);
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.skipBytes(17);
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.skipBytes(4);
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.skipBytes(4);
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.skipBytes(7);
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.skipBytes(6);
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.skipBytes(9);
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.skipBytes(18);
}),
PRE_CHUNK(50, (user, buf) -> {
buf.skipBytes(9);
}),
SPAWN_ITEM(21, (user, buf) -> buf.skipBytes(22)),
COLLECT_ITEM(22, (user, buf) -> buf.skipBytes(8)),
SPAWN_ENTITY(23, (user, buf) -> buf.skipBytes(17)),
DESTROY_ENTITIES(29, (user, buf) -> buf.skipBytes(4)),
ENTITY_MOVEMENT(30, (user, buf) -> buf.skipBytes(4)),
ENTITY_POSITION(31, (user, buf) -> buf.skipBytes(7)),
ENTITY_ROTATION(32, (user, buf) -> buf.skipBytes(6)),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> buf.skipBytes(9)),
ENTITY_TELEPORT(34, (user, buf) -> buf.skipBytes(18)),
PRE_CHUNK(50, (user, buf) -> buf.skipBytes(9)),
CHUNK_DATA(51, (user, buf) -> {
buf.skipBytes(13);
int x = buf.readInt();
Expand All @@ -109,12 +71,8 @@ public enum ClientboundPacketsa1_0_16 implements ClientboundPacketType, PreNetty
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.skipBytes(11);
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
BLOCK_CHANGE(53, (user, buf) -> buf.skipBytes(11)),
DISCONNECT(255, (user, buf) -> readUTF(buf));

private static final ClientboundPacketsa1_0_16[] REGISTRY = new ClientboundPacketsa1_0_16[256];

Expand Down
Loading

0 comments on commit 7ad946c

Please sign in to comment.