Use enhanced switches in more places (#4043)

This commit is contained in:
RK_01 2024-07-24 14:32:36 +02:00 committed by GitHub
parent 2b508567db
commit b1f64fd081
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 120 additions and 205 deletions

View File

@ -2,7 +2,7 @@
charset = utf-8 charset = utf-8
indent_size = 4 indent_size = 4
indent_style = space indent_style = space
insert_final_newline = false insert_final_newline = true
tab_width = 4 tab_width = 4
[*.java] [*.java]
@ -13,4 +13,4 @@ ij_java_generate_final_locals = true
ij_java_generate_final_parameters = true ij_java_generate_final_parameters = true
[{*.json,*.yml}] [{*.json,*.yml}]
indent_size = 2 indent_size = 2

View File

@ -246,7 +246,7 @@ public class CommonBoss implements BossBar {
wrapper.write(Types.UUID, uuid); wrapper.write(Types.UUID, uuid);
wrapper.write(Types.VAR_INT, action.getId()); wrapper.write(Types.VAR_INT, action.getId());
switch (action) { switch (action) {
case ADD: case ADD -> {
try { try {
wrapper.write(Types.COMPONENT, JsonParser.parseString(this.title)); wrapper.write(Types.COMPONENT, JsonParser.parseString(this.title));
} catch (Exception e) { } catch (Exception e) {
@ -256,26 +256,22 @@ public class CommonBoss implements BossBar {
wrapper.write(Types.VAR_INT, color.getId()); wrapper.write(Types.VAR_INT, color.getId());
wrapper.write(Types.VAR_INT, style.getId()); wrapper.write(Types.VAR_INT, style.getId());
wrapper.write(Types.BYTE, (byte) flagToBytes()); wrapper.write(Types.BYTE, (byte) flagToBytes());
break; }
case REMOVE: case REMOVE -> {
break; }
case UPDATE_HEALTH: case UPDATE_HEALTH -> wrapper.write(Types.FLOAT, health);
wrapper.write(Types.FLOAT, health); case UPDATE_TITLE -> {
break;
case UPDATE_TITLE:
try { try {
wrapper.write(Types.COMPONENT, JsonParser.parseString(this.title)); wrapper.write(Types.COMPONENT, JsonParser.parseString(this.title));
} catch (Exception e) { } catch (Exception e) {
wrapper.write(Types.COMPONENT, ComponentUtil.plainToJson(this.title)); wrapper.write(Types.COMPONENT, ComponentUtil.plainToJson(this.title));
} }
break; }
case UPDATE_STYLE: case UPDATE_STYLE -> {
wrapper.write(Types.VAR_INT, color.getId()); wrapper.write(Types.VAR_INT, color.getId());
wrapper.write(Types.VAR_INT, style.getId()); wrapper.write(Types.VAR_INT, style.getId());
break; }
case UPDATE_FLAGS: case UPDATE_FLAGS -> wrapper.write(Types.BYTE, (byte) flagToBytes());
wrapper.write(Types.BYTE, (byte) flagToBytes());
break;
} }
return wrapper; return wrapper;

View File

@ -779,7 +779,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
// Clone item arrays because array and item are mutable, also make sure the array type is the interface // Clone item arrays because array and item are mutable, also make sure the array type is the interface
switch (recipe.type()) { switch (recipe.type()) {
case "crafting_shapeless": { case "crafting_shapeless" -> {
recipesPacket.write(Types.STRING, recipe.group()); recipesPacket.write(Types.STRING, recipe.group());
recipesPacket.write(Types.VAR_INT, recipe.ingredients().length); recipesPacket.write(Types.VAR_INT, recipe.ingredients().length);
for (Item[] ingredient : recipe.ingredients()) { for (Item[] ingredient : recipe.ingredients()) {
@ -791,9 +791,8 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
recipesPacket.write(Types.ITEM1_13_ARRAY, clone); recipesPacket.write(Types.ITEM1_13_ARRAY, clone);
} }
recipesPacket.write(Types.ITEM1_13, recipe.result().copy()); recipesPacket.write(Types.ITEM1_13, recipe.result().copy());
break;
} }
case "crafting_shaped": { case "crafting_shaped" -> {
recipesPacket.write(Types.VAR_INT, recipe.width()); recipesPacket.write(Types.VAR_INT, recipe.width());
recipesPacket.write(Types.VAR_INT, recipe.height()); recipesPacket.write(Types.VAR_INT, recipe.height());
recipesPacket.write(Types.STRING, recipe.group()); recipesPacket.write(Types.STRING, recipe.group());
@ -806,9 +805,8 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
recipesPacket.write(Types.ITEM1_13_ARRAY, clone); recipesPacket.write(Types.ITEM1_13_ARRAY, clone);
} }
recipesPacket.write(Types.ITEM1_13, recipe.result().copy()); recipesPacket.write(Types.ITEM1_13, recipe.result().copy());
break;
} }
case "smelting": { case "smelting" -> {
recipesPacket.write(Types.STRING, recipe.group()); recipesPacket.write(Types.STRING, recipe.group());
Item[] ingredient = new Item[recipe.ingredient().length]; Item[] ingredient = new Item[recipe.ingredient().length];
for (int i = 0; i < ingredient.length; i++) { for (int i = 0; i < ingredient.length; i++) {
@ -819,7 +817,6 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
recipesPacket.write(Types.ITEM1_13, recipe.result().copy()); recipesPacket.write(Types.ITEM1_13, recipe.result().copy());
recipesPacket.write(Types.FLOAT, recipe.experience()); recipesPacket.write(Types.FLOAT, recipe.experience());
recipesPacket.write(Types.VAR_INT, recipe.cookingTime()); recipesPacket.write(Types.VAR_INT, recipe.cookingTime());
break;
} }
} }
} }
@ -922,4 +919,4 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
public ComponentRewriter1_13 getComponentRewriter() { public ComponentRewriter1_13 getComponentRewriter() {
return componentRewriter; return componentRewriter;
} }
} }

View File

@ -61,23 +61,14 @@ public class StairConnectionHandler implements ConnectionHandler {
byte shape; byte shape;
switch (blockData.getValue("shape")) { switch (blockData.getValue("shape")) {
case "straight": case "straight" -> shape = 0;
shape = 0; case "inner_left" -> shape = 1;
break; case "inner_right" -> shape = 2;
case "inner_left": case "outer_left" -> shape = 3;
shape = 1; case "outer_right" -> shape = 4;
break; default -> {
case "inner_right":
shape = 2;
break;
case "outer_left":
shape = 3;
break;
case "outer_right":
shape = 4;
break;
default:
return; return;
}
} }
StairData stairData = new StairData( StairData stairData = new StairData(

View File

@ -453,30 +453,22 @@ public class ItemPacketRewriter1_13 extends ItemRewriter<ClientboundPackets1_12_
public static String getNewPluginChannelId(String old) { public static String getNewPluginChannelId(String old) {
// Default channels that should not be modifiable // Default channels that should not be modifiable
switch (old) { return switch (old) {
case "MC|TrList": case "MC|TrList" -> "minecraft:trader_list";
return "minecraft:trader_list"; case "MC|Brand" -> "minecraft:brand";
case "MC|Brand": case "MC|BOpen" -> "minecraft:book_open";
return "minecraft:brand"; case "MC|DebugPath" -> "minecraft:debug/paths";
case "MC|BOpen": case "MC|DebugNeighborsUpdate" -> "minecraft:debug/neighbors_update";
return "minecraft:book_open"; case "REGISTER" -> "minecraft:register";
case "MC|DebugPath": case "UNREGISTER" -> "minecraft:unregister";
return "minecraft:debug/paths"; case "BungeeCord" -> "bungeecord:main";
case "MC|DebugNeighborsUpdate": case "bungeecord:main" -> null;
return "minecraft:debug/neighbors_update"; default -> {
case "REGISTER":
return "minecraft:register";
case "UNREGISTER":
return "minecraft:unregister";
case "BungeeCord":
return "bungeecord:main";
case "bungeecord:main":
return null;
default:
String mappedChannel = Protocol1_12_2To1_13.MAPPINGS.getChannelMappings().get(old); String mappedChannel = Protocol1_12_2To1_13.MAPPINGS.getChannelMappings().get(old);
if (mappedChannel != null) return mappedChannel; if (mappedChannel != null) yield mappedChannel;
return MappingData1_13.validateNewChannel(old); yield MappingData1_13.validateNewChannel(old);
} }
};
} }
@Override @Override
@ -687,28 +679,21 @@ public class ItemPacketRewriter1_13 extends ItemRewriter<ClientboundPackets1_12_
if (newId == null) return null; if (newId == null) return null;
// Default channels that should not be modifiable // Default channels that should not be modifiable
switch (newId) { return switch (newId) {
case "minecraft:trader_list": case "minecraft:trader_list" -> "MC|TrList";
return "MC|TrList"; case "minecraft:book_open" -> "MC|BOpen";
case "minecraft:book_open": case "minecraft:debug/paths" -> "MC|DebugPath";
return "MC|BOpen"; case "minecraft:debug/neighbors_update" -> "MC|DebugNeighborsUpdate";
case "minecraft:debug/paths": case "minecraft:register" -> "REGISTER";
return "MC|DebugPath"; case "minecraft:unregister" -> "UNREGISTER";
case "minecraft:debug/neighbors_update": case "minecraft:brand" -> "MC|Brand";
return "MC|DebugNeighborsUpdate"; case "bungeecord:main" -> "BungeeCord";
case "minecraft:register": default -> {
return "REGISTER";
case "minecraft:unregister":
return "UNREGISTER";
case "minecraft:brand":
return "MC|Brand";
case "bungeecord:main":
return "BungeeCord";
default:
String mappedChannel = Protocol1_12_2To1_13.MAPPINGS.getChannelMappings().inverse().get(newId); String mappedChannel = Protocol1_12_2To1_13.MAPPINGS.getChannelMappings().inverse().get(newId);
if (mappedChannel != null) return mappedChannel; if (mappedChannel != null) yield mappedChannel;
return newId.length() > 20 ? newId.substring(0, 20) : newId; yield newId.length() > 20 ? newId.substring(0, 20) : newId;
} }
};
} }
public static boolean isDamageable(int id) { public static boolean isDamageable(int id) {
@ -724,4 +709,4 @@ public class ItemPacketRewriter1_13 extends ItemRewriter<ClientboundPackets1_12_
|| id == 442 // shield || id == 442 // shield
|| id == 443; // elytra || id == 443; // elytra
} }
} }

