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))
}
}
@@ -49,7 +49,7 @@ public class EntitiesDataGenerator implements IDataGenerator {
if (entityType == EntityType.PLAYER) return "UNKNOWN";
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";
@@ -59,7 +59,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());
};
}
@@ -11,7 +11,9 @@ import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
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 {
@@ -23,10 +25,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) {
@@ -39,13 +43,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);
}
@@ -57,7 +57,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");
}
}
@@ -0,0 +1,36 @@
/*
* SoulFire
* Copyright (C) 2024 AlexProgrammerDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package dev.u9g.minecraftdatagenerator.mixin;
import net.minecraft.resource.DataPackSettings;
import net.minecraft.resource.featuretoggle.FeatureFlags;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.List;
@Mixin(DataPackSettings.class)
public class DataPackSettingsMixin {
@Inject(method = "getEnabled", at = @At("HEAD"), cancellable = true)
public void getEnabled(CallbackInfoReturnable<List<String>> cir) {
cir.setReturnValue(FeatureFlags.FEATURE_MANAGER.toId(FeatureFlags.FEATURE_MANAGER.getFeatureSet()).stream().map(Identifier::getPath).toList());
}
}
@@ -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(
@@ -4,6 +4,7 @@
"package": "dev.u9g.minecraftdatagenerator.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"DataPackSettingsMixin",
"EULAMixin",
"MiningToolItemAccessor",
"ReadyMixin"