Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev/1.21' into dev/1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Sep 7, 2024
2 parents a944532 + 0b9e82c commit 3e19303
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

###### The next generation cross-platform modular Minecraft modding API.

![fabric](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/supported/fabric_vector.svg)
![neoforge](https://raw.githubusercontent.com/KessokuTeaTime/Badges-Extra/main/assets/cozy/supported/neoforge_vector.svg)
![forge](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/unsupported/forge_vector.svg)
[![fabric](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/supported/fabric_vector.svg)](https://fabricmc.net/)
[![neoforge](https://raw.githubusercontent.com/KessokuTeaTime/Badges-Extra/main/assets/cozy/supported/neoforge_vector.svg)](https://neoforged.net/)
[![forge](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/unsupported/forge_vector.svg)](https://minecraftforge.net/)

<details>
<summary>
Expand Down
7 changes: 6 additions & 1 deletion entrypoint/common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
apply from: rootProject.file("gradle/scripts/klib-common.gradle")

group = "band.kessoku.lib.entrypoint"
base.archivesName = rootProject.name + "-entrypoint"
base.archivesName = rootProject.name + "-entrypoint"

dependencies {
moduleImplementation(project(":base-common"))
implementation libs.aj4j
}
1 change: 1 addition & 0 deletions entrypoint/fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ base.archivesName = rootProject.name + "-entrypoint"

dependencies {
kessoku.moduleImpl("base", "common")
implementation libs.aj4j

common(project(path: ':entrypoint-common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':entrypoint-common', configuration: 'transformProductionFabric')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,55 @@
import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

@SuppressWarnings("unused")
public interface Registry {
@ApiStatus.Internal
static Registry getInstance() {
return KessokuRegistryServices.getRegistry();
}

default <T> T register(net.minecraft.registry.Registry<? super T> registry, String id, T entry) {
static <T> T register(net.minecraft.registry.Registry<? super T> registry, String id, T entry) {
return register(registry, Identifier.of(id), entry);
}

<V, T extends V> T register(net.minecraft.registry.Registry<V> registry, Identifier id, T entry);
@ApiStatus.Internal
<V, T extends V> T registerInternal(net.minecraft.registry.Registry<V> registry, Identifier id, T entry);

default Item registerItem(Identifier id, Item.Settings settings) {
static <V, T extends V> T register(net.minecraft.registry.Registry<V> registry, Identifier id, T entry) {
return Registry.getInstance().registerInternal(registry, id, entry);
}

static Item registerItem(Identifier id, Item.Settings settings) {
return register(Registries.ITEM, id, new Item(settings));
}

default Item registerSimpleItem(Identifier id) {
static Item registerSimpleItem(Identifier id) {
return register(Registries.ITEM, id, new Item(new Item.Settings()));
}

default Block registerBlock(Identifier id, AbstractBlock.Settings settings) {
static Block registerBlock(Identifier id, AbstractBlock.Settings settings) {
return register(Registries.BLOCK, id, new Block(settings));
}

default Block registerSimpleBlock(Identifier id) {
static Block registerSimpleBlock(Identifier id) {
return registerBlock(id, AbstractBlock.Settings.create());
}

default Item registerSimpleBlockItem(Identifier id, Block block) {
static Item registerSimpleBlockItem(Identifier id, Block block) {
return registerSimpleBlockItem(id, block, new Item.Settings());
}

default Item registerSimpleBlockItem(Identifier id, Block block, Item.Settings settings) {
static Item registerSimpleBlockItem(Identifier id, Block block, Item.Settings settings) {
return register(Registries.ITEM, id, new BlockItem(block, settings));
}

default Item registerSimpleBlockItem(RegistryEntry<Block> block, Item.Settings settings) {
static Item registerSimpleBlockItem(RegistryEntry<Block> block, Item.Settings settings) {
return registerSimpleBlockItem(block.getKey().orElseThrow().getValue(), block.value(), settings);
}

default Item registerSimpleBlockItem(RegistryEntry<Block> block) {
static Item registerSimpleBlockItem(RegistryEntry<Block> block) {
return registerSimpleBlockItem(block.getKey().orElseThrow().getValue(), block.value(), new Item.Settings());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@AutoService(Registry.class)
public class RegistryImpl implements Registry {
@Override
public <V, T extends V> T register(net.minecraft.registry.Registry<V> registry, Identifier id, T entry) {
public <V, T extends V> T registerInternal(net.minecraft.registry.Registry<V> registry, Identifier id, T entry) {
return net.minecraft.registry.Registry.register(registry, id, entry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,25 @@
import net.neoforged.neoforge.registries.RegisterEvent;

@AutoService(Registry.class)
@SuppressWarnings("unchecked, rawtypes")
@SuppressWarnings({"unchecked", "rawtypes"})
public class RegistryImpl implements Registry {
private static final Map<net.minecraft.registry.Registry, Set<EntryWithId>> registries = new ConcurrentHashMap<>();
private static final Map<net.minecraft.registry.Registry, Map<Identifier, Object>> registries = new ConcurrentHashMap<>();
private static boolean registered = false;

@ApiStatus.Internal
public static void onRegister(RegisterEvent event) {
registries.forEach((registry, entryWithIds) ->
entryWithIds.forEach(entryWithId ->
event.register(registry.getKey(), entryWithId.id(), () -> entryWithId.entry())
)
);
registries.forEach((registry, map) -> map.forEach((id, entry) -> event.register(registry.getKey(), id, () -> entry)));
registered = true;
}

@Override
public <V, T extends V> T register(net.minecraft.registry.Registry<V> registry, Identifier id, T entry) {
public <V, T extends V> T registerInternal(net.minecraft.registry.Registry<V> registry, Identifier id, T entry) {
if (registered)
throw new IllegalStateException("net.neoforged.neoforge.registries.RegisterEvent has already been called!");
if (!registries.containsKey(registry)) registries.put(registry, new HashSet<>());
registries.get(registry).add(new EntryWithId<>(id, entry));
throw new IllegalStateException("Cannot register new entries after net.neoforged.neoforge.registries.RegisterEvent has been fired.");
if (!registries.containsKey(registry)) registries.put(registry, new HashMap<>());
if (registries.get(registry).putIfAbsent(id, entry) != null) {
throw new IllegalArgumentException("Duplicate registration " + id.toString());
}
return entry;
}

record EntryWithId<T>(Identifier id, T entry) {
}
}

0 comments on commit 3e19303

Please sign in to comment.