View File

@ -86,42 +86,21 @@ public class ItemPacketRewriter1_14 extends ItemRewriter<ClientboundPackets1_13,
int typeId = -1; int typeId = -1;
switch (type) { switch (type) {
case "minecraft:crafting_table": case "minecraft:crafting_table" -> typeId = 11;
typeId = 11; case "minecraft:furnace" -> typeId = 13;
break; case "minecraft:dropper", "minecraft:dispenser" -> typeId = 6;
case "minecraft:furnace": case "minecraft:enchanting_table" -> typeId = 12;
typeId = 13; case "minecraft:brewing_stand" -> typeId = 10;
break; case "minecraft:villager" -> typeId = 18;
case "minecraft:dropper", "minecraft:dispenser": case "minecraft:beacon" -> typeId = 8;
typeId = 6; case "minecraft:anvil" -> typeId = 7;
break; case "minecraft:hopper" -> typeId = 15;
case "minecraft:enchanting_table": case "minecraft:shulker_box" -> typeId = 19;
typeId = 12; default -> {
break;
case "minecraft:brewing_stand":
typeId = 10;
break;
case "minecraft:villager":
typeId = 18;
break;
case "minecraft:beacon":
typeId = 8;
break;
case "minecraft:anvil":
typeId = 7;
break;
case "minecraft:hopper":
typeId = 15;
break;
case "minecraft:shulker_box":
typeId = 19;
break;
case "minecraft:container", "minecraft:chest":
default:
if (slots > 0 && slots <= 54) { if (slots > 0 && slots <= 54) {
typeId = slots / 9 - 1; typeId = slots / 9 - 1;
} }
break; }
} }
if (typeId == -1) { if (typeId == -1) {

View File

@ -51,22 +51,23 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
String dimensionName; String dimensionName;
String outputName; String outputName;
switch (dimension) { switch (dimension) {
case -1: case -1 -> {
dimensionName = "minecraft:the_nether"; dimensionName = "minecraft:the_nether";
outputName = map.nether(); outputName = map.nether();
break; }
case 0: case 0 -> {
dimensionName = "minecraft:overworld"; dimensionName = "minecraft:overworld";
outputName = map.overworld(); outputName = map.overworld();
break; }
case 1: case 1 -> {
dimensionName = "minecraft:the_end"; dimensionName = "minecraft:the_end";
outputName = map.end(); outputName = map.end();
break; }
default: default -> {
protocol.getLogger().warning("Invalid dimension id: " + dimension); protocol.getLogger().warning("Invalid dimension id: " + dimension);
dimensionName = "minecraft:overworld"; dimensionName = "minecraft:overworld";
outputName = map.overworld(); outputName = map.overworld();
}
} }
wrapper.write(Types.STRING, dimensionName); // dimension wrapper.write(Types.STRING, dimensionName); // dimension
@ -231,4 +232,4 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
public EntityType typeFromId(int type) { public EntityType typeFromId(int type) {
return EntityTypes1_16.getTypeFromId(type); return EntityTypes1_16.getTypeFromId(type);
} }
} }

View File

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.v1_19_1to1_19_3.rewriter;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.Protocol1_19_1To1_19_3; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.Protocol1_19_1To1_19_3;
@ -66,7 +65,7 @@ public final class ItemPacketRewriter1_19_3 extends ItemRewriter<ClientboundPack
final String type = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); final String type = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
wrapper.passthrough(Types.STRING); // Recipe Identifier wrapper.passthrough(Types.STRING); // Recipe Identifier
switch (type) { switch (type) {
case "crafting_shapeless": { case "crafting_shapeless" -> {
wrapper.passthrough(Types.STRING); // Group wrapper.passthrough(Types.STRING); // Group
wrapper.write(Types.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY); wrapper.write(Types.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY);
final int ingredients = wrapper.passthrough(Types.VAR_INT); final int ingredients = wrapper.passthrough(Types.VAR_INT);
@ -77,9 +76,8 @@ public final class ItemPacketRewriter1_19_3 extends ItemRewriter<ClientboundPack
} }
} }
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result
break;
} }
case "crafting_shaped": { case "crafting_shaped" -> {
final int ingredients = wrapper.passthrough(Types.VAR_INT) * wrapper.passthrough(Types.VAR_INT); final int ingredients = wrapper.passthrough(Types.VAR_INT) * wrapper.passthrough(Types.VAR_INT);
wrapper.passthrough(Types.STRING); // Group wrapper.passthrough(Types.STRING); // Group
wrapper.write(Types.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY); wrapper.write(Types.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY);
@ -90,12 +88,8 @@ public final class ItemPacketRewriter1_19_3 extends ItemRewriter<ClientboundPack
} }
} }
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result
break;
} }
case "smelting": case "smelting", "campfire_cooking", "blasting", "smoking" -> {
case "campfire_cooking":
case "blasting":
case "smoking":
wrapper.passthrough(Types.STRING); // Group wrapper.passthrough(Types.STRING); // Group
wrapper.write(Types.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY); wrapper.write(Types.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY);
final Item[] items = wrapper.passthrough(Types.ITEM1_13_2_ARRAY); // Ingredients final Item[] items = wrapper.passthrough(Types.ITEM1_13_2_ARRAY); // Ingredients
@ -105,25 +99,12 @@ public final class ItemPacketRewriter1_19_3 extends ItemRewriter<ClientboundPack
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result
wrapper.passthrough(Types.FLOAT); // EXP wrapper.passthrough(Types.FLOAT); // EXP
wrapper.passthrough(Types.VAR_INT); // Cooking time wrapper.passthrough(Types.VAR_INT); // Cooking time
break; }
case "crafting_special_armordye": case "crafting_special_armordye", "crafting_special_bookcloning", "crafting_special_mapcloning", "crafting_special_mapextending",
case "crafting_special_bookcloning": "crafting_special_firework_rocket", "crafting_special_firework_star", "crafting_special_firework_star_fade", "crafting_special_tippedarrow",
case "crafting_special_mapcloning": "crafting_special_bannerduplicate", "crafting_special_shielddecoration", "crafting_special_shulkerboxcoloring", "crafting_special_suspiciousstew",
case "crafting_special_mapextending": "crafting_special_repairitem" -> wrapper.write(Types.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY);
case "crafting_special_firework_rocket": default -> recipeRewriter.handleRecipeType(wrapper, type);
case "crafting_special_firework_star":
case "crafting_special_firework_star_fade":
case "crafting_special_tippedarrow":
case "crafting_special_bannerduplicate":
case "crafting_special_shielddecoration":
case "crafting_special_shulkerboxcoloring":
case "crafting_special_suspiciousstew":
case "crafting_special_repairitem":
wrapper.write(Types.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY);
break;
default:
recipeRewriter.handleRecipeType(wrapper, type);
break;
} }
} }
}); });

