diff --git a/CHANGELOG.md b/CHANGELOG.md index ebde73b..f52545e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ -### 21.4.1 +### 21.4.2 -- Fix registration on fabirc \ No newline at end of file +- Pass ResourceKey for creation of new items \ No newline at end of file diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/ItemRegistryObjects.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/ItemRegistryObjects.java new file mode 100644 index 0000000..ff5e830 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/ItemRegistryObjects.java @@ -0,0 +1,31 @@ +package com.unrealdinnerbone.trenzalore.api.registry; + +import com.google.common.base.Suppliers; +import com.unrealdinnerbone.trenzalore.lib.RLUtils; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; + +public class ItemRegistryObjects extends RegistryObjects { + + public ItemRegistryObjects(String modID) { + super(modID, Registries.ITEM); + } + + public RegistryEntry register(String name, Function object, UnaryOperator itemProperties) { + ResourceLocation rl = RLUtils.rl(modID, name); + ResourceKey key = ResourceKey.create(registryKey, rl); + Supplier memoize = Suppliers.memoize(() -> object.apply(itemProperties.apply(new Item.Properties() + .setId(key)))); + RegistryEntry entry = new RegistryEntry<>(rl, memoize); + objects.add(entry); + return entry; + } + + +} diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/Regeneration.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/Regeneration.java index 27dca70..e4c3847 100644 --- a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/Regeneration.java +++ b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/Regeneration.java @@ -22,8 +22,12 @@ public class Regeneration { - public static RegistryObjects create(ResourceKey> registry) { - return RegistryObjects.of(registry); + public static RegistryObjects create(String modID, ResourceKey> registry) { + return RegistryObjects.of(modID, registry); + } + + public static ItemRegistryObjects createItemRegistry(String modID) { + return new ItemRegistryObjects(modID); } public static void addItemToCreateTab(ResourceKey tabResourceKey, Supplier item) { diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryEntry.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryEntry.java index 4e19add..46ddeb7 100644 --- a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryEntry.java +++ b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryEntry.java @@ -1,18 +1,20 @@ package com.unrealdinnerbone.trenzalore.api.registry; import net.minecraft.core.Holder; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; import java.util.function.Supplier; public class RegistryEntry implements Supplier { - private final String name; + private final ResourceLocation key; private final Supplier entry; private Holder holder; - public RegistryEntry(String name, Supplier entry) { - this.name = name; + public RegistryEntry(ResourceLocation key, Supplier entry) { + this.key = key; this.entry = entry; } @@ -33,8 +35,8 @@ public T get() { return entry.get(); } - public String name() { - return name; + public ResourceLocation getKey() { + return key; } public Supplier entry() { diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryObjects.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryObjects.java index a3b0df0..1f7b8ca 100644 --- a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryObjects.java +++ b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryObjects.java @@ -1,23 +1,54 @@ package com.unrealdinnerbone.trenzalore.api.registry; import com.google.common.base.Suppliers; +import com.unrealdinnerbone.trenzalore.lib.RLUtils; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.function.Function; import java.util.function.Supplier; -public record RegistryObjects(ResourceKey> registryKey, List> objects) { +public class RegistryObjects { + protected final String modID; + protected final ResourceKey> registryKey; + protected final List> objects; - public static RegistryObjects of(ResourceKey> registryKey) { - return new RegistryObjects<>(registryKey, new ArrayList<>()); + public RegistryObjects(String modID, ResourceKey> registryKey) { + this.modID = modID; + this.registryKey = registryKey; + this.objects = new ArrayList<>(); + } + + public static RegistryObjects of(String modID, ResourceKey> registryKey) { + return new RegistryObjects<>(modID, registryKey); } public RegistryEntry register(String name, Supplier object) { - RegistryEntry entry = new RegistryEntry<>(name, Suppliers.memoize(object::get)); + ResourceLocation rl = RLUtils.rl(modID, name); + RegistryEntry entry = new RegistryEntry<>(rl, Suppliers.memoize(object::get)); + objects.add(entry); + return entry; + } + + public RegistryEntry registerWithId(String name, Function, A> object) { + ResourceLocation rl = RLUtils.rl(modID, name); + ResourceKey key = ResourceKey.create(registryKey, rl); + Supplier memoize = Suppliers.memoize(() -> object.apply(key)); + RegistryEntry entry = new RegistryEntry<>(rl, memoize); objects.add(entry); return entry; } + public ResourceKey> registryKey() { + return registryKey; + } + + public List> objects() { + return objects; + } + } diff --git a/fabric/src/main/java/com/unrealdinnerbone/trenzalore/platform/FabricPlatformHelper.java b/fabric/src/main/java/com/unrealdinnerbone/trenzalore/platform/FabricPlatformHelper.java index 4ecbe68..f5998aa 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/trenzalore/platform/FabricPlatformHelper.java +++ b/fabric/src/main/java/com/unrealdinnerbone/trenzalore/platform/FabricPlatformHelper.java @@ -61,8 +61,7 @@ public void registryRegistryObjects(String modId, RegistryObjects registr Registry value = registry.value(); Registry theRegistry = (Registry) value; for (RegistryEntry object : registryObjects.objects()) { - ResourceLocation id = RLUtils.rl(modId, object.name()); - Holder.Reference register = Registry.registerForHolder(theRegistry, id, object.get()); + Holder.Reference register = Registry.registerForHolder(theRegistry, object.getKey(), object.get()); object.setHolder(register); } }, () -> LOGGER.error("Failed to find registry: {}", registryKey.location())); diff --git a/gradle.properties b/gradle.properties index 7c2f8c1..a5ffaa5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project -mod_version=21.4.1 +mod_version=21.4.2 maven_group=com.unrealdinnerbone mod_name=Trenzalore mod_author=UnRealDinnerbone diff --git a/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreNeoRegistry.java b/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreNeoRegistry.java index fed3097..b0ddbe6 100644 --- a/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreNeoRegistry.java +++ b/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreNeoRegistry.java @@ -14,7 +14,7 @@ public class TrenzaloreNeoRegistry implements IRegistry { - private static final RegistryObjects> GLOBAL_LOOT_MODIFIERS = Regeneration.create(NeoForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS); + private static final RegistryObjects> GLOBAL_LOOT_MODIFIERS = Regeneration.create(Trenzalore.MOD_ID, NeoForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS); public static final RegistryEntry> SIMPLE_LOOT_MODIFIER = GLOBAL_LOOT_MODIFIERS.register("replace", () -> ReplaceItemModifier.CODEC); public static final RegistryEntry> ADD_ITEM_MODIFIER = GLOBAL_LOOT_MODIFIERS.register("add", () -> AddItemModifier.CODEC); diff --git a/neo/src/main/java/com/unrealdinnerbone/trenzalore/platform/NeoPlatformHelper.java b/neo/src/main/java/com/unrealdinnerbone/trenzalore/platform/NeoPlatformHelper.java index b717649..117bffa 100644 --- a/neo/src/main/java/com/unrealdinnerbone/trenzalore/platform/NeoPlatformHelper.java +++ b/neo/src/main/java/com/unrealdinnerbone/trenzalore/platform/NeoPlatformHelper.java @@ -45,7 +45,7 @@ public boolean isModLoaded(String modId) { public void registryRegistryObjects(String modId, RegistryObjects registryObjects) { DeferredRegister deferredRegister = DeferredRegister.create(registryObjects.registryKey(), modId); registryObjects.objects().forEach(registryEntry -> { - Holder register = deferredRegister.register(registryEntry.name(), registryEntry.entry()); + Holder register = deferredRegister.register(registryEntry.getKey().getPath(), registryEntry.entry()); registryEntry.setHolder(register); }); IEventBus modEventBus = ModList.get().getModContainerById(modId)