diff --git a/extractor/src/main/java/rs/valence/extractor/ClassComparator.java b/extractor/src/main/java/rs/valence/extractor/ClassComparator.java index f3b2928e9..675f0c82a 100644 --- a/extractor/src/main/java/rs/valence/extractor/ClassComparator.java +++ b/extractor/src/main/java/rs/valence/extractor/ClassComparator.java @@ -11,12 +11,12 @@ public ClassComparator() { } @Override - public int compare(final Class c1, final Class c2) { + public int compare(Class c1, Class c2) { return c1.getSimpleName().compareTo(c2.getSimpleName()); } @Override - public boolean equals(final Object comp) { + public boolean equals(Object comp) { return comp instanceof ClassComparator; } } diff --git a/extractor/src/main/java/rs/valence/extractor/DummyPlayerEntity.java b/extractor/src/main/java/rs/valence/extractor/DummyPlayerEntity.java index 01aa85a6e..0bd933307 100644 --- a/extractor/src/main/java/rs/valence/extractor/DummyPlayerEntity.java +++ b/extractor/src/main/java/rs/valence/extractor/DummyPlayerEntity.java @@ -15,10 +15,10 @@ public class DummyPlayerEntity extends PlayerEntity { static { INSTANCE = Main.magicallyInstantiate(DummyPlayerEntity.class); - DummyPlayerEntity.INSTANCE.initDataTracker(new DataTracker.Builder(DummyPlayerEntity.INSTANCE)); + INSTANCE.initDataTracker(new DataTracker.Builder(INSTANCE)); } - public DummyPlayerEntity(final World world, final BlockPos pos, final float yaw, final GameProfile gameProfile, @Nullable final PlayerPublicKey publicKey) { + public DummyPlayerEntity(World world, BlockPos pos, float yaw, GameProfile gameProfile, @Nullable PlayerPublicKey publicKey) { super(world, pos, yaw, gameProfile); } diff --git a/extractor/src/main/java/rs/valence/extractor/DummyWorld.java b/extractor/src/main/java/rs/valence/extractor/DummyWorld.java index db3e942dd..c2a65f0ae 100644 --- a/extractor/src/main/java/rs/valence/extractor/DummyWorld.java +++ b/extractor/src/main/java/rs/valence/extractor/DummyWorld.java @@ -46,40 +46,40 @@ public class DummyWorld extends World { INSTANCE = Main.magicallyInstantiate(DummyWorld.class); try { - final var randomField = World.class.getDeclaredField("random"); + var randomField = World.class.getDeclaredField("random"); randomField.setAccessible(true); - randomField.set(DummyWorld.INSTANCE, Random.create()); + randomField.set(INSTANCE, Random.create()); - final var propertiesField = World.class.getDeclaredField("properties"); + var propertiesField = World.class.getDeclaredField("properties"); propertiesField.setAccessible(true); - propertiesField.set(DummyWorld.INSTANCE, new DummyMutableWorldProperties()); + propertiesField.set(INSTANCE, new DummyMutableWorldProperties()); - } catch (final NoSuchFieldException | IllegalAccessException e) { + } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } } - private DummyWorld(final MutableWorldProperties properties, final RegistryKey registryRef, final DynamicRegistryManager registryManager, final RegistryEntry dimension, final Supplier profiler, final boolean isClient, final boolean debugWorld, final long seed, final int maxChainedNeighborUpdates) { + private DummyWorld(MutableWorldProperties properties, RegistryKey registryRef, DynamicRegistryManager registryManager, RegistryEntry dimension, Supplier profiler, boolean isClient, boolean debugWorld, long seed, int maxChainedNeighborUpdates) { super(properties, registryRef, registryManager, dimension, profiler, isClient, debugWorld, seed, maxChainedNeighborUpdates); } @Override - public void updateListeners(final BlockPos pos, final BlockState oldState, final BlockState newState, final int flags) { + public void updateListeners(BlockPos pos, BlockState oldState, BlockState newState, int flags) { } @Override - public void playSound(@Nullable final PlayerEntity except, final double x, final double y, final double z, final RegistryEntry sound, final SoundCategory category, final float volume, final float pitch, final long seed) { + public void playSound(@Nullable PlayerEntity except, double x, double y, double z, RegistryEntry sound, SoundCategory category, float volume, float pitch, long seed) { } @Override - public void playSound(@Nullable final PlayerEntity except, final double x, final double y, final double z, final SoundEvent sound, final SoundCategory category, final float volume, final float pitch, final long seed) { + public void playSound(@Nullable PlayerEntity except, double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, long seed) { } @Override - public void playSoundFromEntity(@Nullable final PlayerEntity except, final Entity entity, final RegistryEntry sound, final SoundCategory category, final float volume, final float pitch, final long seed) { + public void playSoundFromEntity(@Nullable PlayerEntity except, Entity entity, RegistryEntry sound, SoundCategory category, float volume, float pitch, long seed) { } @@ -90,7 +90,7 @@ public String asString() { @Nullable @Override - public Entity getEntityById(final int id) { + public Entity getEntityById(int id) { return null; } @@ -101,12 +101,12 @@ public TickManager getTickManager() { @Nullable @Override - public MapState getMapState(final MapIdComponent id) { + public MapState getMapState(MapIdComponent id) { return null; } @Override - public void putMapState(final MapIdComponent id, final MapState state) { + public void putMapState(MapIdComponent id, MapState state) { } @@ -116,7 +116,7 @@ public MapIdComponent increaseAndGetMapId() { } @Override - public void setBlockBreakingInfo(final int entityId, final BlockPos pos, final int progress) { + public void setBlockBreakingInfo(int entityId, BlockPos pos, int progress) { } @@ -151,12 +151,12 @@ public ChunkManager getChunkManager() { } @Override - public void syncWorldEvent(@Nullable final PlayerEntity player, final int eventId, final BlockPos pos, final int data) { + public void syncWorldEvent(@Nullable PlayerEntity player, int eventId, BlockPos pos, int data) { } @Override - public void emitGameEvent(final RegistryEntry event, final Vec3d emitterPos, final GameEvent.Emitter emitter) { + public void emitGameEvent(RegistryEntry event, Vec3d emitterPos, GameEvent.Emitter emitter) { } @@ -177,7 +177,7 @@ public FeatureSet getEnabledFeatures() { } @Override - public float getBrightness(final Direction direction, final boolean shaded) { + public float getBrightness(Direction direction, boolean shaded) { return 0; } @@ -187,7 +187,7 @@ public List getPlayers() { } @Override - public RegistryEntry getGeneratorStoredBiome(final int biomeX, final int biomeY, final int biomeZ) { + public RegistryEntry getGeneratorStoredBiome(int biomeX, int biomeY, int biomeZ) { return null; } @@ -226,7 +226,7 @@ public boolean isRaining() { } @Override - public void setRaining(final boolean raining) { + public void setRaining(boolean raining) { } @@ -251,7 +251,7 @@ public boolean isDifficultyLocked() { } @Override - public void setSpawnPos(final BlockPos pos, final float angle) { + public void setSpawnPos(BlockPos pos, float angle) { } } diff --git a/extractor/src/main/java/rs/valence/extractor/Main.java b/extractor/src/main/java/rs/valence/extractor/Main.java index c8d8cee6e..61a7a9cc9 100644 --- a/extractor/src/main/java/rs/valence/extractor/Main.java +++ b/extractor/src/main/java/rs/valence/extractor/Main.java @@ -20,27 +20,27 @@ public class Main implements ModInitializer { public static final String MOD_ID = "valence_extractor"; - public static final Logger LOGGER = LoggerFactory.getLogger(Main.MOD_ID); + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); /** * Magically creates an instance of a concrete class without calling its constructor. */ - public static T magicallyInstantiate(final Class clazz) { - final var rf = ReflectionFactory.getReflectionFactory(); + public static T magicallyInstantiate(Class clazz) { + var rf = ReflectionFactory.getReflectionFactory(); try { - final var objCon = Object.class.getDeclaredConstructor(); - final var con = rf.newConstructorForSerialization(clazz, objCon); + var objCon = Object.class.getDeclaredConstructor(); + var con = rf.newConstructorForSerialization(clazz, objCon); return clazz.cast(con.newInstance()); - } catch (final Throwable e) { + } catch (Throwable e) { throw new IllegalArgumentException("Failed to magically instantiate " + clazz.getName(), e); } } @Override public void onInitialize() { - Main.LOGGER.info("Starting extractors..."); + LOGGER.info("Starting extractors..."); - final var extractors = new Extractor[]{ + var extractors = new Extractor[]{ new Attributes(), new Blocks(), new Effects(), @@ -51,64 +51,64 @@ public void onInitialize() { new TranslationKeys(), }; - final Path outputDirectory; + Path outputDirectory; try { outputDirectory = Files.createDirectories(Paths.get("valence_extractor_output")); - } catch (final IOException e) { - Main.LOGGER.info("Failed to create output directory.", e); + } catch (IOException e) { + LOGGER.info("Failed to create output directory.", e); return; } - final var gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().serializeNulls().create(); + var gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().serializeNulls().create(); - for (final var ext : extractors) { + for (var ext : extractors) { try { - final var out = outputDirectory.resolve(ext.fileName()); - final var fileWriter = new FileWriter(out.toFile(), StandardCharsets.UTF_8); + var out = outputDirectory.resolve(ext.fileName()); + var fileWriter = new FileWriter(out.toFile(), StandardCharsets.UTF_8); gson.toJson(ext.extract(), fileWriter); fileWriter.close(); - Main.LOGGER.info("Wrote " + out.toAbsolutePath()); - } catch (final Exception e) { - Main.LOGGER.error("Extractor for \"" + ext.fileName() + "\" failed.", e); + LOGGER.info("Wrote " + out.toAbsolutePath()); + } catch (Exception e) { + LOGGER.error("Extractor for \"" + ext.fileName() + "\" failed.", e); } } ServerLifecycleEvents.SERVER_STARTED.register(server -> { - Main.LOGGER.info("Server starting, Running startup extractors..."); + LOGGER.info("Server starting, Running startup extractors..."); // TODO: make `Codec` implement `Extractor` // TODO: the way to get Codex has changed, this is not working anymore - final var packetRegistryExtractor = new PacketRegistries(server); + var packetRegistryExtractor = new PacketRegistries(server); try { - final var out = outputDirectory.resolve(packetRegistryExtractor.fileName()); - final var fileWriter = new FileWriter(out.toFile(), StandardCharsets.UTF_8); + var out = outputDirectory.resolve(packetRegistryExtractor.fileName()); + var fileWriter = new FileWriter(out.toFile(), StandardCharsets.UTF_8); gson.toJson(packetRegistryExtractor.extract(), fileWriter); fileWriter.close(); - Main.LOGGER.info("Wrote " + out.toAbsolutePath()); - } catch (final Exception e) { - Main.LOGGER.error("Extractor for \"" + packetRegistryExtractor.fileName() + "\" failed.", e); + LOGGER.info("Wrote " + out.toAbsolutePath()); + } catch (Exception e) { + LOGGER.error("Extractor for \"" + packetRegistryExtractor.fileName() + "\" failed.", e); } - final var startupExtractors = new Extractor[]{ + var startupExtractors = new Extractor[]{ new Tags(server), new Paintings(server), new Enchants(server), new Entities(server), }; - for (final var ext : startupExtractors) { + for (var ext : startupExtractors) { try { - final var out = outputDirectory.resolve(ext.fileName()); - final var fileWriter = new FileWriter(out.toFile(), StandardCharsets.UTF_8); + var out = outputDirectory.resolve(ext.fileName()); + var fileWriter = new FileWriter(out.toFile(), StandardCharsets.UTF_8); gson.toJson(ext.extract(), fileWriter); fileWriter.close(); - Main.LOGGER.info("Wrote " + out.toAbsolutePath()); - } catch (final Exception e) { - Main.LOGGER.error("Extractor for \"" + ext.fileName() + "\" failed.", e); + LOGGER.info("Wrote " + out.toAbsolutePath()); + } catch (Exception e) { + LOGGER.error("Extractor for \"" + ext.fileName() + "\" failed.", e); } } - Main.LOGGER.info("Done."); + LOGGER.info("Done."); server.stop(false); }); } diff --git a/extractor/src/main/java/rs/valence/extractor/RegistryKeyComparator.java b/extractor/src/main/java/rs/valence/extractor/RegistryKeyComparator.java index efb407231..e69c6d0db 100644 --- a/extractor/src/main/java/rs/valence/extractor/RegistryKeyComparator.java +++ b/extractor/src/main/java/rs/valence/extractor/RegistryKeyComparator.java @@ -10,8 +10,8 @@ public RegistryKeyComparator() { } @Override - public int compare(final RegistryKey o1, final RegistryKey o2) { - final var c1 = o1.getRegistry().compareTo(o2.getRegistry()); + public int compare(RegistryKey o1, RegistryKey o2) { + var c1 = o1.getRegistry().compareTo(o2.getRegistry()); if (0 != c1) { return c1; diff --git a/extractor/src/main/java/rs/valence/extractor/ValenceUtils.java b/extractor/src/main/java/rs/valence/extractor/ValenceUtils.java index f04087167..a116ec81e 100644 --- a/extractor/src/main/java/rs/valence/extractor/ValenceUtils.java +++ b/extractor/src/main/java/rs/valence/extractor/ValenceUtils.java @@ -16,11 +16,11 @@ private ValenceUtils() { * @param str The string to convert. * @return The converted string. */ - public static String toPascalCase(final String str) { - final StringBuilder result = new StringBuilder(); + public static String toPascalCase(String str) { + StringBuilder result = new StringBuilder(); boolean capitalizeNext = true; - for (final char c : str.toCharArray()) { + for (char c : str.toCharArray()) { if (Character.isWhitespace(c) || '_' == c) { capitalizeNext = true; } else if (capitalizeNext) { diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Attributes.java b/extractor/src/main/java/rs/valence/extractor/extractors/Attributes.java index 69a46b954..c22654e9f 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Attributes.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Attributes.java @@ -21,10 +21,10 @@ public String fileName() { @Override public JsonElement extract() { - final var attributesJson = new JsonObject(); + var attributesJson = new JsonObject(); - for (final EntityAttribute attribute : Registries.ATTRIBUTE) { - final var attributeJson = new JsonObject(); + for (EntityAttribute attribute : Registries.ATTRIBUTE) { + var attributeJson = new JsonObject(); attributeJson.addProperty("id", Registries.ATTRIBUTE.getRawId(attribute)); attributeJson.addProperty("name", Registries.ATTRIBUTE.getId(attribute).getPath()); @@ -32,7 +32,7 @@ public JsonElement extract() { attributeJson.addProperty("translation_key", attribute.getTranslationKey()); attributeJson.addProperty("tracked", attribute.isTracked()); - if (attribute instanceof final ClampedEntityAttribute a) { + if (attribute instanceof ClampedEntityAttribute a) { attributeJson.addProperty("min_value", a.getMinValue()); attributeJson.addProperty("max_value", a.getMaxValue()); } diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Blocks.java b/extractor/src/main/java/rs/valence/extractor/extractors/Blocks.java index 8e08c43d3..07a41fb06 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Blocks.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Blocks.java @@ -26,35 +26,35 @@ public String fileName() { @Override public JsonElement extract() { - final var topLevelJson = new JsonObject(); + var topLevelJson = new JsonObject(); - final var blocksJson = new JsonArray(); + var blocksJson = new JsonArray(); var stateIdCounter = 0; - final var shapes = new LinkedHashMap(); + var shapes = new LinkedHashMap(); - for (final var block : Registries.BLOCK) { - final var blockJson = new JsonObject(); + for (var block : Registries.BLOCK) { + var blockJson = new JsonObject(); blockJson.addProperty("id", Registries.BLOCK.getRawId(block)); blockJson.addProperty("name", Registries.BLOCK.getId(block).getPath()); blockJson.addProperty("translation_key", block.getTranslationKey()); blockJson.addProperty("item_id", Registries.ITEM.getRawId(block.asItem())); - if (block.asItem() instanceof final VerticallyAttachableBlockItem wsbItem) { + if (block.asItem() instanceof VerticallyAttachableBlockItem wsbItem) { if (wsbItem.getBlock() == block) { - final var wallBlock = ((ExposeWallBlock) wsbItem).getWallBlock(); + var wallBlock = ((ExposeWallBlock) wsbItem).getWallBlock(); blockJson.addProperty("wall_variant_id", Registries.BLOCK.getRawId(wallBlock)); } } - final var propsJson = new JsonArray(); - for (final var prop : block.getStateManager().getProperties()) { - final var propJson = new JsonObject(); + var propsJson = new JsonArray(); + for (var prop : block.getStateManager().getProperties()) { + var propJson = new JsonObject(); propJson.addProperty("name", prop.getName()); - final var valuesJson = new JsonArray(); - for (final var value : prop.getValues()) { + var valuesJson = new JsonArray(); + for (var value : prop.getValues()) { valuesJson.add(value.toString().toLowerCase(Locale.ROOT)); } propJson.add("values", valuesJson); @@ -63,10 +63,10 @@ public JsonElement extract() { } blockJson.add("properties", propsJson); - final var statesJson = new JsonArray(); - for (final var state : block.getStateManager().getStates()) { - final var stateJson = new JsonObject(); - final var id = stateIdCounter; + var statesJson = new JsonArray(); + for (var state : block.getStateManager().getStates()) { + var stateJson = new JsonObject(); + var id = stateIdCounter; stateIdCounter++; stateJson.addProperty("id", id); stateJson.addProperty("luminance", state.getLuminance()); @@ -79,17 +79,17 @@ public JsonElement extract() { blockJson.addProperty("default_state_id", id); } - final var collisionShapeIdxsJson = new JsonArray(); - for (final var box : state.getCollisionShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN).getBoundingBoxes()) { - final var collisionShape = new Shape(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); + var collisionShapeIdxsJson = new JsonArray(); + for (var box : state.getCollisionShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN).getBoundingBoxes()) { + var collisionShape = new Shape(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); - final var idx = shapes.putIfAbsent(collisionShape, shapes.size()); + var idx = shapes.putIfAbsent(collisionShape, shapes.size()); collisionShapeIdxsJson.add(Objects.requireNonNullElseGet(idx, () -> shapes.size() - 1)); } stateJson.add("collision_shapes", collisionShapeIdxsJson); - for (final var blockEntity : Registries.BLOCK_ENTITY_TYPE) { + for (var blockEntity : Registries.BLOCK_ENTITY_TYPE) { if (blockEntity.supports(state)) { stateJson.addProperty("block_entity_type", Registries.BLOCK_ENTITY_TYPE.getRawId(blockEntity)); } @@ -102,9 +102,9 @@ public JsonElement extract() { blocksJson.add(blockJson); } - final var blockEntitiesJson = new JsonArray(); - for (final var blockEntity : Registries.BLOCK_ENTITY_TYPE) { - final var blockEntityJson = new JsonObject(); + var blockEntitiesJson = new JsonArray(); + for (var blockEntity : Registries.BLOCK_ENTITY_TYPE) { + var blockEntityJson = new JsonObject(); blockEntityJson.addProperty("id", Registries.BLOCK_ENTITY_TYPE.getRawId(blockEntity)); blockEntityJson.addProperty("ident", Registries.BLOCK_ENTITY_TYPE.getId(blockEntity).toString()); blockEntityJson.addProperty("name", Registries.BLOCK_ENTITY_TYPE.getId(blockEntity).getPath()); @@ -112,9 +112,9 @@ public JsonElement extract() { blockEntitiesJson.add(blockEntityJson); } - final var shapesJson = new JsonArray(); - for (final var shape : shapes.keySet()) { - final var shapeJson = new JsonObject(); + var shapesJson = new JsonArray(); + for (var shape : shapes.keySet()) { + var shapeJson = new JsonObject(); shapeJson.addProperty("min_x", shape.minX); shapeJson.addProperty("min_y", shape.minY); shapeJson.addProperty("min_z", shape.minZ); diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Effects.java b/extractor/src/main/java/rs/valence/extractor/extractors/Effects.java index 423991a60..414fdd099 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Effects.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Effects.java @@ -18,10 +18,10 @@ public String fileName() { @Override public JsonElement extract() { - final var effectsJson = new JsonArray(); + var effectsJson = new JsonArray(); - for (final var effect : Registries.STATUS_EFFECT) { - final var effectJson = new JsonObject(); + for (var effect : Registries.STATUS_EFFECT) { + var effectJson = new JsonObject(); effectJson.addProperty("id", Registries.STATUS_EFFECT.getRawId(effect)); effectJson.addProperty("name", Registries.STATUS_EFFECT.getId(effect).getPath()); @@ -30,10 +30,10 @@ public JsonElement extract() { effectJson.addProperty("instant", effect.isInstant()); effectJson.addProperty("category", ValenceUtils.toPascalCase(effect.getCategory().name())); - final var attributeModifiersJson = new JsonArray(); + var attributeModifiersJson = new JsonArray(); effect.forEachAttributeModifier(0, (attribute, modifier) -> { - final var attributeModifierJson = new JsonObject(); + var attributeModifierJson = new JsonObject(); attributeModifierJson.addProperty("attribute", attribute.getIdAsString()); attributeModifierJson.addProperty("operation", modifier.operation().getId()); diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Enchants.java b/extractor/src/main/java/rs/valence/extractor/extractors/Enchants.java index d140e77ee..7407ce67a 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Enchants.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Enchants.java @@ -15,8 +15,8 @@ public class Enchants implements Main.Extractor { private final DynamicRegistryManager.Immutable registryManager; - public Enchants(final MinecraftServer server) { - registryManager = server.getRegistryManager(); + public Enchants(MinecraftServer server) { + this.registryManager = server.getRegistryManager(); } @Override @@ -26,10 +26,10 @@ public String fileName() { @Override public JsonElement extract() { - final var enchantsJson = new JsonObject(); + var enchantsJson = new JsonObject(); - for (final var enchant : this.registryManager.get(RegistryKeys.ENCHANTMENT).streamEntries().toList()) { - enchantsJson.add(enchant.getKey().orElseThrow().getValue().toString(), Enchantment.CODEC.encodeStart(RegistryOps.of(JsonOps.INSTANCE, this.registryManager), enchant.value()).getOrThrow()); + for (var enchant : registryManager.get(RegistryKeys.ENCHANTMENT).streamEntries().toList()) { + enchantsJson.add(enchant.getKey().orElseThrow().getValue().toString(), Enchantment.CODEC.encodeStart(RegistryOps.of(JsonOps.INSTANCE, registryManager), enchant.value()).getOrThrow()); } diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Entities.java b/extractor/src/main/java/rs/valence/extractor/extractors/Entities.java index b3c30da8f..913077314 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Entities.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Entities.java @@ -42,13 +42,13 @@ public class Entities implements Main.Extractor { private final ServerWorld world; - public Entities(final MinecraftServer server) { - world = server.getOverworld(); + public Entities(MinecraftServer server) { + this.world = server.getOverworld(); } - private static Main.Pair trackedDataToJson(final TrackedData data, final DataTracker tracker) { - var handler = data.dataType(); - var val = tracker.get(data); + private static Main.Pair trackedDataToJson(TrackedData data, DataTracker tracker) { + final var handler = data.dataType(); + final var val = tracker.get(data); if (handler == TrackedDataHandlerRegistry.BYTE) { return new Main.Pair<>("byte", new JsonPrimitive((Byte) val)); @@ -64,7 +64,7 @@ private static Main.Pair trackedDataToJson(final TrackedDat // TODO: return text as json element. return new Main.Pair<>("text_component", new JsonPrimitive(((Text) val).getString())); } else if (handler == TrackedDataHandlerRegistry.OPTIONAL_TEXT_COMPONENT) { - final var res = ((Optional) val).map(o -> (JsonElement) new JsonPrimitive(((Text) o).getString())) + var res = ((Optional) val).map(o -> (JsonElement) new JsonPrimitive(((Text) o).getString())) .orElse(JsonNull.INSTANCE); return new Main.Pair<>("optional_text_component", res); } else if (handler == TrackedDataHandlerRegistry.ITEM_STACK) { @@ -73,23 +73,23 @@ private static Main.Pair trackedDataToJson(final TrackedDat } else if (handler == TrackedDataHandlerRegistry.BOOLEAN) { return new Main.Pair<>("boolean", new JsonPrimitive((Boolean) val)); } else if (handler == TrackedDataHandlerRegistry.ROTATION) { - final var json = new JsonObject(); - final var ea = (EulerAngle) val; + var json = new JsonObject(); + var ea = (EulerAngle) val; json.addProperty("pitch", ea.getPitch()); json.addProperty("yaw", ea.getYaw()); json.addProperty("roll", ea.getRoll()); return new Main.Pair<>("rotation", json); } else if (handler == TrackedDataHandlerRegistry.BLOCK_POS) { - final var bp = (BlockPos) val; - final var json = new JsonObject(); + var bp = (BlockPos) val; + var json = new JsonObject(); json.addProperty("x", bp.getX()); json.addProperty("y", bp.getY()); json.addProperty("z", bp.getZ()); return new Main.Pair<>("block_pos", json); } else if (handler == TrackedDataHandlerRegistry.OPTIONAL_BLOCK_POS) { return new Main.Pair<>("optional_block_pos", ((Optional) val).map(o -> { - final var bp = (BlockPos) o; - final var json = new JsonObject(); + var bp = (BlockPos) o; + var json = new JsonObject(); json.addProperty("x", bp.getX()); json.addProperty("y", bp.getY()); json.addProperty("z", bp.getZ()); @@ -98,43 +98,43 @@ private static Main.Pair trackedDataToJson(final TrackedDat } else if (handler == TrackedDataHandlerRegistry.FACING) { return new Main.Pair<>("facing", new JsonPrimitive(val.toString())); } else if (handler == TrackedDataHandlerRegistry.OPTIONAL_UUID) { - final var res = ((Optional) val).map(o -> (JsonElement) new JsonPrimitive(o.toString())) + var res = ((Optional) val).map(o -> (JsonElement) new JsonPrimitive(o.toString())) .orElse(JsonNull.INSTANCE); return new Main.Pair<>("optional_uuid", res); } else if (handler == TrackedDataHandlerRegistry.BLOCK_STATE) { // TODO: get raw block state ID. - final var state = (BlockState) val; + var state = (BlockState) val; return new Main.Pair<>("block_state", new JsonPrimitive(state.toString())); } else if (handler == TrackedDataHandlerRegistry.OPTIONAL_BLOCK_STATE) { // TODO: get raw block state ID. - final var res = ((Optional) val).map(o -> (JsonElement) new JsonPrimitive(o.toString())) + var res = ((Optional) val).map(o -> (JsonElement) new JsonPrimitive(o.toString())) .orElse(JsonNull.INSTANCE); return new Main.Pair<>("optional_block_state", res); } else if (handler == TrackedDataHandlerRegistry.NBT_COMPOUND) { // TODO: base64 binary representation or SNBT? return new Main.Pair<>("nbt_compound", new JsonPrimitive(val.toString())); } else if (handler == TrackedDataHandlerRegistry.PARTICLE) { - final var id = Registries.PARTICLE_TYPE.getId(((ParticleEffect) val).getType()); + var id = Registries.PARTICLE_TYPE.getId(((ParticleEffect) val).getType()); return new Main.Pair<>("particle", new JsonPrimitive(id.getPath())); } else if (handler == TrackedDataHandlerRegistry.PARTICLE_LIST) { - final List particleList = (List) val; - final JsonArray json = new JsonArray(); - for (final ParticleEffect particleEffect : particleList) { - final var id = Registries.PARTICLE_TYPE.getId(((ParticleEffect) val).getType()); + List particleList = (List) val; + JsonArray json = new JsonArray(); + for (ParticleEffect particleEffect : particleList) { + var id = Registries.PARTICLE_TYPE.getId(((ParticleEffect) val).getType()); json.add(id.getPath()); } return new Main.Pair<>("particle_list", json); } else if (handler == TrackedDataHandlerRegistry.VILLAGER_DATA) { - final var vd = (VillagerData) val; - final var json = new JsonObject(); - final var type = Registries.VILLAGER_TYPE.getId(vd.getType()).getPath(); - final var profession = Registries.VILLAGER_PROFESSION.getId(vd.getProfession()).getPath(); + var vd = (VillagerData) val; + var json = new JsonObject(); + var type = Registries.VILLAGER_TYPE.getId(vd.getType()).getPath(); + var profession = Registries.VILLAGER_PROFESSION.getId(vd.getProfession()).getPath(); json.addProperty("type", type); json.addProperty("profession", profession); json.addProperty("level", vd.getLevel()); return new Main.Pair<>("villager_data", json); } else if (handler == TrackedDataHandlerRegistry.OPTIONAL_INT) { - final var opt = (OptionalInt) val; + var opt = (OptionalInt) val; return new Main.Pair<>("optional_int", opt.isPresent() ? new JsonPrimitive(opt.getAsInt()) : JsonNull.INSTANCE); } else if (handler == TrackedDataHandlerRegistry.ENTITY_POSE) { return new Main.Pair<>("entity_pose", new JsonPrimitive(((EntityPose) val).name().toLowerCase(Locale.ROOT))); @@ -149,11 +149,11 @@ private static Main.Pair trackedDataToJson(final TrackedDat new JsonPrimitive(((RegistryEntry) val).getIdAsString())); } else if (handler == TrackedDataHandlerRegistry.OPTIONAL_GLOBAL_POS) { return new Main.Pair<>("optional_global_pos", ((Optional) val).map(o -> { - final var gp = (GlobalPos) o; - final var json = new JsonObject(); + var gp = (GlobalPos) o; + var json = new JsonObject(); json.addProperty("dimension", gp.dimension().getValue().toString()); - final var posJson = new JsonObject(); + var posJson = new JsonObject(); posJson.addProperty("x", gp.pos().getX()); posJson.addProperty("y", gp.pos().getY()); posJson.addProperty("z", gp.pos().getZ()); @@ -162,7 +162,7 @@ private static Main.Pair trackedDataToJson(final TrackedDat return (JsonElement) json; }).orElse(JsonNull.INSTANCE)); } else if (handler == TrackedDataHandlerRegistry.PAINTING_VARIANT) { - final var variant = ((RegistryEntry) val).getKey().map(k -> k.getValue().getPath()).orElse(""); + var variant = ((RegistryEntry) val).getKey().map(k -> k.getValue().getPath()).orElse(""); return new Main.Pair<>("painting_variant", new JsonPrimitive(variant)); } else if (handler == TrackedDataHandlerRegistry.SNIFFER_STATE) { return new Main.Pair<>("sniffer_state", @@ -171,15 +171,15 @@ private static Main.Pair trackedDataToJson(final TrackedDat return new Main.Pair<>("armadillo_state", new JsonPrimitive(((ArmadilloEntity.State) val).name().toLowerCase(Locale.ROOT))); } else if (handler == TrackedDataHandlerRegistry.VECTOR3F) { - final var vec = (Vector3f) val; - final var json = new JsonObject(); + var vec = (Vector3f) val; + var json = new JsonObject(); json.addProperty("x", vec.x); json.addProperty("y", vec.y); json.addProperty("z", vec.z); return new Main.Pair<>("vector3f", json); } else if (handler == TrackedDataHandlerRegistry.QUATERNIONF) { - final var quat = (Quaternionf) val; - final var json = new JsonObject(); + var quat = (Quaternionf) val; + var json = new JsonObject(); json.addProperty("x", quat.x); json.addProperty("y", quat.y); json.addProperty("z", quat.z); @@ -200,25 +200,25 @@ public String fileName() { @SuppressWarnings("unchecked") public JsonElement extract() throws IllegalAccessException, NoSuchFieldException { - var entityList = new ArrayList, EntityType>>(); - final var entityClassTypeMap = new HashMap, EntityType>(); - for (final var f : EntityType.class.getFields()) { + final var entityList = new ArrayList, EntityType>>(); + var entityClassTypeMap = new HashMap, EntityType>(); + for (var f : EntityType.class.getFields()) { if (f.getType().equals(EntityType.class)) { - final var entityClass = (Class) ((ParameterizedType) f.getGenericType()) + var entityClass = (Class) ((ParameterizedType) f.getGenericType()) .getActualTypeArguments()[0]; - final var entityType = (EntityType) f.get(null); + var entityType = (EntityType) f.get(null); entityList.add(new Main.Pair<>(entityClass, entityType)); entityClassTypeMap.put(entityClass, entityType); } } - var dataTrackerField = Entity.class.getDeclaredField("dataTracker"); + final var dataTrackerField = Entity.class.getDeclaredField("dataTracker"); dataTrackerField.setAccessible(true); - final var entitiesMap = new TreeMap, JsonElement>(new ClassComparator()); + var entitiesMap = new TreeMap, JsonElement>(new ClassComparator()); - for (final var entry : entityList) { + for (var entry : entityList) { var entityClass = entry.left(); @Nullable var entityType = entry.right(); @@ -231,18 +231,18 @@ public JsonElement extract() throws IllegalAccessException, NoSuchFieldException // the data tracker field from the base entity class. // We also handle player entities specially since they cannot be spawned with // EntityType#create. - var entityInstance = entityType.equals(EntityType.PLAYER) ? new DummyPlayerEntity(this.world, BlockPos.ofFloored(0, 70, 0), 0, new GameProfile(UUID.randomUUID(), "cooldude"), null) - : entityType.create(this.world); + final var entityInstance = entityType.equals(EntityType.PLAYER) ? new DummyPlayerEntity(world, BlockPos.ofFloored(0, 70, 0), 0, new GameProfile(UUID.randomUUID(), "cooldude"), null) + : entityType.create(world); - var dataTracker = (DataTracker) dataTrackerField.get(entityInstance); + final var dataTracker = (DataTracker) dataTrackerField.get(entityInstance); // final var dataTracker = entityInstance.getDataTracker(); while (null == entitiesMap.get(entityClass)) { - final var entityJson = new JsonObject(); + var entityJson = new JsonObject(); - final var parent = entityClass.getSuperclass(); - final var hasParent = null != parent && Entity.class.isAssignableFrom(parent); + var parent = entityClass.getSuperclass(); + var hasParent = null != parent && Entity.class.isAssignableFrom(parent); if (hasParent) { entityJson.addProperty("parent", parent.getSimpleName()); @@ -254,20 +254,20 @@ public JsonElement extract() throws IllegalAccessException, NoSuchFieldException entityJson.add("translation_key", new JsonPrimitive(entityType.getTranslationKey())); } - final var fieldsJson = new JsonArray(); - for (final var entityField : entityClass.getDeclaredFields()) { + var fieldsJson = new JsonArray(); + for (var entityField : entityClass.getDeclaredFields()) { if (entityField.getType().equals(TrackedData.class)) { entityField.setAccessible(true); - final var trackedData = (TrackedData) entityField.get(null); + var trackedData = (TrackedData) entityField.get(null); - final var fieldJson = new JsonObject(); - final var fieldName = entityField.getName().toLowerCase(Locale.ROOT); + var fieldJson = new JsonObject(); + var fieldName = entityField.getName().toLowerCase(Locale.ROOT); fieldJson.addProperty("name", fieldName); fieldJson.addProperty("index", trackedData.id()); - final var data = trackedDataToJson(trackedData, dataTracker); + var data = Entities.trackedDataToJson(trackedData, dataTracker); fieldJson.addProperty("type", data.left()); fieldJson.add("default_value", data.right()); @@ -276,20 +276,20 @@ public JsonElement extract() throws IllegalAccessException, NoSuchFieldException } entityJson.add("fields", fieldsJson); - if (entityInstance instanceof final LivingEntity livingEntity) { - final var type = (EntityType) entityType; - final var defaultAttributes = DefaultAttributeRegistry.get(type); - final var attributesJson = new JsonArray(); + if (entityInstance instanceof LivingEntity livingEntity) { + var type = (EntityType) entityType; + var defaultAttributes = DefaultAttributeRegistry.get(type); + var attributesJson = new JsonArray(); if (null != defaultAttributes) { - final var instancesField = defaultAttributes.getClass().getDeclaredField("instances"); + var instancesField = defaultAttributes.getClass().getDeclaredField("instances"); instancesField.setAccessible(true); - final var instances = (Map) instancesField + var instances = (Map) instancesField .get(defaultAttributes); - for (final var instance : instances.values()) { - final var attribute = instance.getAttribute().value(); + for (var instance : instances.values()) { + var attribute = instance.getAttribute().value(); - final var attributeJson = new JsonObject(); + var attributeJson = new JsonObject(); attributeJson.addProperty("id", Registries.ATTRIBUTE.getRawId(attribute)); attributeJson.addProperty("name", Registries.ATTRIBUTE.getId(attribute).getPath()); @@ -301,9 +301,9 @@ public JsonElement extract() throws IllegalAccessException, NoSuchFieldException entityJson.add("attributes", attributesJson); } - final var bb = entityInstance.getBoundingBox(); + var bb = entityInstance.getBoundingBox(); if (null != bb && null != entityType) { - final var boundingBoxJson = new JsonObject(); + var boundingBoxJson = new JsonObject(); boundingBoxJson.addProperty("size_x", bb.getLengthX()); boundingBoxJson.addProperty("size_y", bb.getLengthY()); @@ -323,8 +323,8 @@ public JsonElement extract() throws IllegalAccessException, NoSuchFieldException } } - final var entitiesJson = new JsonObject(); - for (final var entry : entitiesMap.entrySet()) { + var entitiesJson = new JsonObject(); + for (var entry : entitiesMap.entrySet()) { entitiesJson.add(entry.getKey().getSimpleName(), entry.getValue()); } diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Items.java b/extractor/src/main/java/rs/valence/extractor/extractors/Items.java index e144e33fd..1d447ba7f 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Items.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Items.java @@ -18,10 +18,10 @@ public String fileName() { @Override public JsonElement extract() throws Exception { - final var itemsJson = new JsonArray(); + var itemsJson = new JsonArray(); - for (final var item : Registries.ITEM) { - final var itemJson = new JsonObject(); + for (var item : Registries.ITEM) { + var itemJson = new JsonObject(); itemJson.addProperty("id", Registries.ITEM.getRawId(item)); itemJson.addProperty("name", Registries.ITEM.getId(item).getPath()); itemJson.addProperty("translation_key", item.getTranslationKey()); @@ -31,8 +31,8 @@ public JsonElement extract() throws Exception { itemJson.addProperty("fireproof", item.getComponents().contains(DataComponentTypes.FIRE_RESISTANT)); if (item.getComponents().contains(DataComponentTypes.FOOD)) { - final var foodJson = new JsonObject(); - final var foodComp = item.getComponents().get(DataComponentTypes.FOOD); + var foodJson = new JsonObject(); + var foodComp = item.getComponents().get(DataComponentTypes.FOOD); foodJson.addProperty("hunger", foodComp.nutrition()); foodJson.addProperty("saturation", foodComp.saturation()); @@ -41,12 +41,12 @@ public JsonElement extract() throws Exception { itemJson.add("food", foodJson); - final var effectsJson = new JsonArray(); - for (final var effectEntry : foodComp.effects()) { - final var effectJson = new JsonObject(); + var effectsJson = new JsonArray(); + for (var effectEntry : foodComp.effects()) { + var effectJson = new JsonObject(); - final var effect = effectEntry.effect(); - final var chance = effectEntry.probability(); + var effect = effectEntry.effect(); + var chance = effectEntry.probability(); effectJson.addProperty("chance", chance); effectJson.addProperty("translation_key", effect.getTranslationKey()); diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Misc.java b/extractor/src/main/java/rs/valence/extractor/extractors/Misc.java index f0721530a..43269280f 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Misc.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Misc.java @@ -28,18 +28,18 @@ public String fileName() { @Override public JsonElement extract() throws Exception { - final var miscJson = new JsonObject(); + var miscJson = new JsonObject(); - final var entityTypeJson = new JsonObject(); - for (final var type : Registries.ENTITY_TYPE) { + var entityTypeJson = new JsonObject(); + for (var type : Registries.ENTITY_TYPE) { entityTypeJson.addProperty(Registries.ENTITY_TYPE.getId(type).getPath(), Registries.ENTITY_TYPE.getRawId(type)); } miscJson.add("entity_type", entityTypeJson); - final var entityStatusJson = new JsonObject(); - for (final var field : EntityStatuses.class.getDeclaredFields()) { - if (field.canAccess(null) && field.get(null) instanceof final Byte code) { + var entityStatusJson = new JsonObject(); + for (var field : EntityStatuses.class.getDeclaredFields()) { + if (field.canAccess(null) && field.get(null) instanceof Byte code) { if ("field_30030".equals(field.getName())) { entityStatusJson.addProperty("stop_attack", code); } else { @@ -49,38 +49,38 @@ public JsonElement extract() throws Exception { } miscJson.add("entity_status", entityStatusJson); - final var entityAnimationJson = new JsonObject(); - for (final var field : EntityAnimationS2CPacket.class.getDeclaredFields()) { + var entityAnimationJson = new JsonObject(); + for (var field : EntityAnimationS2CPacket.class.getDeclaredFields()) { field.setAccessible(true); if (Modifier.isStatic(field.getModifiers()) && field.canAccess(null) - && field.get(null) instanceof final Integer i) { + && field.get(null) instanceof Integer i) { entityAnimationJson.addProperty(field.getName().toLowerCase(Locale.ROOT), i); } } miscJson.add("entity_animation", entityAnimationJson); - final var villagerTypeJson = new JsonObject(); - for (final var type : Registries.VILLAGER_TYPE) { + var villagerTypeJson = new JsonObject(); + for (var type : Registries.VILLAGER_TYPE) { villagerTypeJson.addProperty(Registries.VILLAGER_TYPE.getId(type).getPath(), Registries.VILLAGER_TYPE.getRawId(type)); } miscJson.add("villager_type", villagerTypeJson); - final var villagerProfessionJson = new JsonObject(); - for (final var profession : Registries.VILLAGER_PROFESSION) { + var villagerProfessionJson = new JsonObject(); + for (var profession : Registries.VILLAGER_PROFESSION) { villagerProfessionJson.addProperty(profession.id(), Registries.VILLAGER_PROFESSION.getRawId(profession)); } miscJson.add("villager_profession", villagerProfessionJson); - final var catVariantJson = new JsonObject(); - for (final var variant : Registries.CAT_VARIANT) { + var catVariantJson = new JsonObject(); + for (var variant : Registries.CAT_VARIANT) { catVariantJson.addProperty(Registries.CAT_VARIANT.getId(variant).getPath(), Registries.CAT_VARIANT.getRawId(variant)); } miscJson.add("cat_variant", catVariantJson); - final var frogVariantJson = new JsonObject(); - for (final var variant : Registries.FROG_VARIANT) { + var frogVariantJson = new JsonObject(); + for (var variant : Registries.FROG_VARIANT) { frogVariantJson.addProperty(Registries.FROG_VARIANT.getId(variant).getPath(), Registries.FROG_VARIANT.getRawId(variant)); } @@ -88,38 +88,38 @@ public JsonElement extract() throws Exception { - final var directionJson = new JsonObject(); - for (final var dir : Direction.values()) { + var directionJson = new JsonObject(); + for (var dir : Direction.values()) { directionJson.addProperty(dir.getName(), dir.getId()); } miscJson.add("direction", directionJson); - final var entityPoseJson = new JsonObject(); - final var poses = EntityPose.values(); + var entityPoseJson = new JsonObject(); + var poses = EntityPose.values(); for (int i = 0; i < poses.length; i++) { entityPoseJson.addProperty(poses[i].name().toLowerCase(Locale.ROOT), i); } miscJson.add("entity_pose", entityPoseJson); - final var particleTypesJson = new JsonObject(); - for (final var type : Registries.PARTICLE_TYPE) { + var particleTypesJson = new JsonObject(); + for (var type : Registries.PARTICLE_TYPE) { particleTypesJson.addProperty(Registries.PARTICLE_TYPE.getId(type).getPath(), Registries.PARTICLE_TYPE.getRawId(type)); } miscJson.add("particle_type", particleTypesJson); - final var snifferStateJson = new JsonObject(); - for (final var state : SnifferEntity.State.values()) { + var snifferStateJson = new JsonObject(); + for (var state : SnifferEntity.State.values()) { snifferStateJson.addProperty(state.name().toLowerCase(Locale.ROOT), state.ordinal()); } miscJson.add("sniffer_state", snifferStateJson); - final var trackedDataHandlerJson = new JsonObject(); - for (final var field : TrackedDataHandlerRegistry.class.getDeclaredFields()) { + var trackedDataHandlerJson = new JsonObject(); + for (var field : TrackedDataHandlerRegistry.class.getDeclaredFields()) { field.setAccessible(true); - if (Modifier.isStatic(field.getModifiers()) && field.get(null) instanceof final TrackedDataHandler handler) { - final var name = field.getName().toLowerCase(Locale.ROOT); - final var id = TrackedDataHandlerRegistry.getId(handler); + if (Modifier.isStatic(field.getModifiers()) && field.get(null) instanceof TrackedDataHandler handler) { + var name = field.getName().toLowerCase(Locale.ROOT); + var id = TrackedDataHandlerRegistry.getId(handler); trackedDataHandlerJson.addProperty(name, id); } diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/PacketRegistries.java b/extractor/src/main/java/rs/valence/extractor/extractors/PacketRegistries.java index e05c5628e..36986d645 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/PacketRegistries.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/PacketRegistries.java @@ -16,19 +16,19 @@ public class PacketRegistries implements Main.Extractor { private final DynamicRegistryManager.Immutable registryManager; private final CombinedDynamicRegistries registries; - public PacketRegistries(final MinecraftServer server) { - registryManager = server.getRegistryManager(); - registries = server.getCombinedDynamicRegistries(); + public PacketRegistries(MinecraftServer server) { + this.registryManager = server.getRegistryManager(); + this.registries = server.getCombinedDynamicRegistries(); } public String fileName() { return "registry_codec.json"; } - public static JsonObject mapJson(final RegistryLoader.Entry registry_entry, final DynamicRegistryManager.Immutable registryManager, final CombinedDynamicRegistries combinedRegistries) { - final Codec codec = registry_entry.elementCodec(); - final Registry registry = registryManager.get(registry_entry.key()); - final JsonObject json = new JsonObject(); + public static JsonObject mapJson(RegistryLoader.Entry registry_entry, DynamicRegistryManager.Immutable registryManager, CombinedDynamicRegistries combinedRegistries) { + Codec codec = registry_entry.elementCodec(); + Registry registry = registryManager.get(registry_entry.key()); + JsonObject json = new JsonObject(); registry.streamEntries().forEach(entry -> { json.add(entry.getKey().orElseThrow().getValue().toString(), codec.encodeStart(combinedRegistries.getCombinedRegistryManager().getOps(JsonOps.INSTANCE), entry.value()).resultOrPartial((e) -> Main.LOGGER.error("Cannot encode json: {}", e)).orElseThrow()); }); @@ -36,10 +36,10 @@ public static JsonObject mapJson(final RegistryLoader.Entry registry_entr } public JsonElement extract() { - final Stream> registries = RegistryLoader.SYNCED_REGISTRIES.stream(); - final JsonObject json = new JsonObject(); + Stream> registries = RegistryLoader.SYNCED_REGISTRIES.stream(); + JsonObject json = new JsonObject(); registries.forEach(entry -> { - json.add(entry.key().getValue().toString(), PacketRegistries.mapJson(entry, this.registryManager, this.registries)); + json.add(entry.key().getValue().toString(), mapJson(entry, registryManager, this.registries)); }); return json; } diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Packets.java b/extractor/src/main/java/rs/valence/extractor/extractors/Packets.java index 785b07b42..d007565bd 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Packets.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Packets.java @@ -19,24 +19,24 @@ public String fileName() { @Override public JsonElement extract() throws IOException { - final var packetsJson = new JsonArray(); + var packetsJson = new JsonArray(); - Packets.serializeFactory(HandshakeStates.C2S_FACTORY, packetsJson); - Packets.serializeFactory(QueryStates.C2S_FACTORY, packetsJson); - Packets.serializeFactory(QueryStates.S2C_FACTORY, packetsJson); - Packets.serializeFactory(LoginStates.C2S_FACTORY, packetsJson); - Packets.serializeFactory(LoginStates.S2C_FACTORY, packetsJson); - Packets.serializeFactory(ConfigurationStates.C2S_FACTORY, packetsJson); - Packets.serializeFactory(ConfigurationStates.S2C_FACTORY, packetsJson); - Packets.serializeFactory(PlayStateFactories.C2S, packetsJson); - Packets.serializeFactory(PlayStateFactories.S2C, packetsJson); + serializeFactory(HandshakeStates.C2S_FACTORY, packetsJson); + serializeFactory(QueryStates.C2S_FACTORY, packetsJson); + serializeFactory(QueryStates.S2C_FACTORY, packetsJson); + serializeFactory(LoginStates.C2S_FACTORY, packetsJson); + serializeFactory(LoginStates.S2C_FACTORY, packetsJson); + serializeFactory(ConfigurationStates.C2S_FACTORY, packetsJson); + serializeFactory(ConfigurationStates.S2C_FACTORY, packetsJson); + serializeFactory(PlayStateFactories.C2S, packetsJson); + serializeFactory(PlayStateFactories.S2C, packetsJson); return packetsJson; } - private static void serializeFactory(final NetworkState.Factory factory, final JsonArray json) { + private static void serializeFactory(NetworkState.Factory factory, JsonArray json) { factory.forEachPacketType((type, i) -> { - final var packetJson = new JsonObject(); + var packetJson = new JsonObject(); packetJson.addProperty("name", type.id().getPath()); packetJson.addProperty("phase", factory.phase().getId()); packetJson.addProperty("side", factory.side().getName()); diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Paintings.java b/extractor/src/main/java/rs/valence/extractor/extractors/Paintings.java index 9c8431e2b..8a22a72a1 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Paintings.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Paintings.java @@ -14,8 +14,8 @@ public class Paintings implements Main.Extractor { private final DynamicRegistryManager.Immutable registryManager; - public Paintings(final MinecraftServer server) { - registryManager = server.getRegistryManager(); + public Paintings(MinecraftServer server) { + this.registryManager = server.getRegistryManager(); } @Override @@ -25,15 +25,15 @@ public String fileName() { @Override public JsonElement extract() throws Exception { - final var dataDrivenMiscJson = new JsonObject(); + var dataDrivenMiscJson = new JsonObject(); - final var paintingRegistry = this.registryManager.get(RegistryKeys.PAINTING_VARIANT); + var paintingRegistry = registryManager.get(RegistryKeys.PAINTING_VARIANT); - final var codec = PaintingVariant.CODEC; + var codec = PaintingVariant.CODEC; - final JsonObject json = new JsonObject(); + JsonObject json = new JsonObject(); paintingRegistry.streamEntries().forEach(entry -> { - json.add(entry.getKey().orElseThrow().getValue().toString(), codec.encodeStart(RegistryOps.of(JsonOps.INSTANCE, this.registryManager), entry.value()).getOrThrow()); + json.add(entry.getKey().orElseThrow().getValue().toString(), codec.encodeStart(RegistryOps.of(JsonOps.INSTANCE, registryManager), entry.value()).getOrThrow()); }); return json; diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Sounds.java b/extractor/src/main/java/rs/valence/extractor/extractors/Sounds.java index 40b33b41b..a204be726 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Sounds.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Sounds.java @@ -17,10 +17,10 @@ public String fileName() { @Override public JsonElement extract() throws Exception { - final var itemsJson = new JsonArray(); + var itemsJson = new JsonArray(); - for (final var sound : Registries.SOUND_EVENT) { - final var itemJson = new JsonObject(); + for (var sound : Registries.SOUND_EVENT) { + var itemJson = new JsonObject(); itemJson.addProperty("id", Registries.SOUND_EVENT.getRawId(sound)); itemJson.addProperty("name", Registries.SOUND_EVENT.getId(sound).getPath()); itemsJson.add(itemJson); diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/Tags.java b/extractor/src/main/java/rs/valence/extractor/extractors/Tags.java index 7f7a7e237..f7d3976af 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/Tags.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/Tags.java @@ -22,8 +22,8 @@ public class Tags implements Main.Extractor { private final CombinedDynamicRegistries dynamicRegistryManager; - public Tags(final MinecraftServer server) { - dynamicRegistryManager = server.getCombinedDynamicRegistries(); + public Tags(MinecraftServer server) { + this.dynamicRegistryManager = server.getCombinedDynamicRegistries(); } @Override @@ -33,22 +33,22 @@ public String fileName() { @Override public JsonElement extract() { - final var tagsJson = new JsonObject(); + var tagsJson = new JsonObject(); - var registryTags = - SerializableRegistries.streamRegistryManagerEntries(dynamicRegistryManager) - .map(registry -> Pair.of(registry.key(), Tags.serializeTags(registry.value()))) + final var registryTags = + SerializableRegistries.streamRegistryManagerEntries(this.dynamicRegistryManager) + .map(registry -> Pair.of(registry.key(), serializeTags(registry.value()))) .filter(pair -> !(pair.getSecond()).isEmpty()) .collect(Collectors.toMap(Pair::getFirst, Pair::getSecond, (l, r) -> r, () -> new TreeMap<>(new RegistryKeyComparator()))); - for (final var registry : registryTags.entrySet()) { - final var registryIdent = registry.getKey().getValue().toString(); - final var tagGroupTagsJson = new JsonObject(); + for (var registry : registryTags.entrySet()) { + var registryIdent = registry.getKey().getValue().toString(); + var tagGroupTagsJson = new JsonObject(); - for (final var tag : registry.getValue().entrySet()) { - final var ident = tag.getKey().toString(); - final var rawIds = tag.getValue(); + for (var tag : registry.getValue().entrySet()) { + var ident = tag.getKey().toString(); + var rawIds = tag.getValue(); tagGroupTagsJson.add(ident, rawIds); } @@ -58,12 +58,12 @@ public JsonElement extract() { return tagsJson; } - private static Map serializeTags(final Registry registry) { - final TreeMap map = new TreeMap<>(); + private static Map serializeTags(Registry registry) { + TreeMap map = new TreeMap<>(); registry.streamTagsAndEntries().forEach(pair -> { - final RegistryEntryList registryEntryList = pair.getSecond(); - final JsonArray intList = new JsonArray(registryEntryList.size()); - for (final RegistryEntry registryEntry : registryEntryList) { + RegistryEntryList registryEntryList = pair.getSecond(); + JsonArray intList = new JsonArray(registryEntryList.size()); + for (RegistryEntry registryEntry : registryEntryList) { if (RegistryEntry.Type.REFERENCE != registryEntry.getType()) { throw new IllegalStateException("Can't serialize unregistered value " + registryEntry); } diff --git a/extractor/src/main/java/rs/valence/extractor/extractors/TranslationKeys.java b/extractor/src/main/java/rs/valence/extractor/extractors/TranslationKeys.java index bf773c05d..a44ee34f0 100644 --- a/extractor/src/main/java/rs/valence/extractor/extractors/TranslationKeys.java +++ b/extractor/src/main/java/rs/valence/extractor/extractors/TranslationKeys.java @@ -18,14 +18,14 @@ public String fileName() { @Override public JsonElement extract() { - final JsonArray translationsJson = new JsonArray(); + JsonArray translationsJson = new JsonArray(); - final Map translations = TranslationKeys.extractTranslations(); - for (final var translation : translations.entrySet()) { - final String translationKey = translation.getKey(); - final String translationValue = translation.getValue(); + Map translations = extractTranslations(); + for (var translation : translations.entrySet()) { + String translationKey = translation.getKey(); + String translationValue = translation.getValue(); - final var translationJson = new JsonObject(); + var translationJson = new JsonObject(); translationJson.addProperty("key", translationKey); translationJson.addProperty("english_translation", translationValue); @@ -37,16 +37,16 @@ public JsonElement extract() { @SuppressWarnings("unchecked") private static Map extractTranslations() { - final Language language = Language.getInstance(); + Language language = Language.getInstance(); - final Class anonymousClass = language.getClass(); - for (final Field field : anonymousClass.getDeclaredFields()) { + Class anonymousClass = language.getClass(); + for (Field field : anonymousClass.getDeclaredFields()) { try { - final Object fieldValue = field.get(language); + Object fieldValue = field.get(language); if (fieldValue instanceof Map) { return (Map) fieldValue; } - } catch (final IllegalAccessException e) { + } catch (IllegalAccessException e) { throw new RuntimeException("Failed reflection on field '" + field + "' on class '" + anonymousClass + "'", e); } }