View File

@ -399,19 +399,13 @@ public final class Protocol1_19To1_19_1 extends AbstractProtocol<ClientboundPack
for (final StringTag element : parameters) { for (final StringTag element : parameters) {
JsonElement argument = null; JsonElement argument = null;
switch (element.getValue()) { switch (element.getValue()) {
case "sender": case "sender" -> argument = senderName;
argument = senderName; case "content" -> argument = message;
break; case "team_name", "target" /*So that this method can also be used in VB*/ -> {
case "content":
argument = message;
break;
case "team_name":
case "target": // So that this method can also be used in VB
Preconditions.checkNotNull(targetName, "Team name is null"); Preconditions.checkNotNull(targetName, "Team name is null");
argument = targetName; argument = targetName;
break; }
default: default -> LOGGER.warning("Unknown parameter for chat decoration: " + element.getValue());
LOGGER.warning("Unknown parameter for chat decoration: " + element.getValue());
} }
if (argument != null) { if (argument != null) {
arguments.add(SerializerVersion.V1_18.toComponent(argument)); arguments.add(SerializerVersion.V1_18.toComponent(argument));

View File

@ -67,15 +67,16 @@ public class Protocol1_8To1_9 extends AbstractProtocol<ClientboundPackets1_8, Cl
} }
public static boolean isSword(int id) { public static boolean isSword(int id) {
return switch (id) { switch (id) {
case 267, // Iron sword case 267: // Iron sword
268, // Wooden sword case 268: // Wooden sword
272, // Stone sword case 272: // Stone sword
276, // Diamond sword case 276: // Diamond sword
283 // Gold sword case 283: // Gold sword
-> true; return true;
default -> false; default:
}; return false;
}
} }
@Override @Override

View File

@ -23,10 +23,10 @@ import com.viaversion.viaversion.api.minecraft.EulerAngle;
import com.viaversion.viaversion.api.minecraft.Vector; import com.viaversion.viaversion.api.minecraft.Vector;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType; import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_8; import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_8;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
@ -405,7 +405,7 @@ public class EntityPacketRewriter1_9 extends EntityRewriter<ClientboundPackets1_
Object value = data.getValue(); Object value = data.getValue();
switch (dataIndex.getNewType()) { switch (dataIndex.getNewType()) {
case BYTE: case BYTE -> {
// convert from int, byte // convert from int, byte
if (dataIndex.getOldType() == EntityDataTypes1_8.BYTE) { if (dataIndex.getOldType() == EntityDataTypes1_8.BYTE) {
data.setValue(value); data.setValue(value);
@ -423,8 +423,8 @@ public class EntityPacketRewriter1_9 extends EntityRewriter<ClientboundPackets1_
EntityDataType dataType = EntityDataIndex1_9.PLAYER_HAND.getNewType(); EntityDataType dataType = EntityDataIndex1_9.PLAYER_HAND.getNewType();
event.createExtraData(new EntityData(newIndex, dataType, val)); event.createExtraData(new EntityData(newIndex, dataType, val));
} }
break; }
case OPTIONAL_UUID: case OPTIONAL_UUID -> {
String owner = (String) value; String owner = (String) value;
UUID toWrite = null; UUID toWrite = null;
if (!owner.isEmpty()) { if (!owner.isEmpty()) {
@ -434,8 +434,8 @@ public class EntityPacketRewriter1_9 extends EntityRewriter<ClientboundPackets1_
} }
} }
data.setValue(toWrite); data.setValue(toWrite);
break; }
case VAR_INT: case VAR_INT -> {
// convert from int, short, byte // convert from int, short, byte
if (dataIndex.getOldType() == EntityDataTypes1_8.BYTE) { if (dataIndex.getOldType() == EntityDataTypes1_8.BYTE) {
data.setValue(((Byte) value).intValue()); data.setValue(((Byte) value).intValue());
@ -446,39 +446,33 @@ public class EntityPacketRewriter1_9 extends EntityRewriter<ClientboundPackets1_
if (dataIndex.getOldType() == EntityDataTypes1_8.INT) { if (dataIndex.getOldType() == EntityDataTypes1_8.INT) {
data.setValue(value); data.setValue(value);
} }
break; }
case FLOAT, STRING: case FLOAT, STRING -> data.setValue(value);
data.setValue(value); case BOOLEAN -> {
break;
case BOOLEAN:
if (dataIndex == EntityDataIndex1_9.ABSTRACT_AGEABLE_AGE) if (dataIndex == EntityDataIndex1_9.ABSTRACT_AGEABLE_AGE)
data.setValue((Byte) value < 0); data.setValue((Byte) value < 0);
else else
data.setValue((Byte) value != 0); data.setValue((Byte) value != 0);
break; }
case ITEM: case ITEM -> {
data.setValue(value); data.setValue(value);
protocol.getItemRewriter().handleItemToClient(event.user(), (Item) data.getValue()); protocol.getItemRewriter().handleItemToClient(event.user(), (Item) data.getValue());
break; }
case BLOCK_POSITION: case BLOCK_POSITION -> {
Vector vector = (Vector) value; Vector vector = (Vector) value;
data.setValue(vector); data.setValue(vector);
break; }
case ROTATIONS: case ROTATIONS -> {
EulerAngle angle = (EulerAngle) value; EulerAngle angle = (EulerAngle) value;
data.setValue(angle); data.setValue(angle);
break; }
case COMPONENT: case COMPONENT -> {
// Was previously also a component, so just convert it // Was previously also a component, so just convert it
String text = (String) value; String text = (String) value;
data.setValue(ComponentUtil.convertJsonOrEmpty(text, SerializerVersion.V1_8, SerializerVersion.V1_9)); data.setValue(ComponentUtil.convertJsonOrEmpty(text, SerializerVersion.V1_8, SerializerVersion.V1_9));
break; }
case OPTIONAL_BLOCK_STATE: case OPTIONAL_BLOCK_STATE -> data.setValue(((Number) value).intValue()); // Convert from int, short, byte
// Convert from int, short, byte default -> throw new RuntimeException("Unhandled EntityDataType: " + dataIndex.getNewType());
data.setValue(((Number) value).intValue());
break;
default:
throw new RuntimeException("Unhandled EntityDataType: " + dataIndex.getNewType());
} }
} }

View File

@ -161,12 +161,8 @@ public class ComponentRewriter<C extends ClientboundPacketType> implements com.v
public void passthroughAndProcess(final PacketWrapper wrapper) { public void passthroughAndProcess(final PacketWrapper wrapper) {
switch (type) { switch (type) {
case JSON: case JSON -> processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT)); case NBT -> processTag(wrapper.user(), wrapper.passthrough(Types.TAG));
break;
case NBT:
processTag(wrapper.user(), wrapper.passthrough(Types.TAG));
break;
} }
} }