generated from jaredlll08/MultiLoader-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helpers for passing register Resource Key
- Loading branch information
1 parent
7eefb66
commit 561dd6e
Showing
9 changed files
with
85 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
### 21.4.1 | ||
### 21.4.2 | ||
|
||
- Fix registration on fabirc | ||
- Pass ResourceKey for creation of new items |
31 changes: 31 additions & 0 deletions
31
common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/ItemRegistryObjects.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Item> { | ||
|
||
public ItemRegistryObjects(String modID) { | ||
super(modID, Registries.ITEM); | ||
} | ||
|
||
public <A extends Item> RegistryEntry<A> register(String name, Function<Item.Properties, A> object, UnaryOperator<Item.Properties> itemProperties) { | ||
ResourceLocation rl = RLUtils.rl(modID, name); | ||
ResourceKey<Item> key = ResourceKey.create(registryKey, rl); | ||
Supplier<A> memoize = Suppliers.memoize(() -> object.apply(itemProperties.apply(new Item.Properties() | ||
.setId(key)))); | ||
RegistryEntry<A> entry = new RegistryEntry<>(rl, memoize); | ||
objects.add(entry); | ||
return entry; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 35 additions & 4 deletions
39
common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryObjects.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T>(ResourceKey<Registry<T>> registryKey, List<RegistryEntry<? extends T>> objects) { | ||
public class RegistryObjects<T> { | ||
protected final String modID; | ||
protected final ResourceKey<Registry<T>> registryKey; | ||
protected final List<RegistryEntry<? extends T>> objects; | ||
|
||
public static <T> RegistryObjects<T> of(ResourceKey<Registry<T>> registryKey) { | ||
return new RegistryObjects<>(registryKey, new ArrayList<>()); | ||
public RegistryObjects(String modID, ResourceKey<Registry<T>> registryKey) { | ||
this.modID = modID; | ||
this.registryKey = registryKey; | ||
this.objects = new ArrayList<>(); | ||
} | ||
|
||
public static <T> RegistryObjects<T> of(String modID, ResourceKey<Registry<T>> registryKey) { | ||
return new RegistryObjects<>(modID, registryKey); | ||
} | ||
|
||
public <A extends T> RegistryEntry<A> register(String name, Supplier<A> object) { | ||
RegistryEntry<A> entry = new RegistryEntry<>(name, Suppliers.memoize(object::get)); | ||
ResourceLocation rl = RLUtils.rl(modID, name); | ||
RegistryEntry<A> entry = new RegistryEntry<>(rl, Suppliers.memoize(object::get)); | ||
objects.add(entry); | ||
return entry; | ||
} | ||
|
||
public <A extends T> RegistryEntry<A> registerWithId(String name, Function<ResourceKey<T>, A> object) { | ||
ResourceLocation rl = RLUtils.rl(modID, name); | ||
ResourceKey<T> key = ResourceKey.create(registryKey, rl); | ||
Supplier<A> memoize = Suppliers.memoize(() -> object.apply(key)); | ||
RegistryEntry<A> entry = new RegistryEntry<>(rl, memoize); | ||
objects.add(entry); | ||
return entry; | ||
} | ||
|
||
public ResourceKey<Registry<T>> registryKey() { | ||
return registryKey; | ||
} | ||
|
||
public List<RegistryEntry<? extends T>> objects() { | ||
return objects; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters