generated from DM-Earth/Fabric-Mod-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.
- Loading branch information
Showing
10 changed files
with
85 additions
and
63 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 +1 @@ | ||
# Modid | ||
# Deferred Registries |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/dm/earth/deferred_registries/DeferredObject.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,33 @@ | ||
package com.dm.earth.deferred_registries; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
public class DeferredObject<T> { | ||
private final Identifier id; | ||
private final T entry; | ||
|
||
public DeferredObject(Identifier id, T entry) { | ||
this.id = id; | ||
this.entry = entry; | ||
} | ||
|
||
public DeferredObject(Identifier id, Supplier<T> entry) { | ||
this.id = id; | ||
this.entry = entry.get(); | ||
} | ||
|
||
public Identifier getId() { | ||
return this.id; | ||
} | ||
|
||
public T get() { | ||
return this.entry; | ||
} | ||
|
||
public void register(Registry<? super T> registry) { | ||
Registry.register(registry, this.id, this.entry); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/dm/earth/deferred_registries/DeferredRegistries.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,44 @@ | ||
package com.dm.earth.deferred_registries; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
public class DeferredRegistries<T> { | ||
private final Registry<? super T> registry; | ||
private final String modId; | ||
private final List<DeferredObject<T>> entries; | ||
|
||
private DeferredRegistries(Registry<? super T> registry, String modId) { | ||
this.registry = registry; | ||
this.modId = modId; | ||
this.entries = new ArrayList<>(); | ||
} | ||
|
||
public static <T> DeferredRegistries<T> create(Registry<? super T> registry, String modId) { | ||
return new DeferredRegistries<T>(registry, modId); | ||
} | ||
|
||
public DeferredObject<T> register(String name, T entry) { | ||
if (this.entries.contains(entry)) { | ||
throw new IllegalArgumentException("Entry already exists: " + entry.toString()); | ||
} | ||
|
||
DeferredObject<T> e = new DeferredObject<T>(new Identifier(this.modId, name), entry); | ||
this.entries.add(e); | ||
return e; | ||
} | ||
|
||
public DeferredObject<T> register(String name, Supplier<T> entry) { | ||
return this.register(name, entry.get()); | ||
} | ||
|
||
public void register() { | ||
for (DeferredObject<T> entry : entries) { | ||
entry.register(this.registry); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 was deleted.
Oops, something went wrong.