Skip to content

Commit

Permalink
port some fg features
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Oct 4, 2022
1 parent dfb9e63 commit 210acc9
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Modid
# Deferred Registries
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx3G
# Mod Properties
mod_version = 0.1.0
maven_group = com.dm.earth
archives_base_name = modid
archives_base_name = deferred_registries

# Dependencies
fabric_version=0.58.0+1.18.2
33 changes: 33 additions & 0 deletions src/main/java/com/dm/earth/deferred_registries/DeferredObject.java
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);
}
}
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);
}
}
}
20 changes: 0 additions & 20 deletions src/main/java/com/dm/earth/modid/Modid.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/com/dm/earth/modid/mixin/SimpleMixin.java

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/assets/modid/icon.png
Binary file not shown.
19 changes: 6 additions & 13 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
{
"schemaVersion": 1,
"id": "modid",
"id": "deferred_registries",
"version": "${version}",

"name": "modid",
"description": "This is an example description! Tell everyone what your mod is about!",
"name": "deferred_registries",
"description": "Register things in ease",
"authors": [
"DM Earth"
],
"contact": {
"homepage": "https://github.com/DM-Earth"
"homepage": "https://github.com/DM-Earth/DeferredRegistries"
},

"license": "MIT",
"icon": "assets/modid/icon.png",
"icon": "assets/deferred_registries/icon.png",

"environment": "*",
"entrypoints": {
"main": [
"com.dm.earth.modid.ModId"
]
},
"mixins": [
"modid.mixins.json"
],
"entrypoints": {},

"depends": {
"fabricloader": ">=0.14.6",
Expand Down
14 changes: 0 additions & 14 deletions src/main/resources/modid.mixins.json

This file was deleted.

0 comments on commit 210acc9

Please sign in to comment.