Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JackCrumpLeys committed Aug 24, 2024
1 parent ac2e67e commit 6251a58
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
40 changes: 20 additions & 20 deletions extractor/src/main/java/rs/valence/extractor/DummyWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<World> registryRef, final DynamicRegistryManager registryManager, final RegistryEntry<DimensionType> dimension, final Supplier<Profiler> profiler, final boolean isClient, final boolean debugWorld, final long seed, final int maxChainedNeighborUpdates) {
private DummyWorld(MutableWorldProperties properties, RegistryKey<World> registryRef, DynamicRegistryManager registryManager, RegistryEntry<DimensionType> dimension, Supplier<Profiler> 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<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, RegistryEntry<SoundEvent> 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<SoundEvent> sound, final SoundCategory category, final float volume, final float pitch, final long seed) {
public void playSoundFromEntity(@Nullable PlayerEntity except, Entity entity, RegistryEntry<SoundEvent> sound, SoundCategory category, float volume, float pitch, long seed) {

}

Expand All @@ -90,7 +90,7 @@ public String asString() {

@Nullable
@Override
public Entity getEntityById(final int id) {
public Entity getEntityById(int id) {
return null;
}

Expand All @@ -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) {

}

Expand All @@ -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) {

}

Expand Down Expand Up @@ -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<GameEvent> event, final Vec3d emitterPos, final GameEvent.Emitter emitter) {
public void emitGameEvent(RegistryEntry<GameEvent> event, Vec3d emitterPos, GameEvent.Emitter emitter) {

}

Expand All @@ -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;
}

Expand All @@ -187,7 +187,7 @@ public List<? extends PlayerEntity> getPlayers() {
}

@Override
public RegistryEntry<Biome> getGeneratorStoredBiome(final int biomeX, final int biomeY, final int biomeZ) {
public RegistryEntry<Biome> getGeneratorStoredBiome(int biomeX, int biomeY, int biomeZ) {
return null;
}

Expand Down Expand Up @@ -226,7 +226,7 @@ public boolean isRaining() {
}

@Override
public void setRaining(final boolean raining) {
public void setRaining(boolean raining) {

}

Expand All @@ -251,7 +251,7 @@ public boolean isDifficultyLocked() {
}

@Override
public void setSpawnPos(final BlockPos pos, final float angle) {
public void setSpawnPos(BlockPos pos, float angle) {

}
}
Expand Down
66 changes: 33 additions & 33 deletions extractor/src/main/java/rs/valence/extractor/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>concrete</i> class without calling its constructor.
*/
public static <T> T magicallyInstantiate(final Class<T> clazz) {
final var rf = ReflectionFactory.getReflectionFactory();
public static <T> T magicallyInstantiate(Class<T> 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(),
Expand All @@ -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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ 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());
attributeJson.addProperty("default_value", attribute.getDefaultValue());
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());
}
Expand Down
Loading

0 comments on commit 6251a58

Please sign in to comment.