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:
@@ -45,3 +45,9 @@ tasks.withType(RemapJarTask).configureEach {
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(21))
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -53,7 +53,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";
|
||||
@@ -63,7 +63,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());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+12
-15
@@ -5,16 +5,17 @@ import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.BuiltinRegistries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemsDataGenerator implements IDataGenerator {
|
||||
@@ -26,13 +27,13 @@ public class ItemsDataGenerator implements IDataGenerator {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static List<TagKey<Item>> getApplicableEnchantmentTargets(Item sourceItem) {
|
||||
return sourceItem.getComponents().get(DataComponentTypes.ENCHANTMENTS)
|
||||
.getEnchantments()
|
||||
.stream()
|
||||
.map(RegistryEntry::value)
|
||||
private static Set<String> getApplicableEnchantmentTargets(RegistryEntry<Item> sourceItem) {
|
||||
return DGU.getWorld().getRegistryManager().get(RegistryKeys.ENCHANTMENT).stream()
|
||||
.map(Enchantment::getApplicableItems)
|
||||
.toList();
|
||||
.filter(sourceItem::isIn)
|
||||
.map(EnchantmentsDataGenerator::getEnchantmentTargetName)
|
||||
.sorted()
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
}
|
||||
|
||||
public static JsonObject generateItem(Registry<Item> itemRegistry, Item item) {
|
||||
@@ -45,13 +46,9 @@ public class ItemsDataGenerator implements IDataGenerator {
|
||||
itemDesc.addProperty("displayName", DGU.translateText(item.getTranslationKey()));
|
||||
itemDesc.addProperty("stackSize", item.getMaxCount());
|
||||
|
||||
List<TagKey<Item>> enchantmentTargets = getApplicableEnchantmentTargets(item);
|
||||
|
||||
JsonArray enchantCategoriesArray = new JsonArray();
|
||||
for (TagKey<Item> target : enchantmentTargets) {
|
||||
enchantCategoriesArray.add(EnchantmentsDataGenerator.getEnchantmentTargetName(target));
|
||||
}
|
||||
if (enchantCategoriesArray.size() > 0) {
|
||||
getApplicableEnchantmentTargets(itemRegistry.getEntry(item)).forEach(enchantCategoriesArray::add);
|
||||
if (!enchantCategoriesArray.isEmpty()) {
|
||||
itemDesc.add("enchantCategories", enchantCategoriesArray);
|
||||
}
|
||||
|
||||
@@ -63,7 +60,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);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -9,6 +9,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.ToolComponent;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.MiningToolItem;
|
||||
@@ -85,7 +86,7 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
itemRegistry.forEach(item -> {
|
||||
if (item instanceof MiningToolItem toolItem) {
|
||||
item.getComponents().get(DataComponentTypes.TOOL).rules()
|
||||
.stream().map(rule -> rule.blocks())
|
||||
.stream().map(ToolComponent.Rule::blocks)
|
||||
.forEach(blocks -> {
|
||||
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
|
||||
if (tagKey.isPresent()) {
|
||||
@@ -137,7 +138,7 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
//Tools are handled rather easily and do not require anything else
|
||||
if (item instanceof MiningToolItem toolItem) {
|
||||
item.getComponents().get(DataComponentTypes.TOOL).rules()
|
||||
.stream().map(rule -> rule.blocks())
|
||||
.stream().map(ToolComponent.Rule::blocks)
|
||||
.forEach(blocks -> {
|
||||
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
|
||||
if (tagKey.isPresent()) {
|
||||
|
||||
@@ -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,10 @@ 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) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"package": "dev.u9g.minecraftdatagenerator.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"DataPackSettingsMixin",
|
||||
"EULAMixin",
|
||||
"ReadyMixin"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user