Skip to content

Commit

Permalink
0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Oct 9, 2022
1 parent eec76e3 commit 8b1b0be
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx3G
loader_version=0.14.9

# Mod Properties
mod_version = 0.1.1
mod_version = 0.1.2
maven_group = com.dm.earth
archives_base_name = deferred_registries

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ public T get() {
public void register(Registry<? super T> registry) {
Registry.register(registry, this.id, this.entry);
}


public static <T> DeferredObject<T> of(Identifier id, T entry) {
return new DeferredObject<T>(id, entry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.Nullable;

public class DeferredRegistries<T> {
private final Registry<? super T> registry;
Expand All @@ -24,10 +25,7 @@ public static <T> DeferredRegistries<T> create(Registry<? super T> registry, Str
}

public DeferredObject<T> register(String name, T entry) {
if (this.entries.contains(entry)) {
throw new IllegalArgumentException("Entry already exists: " + entry.toString());
}

if (this.getKey(entry) != null) 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;
Expand All @@ -54,4 +52,25 @@ public Collection<T> getEntries() {
}
return entriesL;
}

@Nullable
public Identifier getKey(T entry) {
for (DeferredObject<T> object : this.entries) {
if (object.get().equals(entry)) return object.getId();
}
return null;
}

@Nullable
public T get(Identifier id) {
for (DeferredObject<T> object : this.entries) {
if (object.getId().equals(id)) return object.get();
}
return null;
}

@Nullable
public Identifier get(T entry) {
return this.getKey(entry);
}
}
3 changes: 1 addition & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

"depends": {
"fabricloader": ">=0.14.6",
"fabric": "*",
"minecraft": "~1.18.2",
"minecraft": ">=1.18",
"java": ">=17"
},
"suggests": {
Expand Down

0 comments on commit 8b1b0be

Please sign in to comment.