Small improvements (#22)

* Remove sky color hardcoding

* Bind to available port instead of 25565

* Fix error class and reduce accessors

* Fix language errors

* Cleanup imports and remove weird behaviour

* Print properly message

* Print version name

* Bump gson, update API usage and use linkedhashset over list

* Reimplement approach to categories

* Enable all feature flags by default

* Use jul instead of slf4j

* Call mc repo before maven central to fix build on mac
This commit is contained in:
Alex
2024-10-27 10:55:58 +01:00
committed by GitHub
parent 1c4802d97e
commit 131218ce79
124 changed files with 639 additions and 1258 deletions
+6
View File
@@ -45,3 +45,9 @@ tasks.withType(RemapJarTask).configureEach {
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
@@ -48,7 +48,7 @@ public class EntitiesDataGenerator implements IDataGenerator {
if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities
Entity entity = entityType.create(DGU.getWorld());
if (entity == null)
throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey()));
throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey()));
entity.discard();
return switch (entity.getClass().getPackageName()) {
case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile";
@@ -58,7 +58,7 @@ public class EntitiesDataGenerator implements IDataGenerator {
case "net.minecraft.entity.passive" -> "Passive mobs";
case "net.minecraft.entity.vehicle" -> "Vehicles";
case "net.minecraft.entity" -> "UNKNOWN";
default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName());
default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName());
};
}
@@ -10,7 +10,9 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class ItemsDataGenerator implements IDataGenerator {
@@ -22,10 +24,12 @@ public class ItemsDataGenerator implements IDataGenerator {
.collect(Collectors.toList());
}
private static List<EnchantmentTarget> getApplicableEnchantmentTargets(Item sourceItem) {
private static Set<String> getApplicableEnchantmentTargets(Item sourceItem) {
return Arrays.stream(EnchantmentTarget.values())
.filter(target -> target.isAcceptableItem(sourceItem))
.collect(Collectors.toList());
.map(EnchantmentsDataGenerator::getEnchantmentTargetName)
.sorted()
.collect(Collectors.toCollection(LinkedHashSet::new));
}
public static JsonObject generateItem(Registry<Item> itemRegistry, Item item) {
@@ -38,13 +42,9 @@ public class ItemsDataGenerator implements IDataGenerator {
itemDesc.addProperty("displayName", DGU.translateText(item.getTranslationKey()));
itemDesc.addProperty("stackSize", item.getMaxCount());
List<EnchantmentTarget> enchantmentTargets = getApplicableEnchantmentTargets(item);
JsonArray enchantCategoriesArray = new JsonArray();
for (EnchantmentTarget target : enchantmentTargets) {
enchantCategoriesArray.add(EnchantmentsDataGenerator.getEnchantmentTargetName(target));
}
if (enchantCategoriesArray.size() > 0) {
getApplicableEnchantmentTargets(item).forEach(enchantCategoriesArray::add);
if (!enchantCategoriesArray.isEmpty()) {
itemDesc.add("enchantCategories", enchantCategoriesArray);
}
@@ -56,7 +56,7 @@ public class ItemsDataGenerator implements IDataGenerator {
Identifier repairWithName = itemRegistry.getKey(repairWithItem).orElseThrow().getValue();
fixedWithArray.add(repairWithName.getPath());
}
if (fixedWithArray.size() > 0) {
if (!fixedWithArray.isEmpty()) {
itemDesc.add("repairWith", fixedWithArray);
}
@@ -20,8 +20,8 @@ public class LanguageDataGenerator implements IDataGenerator {
try {
InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json"));
return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class);
} catch (Exception ignored) {
} catch (Exception e) {
throw new RuntimeException("Failed to generate language file", e);
}
throw new RuntimeException("Failed to generate language file");
}
}
@@ -11,6 +11,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(MinecraftDedicatedServer.class)
public class ReadyMixin {
@Inject(method = "setupServer()Z", at = @At("HEAD"))
private void constructor(CallbackInfoReturnable<Boolean> cir) {
((MinecraftDedicatedServer) (Object) this).setServerPort(0);
}
@Inject(method = "setupServer()Z", at = @At("TAIL"))
private void init(CallbackInfoReturnable<Boolean> cir) {
MinecraftDataGenerator.start(