From 6ade13998b631659c9807d551fcdad7c0a4621a9 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 17 Mar 2024 18:38:28 +0100 Subject: [PATCH 01/36] Initial work on registry-sync-v2 --- gradle.properties | 1 + .../common.gradle | 3 +- .../1.12.2/build.gradle | 0 .../1.12.2/gradle.properties | 2 + .../sync/versioned/SimpleRegistryMixin.java | 23 +++++++ .../1.12.2/src/main/resources/fabric.mod.json | 42 ++++++++++++ ...cy-fabric-registry-sync-api-v2.mixins.json | 13 ++++ .../common.gradle | 5 ++ .../common/build.gradle | 0 .../common/gradle.properties | 2 + .../api/registry/v2/RegistryHelper.java | 28 ++++++++ .../api/registry/v2/RegistryHolder.java | 16 +++++ .../v2/event/RegistryBeforeAddCallback.java | 19 ++++++ .../v2/event/RegistryEntryAddedCallback.java | 19 ++++++ .../v2/event/RegistryInitializedEvent.java | 18 +++++ .../RegistryHelperImplementation.java | 65 ++++++++++++++++++ .../registry/accessor/RegistryIdSetter.java | 7 ++ .../registry/sync/SimpleRegistryMixinV2.java | 67 +++++++++++++++++++ .../common/src/main/resources/fabric.mod.json | 45 +++++++++++++ ...ic-registry-sync-api-v2-common.mixins.json | 13 ++++ settings.gradle | 1 + 21 files changed, 388 insertions(+), 1 deletion(-) create mode 100644 legacy-fabric-registry-sync-api-v2/1.12.2/build.gradle create mode 100644 legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties create mode 100644 legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java create mode 100644 legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json create mode 100644 legacy-fabric-registry-sync-api-v2/common.gradle create mode 100644 legacy-fabric-registry-sync-api-v2/common/build.gradle create mode 100644 legacy-fabric-registry-sync-api-v2/common/gradle.properties create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHolder.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json diff --git a/gradle.properties b/gradle.properties index 6a8076ef5..ee50d6924 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,5 +19,6 @@ legacy-fabric-logger-api-v1.version = 1.0.4 legacy-fabric-networking-api-v1.version = 2.0.1 legacy-fabric-permissions-api-v1.version = 1.0.1 legacy-fabric-registry-sync-api-v1.version = 2.2.0 +legacy-fabric-registry-sync-api-v2.version = 1.0.0 legacy-fabric-rendering-api-v1.version = 1.0.0 legacy-fabric-resource-loader-v1.version = 2.1.1 diff --git a/legacy-fabric-registry-sync-api-v1/common.gradle b/legacy-fabric-registry-sync-api-v1/common.gradle index 594e150a8..4e74f3a5e 100644 --- a/legacy-fabric-registry-sync-api-v1/common.gradle +++ b/legacy-fabric-registry-sync-api-v1/common.gradle @@ -1,5 +1,6 @@ moduleDependencies(project, [ "legacy-fabric-api-base", "legacy-fabric-networking-api-v1", - "legacy-fabric-resource-loader-v1" + "legacy-fabric-resource-loader-v1", + "legacy-fabric-registry-sync-v2" ]) diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/build.gradle b/legacy-fabric-registry-sync-api-v2/1.12.2/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties new file mode 100644 index 000000000..a104a3a86 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties @@ -0,0 +1,2 @@ +minVersionExcluded=1.10.2 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java new file mode 100644 index 000000000..4dd372dd9 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java @@ -0,0 +1,23 @@ +package net.legacyfabric.fabric.mixin.registry.sync.versioned; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; + +import net.legacyfabric.fabric.api.util.Identifier; + +import net.minecraft.util.registry.SimpleRegistry; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(SimpleRegistry.class) +public abstract class SimpleRegistryMixin implements RegistryHolder { + @Shadow + public abstract void add(int id, K identifier, V object); + + @Override + public void register(int rawId, Identifier identifier, V value) { + getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); + add(rawId, toKeyType(identifier), value); + getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..1f20467ce --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/fabric.mod.json @@ -0,0 +1,42 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-registry-sync-api-v2", + "name": "Legacy Fabric Registry Sync API (V2)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Registry hooks", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + "legacy-fabric-registry-sync-api-v2.mixins.json" + ], + "custom": { + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json new file mode 100644 index 000000000..b4992aa42 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.SimpleRegistryMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v2/common.gradle b/legacy-fabric-registry-sync-api-v2/common.gradle new file mode 100644 index 000000000..594e150a8 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common.gradle @@ -0,0 +1,5 @@ +moduleDependencies(project, [ + "legacy-fabric-api-base", + "legacy-fabric-networking-api-v1", + "legacy-fabric-resource-loader-v1" +]) diff --git a/legacy-fabric-registry-sync-api-v2/common/build.gradle b/legacy-fabric-registry-sync-api-v2/common/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-registry-sync-api-v2/common/gradle.properties b/legacy-fabric-registry-sync-api-v2/common/gradle.properties new file mode 100644 index 000000000..a499ab733 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java new file mode 100644 index 000000000..15c6b4665 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java @@ -0,0 +1,28 @@ +package net.legacyfabric.fabric.api.registry.v2; + +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; + +import java.util.function.Function; + +public class RegistryHelper { + public static void register(RegistryHolder registry, Identifier identifier, T value) { + RegistryHelperImplementation.register(registry, identifier, value); + } + + public static void registry(Identifier registryId, Identifier identifier, T value) { + register(RegistryHelperImplementation.getRegistry(registryId), identifier, value); + } + + public static T register(RegistryHolder registry, Identifier identifier, Function valueConstructor) { + return RegistryHelperImplementation.register(registry, identifier, valueConstructor); + } + + public static T registry(Identifier registryId, Identifier identifier, Function valueConstructor) { + return register(RegistryHelperImplementation.getRegistry(registryId), identifier, valueConstructor); + } + + public static void addRegistry(Identifier identifier, RegistryHolder registryHolder) { + RegistryHelperImplementation.registerRegistry(identifier, registryHolder); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHolder.java new file mode 100644 index 000000000..b7e8aada1 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHolder.java @@ -0,0 +1,16 @@ +package net.legacyfabric.fabric.api.registry.v2; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; +import net.legacyfabric.fabric.api.util.Identifier; + +public interface RegistryHolder { + Identifier getId(); + Event> getEntryAddedCallback(); + Event> getBeforeAddedCallback(); + + void register(int rawId, Identifier identifier, T value); + + K toKeyType(Object o); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java new file mode 100644 index 000000000..c4206bf40 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java @@ -0,0 +1,19 @@ +package net.legacyfabric.fabric.api.registry.v2.event; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; + +@FunctionalInterface +public interface RegistryBeforeAddCallback { + void onEntryAdding(int rawId, Identifier id, T object); + + static Event> event(Identifier registryId) { + return event(RegistryHelperImplementation.getRegistry(registryId)); + } + + static Event> event(RegistryHolder registry) { + return registry.getBeforeAddedCallback(); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java new file mode 100644 index 000000000..72562274b --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java @@ -0,0 +1,19 @@ +package net.legacyfabric.fabric.api.registry.v2.event; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; + +@FunctionalInterface +public interface RegistryEntryAddedCallback { + void onEntryAdded(int rawId, Identifier id, T object); + + static Event> event(Identifier registryId) { + return event(RegistryHelperImplementation.getRegistry(registryId)); + } + + static Event> event(RegistryHolder registry) { + return registry.getEntryAddedCallback(); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java new file mode 100644 index 000000000..9bf29f371 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java @@ -0,0 +1,18 @@ +package net.legacyfabric.fabric.api.registry.v2.event; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; + +/** + * Triggered only when a new registry is registered. + */ +@FunctionalInterface +public interface RegistryInitializedEvent { + void initialized(RegistryHolder registry); + + static Event event(Identifier registryId) { + return RegistryHelperImplementation.getInitializationEvent(registryId); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java new file mode 100644 index 000000000..a8057e00d --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java @@ -0,0 +1,65 @@ +package net.legacyfabric.fabric.impl.registry; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.event.EventFactory; +import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.util.Identifier; + +import net.legacyfabric.fabric.api.util.VersionUtils; +import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +public class RegistryHelperImplementation { + public static final boolean hasFlatteningBegun = VersionUtils.matches(">=1.8 <=1.12.2"); + public static final Map> INITIALIZATION_EVENTS = new HashMap<>(); + private static final Map> REGISTRIES = new HashMap<>(); + + public static Event getInitializationEvent(Identifier registryId) { + Event event; + + if (INITIALIZATION_EVENTS.containsKey(registryId)) { + event = INITIALIZATION_EVENTS.get(registryId); + } else { + event = EventFactory.createArrayBacked(RegistryInitializedEvent.class, + (callbacks) -> new RegistryInitializedEvent() { + @Override + public void initialized(RegistryHolder registry) { + for (RegistryInitializedEvent callback : callbacks) { + callback.initialized(registry); + } + } + } + ); + INITIALIZATION_EVENTS.put(registryId, event); + } + + return event; + } + + public static RegistryHolder getRegistry(Identifier identifier) { + return (RegistryHolder) REGISTRIES.get(identifier); + } + + public static void registerRegistry(Identifier identifier, RegistryHolder holder) { + if (REGISTRIES.containsKey(identifier)) throw new IllegalArgumentException("Attempted to register registry " + identifier.toString() + " twices!"); + REGISTRIES.put(identifier, holder); + + if (holder instanceof RegistryIdSetter) ((RegistryIdSetter) holder).fabric$setId(identifier); + } + + public static void register(RegistryHolder registry, Identifier identifier, T value) { + int computedId = -1; + registry.register(computedId, identifier, value); + } + + public static T register(RegistryHolder registry, Identifier identifier, Function valueConstructor) { + int computedId = -1; + T value = valueConstructor.apply(computedId); + registry.register(computedId, identifier, value); + return value; + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java new file mode 100644 index 000000000..f01623b83 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java @@ -0,0 +1,7 @@ +package net.legacyfabric.fabric.impl.registry.accessor; + +import net.legacyfabric.fabric.api.util.Identifier; + +public interface RegistryIdSetter { + void fabric$setId(Identifier identifier); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java new file mode 100644 index 000000000..e33f91f4e --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java @@ -0,0 +1,67 @@ +package net.legacyfabric.fabric.mixin.registry.sync; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.event.EventFactory; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; +import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; + +import net.legacyfabric.fabric.api.util.Identifier; + +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; +import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter; + +import net.minecraft.util.registry.SimpleRegistry; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(SimpleRegistry.class) +public abstract class SimpleRegistryMixinV2 implements RegistryHolder, RegistryIdSetter { + @Unique + private final Event> fabric_addObjectEvent = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryEntryAddedCallback callback : callbacks) { + callback.onEntryAdded(rawId, id, object); + } + } + ); + + @Unique + private final Event> fabric_beforeAddObjectEvent = EventFactory.createArrayBacked(RegistryBeforeAddCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryBeforeAddCallback callback : callbacks) { + callback.onEntryAdding(rawId, id, object); + } + } + ); + + @Unique + private Identifier fabric_id; + + @Override + public Event> getEntryAddedCallback() { + return this.fabric_addObjectEvent; + } + + @Override + public Event> getBeforeAddedCallback() { + return this.fabric_beforeAddObjectEvent; + } + + @Override + public Identifier getId() { + return this.fabric_id; + } + + @Override + public void fabric$setId(Identifier identifier) { + assert this.fabric_id == null; + this.fabric_id = identifier; + } + + @Override + public K toKeyType(Object o) { + return RegistryHelperImplementation.hasFlatteningBegun ? (K) new net.minecraft.util.Identifier(o.toString()) : (K) o.toString(); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..fbb16d7b2 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json @@ -0,0 +1,45 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-registry-sync-api-v2-common", + "name": "Legacy Fabric Registry Sync API (V2)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Registry hooks", + "entrypoints": { + "client": [ + ] + }, + "mixins": [ + "legacy-fabric-registry-sync-api-v2-common.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + "net/minecraft/class_1943": ["net/legacyfabric/fabric/api/registry/v2/RegistryHolder"] + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json new file mode 100644 index 000000000..5c08a8478 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "SimpleRegistryMixinV2" + ], + "client": [ + ] +} diff --git a/settings.gradle b/settings.gradle index 9181e3e3d..542e79270 100644 --- a/settings.gradle +++ b/settings.gradle @@ -37,6 +37,7 @@ loadProject("legacy-fabric-keybindings-api-v1") loadProject("legacy-fabric-networking-api-v1") loadProject("legacy-fabric-permissions-api-v1") loadProject("legacy-fabric-registry-sync-api-v1") +loadProject("legacy-fabric-registry-sync-api-v2") loadProject("legacy-fabric-rendering-api-v1") loadProject("legacy-fabric-crash-report-info-v1") loadProject("legacy-fabric-command-api-v2") From f4822321fa963dcf40618578d3242faa8c85acd5 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sat, 23 Mar 2024 19:47:33 +0100 Subject: [PATCH 02/36] More progress on registry api v2 - differentiate "synced" Index-Key-Value registries from simple Key-Value registries - start preparing registry remapping --- build.gradle | 7 +- .../fabric/api/util/Identifier.java | 4 + .../api/registry/v1/RegistryHelper.java | 6 +- .../mixin/registry/sync/class_2929Mixin.java | 47 +++++++ .../sync/versioned/SimpleRegistryMixin.java | 49 ++++++-- ...cy-fabric-registry-sync-api-v2.mixins.json | 1 + .../api/registry/v2/RegistryHelper.java | 39 +++++- .../api/registry/v2/RegistryHolder.java | 16 --- .../fabric/api/registry/v2/RegistryIds.java | 30 +++++ .../v2/event/RegistryBeforeAddCallback.java | 21 +++- .../v2/event/RegistryEntryAddedCallback.java | 21 +++- .../v2/event/RegistryInitializedEvent.java | 19 ++- .../v2/registry/holder/RegistryHolder.java | 34 +++++ .../registry/holder/SyncedRegistryHolder.java | 27 ++++ .../v2/registry/registrable/IdsHolder.java | 24 ++++ .../v2/registry/registrable/Registrable.java | 24 ++++ .../registrable/SyncedRegistrable.java | 26 ++++ .../RegistryHelperImplementation.java | 50 ++++++-- .../registry/accessor/RegistryIdSetter.java | 17 +++ .../mixin/registry/sync/IdListMixinV2.java | 45 +++++++ .../registry/sync/MutableRegistryMixin.java | 119 ++++++++++++++++++ .../registry/sync/SimpleRegistryMixinV2.java | 79 +++--------- .../common/src/main/resources/fabric.mod.json | 5 +- ...ic-registry-sync-api-v2-common.mixins.json | 2 + 24 files changed, 605 insertions(+), 107 deletions(-) create mode 100644 legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java delete mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHolder.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryIds.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java diff --git a/build.gradle b/build.gradle index c2b40c659..7af16618d 100644 --- a/build.gradle +++ b/build.gradle @@ -284,6 +284,10 @@ allprojects { useLegacyMixinAp = true } + interfaceInjection { + enableDependencyInterfaceInjection = true + } + runs { "testModClient$mcVersion" { client() @@ -436,7 +440,8 @@ def addPomMetadataInformation(Project project, MavenPom pom) { def modJsonFile = project.file("src/main/resources/fabric.mod.json") if (!modJsonFile.exists()) { - modJsonFile = project.file("src/client/resources/fabric.mod.json") + System.out.println("Can't find fabric.mod.json at ${modJsonFile.toString()}!") + return; } def modJson = new JsonSlurper().parse(modJsonFile) diff --git a/legacy-fabric-api-base/common/src/main/java/net/legacyfabric/fabric/api/util/Identifier.java b/legacy-fabric-api-base/common/src/main/java/net/legacyfabric/fabric/api/util/Identifier.java index 32a65c7b3..51d3da699 100644 --- a/legacy-fabric-api-base/common/src/main/java/net/legacyfabric/fabric/api/util/Identifier.java +++ b/legacy-fabric-api-base/common/src/main/java/net/legacyfabric/fabric/api/util/Identifier.java @@ -71,6 +71,10 @@ public String toString() { return this.namespace + ':' + this.path; } + public String toTranslationKey() { + return this.namespace + "." + this.path; + } + public boolean equals(Object object) { if (this == object) { return true; diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java index 3f18a60cc..9a6f3745e 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java @@ -88,11 +88,13 @@ public static Block getBlock(Identifier id) { * @return The item registered */ public static Item registerItem(Item item, Identifier id) { - return RegistryHelperImpl.registerItem(item, id); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register(net.legacyfabric.fabric.api.registry.v2.RegistryIds.ITEMS, id, item); + + return item; } public static Item getItem(Identifier id) { - return RegistryHelperImpl.getValue(id, RegistryIds.ITEMS); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(RegistryIds.ITEMS, id); } /** diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java new file mode 100644 index 000000000..1f8020359 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.registry.sync; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.class_2929; + +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; + +@Mixin(class_2929.class) +public abstract class class_2929Mixin implements IdsHolder { + @Shadow + @Nullable + public abstract T getById(int id); + + @Override + public IdsHolder fabric$new() { + return (IdsHolder) new class_2929<>(256); + } + + @Override + public int fabric$nextId() { + int id = 0; + + while (this.getById(id) != null) id++; + + return id; + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java index 4dd372dd9..4b6b945c4 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java @@ -1,23 +1,52 @@ -package net.legacyfabric.fabric.mixin.registry.sync.versioned; +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; +package net.legacyfabric.fabric.mixin.registry.sync.versioned; -import net.legacyfabric.fabric.api.util.Identifier; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import net.minecraft.class_2929; import net.minecraft.util.registry.SimpleRegistry; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; +import net.legacyfabric.fabric.api.util.Identifier; @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements RegistryHolder { +public abstract class SimpleRegistryMixin implements SyncedRegistryHolder, SyncedRegistrable { @Shadow public abstract void add(int id, K identifier, V object); + @Shadow + @Final + protected class_2929 field_13718; + + @Override + public void fabric$register(int rawId, Identifier identifier, V value) { + fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); + add(rawId, fabric$toKeyType(identifier), value); + fabric$getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); + } + @Override - public void register(int rawId, Identifier identifier, V value) { - getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); - add(rawId, toKeyType(identifier), value); - getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); + public IdsHolder fabric$getIdsHolder() { + return (IdsHolder) field_13718; } } diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json index b4992aa42..008e6ed69 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json @@ -6,6 +6,7 @@ "defaultRequire": 1 }, "mixins": [ + "class_2929Mixin", "versioned.SimpleRegistryMixin" ], "client": [ diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java index 15c6b4665..a7852b2c0 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java @@ -1,16 +1,34 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.legacyfabric.fabric.api.registry.v2; +import java.util.function.Function; + +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; -import java.util.function.Function; - public class RegistryHelper { public static void register(RegistryHolder registry, Identifier identifier, T value) { RegistryHelperImplementation.register(registry, identifier, value); } - public static void registry(Identifier registryId, Identifier identifier, T value) { + public static void register(Identifier registryId, Identifier identifier, T value) { register(RegistryHelperImplementation.getRegistry(registryId), identifier, value); } @@ -18,11 +36,24 @@ public static T register(RegistryHolder registry, Identifier identifier, return RegistryHelperImplementation.register(registry, identifier, valueConstructor); } - public static T registry(Identifier registryId, Identifier identifier, Function valueConstructor) { + public static T register(Identifier registryId, Identifier identifier, Function valueConstructor) { return register(RegistryHelperImplementation.getRegistry(registryId), identifier, valueConstructor); } public static void addRegistry(Identifier identifier, RegistryHolder registryHolder) { RegistryHelperImplementation.registerRegistry(identifier, registryHolder); } + + public static RegistryHolder getRegistry(Identifier identifier) { + return RegistryHelperImplementation.getRegistry(identifier); + } + + public static T getValue(Identifier registryId, Identifier identifier) { + return RegistryHelperImplementation.getRegistry(registryId) + .fabric$getValue(identifier); + } + + public static T getValue(RegistryHolder registry, Identifier identifier) { + return registry.fabric$getValue(identifier); + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHolder.java deleted file mode 100644 index b7e8aada1..000000000 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHolder.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.legacyfabric.fabric.api.registry.v2; - -import net.legacyfabric.fabric.api.event.Event; -import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; -import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; -import net.legacyfabric.fabric.api.util.Identifier; - -public interface RegistryHolder { - Identifier getId(); - Event> getEntryAddedCallback(); - Event> getBeforeAddedCallback(); - - void register(int rawId, Identifier identifier, T value); - - K toKeyType(Object o); -} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryIds.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryIds.java new file mode 100644 index 000000000..83f11fba7 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryIds.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2; + +import net.legacyfabric.fabric.api.util.Identifier; + +public class RegistryIds { + public static final Identifier ITEMS = new Identifier("items"); + public static final Identifier BLOCKS = new Identifier("blocks"); + public static final Identifier BLOCK_ENTITY_TYPES = new Identifier("block_entity_types"); + public static final Identifier STATUS_EFFECTS = new Identifier("status_effects"); + public static final Identifier ENCHANTMENTS = new Identifier("enchantments"); + public static final Identifier BIOMES = new Identifier("biomes"); + public static final Identifier ENTITY_TYPES = new Identifier("entity_types"); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java index c4206bf40..362777c05 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java @@ -1,7 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.legacyfabric.fabric.api.registry.v2.event; import net.legacyfabric.fabric.api.event.Event; -import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @@ -14,6 +31,6 @@ static Event> event(Identifier registryId) { } static Event> event(RegistryHolder registry) { - return registry.getBeforeAddedCallback(); + return registry.fabric$getBeforeAddedCallback(); } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java index 72562274b..a165441bb 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java @@ -1,7 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.legacyfabric.fabric.api.registry.v2.event; import net.legacyfabric.fabric.api.event.Event; -import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @@ -14,6 +31,6 @@ static Event> event(Identifier registryId) { } static Event> event(RegistryHolder registry) { - return registry.getEntryAddedCallback(); + return registry.fabric$getEntryAddedCallback(); } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java index 9bf29f371..54f07c034 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java @@ -1,7 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.legacyfabric.fabric.api.registry.v2.event; import net.legacyfabric.fabric.api.event.Event; -import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java new file mode 100644 index 000000000..d72879eb4 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.holder; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; +import net.legacyfabric.fabric.api.util.Identifier; + +public interface RegistryHolder { + Identifier fabric$getId(); + Event> fabric$getEntryAddedCallback(); + Event> fabric$getBeforeAddedCallback(); + + K fabric$toKeyType(Object o); + + T fabric$getValue(Identifier id); + Identifier fabric$getId(T value); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java new file mode 100644 index 000000000..2d0ac6853 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.holder; + +import net.legacyfabric.fabric.api.util.Identifier; + +public interface SyncedRegistryHolder extends RegistryHolder { + int fabric$getRawId(T value); + int fabric$getRawId(Identifier identifier); + T fabric$getValue(int rawId); + Identifier fabric$getId(int rawId); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java new file mode 100644 index 000000000..26b37016e --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; + +public interface IdsHolder extends Iterable { + IdsHolder fabric$new(); + + int fabric$nextId(); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java new file mode 100644 index 000000000..2bcac0a91 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; + +import net.legacyfabric.fabric.api.util.Identifier; + +public interface Registrable { + void fabric$register(int rawId, Identifier identifier, T value); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java new file mode 100644 index 000000000..bcbcfeed7 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; + +public interface SyncedRegistrable extends Registrable { + IdsHolder fabric$getIdsHolder(); + + default int fabric$nextId() { + return fabric$getIdsHolder().fabric$nextId(); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java index a8057e00d..ef16ee3b0 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java @@ -1,18 +1,36 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.legacyfabric.fabric.impl.registry; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.event.EventFactory; -import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; - import net.legacyfabric.fabric.api.util.VersionUtils; import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - public class RegistryHelperImplementation { public static final boolean hasFlatteningBegun = VersionUtils.matches(">=1.8 <=1.12.2"); public static final Map> INITIALIZATION_EVENTS = new HashMap<>(); @@ -52,14 +70,28 @@ public static void registerRegistry(Identifier identifier, RegistryHolder hol } public static void register(RegistryHolder registry, Identifier identifier, T value) { + if (!(registry instanceof Registrable)) throw new IllegalArgumentException("Can't register object to non registrable registry " + registry.fabric$getId()); + + Registrable registrable = (Registrable) registry; int computedId = -1; - registry.register(computedId, identifier, value); + + if (registry instanceof SyncedRegistrable) { + computedId = ((SyncedRegistrable) registrable).fabric$nextId(); + } + + registrable.fabric$register(computedId, identifier, value); } public static T register(RegistryHolder registry, Identifier identifier, Function valueConstructor) { - int computedId = -1; + if (!(registry instanceof SyncedRegistrable)) throw new IllegalArgumentException("Can't register object to non registrable registry " + registry.fabric$getId()); + + SyncedRegistrable registrable = (SyncedRegistrable) registry; + int computedId = registrable.fabric$nextId(); + T value = valueConstructor.apply(computedId); - registry.register(computedId, identifier, value); + + registrable.fabric$register(computedId, identifier, value); + return value; } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java index f01623b83..f320032a0 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.legacyfabric.fabric.impl.registry.accessor; import net.legacyfabric.fabric.api.util.Identifier; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java new file mode 100644 index 000000000..3d4f9fded --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.registry.sync; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.util.collection.IdList; + +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; + +@Mixin(IdList.class) +public abstract class IdListMixinV2 implements IdsHolder { + @Shadow + public abstract Object fromId(int index); + + @Override + public IdsHolder fabric$new() { + return (IdsHolder) new IdList<>(); + } + + @Override + public int fabric$nextId() { + int id = 0; + + while (this.fromId(id) != null) id++; + + return id; + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java new file mode 100644 index 000000000..db0c9ce68 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.registry.sync; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; + +import net.minecraft.util.registry.MutableRegistry; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.event.EventFactory; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; +import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter; + +@Mixin(MutableRegistry.class) +public abstract class MutableRegistryMixin implements RegistryHolder, RegistryIdSetter, Registrable { + @Shadow + public abstract void put(Object key, Object value); + + @Shadow + public abstract Object get(Object key); + + @Shadow + @Final + protected Map map; + @Unique + private final Event> fabric_addObjectEvent = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryEntryAddedCallback callback : callbacks) { + callback.onEntryAdded(rawId, id, object); + } + } + ); + + @Unique + private final Event> fabric_beforeAddObjectEvent = EventFactory.createArrayBacked(RegistryBeforeAddCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryBeforeAddCallback callback : callbacks) { + callback.onEntryAdding(rawId, id, object); + } + } + ); + + @Unique + private Identifier fabric_id; + + @Override + public Event> fabric$getEntryAddedCallback() { + return this.fabric_addObjectEvent; + } + + @Override + public Event> fabric$getBeforeAddedCallback() { + return this.fabric_beforeAddObjectEvent; + } + + @Override + public Identifier fabric$getId() { + return this.fabric_id; + } + + @Override + public void fabric$setId(Identifier identifier) { + assert this.fabric_id == null; + this.fabric_id = identifier; + } + + @Override + public K fabric$toKeyType(Object o) { + return RegistryHelperImplementation.hasFlatteningBegun ? (K) new net.minecraft.util.Identifier(o.toString()) : (K) o.toString(); + } + + @Override + public void fabric$register(int rawId, Identifier identifier, V value) { + fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); + put(fabric$toKeyType(identifier), value); + fabric$getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); + } + + @Override + public V fabric$getValue(Identifier id) { + return (V) get(fabric$toKeyType(id)); + } + + @Override + public Identifier fabric$getId(V value) { + if (map.containsValue(value)) { + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() != null && entry.getValue().equals(value)) return new Identifier(entry.getKey()); + } + } + + return null; + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java index e33f91f4e..b9843a79b 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java @@ -1,67 +1,28 @@ -package net.legacyfabric.fabric.mixin.registry.sync; - -import net.legacyfabric.fabric.api.event.Event; -import net.legacyfabric.fabric.api.event.EventFactory; -import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; -import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; -import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import net.legacyfabric.fabric.api.util.Identifier; +package net.legacyfabric.fabric.mixin.registry.sync; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; -import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter; +import org.spongepowered.asm.mixin.Mixin; import net.minecraft.util.registry.SimpleRegistry; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder; @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixinV2 implements RegistryHolder, RegistryIdSetter { - @Unique - private final Event> fabric_addObjectEvent = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class, - (callbacks) -> (rawId, id, object) -> { - for (RegistryEntryAddedCallback callback : callbacks) { - callback.onEntryAdded(rawId, id, object); - } - } - ); - - @Unique - private final Event> fabric_beforeAddObjectEvent = EventFactory.createArrayBacked(RegistryBeforeAddCallback.class, - (callbacks) -> (rawId, id, object) -> { - for (RegistryBeforeAddCallback callback : callbacks) { - callback.onEntryAdding(rawId, id, object); - } - } - ); - - @Unique - private Identifier fabric_id; - - @Override - public Event> getEntryAddedCallback() { - return this.fabric_addObjectEvent; - } - - @Override - public Event> getBeforeAddedCallback() { - return this.fabric_beforeAddObjectEvent; - } - - @Override - public Identifier getId() { - return this.fabric_id; - } - - @Override - public void fabric$setId(Identifier identifier) { - assert this.fabric_id == null; - this.fabric_id = identifier; - } - - @Override - public K toKeyType(Object o) { - return RegistryHelperImplementation.hasFlatteningBegun ? (K) new net.minecraft.util.Identifier(o.toString()) : (K) o.toString(); - } +public abstract class SimpleRegistryMixinV2 implements SyncedRegistryHolder { } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json index fbb16d7b2..f5406e502 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json @@ -29,7 +29,10 @@ ], "custom": { "loom:injected_interfaces": { - "net/minecraft/class_1943": ["net/legacyfabric/fabric/api/registry/v2/RegistryHolder"] + "net/minecraft/class_1367": ["net/legacyfabric/fabric/api/registry/v2/RegistryHolder"], + "net/minecraft/class_1943": ["net/legacyfabric/fabric/api/registry/v2/SyncedRegistryHolder"], + "net/minecraft/class_1942": ["net/legacyfabric/fabric/api/registry/v2/registrable/IdsHolder"], + "net/minecraft/class_2929": ["net/legacyfabric/fabric/api/registry/v2/registrable/IdsHolder"] }, "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json index 5c08a8478..7062c3539 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json @@ -6,6 +6,8 @@ "defaultRequire": 1 }, "mixins": [ + "IdListMixinV2", + "MutableRegistryMixin", "SimpleRegistryMixinV2" ], "client": [ From c12dfb6230f0733049b2f081959d0a9e516a1491 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sat, 23 Mar 2024 19:48:29 +0100 Subject: [PATCH 03/36] Initial work on item-api --- gradle.properties | 1 + legacy-fabric-item-api-v1/1.12.2/build.gradle | 0 .../1.12.2/gradle.properties | 2 + .../impl/item/versioned/EarlyInitializer.java | 46 +++++++++++++++++++ .../mixin/item/versioned/ItemAccessor.java | 34 ++++++++++++++ .../1.12.2/src/main/resources/fabric.mod.json | 45 ++++++++++++++++++ .../legacy-fabric-item-api-v1.mixins.json | 13 ++++++ legacy-fabric-item-api-v1/common.gradle | 6 +++ legacy-fabric-item-api-v1/common/build.gradle | 0 .../common/gradle.properties | 2 + .../fabric/impl/item/EarlyInitializer.java | 39 ++++++++++++++++ .../fabric/mixin/item/ItemMixin.java | 44 ++++++++++++++++++ .../common/src/main/resources/fabric.mod.json | 45 ++++++++++++++++++ ...gacy-fabric-item-api-v1-common.mixins.json | 13 ++++++ .../common.gradle | 3 +- .../impl/registry/RegistryHelperImpl.java | 13 ------ .../fabric/mixin/registry/sync/AAAAAA.java | 21 +++++++++ settings.gradle | 1 + 18 files changed, 314 insertions(+), 14 deletions(-) create mode 100644 legacy-fabric-item-api-v1/1.12.2/build.gradle create mode 100644 legacy-fabric-item-api-v1/1.12.2/gradle.properties create mode 100644 legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java create mode 100644 legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemAccessor.java create mode 100644 legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json create mode 100644 legacy-fabric-item-api-v1/common.gradle create mode 100644 legacy-fabric-item-api-v1/common/build.gradle create mode 100644 legacy-fabric-item-api-v1/common/gradle.properties create mode 100644 legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java create mode 100644 legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java create mode 100644 legacy-fabric-item-api-v1/common/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-item-api-v1/common/src/main/resources/legacy-fabric-item-api-v1-common.mixins.json create mode 100644 legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/AAAAAA.java diff --git a/gradle.properties b/gradle.properties index ee50d6924..b089349bb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,5 +20,6 @@ legacy-fabric-networking-api-v1.version = 2.0.1 legacy-fabric-permissions-api-v1.version = 1.0.1 legacy-fabric-registry-sync-api-v1.version = 2.2.0 legacy-fabric-registry-sync-api-v2.version = 1.0.0 +legacy-fabric-item-api-v1.version = 1.0.0 legacy-fabric-rendering-api-v1.version = 1.0.0 legacy-fabric-resource-loader-v1.version = 2.1.1 diff --git a/legacy-fabric-item-api-v1/1.12.2/build.gradle b/legacy-fabric-item-api-v1/1.12.2/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-item-api-v1/1.12.2/gradle.properties b/legacy-fabric-item-api-v1/1.12.2/gradle.properties new file mode 100644 index 000000000..7d5606688 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.8 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java new file mode 100644 index 000000000..ef7865a86 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.item.versioned; + +import net.legacyfabric.fabric.mixin.item.versioned.ItemAccessor; + +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); + } + + private static void itemRegistryInit(RegistryHolder holder) { + RegistryHolder registry = (RegistryHolder) holder; + + registry.fabric$getEntryAddedCallback().register((rawId, id, item) -> { + if (item instanceof BlockItem) { + ItemAccessor.getBLOCK_ITEMS().put(((BlockItem) item).getBlock(), item); + } + }); + } +} diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemAccessor.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemAccessor.java new file mode 100644 index 000000000..37bcb308f --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemAccessor.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.item.versioned; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; + +@Mixin(Item.class) +public interface ItemAccessor { + @Accessor + static Map getBLOCK_ITEMS() { + return null; + } +} diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..579c49825 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json @@ -0,0 +1,45 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-item-api-v1", + "name": "Legacy Fabric Item API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Item utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.item.versionned.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-item-api-v1.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json new file mode 100644 index 000000000..e79ed78b9 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.item", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.ItemAccessor" + ], + "client": [ + ] +} diff --git a/legacy-fabric-item-api-v1/common.gradle b/legacy-fabric-item-api-v1/common.gradle new file mode 100644 index 000000000..e139671fc --- /dev/null +++ b/legacy-fabric-item-api-v1/common.gradle @@ -0,0 +1,6 @@ +moduleDependencies(project, [ + "legacy-fabric-api-base", + "legacy-fabric-networking-api-v1", + "legacy-fabric-resource-loader-v1", + "legacy-fabric-registry-sync-api-v2" +]) diff --git a/legacy-fabric-item-api-v1/common/build.gradle b/legacy-fabric-item-api-v1/common/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-item-api-v1/common/gradle.properties b/legacy-fabric-item-api-v1/common/gradle.properties new file mode 100644 index 000000000..a499ab733 --- /dev/null +++ b/legacy-fabric-item-api-v1/common/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java new file mode 100644 index 000000000..6dbc6d84a --- /dev/null +++ b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.item; + +import net.minecraft.item.Item; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); + } + + private static void itemRegistryInit(RegistryHolder holder) { + RegistryHolder registry = (RegistryHolder) holder; + + registry.fabric$getBeforeAddedCallback().register((rawId, id, item) -> item.setTranslationKey(id.toTranslationKey())); + } +} diff --git a/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java new file mode 100644 index 000000000..a8098bd78 --- /dev/null +++ b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.item; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.item.Item; +import net.minecraft.util.registry.SimpleRegistry; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; + +@Mixin(Item.class) +public class ItemMixin { + @Shadow + @Final + public static SimpleRegistry REGISTRY; + + @Inject(method = "", at = @At("RETURN")) + private static void registerRegistry(CallbackInfo ci) { + RegistryHelper.addRegistry(RegistryIds.ITEMS, (RegistryHolder) REGISTRY); + } +} diff --git a/legacy-fabric-item-api-v1/common/src/main/resources/fabric.mod.json b/legacy-fabric-item-api-v1/common/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..4f5fde51c --- /dev/null +++ b/legacy-fabric-item-api-v1/common/src/main/resources/fabric.mod.json @@ -0,0 +1,45 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-item-api-v1-common", + "name": "Legacy Fabric Item API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Item utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.item.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-item-api-v1-common.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-item-api-v1/common/src/main/resources/legacy-fabric-item-api-v1-common.mixins.json b/legacy-fabric-item-api-v1/common/src/main/resources/legacy-fabric-item-api-v1-common.mixins.json new file mode 100644 index 000000000..fb9e6d8f5 --- /dev/null +++ b/legacy-fabric-item-api-v1/common/src/main/resources/legacy-fabric-item-api-v1-common.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.item", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "ItemMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v1/common.gradle b/legacy-fabric-registry-sync-api-v1/common.gradle index 4e74f3a5e..561f4dfa6 100644 --- a/legacy-fabric-registry-sync-api-v1/common.gradle +++ b/legacy-fabric-registry-sync-api-v1/common.gradle @@ -2,5 +2,6 @@ moduleDependencies(project, [ "legacy-fabric-api-base", "legacy-fabric-networking-api-v1", "legacy-fabric-resource-loader-v1", - "legacy-fabric-registry-sync-v2" + "legacy-fabric-registry-sync-api-v2", + "legacy-fabric-item-api-v2" ]) diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java index 4ad5ae3c0..e1bf9f7c7 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java @@ -100,19 +100,6 @@ public static Block registerBlock(Block block, Identifier id) { return block; } - public static Item registerItem(Item item, Identifier id) { - item.setTranslationKey(formatTranslationKey(id)); - register(item, id, RegistryIds.ITEMS); - - if (hasFlatteningBegun) { - if (item instanceof BlockItem) { - ((ItemCompat) item).getBLOCK_ITEMS().put(((BlockItem) item).getBlock(), item); - } - } - - return item; - } - public static Class registerBlockEntityType(Class blockEntityClass, Identifier id) { register(blockEntityClass, id, RegistryIds.BLOCK_ENTITY_TYPES); diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/AAAAAA.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/AAAAAA.java new file mode 100644 index 000000000..8e3277db6 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/AAAAAA.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.registry.sync; + +public class AAAAAA { +} diff --git a/settings.gradle b/settings.gradle index 542e79270..669e4b740 100644 --- a/settings.gradle +++ b/settings.gradle @@ -38,6 +38,7 @@ loadProject("legacy-fabric-networking-api-v1") loadProject("legacy-fabric-permissions-api-v1") loadProject("legacy-fabric-registry-sync-api-v1") loadProject("legacy-fabric-registry-sync-api-v2") +loadProject("legacy-fabric-item-api-v1") loadProject("legacy-fabric-rendering-api-v1") loadProject("legacy-fabric-crash-report-info-v1") loadProject("legacy-fabric-command-api-v2") From 2b57a729287a7ba61fdf39cdf173a0c7deaf9d22 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 24 Mar 2024 17:24:40 +0100 Subject: [PATCH 04/36] spotless apply --- .../fabric/impl/item/versioned/EarlyInitializer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java index ef7865a86..21cc0797c 100644 --- a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java @@ -17,8 +17,6 @@ package net.legacyfabric.fabric.impl.item.versioned; -import net.legacyfabric.fabric.mixin.item.versioned.ItemAccessor; - import net.minecraft.item.BlockItem; import net.minecraft.item.Item; @@ -27,6 +25,7 @@ import net.legacyfabric.fabric.api.registry.v2.RegistryIds; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.mixin.item.versioned.ItemAccessor; public class EarlyInitializer implements PreLaunchEntrypoint { @Override From d949960805373b0e3b7caff877ce0f0e38e96697 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 24 Mar 2024 17:26:03 +0100 Subject: [PATCH 05/36] Start working on new registry remapper --- .../common.gradle | 2 +- .../impl/registry/RegistryHelperImpl.java | 3 - .../1.12.2/gradle.properties | 2 +- .../mixin/registry/sync/class_2929Mixin.java | 8 ++ .../sync/versioned/SimpleRegistryMixin.java | 29 +++++ .../registry/v2/registry/SyncedRegistry.java | 24 ++++ .../v2/registry/holder/RegistryHolder.java | 9 +- .../registry/holder/SyncedRegistryHolder.java | 11 +- .../v2/registry/registrable/IdsHolder.java | 2 + .../impl/registry/RegistryRemapper.java | 105 ++++++++++++++++++ .../mixin/registry/sync/IdListMixinV2.java | 8 ++ .../registry/sync/MutableRegistryMixin.java | 13 +-- .../registry/sync/SimpleRegistryMixinV2.java | 5 +- 13 files changed, 204 insertions(+), 17 deletions(-) create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java diff --git a/legacy-fabric-registry-sync-api-v1/common.gradle b/legacy-fabric-registry-sync-api-v1/common.gradle index 4e74f3a5e..e139671fc 100644 --- a/legacy-fabric-registry-sync-api-v1/common.gradle +++ b/legacy-fabric-registry-sync-api-v1/common.gradle @@ -2,5 +2,5 @@ moduleDependencies(project, [ "legacy-fabric-api-base", "legacy-fabric-networking-api-v1", "legacy-fabric-resource-loader-v1", - "legacy-fabric-registry-sync-v2" + "legacy-fabric-registry-sync-api-v2" ]) diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java index 4ad5ae3c0..659b5f9d2 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java @@ -31,8 +31,6 @@ import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; import net.minecraft.world.biome.Biome; import net.fabricmc.api.EnvType; @@ -45,7 +43,6 @@ import net.legacyfabric.fabric.impl.client.registry.sync.ClientRegistryRemapper; import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; import net.legacyfabric.fabric.impl.registry.sync.compat.RegistriesGetter; import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties index a104a3a86..22c79abec 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties @@ -1,2 +1,2 @@ -minVersionExcluded=1.10.2 +minVersionExcluded=1.8.9 maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java index 1f8020359..8ac0cfb7e 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java @@ -31,6 +31,9 @@ public abstract class class_2929Mixin implements IdsHolder { @Nullable public abstract T getById(int id); + @Shadow + public abstract void add(T value, int id); + @Override public IdsHolder fabric$new() { return (IdsHolder) new class_2929<>(256); @@ -44,4 +47,9 @@ public abstract class class_2929Mixin implements IdsHolder { return id; } + + @Override + public void fabric$setValue(T value, int id) { + add(value, id); + } } diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java index 4b6b945c4..d04669d94 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java @@ -31,13 +31,27 @@ @Mixin(SimpleRegistry.class) public abstract class SimpleRegistryMixin implements SyncedRegistryHolder, SyncedRegistrable { + // 1.8+ @Shadow public abstract void add(int id, K identifier, V object); + // 1.9+ @Shadow @Final protected class_2929 field_13718; + // 1.8+ + @Shadow + public abstract K getIdentifier(Object par1); + + // 1.9+ + @Shadow + public abstract int getRawId(Object object); + + // 1.7+ + @Shadow + public abstract Object getByRawId(int index); + @Override public void fabric$register(int rawId, Identifier identifier, V value) { fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); @@ -49,4 +63,19 @@ public abstract class SimpleRegistryMixin implements SyncedRegistryHolder< public IdsHolder fabric$getIdsHolder() { return (IdsHolder) field_13718; } + + @Override + public Identifier fabric$getId(V value) { + return new Identifier(getIdentifier(this.fabric$toKeyType(value))); + } + + @Override + public int fabric$getRawId(V value) { + return getRawId(value); + } + + @Override + public V fabric$getValue(int rawId) { + return (V) getByRawId(rawId); + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java new file mode 100644 index 000000000..fc27a1826 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry; + +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; + +public interface SyncedRegistry extends SyncedRegistryHolder, SyncedRegistrable { +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java index d72879eb4..d2c42b146 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java @@ -17,12 +17,15 @@ package net.legacyfabric.fabric.api.registry.v2.registry.holder; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; import net.legacyfabric.fabric.api.util.Identifier; -public interface RegistryHolder { +public interface RegistryHolder extends Iterable { Identifier fabric$getId(); Event> fabric$getEntryAddedCallback(); Event> fabric$getBeforeAddedCallback(); @@ -31,4 +34,8 @@ public interface RegistryHolder { T fabric$getValue(Identifier id); Identifier fabric$getId(T value); + + default Stream stream() { + return StreamSupport.stream(spliterator(), false); + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java index 2d0ac6853..04f762a71 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java @@ -21,7 +21,14 @@ public interface SyncedRegistryHolder extends RegistryHolder { int fabric$getRawId(T value); - int fabric$getRawId(Identifier identifier); + default int fabric$getRawId(Identifier identifier) { + T value = fabric$getValue(identifier); + return fabric$getRawId(value); + } + T fabric$getValue(int rawId); - Identifier fabric$getId(int rawId); + default Identifier fabric$getId(int rawId) { + T value = fabric$getValue(rawId); + return fabric$getId(value); + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java index 26b37016e..1afcb2cd3 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java @@ -21,4 +21,6 @@ public interface IdsHolder extends Iterable { IdsHolder fabric$new(); int fabric$nextId(); + + void fabric$setValue(T value, int id); } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java new file mode 100644 index 000000000..063d26e9e --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.registry; + +import java.util.stream.Collectors; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +import net.minecraft.nbt.NbtCompound; + +import net.legacyfabric.fabric.api.logger.v1.Logger; +import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.logger.LoggerImpl; + +public class RegistryRemapper { + protected static final Logger LOGGER = Logger.get(LoggerImpl.API, "RegistryRemapper"); + private final SyncedRegistry registry; + private BiMap entryDump; + private BiMap missingMap = HashBiMap.create(); + + public RegistryRemapper(SyncedRegistry registry) { + this.registry = registry; + } + + public void dump() { + if (this.entryDump != null && !this.entryDump.isEmpty()) return; + + this.entryDump = HashBiMap.create(); + + LOGGER.debug("Dumping registry %s.", this.registry.fabric$getId()); + + this.registry.stream() + .collect(Collectors.toMap( + this.registry::fabric$getId, + this.registry::fabric$getRawId + )) + .entrySet() + .stream() + .filter(entry -> entry.getKey() != null && entry.getValue() != -1) + .forEach(entry -> { + T value = this.registry.fabric$getValue(entry.getKey()); + LOGGER.debug("[%s] %s %s %s", this.registry.fabric$getId(), entry.getKey(), entry.getValue(), value); + this.entryDump.put(entry.getKey(), entry.getValue()); + }); + } + + public NbtCompound toNbt() { + this.dump(); + + NbtCompound nbt = new NbtCompound(); + this.entryDump.forEach((key, value) -> nbt.putInt(key.toString(), value)); + return nbt; + } + + public void readNbt(NbtCompound tag) { + this.entryDump = HashBiMap.create(); + + for (String key : tag.getKeys()) { + Identifier identifier = new Identifier(key); + int id = tag.getInt(key); + this.entryDump.put(identifier, id); + } + } + + public void remap() { + LOGGER.info("Remapping registry %s", this.registry.fabric$getId()); + + this.dump(); + + IdsHolder dumpIds = getDumpIds(); + } + + private IdsHolder getDumpIds() { + IdsHolder ids = this.registry.fabric$getIdsHolder().fabric$new(); + + this.entryDump.forEach((id, rawId) -> { + T value = this.registry.fabric$getValue(id); + + if (value == null) { + LOGGER.warn("[%s] Missing entry %s with raw id %s", this.registry.fabric$getId(), id, rawId); + this.missingMap.put(id, rawId); + } else { + ids.fabric$setValue(value, rawId); + } + }); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java index 3d4f9fded..979fee942 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java @@ -29,6 +29,9 @@ public abstract class IdListMixinV2 implements IdsHolder { @Shadow public abstract Object fromId(int index); + @Shadow + public abstract void set(Object value, int index); + @Override public IdsHolder fabric$new() { return (IdsHolder) new IdList<>(); @@ -42,4 +45,9 @@ public abstract class IdListMixinV2 implements IdsHolder { return id; } + + @Override + public void fabric$setValue(T value, int id) { + set(value, id); + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java index db0c9ce68..f07a965a3 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java @@ -108,12 +108,11 @@ public abstract class MutableRegistryMixin implements RegistryHolder, R @Override public Identifier fabric$getId(V value) { - if (map.containsValue(value)) { - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() != null && entry.getValue().equals(value)) return new Identifier(entry.getKey()); - } - } - - return null; + return map.entrySet() + .stream() + .filter(entry -> entry.getValue().equals(value)) + .findFirst() + .map(entry -> new Identifier(entry.getKey())) + .orElse(null); } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java index b9843a79b..be5d67321 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java @@ -21,8 +21,9 @@ import net.minecraft.util.registry.SimpleRegistry; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; + @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixinV2 implements SyncedRegistryHolder { +public abstract class SimpleRegistryMixinV2 implements SyncedRegistry { } From 3002ffc9806df5d295013746f3503b806ae40f57 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 24 Apr 2024 18:24:02 +0200 Subject: [PATCH 06/36] Rename some classes --- .../fabric/impl/item/versioned/EarlyInitializer.java | 6 +++--- .../net/legacyfabric/fabric/impl/item/EarlyInitializer.java | 6 +++--- .../java/net/legacyfabric/fabric/mixin/item/ItemMixin.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java index 21cc0797c..d8a9bfe22 100644 --- a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java @@ -24,7 +24,7 @@ import net.legacyfabric.fabric.api.registry.v2.RegistryIds; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.mixin.item.versioned.ItemAccessor; public class EarlyInitializer implements PreLaunchEntrypoint { @@ -33,8 +33,8 @@ public void onPreLaunch() { RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); } - private static void itemRegistryInit(RegistryHolder holder) { - RegistryHolder registry = (RegistryHolder) holder; + private static void itemRegistryInit(Registry holder) { + Registry registry = (Registry) holder; registry.fabric$getEntryAddedCallback().register((rawId, id, item) -> { if (item instanceof BlockItem) { diff --git a/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java index 6dbc6d84a..f33d072c5 100644 --- a/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java +++ b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java @@ -23,7 +23,7 @@ import net.legacyfabric.fabric.api.registry.v2.RegistryIds; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; public class EarlyInitializer implements PreLaunchEntrypoint { @Override @@ -31,8 +31,8 @@ public void onPreLaunch() { RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); } - private static void itemRegistryInit(RegistryHolder holder) { - RegistryHolder registry = (RegistryHolder) holder; + private static void itemRegistryInit(Registry holder) { + Registry registry = (Registry) holder; registry.fabric$getBeforeAddedCallback().register((rawId, id, item) -> item.setTranslationKey(id.toTranslationKey())); } diff --git a/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java index a8098bd78..b0c379210 100644 --- a/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java +++ b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java @@ -29,7 +29,7 @@ import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; import net.legacyfabric.fabric.api.registry.v2.RegistryIds; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; @Mixin(Item.class) public class ItemMixin { @@ -39,6 +39,6 @@ public class ItemMixin { @Inject(method = "", at = @At("RETURN")) private static void registerRegistry(CallbackInfo ci) { - RegistryHelper.addRegistry(RegistryIds.ITEMS, (RegistryHolder) REGISTRY); + RegistryHelper.addRegistry(RegistryIds.ITEMS, (Registry) REGISTRY); } } From 395e3725498a71edbe979149ff9e0f2abec4f395 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 24 Apr 2024 18:24:17 +0200 Subject: [PATCH 07/36] Rename some classes --- .../sync/versioned/SimpleRegistryMixin.java | 4 ++-- .../fabric/api/registry/v2/RegistryHelper.java | 14 +++++++------- .../v2/event/RegistryBeforeAddCallback.java | 4 ++-- .../v2/event/RegistryEntryAddedCallback.java | 4 ++-- .../v2/event/RegistryInitializedEvent.java | 4 ++-- .../api/registry/v2/registry/SyncedRegistry.java | 3 +-- .../{RegistryHolder.java => Registry.java} | 2 +- ...edRegistryHolder.java => SyncedRegistry.java} | 2 +- .../registry/RegistryHelperImplementation.java | 16 ++++++++-------- .../registry/sync/MutableRegistryMixin.java | 4 ++-- 10 files changed, 28 insertions(+), 29 deletions(-) rename legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/{RegistryHolder.java => Registry.java} (96%) rename legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/{SyncedRegistryHolder.java => SyncedRegistry.java} (93%) diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java index d04669d94..b3eb33d2a 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java @@ -24,13 +24,13 @@ import net.minecraft.class_2929; import net.minecraft.util.registry.SimpleRegistry; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements SyncedRegistryHolder, SyncedRegistrable { +public abstract class SimpleRegistryMixin implements SyncedRegistry, SyncedRegistrable { // 1.8+ @Shadow public abstract void add(int id, K identifier, V object); diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java index a7852b2c0..d9053b4a5 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java @@ -19,12 +19,12 @@ import java.util.function.Function; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; public class RegistryHelper { - public static void register(RegistryHolder registry, Identifier identifier, T value) { + public static void register(Registry registry, Identifier identifier, T value) { RegistryHelperImplementation.register(registry, identifier, value); } @@ -32,7 +32,7 @@ public static void register(Identifier registryId, Identifier identifier, T register(RegistryHelperImplementation.getRegistry(registryId), identifier, value); } - public static T register(RegistryHolder registry, Identifier identifier, Function valueConstructor) { + public static T register(Registry registry, Identifier identifier, Function valueConstructor) { return RegistryHelperImplementation.register(registry, identifier, valueConstructor); } @@ -40,11 +40,11 @@ public static T register(Identifier registryId, Identifier identifier, Funct return register(RegistryHelperImplementation.getRegistry(registryId), identifier, valueConstructor); } - public static void addRegistry(Identifier identifier, RegistryHolder registryHolder) { - RegistryHelperImplementation.registerRegistry(identifier, registryHolder); + public static void addRegistry(Identifier identifier, Registry registry) { + RegistryHelperImplementation.registerRegistry(identifier, registry); } - public static RegistryHolder getRegistry(Identifier identifier) { + public static Registry getRegistry(Identifier identifier) { return RegistryHelperImplementation.getRegistry(identifier); } @@ -53,7 +53,7 @@ public static T getValue(Identifier registryId, Identifier identifier) { .fabric$getValue(identifier); } - public static T getValue(RegistryHolder registry, Identifier identifier) { + public static T getValue(Registry registry, Identifier identifier) { return registry.fabric$getValue(identifier); } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java index 362777c05..6136747e9 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java @@ -18,7 +18,7 @@ package net.legacyfabric.fabric.api.registry.v2.event; import net.legacyfabric.fabric.api.event.Event; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @@ -30,7 +30,7 @@ static Event> event(Identifier registryId) { return event(RegistryHelperImplementation.getRegistry(registryId)); } - static Event> event(RegistryHolder registry) { + static Event> event(Registry registry) { return registry.fabric$getBeforeAddedCallback(); } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java index a165441bb..c571737c2 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java @@ -18,7 +18,7 @@ package net.legacyfabric.fabric.api.registry.v2.event; import net.legacyfabric.fabric.api.event.Event; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @@ -30,7 +30,7 @@ static Event> event(Identifier registryId) { return event(RegistryHelperImplementation.getRegistry(registryId)); } - static Event> event(RegistryHolder registry) { + static Event> event(Registry registry) { return registry.fabric$getEntryAddedCallback(); } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java index 54f07c034..d1b5e7d01 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java @@ -18,7 +18,7 @@ package net.legacyfabric.fabric.api.registry.v2.event; import net.legacyfabric.fabric.api.event.Event; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @@ -27,7 +27,7 @@ */ @FunctionalInterface public interface RegistryInitializedEvent { - void initialized(RegistryHolder registry); + void initialized(Registry registry); static Event event(Identifier registryId) { return RegistryHelperImplementation.getInitializationEvent(registryId); diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java index fc27a1826..b91b65820 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java @@ -17,8 +17,7 @@ package net.legacyfabric.fabric.api.registry.v2.registry; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; -public interface SyncedRegistry extends SyncedRegistryHolder, SyncedRegistrable { +public interface SyncedRegistry extends net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry, SyncedRegistrable { } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java similarity index 96% rename from legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java index d2c42b146..a81c3a986 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryHolder.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java @@ -25,7 +25,7 @@ import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; import net.legacyfabric.fabric.api.util.Identifier; -public interface RegistryHolder extends Iterable { +public interface Registry extends Iterable { Identifier fabric$getId(); Event> fabric$getEntryAddedCallback(); Event> fabric$getBeforeAddedCallback(); diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java similarity index 93% rename from legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java index 04f762a71..bfb8ec27a 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistryHolder.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java @@ -19,7 +19,7 @@ import net.legacyfabric.fabric.api.util.Identifier; -public interface SyncedRegistryHolder extends RegistryHolder { +public interface SyncedRegistry extends Registry { int fabric$getRawId(T value); default int fabric$getRawId(Identifier identifier) { T value = fabric$getValue(identifier); diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java index ef16ee3b0..61f9f5032 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java @@ -24,7 +24,7 @@ import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.event.EventFactory; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; @@ -34,7 +34,7 @@ public class RegistryHelperImplementation { public static final boolean hasFlatteningBegun = VersionUtils.matches(">=1.8 <=1.12.2"); public static final Map> INITIALIZATION_EVENTS = new HashMap<>(); - private static final Map> REGISTRIES = new HashMap<>(); + private static final Map> REGISTRIES = new HashMap<>(); public static Event getInitializationEvent(Identifier registryId) { Event event; @@ -45,7 +45,7 @@ public static Event getInitializationEvent(Identifier event = EventFactory.createArrayBacked(RegistryInitializedEvent.class, (callbacks) -> new RegistryInitializedEvent() { @Override - public void initialized(RegistryHolder registry) { + public void initialized(Registry registry) { for (RegistryInitializedEvent callback : callbacks) { callback.initialized(registry); } @@ -58,18 +58,18 @@ public void initialized(RegistryHolder registry) { return event; } - public static RegistryHolder getRegistry(Identifier identifier) { - return (RegistryHolder) REGISTRIES.get(identifier); + public static Registry getRegistry(Identifier identifier) { + return (Registry) REGISTRIES.get(identifier); } - public static void registerRegistry(Identifier identifier, RegistryHolder holder) { + public static void registerRegistry(Identifier identifier, Registry holder) { if (REGISTRIES.containsKey(identifier)) throw new IllegalArgumentException("Attempted to register registry " + identifier.toString() + " twices!"); REGISTRIES.put(identifier, holder); if (holder instanceof RegistryIdSetter) ((RegistryIdSetter) holder).fabric$setId(identifier); } - public static void register(RegistryHolder registry, Identifier identifier, T value) { + public static void register(Registry registry, Identifier identifier, T value) { if (!(registry instanceof Registrable)) throw new IllegalArgumentException("Can't register object to non registrable registry " + registry.fabric$getId()); Registrable registrable = (Registrable) registry; @@ -82,7 +82,7 @@ public static void register(RegistryHolder registry, Identifier identifie registrable.fabric$register(computedId, identifier, value); } - public static T register(RegistryHolder registry, Identifier identifier, Function valueConstructor) { + public static T register(Registry registry, Identifier identifier, Function valueConstructor) { if (!(registry instanceof SyncedRegistrable)) throw new IllegalArgumentException("Can't register object to non registrable registry " + registry.fabric$getId()); SyncedRegistrable registrable = (SyncedRegistrable) registry; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java index f07a965a3..75c4e0697 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java @@ -30,14 +30,14 @@ import net.legacyfabric.fabric.api.event.EventFactory; import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter; @Mixin(MutableRegistry.class) -public abstract class MutableRegistryMixin implements RegistryHolder, RegistryIdSetter, Registrable { +public abstract class MutableRegistryMixin implements Registry, RegistryIdSetter, Registrable { @Shadow public abstract void put(Object key, Object value); From 3c6e7eead782a7b23f602f5d527c5eac380cab1f Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 5 May 2024 21:49:54 +0200 Subject: [PATCH 08/36] Move registry related test mods to per version global test mods --- .../1.12.2/src/main/resources/fabric.mod.json | 2 +- .../src/testmod/resources/fabric.mod.json | 14 ---- .../src/testmod/resources/fabric.mod.json | 14 ---- .../src/testmod/resources/fabric.mod.json | 14 ---- .../src/testmod/resources/fabric.mod.json | 14 ---- .../1.8/src/testmod/resources/fabric.mod.json | 14 ---- .../src/testmod/resources/fabric.mod.json | 14 ---- .../legacyfabric/fabric/testing/TestMod.java | 12 ++-- .../src/testmod/resources/fabric.mod.json | 48 ++++++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 19 ++++-- .../src/testmod/resources/fabric.mod.json | 48 ++++++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 66 +++++++++++++++++++ .../src/testmod/resources/fabric.mod.json | 48 ++++++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 8 ++- .../src/testmod/resources/fabric.mod.json | 49 ++++++++++++++ .../testmod/resources/testmods.accesswidener | 3 + .../legacyfabric/fabric/testing/TestMod.java | 8 ++- .../src/testmod/resources/fabric.mod.json | 48 ++++++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 14 +++- .../1.8/src/testmod/resources/fabric.mod.json | 49 ++++++++++++++ .../testmod/resources/testmods.accesswidener | 3 + .../legacyfabric/fabric/testing/TestMod.java | 8 ++- .../src/testmod/resources/fabric.mod.json | 48 ++++++++++++++ legacyfabric-api/common.gradle | 2 + 24 files changed, 464 insertions(+), 103 deletions(-) delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/testmod/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/resources/fabric.mod.json rename legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java => legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java (85%) create mode 100644 legacyfabric-api/1.10.2/src/testmod/resources/fabric.mod.json rename legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java => legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java (78%) create mode 100644 legacyfabric-api/1.11.2/src/testmod/resources/fabric.mod.json create mode 100644 legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java create mode 100644 legacyfabric-api/1.12.2/src/testmod/resources/fabric.mod.json rename legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java => legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java (93%) create mode 100644 legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json create mode 100644 legacyfabric-api/1.7.10/src/testmod/resources/testmods.accesswidener rename legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java => legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java (93%) create mode 100644 legacyfabric-api/1.8.9/src/testmod/resources/fabric.mod.json rename legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java => legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java (77%) create mode 100644 legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json create mode 100644 legacyfabric-api/1.8/src/testmod/resources/testmods.accesswidener rename legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java => legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java (93%) create mode 100644 legacyfabric-api/1.9.4/src/testmod/resources/fabric.mod.json diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json index 579c49825..7132ed22b 100644 --- a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json @@ -22,7 +22,7 @@ "description": "Item utils", "entrypoints": { "preLaunch": [ - "net.legacyfabric.fabric.impl.item.versionned.EarlyInitializer" + "net.legacyfabric.fabric.impl.item.versioned.EarlyInitializer" ] }, "mixins": [ diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/resources/fabric.mod.json deleted file mode 100644 index d6b0884ad..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1-testmod", - "description": "Tests for registry", - "version": "1.0.0", - "entrypoints": { - "main": [ - "net.legacyfabric.fabric.test.registry.RegistryTest" - ] - }, - "depends": { - "minecraft": "${minecraft_version}" - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/resources/fabric.mod.json deleted file mode 100644 index d6b0884ad..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1-testmod", - "description": "Tests for registry", - "version": "1.0.0", - "entrypoints": { - "main": [ - "net.legacyfabric.fabric.test.registry.RegistryTest" - ] - }, - "depends": { - "minecraft": "${minecraft_version}" - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/resources/fabric.mod.json deleted file mode 100644 index d6b0884ad..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1-testmod", - "description": "Tests for registry", - "version": "1.0.0", - "entrypoints": { - "main": [ - "net.legacyfabric.fabric.test.registry.RegistryTest" - ] - }, - "depends": { - "minecraft": "${minecraft_version}" - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/resources/fabric.mod.json deleted file mode 100644 index d6b0884ad..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1-testmod", - "description": "Tests for registry", - "version": "1.0.0", - "entrypoints": { - "main": [ - "net.legacyfabric.fabric.test.registry.RegistryTest" - ] - }, - "depends": { - "minecraft": "${minecraft_version}" - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/resources/fabric.mod.json deleted file mode 100644 index d6b0884ad..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1-testmod", - "description": "Tests for registry", - "version": "1.0.0", - "entrypoints": { - "main": [ - "net.legacyfabric.fabric.test.registry.RegistryTest" - ] - }, - "depends": { - "minecraft": "${minecraft_version}" - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/resources/fabric.mod.json deleted file mode 100644 index d6b0884ad..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1-testmod", - "description": "Tests for registry", - "version": "1.0.0", - "entrypoints": { - "main": [ - "net.legacyfabric.fabric.test.registry.RegistryTest" - ] - }, - "depends": { - "minecraft": "${minecraft_version}" - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 85% rename from legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 3d72858aa..332182e28 100644 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; import java.util.concurrent.ThreadLocalRandom; @@ -32,9 +32,13 @@ import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; @@ -48,8 +52,8 @@ public void onInitialize() { Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); - RegistryHelper.registerBlock(block, identifier); - RegistryHelper.registerItem(new BlockItem(block), identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); diff --git a/legacyfabric-api/1.10.2/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.10.2/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.10.2/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 78% rename from legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 3d72858aa..dd6cb8e7b 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; import java.util.concurrent.ThreadLocalRandom; @@ -28,13 +28,17 @@ import net.fabricmc.api.ModInitializer; -import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; @@ -48,12 +52,15 @@ public void onInitialize() { Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); - RegistryHelper.registerBlock(block, identifier); - RegistryHelper.registerItem(new BlockItem(block), identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); - RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); + RegistryHelper.register( + Item.REGISTRY, + new Identifier("legacy-fabric-api", "test_item"), testItem + ); ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); } } diff --git a/legacyfabric-api/1.11.2/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.11.2/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.11.2/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java new file mode 100644 index 000000000..dd6cb8e7b --- /dev/null +++ b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.testing; + +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialColor; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.itemgroup.ItemGroup; + +import net.fabricmc.api.ModInitializer; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.resource.ItemModelRegistry; +import net.legacyfabric.fabric.api.util.Identifier; + +public class TestMod implements ModInitializer { + @Override + public void onInitialize() { + registerItem(); + } + + private void registerItem() { + Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); + Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); + Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; + + for (Block block : blocks) { + int color = 1644825; + + if (block == concBlock2) { + color = 3361970; + } + + Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); + + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); + } + + Item testItem = new Item().setItemGroup(ItemGroup.FOOD); + RegistryHelper.register( + Item.REGISTRY, + new Identifier("legacy-fabric-api", "test_item"), testItem + ); + ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); + } +} diff --git a/legacyfabric-api/1.12.2/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.12.2/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.12.2/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 93% rename from legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 987555b4e..e96611725 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; import java.util.concurrent.ThreadLocalRandom; @@ -31,9 +31,13 @@ import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; diff --git a/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..4f47e2473 --- /dev/null +++ b/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json @@ -0,0 +1,49 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "accessWidener": "testmods.accesswidener", + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacyfabric-api/1.7.10/src/testmod/resources/testmods.accesswidener b/legacyfabric-api/1.7.10/src/testmod/resources/testmods.accesswidener new file mode 100644 index 000000000..45ae69ced --- /dev/null +++ b/legacyfabric-api/1.7.10/src/testmod/resources/testmods.accesswidener @@ -0,0 +1,3 @@ +accessWidener v2 named + +transitive-accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 93% rename from legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 903995adf..80cf2d90e 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; import java.util.concurrent.ThreadLocalRandom; @@ -32,9 +32,13 @@ import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; diff --git a/legacyfabric-api/1.8.9/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.8.9/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.8.9/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 77% rename from legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index d44e15cdf..e96611725 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,23 +15,29 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; import java.util.concurrent.ThreadLocalRandom; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; import net.fabricmc.api.ModInitializer; import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; +import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; @@ -41,5 +47,9 @@ public void onInitialize() { RegistryHelper.registerBlock(block, identifier); RegistryHelper.registerItem(new BlockItem(block), identifier); } + + Item testItem = new Item().setItemGroup(ItemGroup.FOOD); + RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); + ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); } } diff --git a/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..4f47e2473 --- /dev/null +++ b/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json @@ -0,0 +1,49 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "accessWidener": "testmods.accesswidener", + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacyfabric-api/1.8/src/testmod/resources/testmods.accesswidener b/legacyfabric-api/1.8/src/testmod/resources/testmods.accesswidener new file mode 100644 index 000000000..8f8db9c23 --- /dev/null +++ b/legacyfabric-api/1.8/src/testmod/resources/testmods.accesswidener @@ -0,0 +1,3 @@ +accessWidener v2 named + +accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 93% rename from legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 3d72858aa..f0f18e18a 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; import java.util.concurrent.ThreadLocalRandom; @@ -32,9 +32,13 @@ import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; diff --git a/legacyfabric-api/1.9.4/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.9.4/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.9.4/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacyfabric-api/common.gradle b/legacyfabric-api/common.gradle index 57e88309f..1ec69e2e6 100644 --- a/legacyfabric-api/common.gradle +++ b/legacyfabric-api/common.gradle @@ -10,6 +10,8 @@ moduleDependencies(project, [ "legacy-fabric-networking-api-v1", "legacy-fabric-permissions-api-v1", "legacy-fabric-registry-sync-api-v1", + "legacy-fabric-registry-sync-api-v2", + "legacy-fabric-item-api-v1", "legacy-fabric-rendering-api-v1", "legacy-fabric-crash-report-info-v1", "legacy-fabric-command-api-v2" From dec3757068d89fa7206d7e7fde3dceb026c583f5 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 5 May 2024 21:51:13 +0200 Subject: [PATCH 09/36] Update loom and gradle --- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 0d22c1ea7..73756e661 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ plugins { id "eclipse" id "idea" id "maven-publish" - id "fabric-loom" version "1.5.4" apply false - id "legacy-looming" version "1.5.3" apply false + id "fabric-loom" version "1.6.5" apply false + id "legacy-looming" version "1.6.3" apply false id "com.diffplug.spotless" version "6.20.0" id "org.ajoberstar.grgit" version "3.1.1" id "me.modmuss50.mod-publish-plugin" version "0.4.5" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e0930..b82aa23a4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From 6f5bf3b8d21a002d839cb4ef80354d542f268d58 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 5 May 2024 21:52:46 +0200 Subject: [PATCH 10/36] Port remapping system to v2 and port to every supported version --- .../versioned/PacketByteBufMixin.java | 38 ++++++ .../mixin/networking/PacketByteBufMixin.java | 2 +- .../versioned/PacketByteBufMixin.java | 38 ++++++ ...egacy-fabric-networking-api-v1.mixins.json | 3 +- .../versioned/PacketByteBufMixin.java | 38 ++++++ ...egacy-fabric-networking-api-v1.mixins.json | 3 +- .../networking/PacketByteBufExtension.java | 12 +- ...cy-fabric-registry-sync-api-v1.mixins.json | 1 - .../registry/sync/PlayerManagerMixin.java | 71 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 1 - ...cy-fabric-registry-sync-api-v1.mixins.json | 1 - .../main/resources/registrysync.accesswidener | 4 +- .../registry/sync/PlayerManagerMixin.java | 71 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 1 - ...cy-fabric-registry-sync-api-v1.mixins.json | 1 - .../main/resources/registrysync.accesswidener | 4 +- .../registry/sync/PlayerManagerMixin.java | 71 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 1 - .../registry/sync/MinecraftServerMixin.java | 12 +- .../sync/client/MinecraftClientMixin.java | 12 +- .../registry/sync/registry/ItemMixin.java | 48 -------- ...ic-registry-sync-api-v1-common.mixins.json | 2 - .../OtherIdListMixin.java} | 20 +++- .../sync/versioned}/PlayerManagerMixin.java | 7 +- .../sync/versioned/SimpleRegistryMixin.java | 31 ++++- ...cy-fabric-registry-sync-api-v2.mixins.json | 3 +- .../1.7.10/build.gradle | 0 .../1.7.10/gradle.properties | 2 + .../sync/versioned}/PlayerManagerMixin.java | 7 +- .../sync/versioned/SimpleRegistryMixinV2.java | 108 +++++++++++++++++ .../1.7.10/src/main/resources/fabric.mod.json | 42 +++++++ ...cy-fabric-registry-sync-api-v2.mixins.json | 14 +++ .../1.8.9/build.gradle | 0 .../1.8.9/gradle.properties | 2 + .../sync/versioned}/PlayerManagerMixin.java | 7 +- .../sync/versioned/SimpleRegistryMixinV2.java | 109 ++++++++++++++++++ .../1.8.9/src/main/resources/fabric.mod.json | 42 +++++++ ...cy-fabric-registry-sync-api-v2.mixins.json | 14 +++ .../v2/event/RegistryRemapCallback.java | 42 +++++++ .../v2/registry/holder/RegistryEntry.java | 26 +++++ .../v2/registry/holder/SyncedRegistry.java | 4 + .../v2/registry/registrable/IdsHolder.java | 5 + .../registrable/SyncedRegistrable.java | 2 + .../impl/registry/ClientRemapInitializer.java | 44 +++++++ .../RegistryHelperImplementation.java | 62 ++++++++++ .../impl/registry/RegistryRemapper.java | 97 ++++++++++++++++ .../mixin/registry/sync/IdListMixinV2.java | 20 ++++ ...Mixin.java => MutableRegistryMixinV2.java} | 39 ++++--- .../registry/sync/SimpleRegistryMixinV2.java | 1 - .../registry/sync/WorldSaveHandlerMixin.java | 6 +- .../common/src/main/resources/fabric.mod.json | 8 +- ...ic-registry-sync-api-v2-common.mixins.json | 5 +- 52 files changed, 868 insertions(+), 336 deletions(-) create mode 100644 legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java create mode 100644 legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java create mode 100644 legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/ItemMixin.java rename legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/{class_2929Mixin.java => versioned/OtherIdListMixin.java} (78%) rename {legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync => legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned}/PlayerManagerMixin.java (86%) create mode 100644 legacy-fabric-registry-sync-api-v2/1.7.10/build.gradle create mode 100644 legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties rename {legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync => legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned}/PlayerManagerMixin.java (87%) create mode 100644 legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java create mode 100644 legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json create mode 100644 legacy-fabric-registry-sync-api-v2/1.8.9/build.gradle create mode 100644 legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties rename {legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync => legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned}/PlayerManagerMixin.java (86%) create mode 100644 legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java create mode 100644 legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryRemapCallback.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java rename legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/{MutableRegistryMixin.java => MutableRegistryMixinV2.java} (75%) rename {legacy-fabric-registry-sync-api-v1 => legacy-fabric-registry-sync-api-v2}/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/WorldSaveHandlerMixin.java (95%) diff --git a/legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java new file mode 100644 index 000000000..c6e206be2 --- /dev/null +++ b/legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.networking.versioned; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.PacketByteBuf; + +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; + +@Mixin(PacketByteBuf.class) +public abstract class PacketByteBufMixin implements PacketByteBufExtension { + @Shadow + public abstract PacketByteBuf writeNbtCompound(@Nullable NbtCompound nbt); + + @Override + public PacketByteBuf writeCompound(NbtCompound tag) { + return writeNbtCompound(tag); + } +} diff --git a/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/PacketByteBufMixin.java index c360a2c04..1ed1a52a3 100644 --- a/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/PacketByteBufMixin.java +++ b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/PacketByteBufMixin.java @@ -30,7 +30,7 @@ import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; @Mixin(PacketByteBuf.class) -public class PacketByteBufMixin implements PacketByteBufExtension { +public abstract class PacketByteBufMixin implements PacketByteBufExtension { @Override @Environment(EnvType.CLIENT) public Packet createCustomPayloadC2SPacket(String channelName) { diff --git a/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java new file mode 100644 index 000000000..d4611ec2b --- /dev/null +++ b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.networking.versioned; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.PacketByteBuf; + +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; + +@Mixin(PacketByteBuf.class) +public abstract class PacketByteBufMixin implements PacketByteBufExtension { + @Shadow + public abstract void writeNbtCompound(NbtCompound par1); + + @Override + public PacketByteBuf writeCompound(NbtCompound tag) { + this.writeNbtCompound(tag); + return (PacketByteBuf) (Object) this; + } +} diff --git a/legacy-fabric-networking-api-v1/1.7.10/src/main/resources/legacy-fabric-networking-api-v1.mixins.json b/legacy-fabric-networking-api-v1/1.7.10/src/main/resources/legacy-fabric-networking-api-v1.mixins.json index a09e89bfc..8cd108280 100644 --- a/legacy-fabric-networking-api-v1/1.7.10/src/main/resources/legacy-fabric-networking-api-v1.mixins.json +++ b/legacy-fabric-networking-api-v1/1.7.10/src/main/resources/legacy-fabric-networking-api-v1.mixins.json @@ -7,7 +7,8 @@ "CustomPayloadC2SPacketMixin", "MinecraftServerMixin", "PacketByteBufMixin", - "PlayerManagerMixin" + "PlayerManagerMixin", + "versioned.PacketByteBufMixin" ], "client": [ "client.CustomPayloadS2CPacketMixin", diff --git a/legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java new file mode 100644 index 000000000..d4611ec2b --- /dev/null +++ b/legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.networking.versioned; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.PacketByteBuf; + +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; + +@Mixin(PacketByteBuf.class) +public abstract class PacketByteBufMixin implements PacketByteBufExtension { + @Shadow + public abstract void writeNbtCompound(NbtCompound par1); + + @Override + public PacketByteBuf writeCompound(NbtCompound tag) { + this.writeNbtCompound(tag); + return (PacketByteBuf) (Object) this; + } +} diff --git a/legacy-fabric-networking-api-v1/1.8.9/src/main/resources/legacy-fabric-networking-api-v1.mixins.json b/legacy-fabric-networking-api-v1/1.8.9/src/main/resources/legacy-fabric-networking-api-v1.mixins.json index a75644c36..8b1ca4521 100644 --- a/legacy-fabric-networking-api-v1/1.8.9/src/main/resources/legacy-fabric-networking-api-v1.mixins.json +++ b/legacy-fabric-networking-api-v1/1.8.9/src/main/resources/legacy-fabric-networking-api-v1.mixins.json @@ -6,7 +6,8 @@ "ClientConnectionMixin", "CustomPayloadC2SPacketMixin", "MinecraftServerMixin", - "PlayerManagerMixin" + "PlayerManagerMixin", + "versioned.PacketByteBufMixin" ], "client": [ "client.CustomPayloadS2CPacketMixin", diff --git a/legacy-fabric-networking-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/networking/PacketByteBufExtension.java b/legacy-fabric-networking-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/networking/PacketByteBufExtension.java index fff07bcc5..ae97f6e9e 100644 --- a/legacy-fabric-networking-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/networking/PacketByteBufExtension.java +++ b/legacy-fabric-networking-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/networking/PacketByteBufExtension.java @@ -17,13 +17,21 @@ package net.legacyfabric.fabric.impl.networking; +import net.minecraft.nbt.NbtCompound; import net.minecraft.network.Packet; +import net.minecraft.util.PacketByteBuf; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; public interface PacketByteBufExtension { @Environment(EnvType.CLIENT) - Packet createCustomPayloadC2SPacket(String channelName); - Packet createCustomPayloadS2CPacket(String channelName); + default Packet createCustomPayloadC2SPacket(String channelName) { + return null; + } + default Packet createCustomPayloadS2CPacket(String channelName) { + return null; + } + + PacketByteBuf writeCompound(NbtCompound tag); } diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 9e64957e8..fb5274ab6 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,7 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "class_2929Mixin", - "PlayerManagerMixin", "BlockMixin", "ItemMixin", "PacketByteBufMixin", diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java deleted file mode 100644 index 84ebd46f7..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.ClientConnection; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.integrated.IntegratedServer; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.loader.api.FabricLoader; - -import net.legacyfabric.fabric.api.networking.v1.ServerPlayNetworking; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; - -@Mixin(PlayerManager.class) -public class PlayerManagerMixin { - @Shadow - @Final - private MinecraftServer server; - - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 2), method = "method_12827") - public void playerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { - if (fabric_shouldSend()) { - player.networkHandler.sendPacket(ServerPlayNetworking.createS2CPacket(RegistryRemapperAccess.PACKET_ID, ServerRegistryRemapper.getInstance().createBuf())); - } - } - - @Unique - private boolean fabric_shouldSend() { - boolean published = false; - - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - published = fabric_isPublished(); - } - - return this.server.isDedicated() || published; - } - - @Environment(EnvType.CLIENT) - @Unique - private boolean fabric_isPublished() { - return ((IntegratedServer) this.server).isPublished(); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index c95574ffd..28dbfae1b 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,7 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "class_2929Mixin", - "PlayerManagerMixin", "BlockMixin", "ItemMixin", "PacketByteBufMixin", diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index c1478703e..2b3435c36 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -7,7 +7,6 @@ }, "mixins": [ "SimpleRegistryMixin", - "PlayerManagerMixin", "PacketByteBufMixin", "BlockEntityAccessor", "BlockEntityMixin", diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener index be5a8fb24..45ae69ced 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener +++ b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener @@ -1,3 +1,3 @@ -accessWidener v1 named +accessWidener v2 named -accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V +transitive-accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java deleted file mode 100644 index 45c40826a..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.ClientConnection; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.integrated.IntegratedServer; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.loader.api.FabricLoader; - -import net.legacyfabric.fabric.api.networking.v1.ServerPlayNetworking; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; - -@Mixin(PlayerManager.class) -public class PlayerManagerMixin { - @Shadow - @Final - private MinecraftServer server; - - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 2), method = "onPlayerConnect") - public void playerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { - if (fabric_shouldSend()) { - player.networkHandler.sendPacket(ServerPlayNetworking.createS2CPacket(RegistryRemapperAccess.PACKET_ID, ServerRegistryRemapper.getInstance().createBuf())); - } - } - - @Unique - private boolean fabric_shouldSend() { - boolean published = false; - - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - published = fabric_isPublished(); - } - - return this.server.isDedicated() || published; - } - - @Environment(EnvType.CLIENT) - @Unique - private boolean fabric_isPublished() { - return ((IntegratedServer) this.server).isPublished(); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index cb9f7aaad..eae009f7d 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -7,7 +7,6 @@ }, "mixins": [ "SimpleRegistryMixin", - "PlayerManagerMixin", "BlockMixin", "ItemMixin", "PacketByteBufMixin", diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index cb9f7aaad..eae009f7d 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -7,7 +7,6 @@ }, "mixins": [ "SimpleRegistryMixin", - "PlayerManagerMixin", "BlockMixin", "ItemMixin", "PacketByteBufMixin", diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener index be5a8fb24..45ae69ced 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener +++ b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener @@ -1,3 +1,3 @@ -accessWidener v1 named +accessWidener v2 named -accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V +transitive-accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java deleted file mode 100644 index 84ebd46f7..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.ClientConnection; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.integrated.IntegratedServer; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.loader.api.FabricLoader; - -import net.legacyfabric.fabric.api.networking.v1.ServerPlayNetworking; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; - -@Mixin(PlayerManager.class) -public class PlayerManagerMixin { - @Shadow - @Final - private MinecraftServer server; - - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 2), method = "method_12827") - public void playerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { - if (fabric_shouldSend()) { - player.networkHandler.sendPacket(ServerPlayNetworking.createS2CPacket(RegistryRemapperAccess.PACKET_ID, ServerRegistryRemapper.getInstance().createBuf())); - } - } - - @Unique - private boolean fabric_shouldSend() { - boolean published = false; - - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - published = fabric_isPublished(); - } - - return this.server.isDedicated() || published; - } - - @Environment(EnvType.CLIENT) - @Unique - private boolean fabric_isPublished() { - return ((IntegratedServer) this.server).isPublished(); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 9e64957e8..fb5274ab6 100644 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,7 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "class_2929Mixin", - "PlayerManagerMixin", "BlockMixin", "ItemMixin", "PacketByteBufMixin", diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java index 9069ffca9..c66b93cff 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java @@ -18,18 +18,14 @@ package net.legacyfabric.fabric.mixin.registry.sync; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.server.MinecraftServer; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; @Mixin(MinecraftServer.class) public class MinecraftServerMixin { - @Inject(method = "", at = @At("RETURN")) - private static void remapperInit(CallbackInfo ci) { - ServerRegistryRemapper.getInstance(); - } +// @Inject(method = "", at = @At("RETURN")) +// private static void remapperInit(CallbackInfo ci) { +// ServerRegistryRemapper.getInstance(); +// } } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java index 3f6281b9e..9aa0aed9a 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java @@ -18,22 +18,18 @@ package net.legacyfabric.fabric.mixin.registry.sync.client; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.client.MinecraftClient; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.legacyfabric.fabric.impl.client.registry.sync.ClientRegistryRemapper; @Environment(EnvType.CLIENT) @Mixin(MinecraftClient.class) public class MinecraftClientMixin { - @Inject(method = "", at = @At("RETURN")) - private static void remapperInit(CallbackInfo ci) { - ClientRegistryRemapper.getInstance(); - } +// @Inject(method = "", at = @At("RETURN")) +// private static void remapperInit(CallbackInfo ci) { +// ClientRegistryRemapper.getInstance(); +// } } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/ItemMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/ItemMixin.java deleted file mode 100644 index 70edb7a39..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/ItemMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync.registry; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.item.Item; -import net.minecraft.world.biome.Biome; - -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.ItemRegistryRemapper; - -@Mixin(Item.class) -public class ItemMixin { - @Inject(method = "setup", at = @At("RETURN")) - private static void initRegistryRemapper(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(ItemRegistryRemapper::new); - - if (!RegistryHelperImpl.bootstrap) { - try { - Class.forName(Biome.class.getName()); - - Class.forName(BlockEntity.class.getName()); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json index baf230136..c3ad0db1e 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json @@ -7,9 +7,7 @@ }, "mixins": [ "MinecraftServerMixin", - "WorldSaveHandlerMixin", "IdListMixin", - "registry.ItemMixin", "registry.BlockMixin", "registry.BlockEntityMixin", "registry.StatusEffectMixin", diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java similarity index 78% rename from legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java rename to legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java index 8ac0cfb7e..d01f6ea1c 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.registry.sync.versioned; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; @@ -26,7 +26,7 @@ import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; @Mixin(class_2929.class) -public abstract class class_2929Mixin implements IdsHolder { +public abstract class OtherIdListMixin implements IdsHolder { @Shadow @Nullable public abstract T getById(int id); @@ -34,6 +34,12 @@ public abstract class class_2929Mixin implements IdsHolder { @Shadow public abstract void add(T value, int id); + @Shadow + private T[] field_14375; + + @Shadow + public abstract int getId(T value); + @Override public IdsHolder fabric$new() { return (IdsHolder) new class_2929<>(256); @@ -52,4 +58,14 @@ public abstract class class_2929Mixin implements IdsHolder { public void fabric$setValue(T value, int id) { add(value, id); } + + @Override + public int fabric$size() { + return this.field_14375.length; + } + + @Override + public int fabric$getId(T value) { + return getId(value); + } } diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java similarity index 86% rename from legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java rename to legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java index 84ebd46f7..6aa50b40f 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.registry.sync.versioned; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -36,8 +36,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.legacyfabric.fabric.api.networking.v1.ServerPlayNetworking; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @Mixin(PlayerManager.class) public class PlayerManagerMixin { @@ -48,7 +47,7 @@ public class PlayerManagerMixin { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 2), method = "method_12827") public void playerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { if (fabric_shouldSend()) { - player.networkHandler.sendPacket(ServerPlayNetworking.createS2CPacket(RegistryRemapperAccess.PACKET_ID, ServerRegistryRemapper.getInstance().createBuf())); + ServerPlayNetworking.send(player, RegistryHelperImplementation.PACKET_ID, RegistryHelperImplementation.createBuf()); } } diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java index b3eb33d2a..5423f2924 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java @@ -19,11 +19,16 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import net.minecraft.class_2929; import net.minecraft.util.registry.SimpleRegistry; +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.event.EventFactory; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; @@ -36,6 +41,7 @@ public abstract class SimpleRegistryMixin implements SyncedRegistry, Sy public abstract void add(int id, K identifier, V object); // 1.9+ + @Mutable @Shadow @Final protected class_2929 field_13718; @@ -66,7 +72,7 @@ public abstract class SimpleRegistryMixin implements SyncedRegistry, Sy @Override public Identifier fabric$getId(V value) { - return new Identifier(getIdentifier(this.fabric$toKeyType(value))); + return new Identifier(getIdentifier(value)); } @Override @@ -78,4 +84,27 @@ public abstract class SimpleRegistryMixin implements SyncedRegistry, Sy public V fabric$getValue(int rawId) { return (V) getByRawId(rawId); } + + @Override + public void fabric$updateRegistry(IdsHolder ids) { + this.field_13718 = (class_2929) ids; + } + + @Unique + private Event> fabric_remapCallbackEvent; + + @Override + public Event> fabric$getRegistryRemapCallback() { + if (this.fabric_remapCallbackEvent == null) { + this.fabric_remapCallbackEvent = EventFactory.createArrayBacked(RegistryRemapCallback.class, + (callbacks) -> (changedMap) -> { + for (RegistryRemapCallback callback : callbacks) { + callback.callback(changedMap); + } + } + ); + } + + return this.fabric_remapCallbackEvent; + } } diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json index 008e6ed69..f2e024e25 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json @@ -6,7 +6,8 @@ "defaultRequire": 1 }, "mixins": [ - "class_2929Mixin", + "versioned.OtherIdListMixin", + "versioned.PlayerManagerMixin", "versioned.SimpleRegistryMixin" ], "client": [ diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/build.gradle b/legacy-fabric-registry-sync-api-v2/1.7.10/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties new file mode 100644 index 000000000..af031afbf --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7.10 +maxVersionIncluded=1.7.10 diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java similarity index 87% rename from legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java rename to legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java index f26b66ee0..67599b93c 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.registry.sync.versioned; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -36,8 +36,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.legacyfabric.fabric.api.networking.v1.ServerPlayNetworking; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @Mixin(PlayerManager.class) public class PlayerManagerMixin { @@ -48,7 +47,7 @@ public class PlayerManagerMixin { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 2), method = "onPlayerConnect") public void playerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { if (fabric_shouldSend()) { - ServerPlayNetworking.send(player, RegistryRemapperAccess.PACKET_ID, ServerRegistryRemapper.getInstance().createBuf()); + ServerPlayNetworking.send(player, RegistryHelperImplementation.PACKET_ID, RegistryHelperImplementation.createBuf()); } } diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java new file mode 100644 index 000000000..fe060410e --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.registry.sync.versioned; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; + +import net.minecraft.util.collection.IdList; +import net.minecraft.util.registry.SimpleRegistry; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.event.EventFactory; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; +import net.legacyfabric.fabric.api.util.Identifier; + +@Mixin(SimpleRegistry.class) +public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, SyncedRegistrable { + // 1.8+ + @Shadow + public abstract void add(int id, String identifier, Object object); + + // 1.9+ + @Shadow + public abstract int getRawId(Object object); + + // 1.7+ + @Shadow + public abstract Object getByRawId(int index); + + @Mutable + @Shadow + @Final + protected IdList ids; + + @Shadow + public abstract String getId(Object par1); + + @Override + public void fabric$register(int rawId, Identifier identifier, V value) { + fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); + add(rawId, fabric$toKeyType(identifier), value); + fabric$getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); + } + + @Override + public IdsHolder fabric$getIdsHolder() { + return (IdsHolder) ids; + } + + @Override + public Identifier fabric$getId(V value) { + return new Identifier(getId(value)); + } + + @Override + public int fabric$getRawId(V value) { + return getRawId(value); + } + + @Override + public V fabric$getValue(int rawId) { + return (V) getByRawId(rawId); + } + + @Override + public void fabric$updateRegistry(IdsHolder ids) { + this.ids = (IdList) ids; + } + + @Unique + private Event> fabric_remapCallbackEvent; + + @Override + public Event> fabric$getRegistryRemapCallback() { + if (this.fabric_remapCallbackEvent == null) { + this.fabric_remapCallbackEvent = EventFactory.createArrayBacked(RegistryRemapCallback.class, + (callbacks) -> (changedMap) -> { + for (RegistryRemapCallback callback : callbacks) { + callback.callback(changedMap); + } + } + ); + } + + return this.fabric_remapCallbackEvent; + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..1f20467ce --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/fabric.mod.json @@ -0,0 +1,42 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-registry-sync-api-v2", + "name": "Legacy Fabric Registry Sync API (V2)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Registry hooks", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + "legacy-fabric-registry-sync-api-v2.mixins.json" + ], + "custom": { + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json new file mode 100644 index 000000000..9298f31f9 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.PlayerManagerMixin", + "versioned.SimpleRegistryMixinV2" + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/build.gradle b/legacy-fabric-registry-sync-api-v2/1.8.9/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties new file mode 100644 index 000000000..9056fbd37 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.8 +maxVersionIncluded=1.8.9 diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java similarity index 86% rename from legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java rename to legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java index 45c40826a..67599b93c 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.registry.sync.versioned; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -36,8 +36,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.legacyfabric.fabric.api.networking.v1.ServerPlayNetworking; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @Mixin(PlayerManager.class) public class PlayerManagerMixin { @@ -48,7 +47,7 @@ public class PlayerManagerMixin { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 2), method = "onPlayerConnect") public void playerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { if (fabric_shouldSend()) { - player.networkHandler.sendPacket(ServerPlayNetworking.createS2CPacket(RegistryRemapperAccess.PACKET_ID, ServerRegistryRemapper.getInstance().createBuf())); + ServerPlayNetworking.send(player, RegistryHelperImplementation.PACKET_ID, RegistryHelperImplementation.createBuf()); } } diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java new file mode 100644 index 000000000..0cffc2b81 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.registry.sync.versioned; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; + +import net.minecraft.util.collection.IdList; +import net.minecraft.util.registry.SimpleRegistry; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.event.EventFactory; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; +import net.legacyfabric.fabric.api.util.Identifier; + +@Mixin(SimpleRegistry.class) +public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, SyncedRegistrable { + // 1.8+ + @Shadow + public abstract void add(int id, K identifier, V object); + + // 1.8+ + @Shadow + public abstract K getIdentifier(Object par1); + + // 1.9+ + @Shadow + public abstract int getRawId(Object object); + + // 1.7+ + @Shadow + public abstract Object getByRawId(int index); + + @Mutable + @Shadow + @Final + protected IdList ids; + + @Override + public void fabric$register(int rawId, Identifier identifier, V value) { + fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); + add(rawId, fabric$toKeyType(identifier), value); + fabric$getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); + } + + @Override + public IdsHolder fabric$getIdsHolder() { + return (IdsHolder) ids; + } + + @Override + public Identifier fabric$getId(V value) { + return new Identifier(getIdentifier(value)); + } + + @Override + public int fabric$getRawId(V value) { + return getRawId(value); + } + + @Override + public V fabric$getValue(int rawId) { + return (V) getByRawId(rawId); + } + + @Override + public void fabric$updateRegistry(IdsHolder ids) { + this.ids = (IdList) ids; + } + + @Unique + private Event> fabric_remapCallbackEvent; + + @Override + public Event> fabric$getRegistryRemapCallback() { + if (this.fabric_remapCallbackEvent == null) { + this.fabric_remapCallbackEvent = EventFactory.createArrayBacked(RegistryRemapCallback.class, + (callbacks) -> (changedMap) -> { + for (RegistryRemapCallback callback : callbacks) { + callback.callback(changedMap); + } + } + ); + } + + return this.fabric_remapCallbackEvent; + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..1f20467ce --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/fabric.mod.json @@ -0,0 +1,42 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-registry-sync-api-v2", + "name": "Legacy Fabric Registry Sync API (V2)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Registry hooks", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + "legacy-fabric-registry-sync-api-v2.mixins.json" + ], + "custom": { + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json new file mode 100644 index 000000000..9298f31f9 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.PlayerManagerMixin", + "versioned.SimpleRegistryMixinV2" + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryRemapCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryRemapCallback.java new file mode 100644 index 000000000..2c7520cb8 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryRemapCallback.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.event; + +import java.util.Map; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; + +@FunctionalInterface +public interface RegistryRemapCallback { + void callback(Map> changedIdsMap); + + static Event> event(Identifier registryId) { + return event(RegistryHelperImplementation.getRegistry(registryId)); + } + + static Event> event(Registry registry) { + if (!(registry instanceof SyncedRegistry)) throw new IllegalArgumentException("Provided registry is not remappable!"); + + return ((SyncedRegistry) registry).fabric$getRegistryRemapCallback(); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java new file mode 100644 index 000000000..a2d123f28 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.holder; + +import net.legacyfabric.fabric.api.util.Identifier; + +public interface RegistryEntry { + int getId(); + Identifier getIdentifier(); + T getValue(); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java index bfb8ec27a..7665f7636 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java @@ -17,6 +17,8 @@ package net.legacyfabric.fabric.api.registry.v2.registry.holder; +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; import net.legacyfabric.fabric.api.util.Identifier; public interface SyncedRegistry extends Registry { @@ -31,4 +33,6 @@ public interface SyncedRegistry extends Registry { T value = fabric$getValue(rawId); return fabric$getId(value); } + + Event> fabric$getRegistryRemapCallback(); } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java index 1afcb2cd3..6abd3ae1b 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java @@ -23,4 +23,9 @@ public interface IdsHolder extends Iterable { int fabric$nextId(); void fabric$setValue(T value, int id); + int fabric$size(); + int fabric$getId(T value); + default boolean fabric$contains(T value) { + return fabric$getId(value) != -1; + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java index bcbcfeed7..bb8d0eeb1 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java @@ -23,4 +23,6 @@ public interface SyncedRegistrable extends Registrable { default int fabric$nextId() { return fabric$getIdsHolder().fabric$nextId(); } + + void fabric$updateRegistry(IdsHolder ids); } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java new file mode 100644 index 000000000..45af51ed1 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.registry; + +import java.io.IOException; +import java.io.UncheckedIOException; + +import net.minecraft.nbt.NbtCompound; + +import net.fabricmc.api.ClientModInitializer; + +import net.legacyfabric.fabric.api.client.networking.v1.ClientPlayNetworking; + +public class ClientRemapInitializer implements ClientModInitializer { + @Override + public void onInitializeClient() { + ClientPlayNetworking.registerGlobalReceiver(RegistryHelperImplementation.PACKET_ID, (client, handler, buf, responseSender) -> { + NbtCompound nbt; + + try { + nbt = buf.readNbtCompound(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + + client.submit(() -> RegistryHelperImplementation.readAndRemap(nbt)); + }); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java index 61f9f5032..cfb07a6ff 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java @@ -21,20 +21,29 @@ import java.util.Map; import java.util.function.Function; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.PacketByteBuf; + import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.event.EventFactory; +import net.legacyfabric.fabric.api.networking.v1.PacketByteBufs; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.VersionUtils; +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter; public class RegistryHelperImplementation { + public static final Identifier PACKET_ID = new Identifier("legacy-fabric-api:registry_remap"); public static final boolean hasFlatteningBegun = VersionUtils.matches(">=1.8 <=1.12.2"); public static final Map> INITIALIZATION_EVENTS = new HashMap<>(); private static final Map> REGISTRIES = new HashMap<>(); + private static final Map> REMAPPERS = new HashMap<>(); public static Event getInitializationEvent(Identifier registryId) { Event event; @@ -67,9 +76,16 @@ public static void registerRegistry(Identifier identifier, Registry holder) { REGISTRIES.put(identifier, holder); if (holder instanceof RegistryIdSetter) ((RegistryIdSetter) holder).fabric$setId(identifier); + + if (holder instanceof SyncedRegistry) { + REMAPPERS.put(identifier, new RegistryRemapper<>((SyncedRegistry) holder)); + } + + getInitializationEvent(identifier).invoker().initialized(holder); } public static void register(Registry registry, Identifier identifier, T value) { + if (registry == null) throw new IllegalArgumentException("Can't register to a null registry!"); if (!(registry instanceof Registrable)) throw new IllegalArgumentException("Can't register object to non registrable registry " + registry.fabric$getId()); Registrable registrable = (Registrable) registry; @@ -83,6 +99,7 @@ public static void register(Registry registry, Identifier identifier, T v } public static T register(Registry registry, Identifier identifier, Function valueConstructor) { + if (registry == null) throw new IllegalArgumentException("Can't register to a null registry!"); if (!(registry instanceof SyncedRegistrable)) throw new IllegalArgumentException("Can't register object to non registrable registry " + registry.fabric$getId()); SyncedRegistrable registrable = (SyncedRegistrable) registry; @@ -94,4 +111,49 @@ public static T register(Registry registry, Identifier identifier, Functi return value; } + + public static void remapRegistries() { + for (RegistryRemapper remapper : REMAPPERS.values()) { + remapper.remap(); + } + } + + public static void readAndRemap(NbtCompound compound) { + for (String key : compound.getKeys()) { + String registryKey = key; + + if (BACKWARD_COMPATIBILITY.containsKey(key)) { + registryKey = BACKWARD_COMPATIBILITY.get(key); + } + + Identifier identifier = new Identifier(registryKey); + RegistryRemapper remapper = REMAPPERS.get(identifier); + + if (remapper != null) { + remapper.readNbt(compound.getCompound(key)); + } + } + + remapRegistries(); + } + + private static final Map BACKWARD_COMPATIBILITY = new HashMap<>(); + static { + BACKWARD_COMPATIBILITY.put("Items", RegistryIds.ITEMS.toString()); + } + + public static NbtCompound toNbt() { + NbtCompound compound = new NbtCompound(); + + for (Map.Entry> entry : REMAPPERS.entrySet()) { + compound.put(entry.getKey().toString(), entry.getValue().toNbt()); + } + + return compound; + } + + public static PacketByteBuf createBuf() { + PacketByteBuf buf = PacketByteBufs.create(); + return ((PacketByteBufExtension) buf).writeCompound(toNbt()); + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java index 063d26e9e..e5e03c1a5 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java @@ -17,6 +17,9 @@ package net.legacyfabric.fabric.impl.registry; +import java.util.HashMap; +import java.util.Map; +import java.util.function.IntSupplier; import java.util.stream.Collectors; import com.google.common.collect.BiMap; @@ -26,6 +29,7 @@ import net.legacyfabric.fabric.api.logger.v1.Logger; import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.logger.LoggerImpl; @@ -86,6 +90,16 @@ public void remap() { this.dump(); IdsHolder dumpIds = getDumpIds(); + + IntSupplier previousSize = normalizeEntryList(dumpIds); + + invokeListeners(dumpIds); + + updateRegistry(dumpIds); + + this.entryDump.clear(); + this.dump(); + LOGGER.info("Remapped " + previousSize.getAsInt() + " entries"); } private IdsHolder getDumpIds() { @@ -101,5 +115,88 @@ private IdsHolder getDumpIds() { ids.fabric$setValue(value, rawId); } }); + + return ids; + } + + private IntSupplier normalizeEntryList(IdsHolder ids) { + IntSupplier currentSize = ids::fabric$size; + IntSupplier previousSize = () -> this.registry.fabric$getIdsHolder().fabric$size(); + + if (currentSize.getAsInt() > previousSize.getAsInt()) { + if (this.missingMap.isEmpty()) { + throw new IllegalStateException("Registry size increased from " + previousSize.getAsInt() + " to " + currentSize.getAsInt() + " after remapping! This is not possible!"); + } + } else if (currentSize.getAsInt() < previousSize.getAsInt()) { + addNewEntries(ids, currentSize, previousSize); + } + + if (currentSize.getAsInt() != previousSize.getAsInt() && this.missingMap.isEmpty()) { + throw new IllegalStateException("An error occured during remapping"); + } + + return previousSize; + } + + private void addNewEntries(IdsHolder newList, IntSupplier currentSize, IntSupplier previousSize) { + LOGGER.info("Adding " + (previousSize.getAsInt() - currentSize.getAsInt()) + " missing entries to registry"); + + this.registry.stream() + .filter(obj -> !newList.fabric$contains(obj)) + .collect(Collectors.toList()) + .forEach(missingEntry -> { + int newId = newList.fabric$nextId(); + + newList.fabric$setValue(missingEntry, newId); + + LOGGER.info("Adding %s %s with numerical id %d to registry", this.registry.fabric$getId(), this.registry.fabric$getId(missingEntry), newId); + }); + } + + private void invokeListeners(IdsHolder ids) { + Map> changed = new HashMap<>(); + + for (T value : ids) { + int oldId = this.registry.fabric$getIdsHolder().fabric$getId(value); + int newId = ids.fabric$getId(value); + + if (oldId != -1 && oldId != newId) { + LOGGER.info("Remapped %s %s from id %d to id %d", this.registry.fabric$getId(), this.registry.fabric$getId(value), oldId, newId); + changed.put(oldId, new RegistryEntryImpl<>(newId, this.registry.fabric$getId(value), value)); + } + } + + this.registry.fabric$getRegistryRemapCallback().invoker().callback(changed); + } + + private void updateRegistry(IdsHolder ids) { + this.registry.fabric$updateRegistry(ids); + } + + private static class RegistryEntryImpl implements RegistryEntry { + private final int id; + private final Identifier identifier; + private final T value; + + RegistryEntryImpl(int id, Identifier identifier, T value) { + this.id = id; + this.identifier = identifier; + this.value = value; + } + + @Override + public int getId() { + return 0; + } + + @Override + public Identifier getIdentifier() { + return null; + } + + @Override + public T getValue() { + return null; + } } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java index 979fee942..77720f077 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java @@ -17,6 +17,9 @@ package net.legacyfabric.fabric.mixin.registry.sync; +import java.util.IdentityHashMap; + +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -32,6 +35,13 @@ public abstract class IdListMixinV2 implements IdsHolder { @Shadow public abstract void set(Object value, int index); + @Shadow + @Final + private IdentityHashMap idMap; + + @Shadow + public abstract int getId(T value); + @Override public IdsHolder fabric$new() { return (IdsHolder) new IdList<>(); @@ -50,4 +60,14 @@ public abstract class IdListMixinV2 implements IdsHolder { public void fabric$setValue(T value, int id) { set(value, id); } + + @Override + public int fabric$size() { + return idMap.size(); + } + + @Override + public int fabric$getId(T value) { + return getId(value); + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixinV2.java similarity index 75% rename from legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixinV2.java index 75c4e0697..d904555cc 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixinV2.java @@ -30,14 +30,13 @@ import net.legacyfabric.fabric.api.event.EventFactory; import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; -import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter; @Mixin(MutableRegistry.class) -public abstract class MutableRegistryMixin implements Registry, RegistryIdSetter, Registrable { +public abstract class MutableRegistryMixinV2 implements net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry, RegistryIdSetter, Registrable { @Shadow public abstract void put(Object key, Object value); @@ -48,33 +47,41 @@ public abstract class MutableRegistryMixin implements Registry, Registr @Final protected Map map; @Unique - private final Event> fabric_addObjectEvent = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class, - (callbacks) -> (rawId, id, object) -> { - for (RegistryEntryAddedCallback callback : callbacks) { - callback.onEntryAdded(rawId, id, object); - } - } - ); + private Event> fabric_addObjectEvent; @Unique - private final Event> fabric_beforeAddObjectEvent = EventFactory.createArrayBacked(RegistryBeforeAddCallback.class, - (callbacks) -> (rawId, id, object) -> { - for (RegistryBeforeAddCallback callback : callbacks) { - callback.onEntryAdding(rawId, id, object); - } - } - ); + private Event> fabric_beforeAddObjectEvent; @Unique private Identifier fabric_id; @Override public Event> fabric$getEntryAddedCallback() { + if (this.fabric_addObjectEvent == null) { + fabric_addObjectEvent = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryEntryAddedCallback callback : callbacks) { + callback.onEntryAdded(rawId, id, object); + } + } + ); + } + return this.fabric_addObjectEvent; } @Override public Event> fabric$getBeforeAddedCallback() { + if (this.fabric_beforeAddObjectEvent == null) { + fabric_beforeAddObjectEvent = EventFactory.createArrayBacked(RegistryBeforeAddCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryBeforeAddCallback callback : callbacks) { + callback.onEntryAdding(rawId, id, object); + } + } + ); + } + return this.fabric_beforeAddObjectEvent; } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java index be5d67321..c857f6477 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java @@ -23,7 +23,6 @@ import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; - @Mixin(SimpleRegistry.class) public abstract class SimpleRegistryMixinV2 implements SyncedRegistry { } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/WorldSaveHandlerMixin.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/WorldSaveHandlerMixin.java similarity index 95% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/WorldSaveHandlerMixin.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/WorldSaveHandlerMixin.java index 1c712a1d9..a08240335 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/WorldSaveHandlerMixin.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/WorldSaveHandlerMixin.java @@ -39,7 +39,7 @@ import net.legacyfabric.fabric.api.logger.v1.Logger; import net.legacyfabric.fabric.impl.logger.LoggerImpl; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @Mixin(WorldSaveHandler.class) public class WorldSaveHandlerMixin { @@ -63,7 +63,7 @@ private boolean fabric_readIdMapFile(File file) throws IOException { } if (nbt != null) { - ServerRegistryRemapper.getInstance().readAndRemap(nbt); + RegistryHelperImplementation.readAndRemap(nbt); return true; } } @@ -78,7 +78,7 @@ private File fabric_getWorldIdMapFile(int i) { @Unique private void fabric_saveRegistryData() { - NbtCompound newIdMap = ServerRegistryRemapper.getInstance().toNbtCompound(); + NbtCompound newIdMap = RegistryHelperImplementation.toNbt(); if (!newIdMap.equals(this.fabric_lastSavedIdMap)) { for (int i = FABRIC_ID_REGISTRY_BACKUPS - 1; i >= 0; i--) { diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json index f5406e502..027f6bc9f 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json @@ -22,6 +22,7 @@ "description": "Registry hooks", "entrypoints": { "client": [ + "net.legacyfabric.fabric.impl.registry.ClientRemapInitializer" ] }, "mixins": [ @@ -29,10 +30,9 @@ ], "custom": { "loom:injected_interfaces": { - "net/minecraft/class_1367": ["net/legacyfabric/fabric/api/registry/v2/RegistryHolder"], - "net/minecraft/class_1943": ["net/legacyfabric/fabric/api/registry/v2/SyncedRegistryHolder"], - "net/minecraft/class_1942": ["net/legacyfabric/fabric/api/registry/v2/registrable/IdsHolder"], - "net/minecraft/class_2929": ["net/legacyfabric/fabric/api/registry/v2/registrable/IdsHolder"] + "net/minecraft/class_1367": ["net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry"], + "net/minecraft/class_1943": ["net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry"], + "net/minecraft/class_1942": ["net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder"] }, "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json index 7062c3539..f0cedd1d4 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json @@ -7,8 +7,9 @@ }, "mixins": [ "IdListMixinV2", - "MutableRegistryMixin", - "SimpleRegistryMixinV2" + "MutableRegistryMixinV2", + "SimpleRegistryMixinV2", + "WorldSaveHandlerMixin" ], "client": [ ] From b533add6a66804de5b01ff4700567ba9029303c8 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 5 May 2024 22:51:53 +0200 Subject: [PATCH 11/36] Ensure backward compatibility with registry-sync-api-v1 --- .../registry/v1/RegistryEntryAddCallback.java | 4 +- .../v1/RegistryEntryRemapCallback.java | 4 +- .../api/registry/v1/RegistryHelper.java | 76 +++++++++++---- .../fabric/api/registry/v1/RegistryIds.java | 14 +-- .../registry/BackwardCompatibilityHelper.java | 74 +++++++++++++++ .../impl/registry/RegistryHelperImpl.java | 3 + .../common/src/main/resources/fabric.mod.json | 4 +- .../v2/event/RegistryBeforeAddCallback.java | 4 +- .../v2/event/RegistryEntryAddedCallback.java | 4 +- .../v2/event/RegistryRemapCallback.java | 4 +- .../impl/registry/RegistryEventHelper.java | 93 +++++++++++++++++++ .../RegistryHelperImplementation.java | 41 +++++++- 12 files changed, 288 insertions(+), 37 deletions(-) create mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEventHelper.java diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryAddCallback.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryAddCallback.java index 47e70a0f9..55023e78d 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryAddCallback.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryAddCallback.java @@ -19,13 +19,13 @@ import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; +import net.legacyfabric.fabric.impl.registry.BackwardCompatibilityHelper; @FunctionalInterface public interface RegistryEntryAddCallback { void onEntryAdded(int rawId, Identifier key, T object); static Event> event(Identifier registryId) { - return RegistryRemapper.getEventsHolder(registryId).getAddEvent(); + return BackwardCompatibilityHelper.getEventHolder(registryId).getAddEvent(); } } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryRemapCallback.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryRemapCallback.java index 41aa0dcce..c947e5f4d 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryRemapCallback.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryRemapCallback.java @@ -19,13 +19,13 @@ import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; +import net.legacyfabric.fabric.impl.registry.BackwardCompatibilityHelper; @FunctionalInterface public interface RegistryEntryRemapCallback { void onEntryAdded(int oldId, int newId, Identifier key, T object); static Event> event(Identifier registryId) { - return RegistryRemapper.getEventsHolder(registryId).getRemapEvent(); + return BackwardCompatibilityHelper.getEventHolder(registryId).getRemapEvent(); } } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java index 9a6f3745e..d9179d2b5 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java @@ -71,11 +71,16 @@ public static Event onRegistryInitialized(Identifier identi * @return The block registered */ public static Block registerBlock(Block block, Identifier id) { - return RegistryHelperImpl.registerBlock(block, id); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.BLOCKS, + id, block + ); + + return block; } public static Block getBlock(Identifier id) { - return RegistryHelperImpl.getValue(id, RegistryIds.BLOCKS); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(net.legacyfabric.fabric.api.registry.v2.RegistryIds.BLOCKS, id); } /** @@ -88,7 +93,10 @@ public static Block getBlock(Identifier id) { * @return The item registered */ public static Item registerItem(Item item, Identifier id) { - net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register(net.legacyfabric.fabric.api.registry.v2.RegistryIds.ITEMS, id, item); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.ITEMS, + id, item + ); return item; } @@ -105,11 +113,16 @@ public static Item getItem(Identifier id) { * @return The block entity type class registered */ public static Class registerBlockEntityType(Class blockEntityTypeClass, Identifier id) { - return RegistryHelperImpl.registerBlockEntityType(blockEntityTypeClass, id); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.BLOCK_ENTITY_TYPES, + id, blockEntityTypeClass + ); + + return blockEntityTypeClass; } public static Class getBlockEntityType(Identifier id) { - return RegistryHelperImpl.getValue(id, RegistryIds.BLOCK_ENTITY_TYPES); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(RegistryIds.BLOCK_ENTITY_TYPES, id); } /** @@ -123,7 +136,12 @@ public static Class getBlockEntityType(Identifier id) { */ @SinceMC("1.9") public static StatusEffect registerStatusEffect(StatusEffect statusEffect, Identifier id) { - return RegistryHelperImpl.registerStatusEffect(statusEffect, id); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.STATUS_EFFECTS, + id, statusEffect + ); + + return statusEffect; } /** @@ -137,11 +155,14 @@ public static StatusEffect registerStatusEffect(StatusEffect statusEffect, Ident */ @BeforeMC("1.9") public static StatusEffect registerStatusEffect(EntryCreator statusEffect, Identifier id) { - return RegistryHelperImpl.registerStatusEffect(statusEffect, id); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.STATUS_EFFECTS, + id, statusEffect::create + ); } public static StatusEffect getStatusEffect(Identifier id) { - return RegistryHelperImpl.getValue(id, RegistryIds.STATUS_EFFECTS); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(RegistryIds.STATUS_EFFECTS, id); } /** @@ -155,7 +176,12 @@ public static StatusEffect getStatusEffect(Identifier id) { */ @SinceMC("1.9") public static Enchantment registerEnchantment(Enchantment enchantment, Identifier id) { - return RegistryHelperImpl.registerEnchantment(enchantment, id); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.ENCHANTMENTS, + id, enchantment + ); + + return enchantment; } /** @@ -169,11 +195,14 @@ public static Enchantment registerEnchantment(Enchantment enchantment, Identifie */ @BeforeMC("1.9") public static Enchantment registerEnchantment(EntryCreator enchantment, Identifier id) { - return RegistryHelperImpl.registerEnchantment(enchantment, id); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.ENCHANTMENTS, + id, enchantment::create + ); } public static Enchantment getEnchantment(Identifier id) { - return RegistryHelperImpl.getValue(id, RegistryIds.ENCHANTMENTS); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(RegistryIds.ENCHANTMENTS, id); } /** @@ -185,7 +214,12 @@ public static Enchantment getEnchantment(Identifier id) { */ @SinceMC("1.9") public static Biome registerBiome(Biome biome, Identifier id) { - return RegistryHelperImpl.registerBiome(biome, id); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.BIOMES, + id, biome + ); + + return biome; } /** @@ -197,7 +231,10 @@ public static Biome registerBiome(Biome biome, Identifier id) { */ @BeforeMC("1.9") public static Biome registerBiome(EntryCreator biome, Identifier id) { - return RegistryHelperImpl.registerBiome(biome, id); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.BIOMES, + id, biome::create + ); } /** @@ -217,8 +254,8 @@ public static BiomePair registerBiomeWithMutatedVariant( return RegistryHelperImpl.registerBiomeWithMutatedVariant(parentBiome, parentId, mutatedBiome, mutatedId); } - public static Biome getBiome(Identifier identifier) { - return RegistryHelperImpl.getValue(identifier, RegistryIds.BIOMES); + public static Biome getBiome(Identifier id) { + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(RegistryIds.BIOMES, id); } /** @@ -229,11 +266,16 @@ public static Biome getBiome(Identifier identifier) { * @return The entity type class registered */ public static Class registerEntityType(Class entityTypeClass, Identifier id) { - return RegistryHelperImpl.registerEntityType(entityTypeClass, id); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.ENTITY_TYPES, + id, entityTypeClass + ); + + return entityTypeClass; } public static Class getEntityType(Identifier id) { - return RegistryHelperImpl.getValue(id, RegistryIds.ENTITY_TYPES); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(RegistryIds.ENTITY_TYPES, id); } @FunctionalInterface diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryIds.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryIds.java index 1f9ccb673..9fd34e60e 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryIds.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryIds.java @@ -21,11 +21,11 @@ public class RegistryIds { public static final Identifier REGISTRY_REMAPPER = new Identifier("legacy-fabric-registry-sync-api-v1-common", "registry_remappers"); - public static final Identifier ITEMS = new Identifier("items"); - public static final Identifier BLOCKS = new Identifier("blocks"); - public static final Identifier BLOCK_ENTITY_TYPES = new Identifier("block_entity_types"); - public static final Identifier STATUS_EFFECTS = new Identifier("status_effects"); - public static final Identifier ENCHANTMENTS = new Identifier("enchantments"); - public static final Identifier BIOMES = new Identifier("biomes"); - public static final Identifier ENTITY_TYPES = new Identifier("entity_types"); + public static final Identifier ITEMS = net.legacyfabric.fabric.api.registry.v2.RegistryIds.ITEMS; + public static final Identifier BLOCKS = net.legacyfabric.fabric.api.registry.v2.RegistryIds.BLOCKS; + public static final Identifier BLOCK_ENTITY_TYPES = net.legacyfabric.fabric.api.registry.v2.RegistryIds.BLOCK_ENTITY_TYPES; + public static final Identifier STATUS_EFFECTS = net.legacyfabric.fabric.api.registry.v2.RegistryIds.STATUS_EFFECTS; + public static final Identifier ENCHANTMENTS = net.legacyfabric.fabric.api.registry.v2.RegistryIds.ENCHANTMENTS; + public static final Identifier BIOMES = net.legacyfabric.fabric.api.registry.v2.RegistryIds.BIOMES; + public static final Identifier ENTITY_TYPES = net.legacyfabric.fabric.api.registry.v2.RegistryIds.ENTITY_TYPES; } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java new file mode 100644 index 000000000..7fd019ec9 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.registry; + +import java.util.HashMap; +import java.util.Map; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.registry.util.RegistryEventsHolder; + +public class BackwardCompatibilityHelper implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryHelperImplementation.registerRegisterEvent(identifier -> { + Event event = RegistryHelper.IDENTIFIER_EVENT_MAP.get(identifier); + + if (event != null) { + event.invoker().initialized(); + } + }); + } + + private static final Map> CALLBACKS = new HashMap<>(); + + public static RegistryEventsHolder getEventHolder(Identifier identifier) { + if (!CALLBACKS.containsKey(identifier)) { + initCallback(identifier); + } + + return (RegistryEventsHolder) CALLBACKS.get(identifier); + } + + private static void initCallback(Identifier identifier) { + RegistryEventsHolder holder = new RegistryEventsHolder<>(); + CALLBACKS.put(identifier, holder); + + RegistryEntryAddedCallback.event(identifier) + .register(holder.getAddEvent().invoker()::onEntryAdded); + RegistryRemapCallback.event(identifier) + .register(changedIdsMap -> { + for (Map.Entry> entry : changedIdsMap.entrySet()) { + holder.getRemapEvent().invoker() + .onEntryAdded( + entry.getKey(), + entry.getValue().getId(), + entry.getValue().getIdentifier(), + entry.getValue().getValue() + ); + } + }); + } +} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java index 659b5f9d2..4ad5ae3c0 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java @@ -31,6 +31,8 @@ import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; import net.minecraft.world.biome.Biome; import net.fabricmc.api.EnvType; @@ -43,6 +45,7 @@ import net.legacyfabric.fabric.impl.client.registry.sync.ClientRegistryRemapper; import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; +import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; import net.legacyfabric.fabric.impl.registry.sync.compat.RegistriesGetter; import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/fabric.mod.json index 261a4f9a4..99e4b85f7 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/fabric.mod.json +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/fabric.mod.json @@ -21,8 +21,8 @@ }, "description": "Registry hooks", "entrypoints": { - "client": [ - "net.legacyfabric.fabric.impl.client.registry.sync.ClientRemapInitializer" + "preLaunch": [ + "net.legacyfabric.fabric.impl.registry.BackwardCompatibilityHelper" ] }, "mixins": [ diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java index 6136747e9..aefcac6fd 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java @@ -20,14 +20,14 @@ import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; +import net.legacyfabric.fabric.impl.registry.RegistryEventHelper; @FunctionalInterface public interface RegistryBeforeAddCallback { void onEntryAdding(int rawId, Identifier id, T object); static Event> event(Identifier registryId) { - return event(RegistryHelperImplementation.getRegistry(registryId)); + return RegistryEventHelper.addRegistryBeforeCallback(registryId); } static Event> event(Registry registry) { diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java index c571737c2..58ec8db6c 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryEntryAddedCallback.java @@ -20,14 +20,14 @@ import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; +import net.legacyfabric.fabric.impl.registry.RegistryEventHelper; @FunctionalInterface public interface RegistryEntryAddedCallback { void onEntryAdded(int rawId, Identifier id, T object); static Event> event(Identifier registryId) { - return event(RegistryHelperImplementation.getRegistry(registryId)); + return RegistryEventHelper.addedCallbackEvent(registryId); } static Event> event(Registry registry) { diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryRemapCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryRemapCallback.java index 2c7520cb8..e904c7c0e 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryRemapCallback.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryRemapCallback.java @@ -24,14 +24,14 @@ import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; +import net.legacyfabric.fabric.impl.registry.RegistryEventHelper; @FunctionalInterface public interface RegistryRemapCallback { void callback(Map> changedIdsMap); static Event> event(Identifier registryId) { - return event(RegistryHelperImplementation.getRegistry(registryId)); + return RegistryEventHelper.remapCallbackEvent(registryId); } static Event> event(Registry registry) { diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEventHelper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEventHelper.java new file mode 100644 index 000000000..94549c4ec --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEventHelper.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.registry; + +import java.util.HashMap; +import java.util.Map; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.event.EventFactory; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.util.Identifier; + +public class RegistryEventHelper { + protected static final Map>> IDENTIFIER_BEFORE_MAP = new HashMap<>(); + protected static final Map>> IDENTIFIER_ADDED_MAP = new HashMap<>(); + protected static final Map>> IDENTIFIER_REMAP_MAP = new HashMap<>(); + + public static Event> addRegistryBeforeCallback(Identifier registryId) { + Registry registry = RegistryHelperImplementation.getRegistry(registryId); + + if (registry != null) return registry.fabric$getBeforeAddedCallback(); + + if (!IDENTIFIER_BEFORE_MAP.containsKey(registryId)) { + Event> event = EventFactory.createArrayBacked(RegistryBeforeAddCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryBeforeAddCallback callback : callbacks) { + callback.onEntryAdding(rawId, id, object); + } + } + ); + IDENTIFIER_BEFORE_MAP.put(registryId, (Event>) (Object) event); + } + + return (Event>) (Object) IDENTIFIER_BEFORE_MAP.get(registryId); + } + + public static Event> addedCallbackEvent(Identifier registryId) { + Registry registry = RegistryHelperImplementation.getRegistry(registryId); + + if (registry != null) return registry.fabric$getEntryAddedCallback(); + + if (!IDENTIFIER_ADDED_MAP.containsKey(registryId)) { + Event> event = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryEntryAddedCallback callback : callbacks) { + callback.onEntryAdded(rawId, id, object); + } + } + ); + IDENTIFIER_ADDED_MAP.put(registryId, (Event>) (Object) event); + } + + return (Event>) (Object) IDENTIFIER_ADDED_MAP.get(registryId); + } + + public static Event> remapCallbackEvent(Identifier registryId) { + Registry registry = RegistryHelperImplementation.getRegistry(registryId); + + if (registry != null) return ((SyncedRegistry) registry).fabric$getRegistryRemapCallback(); + + if (!IDENTIFIER_REMAP_MAP.containsKey(registryId)) { + Event> event = EventFactory.createArrayBacked(RegistryRemapCallback.class, + (callbacks) -> (changeMap) -> { + for (RegistryRemapCallback callback : callbacks) { + callback.callback(changeMap); + } + } + ); + IDENTIFIER_REMAP_MAP.put(registryId, (Event>) (Object) event); + } + + return (Event>) (Object) IDENTIFIER_REMAP_MAP.get(registryId); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java index cfb07a6ff..c1c87e670 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java @@ -17,8 +17,11 @@ package net.legacyfabric.fabric.impl.registry; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.function.Consumer; import java.util.function.Function; import net.minecraft.nbt.NbtCompound; @@ -28,7 +31,10 @@ import net.legacyfabric.fabric.api.event.EventFactory; import net.legacyfabric.fabric.api.networking.v1.PacketByteBufs; import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; @@ -44,6 +50,11 @@ public class RegistryHelperImplementation { public static final Map> INITIALIZATION_EVENTS = new HashMap<>(); private static final Map> REGISTRIES = new HashMap<>(); private static final Map> REMAPPERS = new HashMap<>(); + private static final List> REGISTRY_REGISTERED = new ArrayList<>(); + + public static void registerRegisterEvent(Consumer callback) { + REGISTRY_REGISTERED.add(callback); + } public static Event getInitializationEvent(Identifier registryId) { Event event; @@ -71,7 +82,7 @@ public static Registry getRegistry(Identifier identifier) { return (Registry) REGISTRIES.get(identifier); } - public static void registerRegistry(Identifier identifier, Registry holder) { + public static void registerRegistry(Identifier identifier, Registry holder) { if (REGISTRIES.containsKey(identifier)) throw new IllegalArgumentException("Attempted to register registry " + identifier.toString() + " twices!"); REGISTRIES.put(identifier, holder); @@ -81,7 +92,29 @@ public static void registerRegistry(Identifier identifier, Registry holder) { REMAPPERS.put(identifier, new RegistryRemapper<>((SyncedRegistry) holder)); } + REGISTRY_REGISTERED.forEach(c -> c.accept(identifier)); + getInitializationEvent(identifier).invoker().initialized(holder); + + holder.fabric$getBeforeAddedCallback().register((rawId, id, object) -> { + Event> event = (Event>) (Object) RegistryEventHelper.IDENTIFIER_BEFORE_MAP.get(identifier); + + if (event != null) event.invoker().onEntryAdding(rawId, id, object); + }); + + holder.fabric$getEntryAddedCallback().register((rawId, id, object) -> { + Event> event = (Event>) (Object) RegistryEventHelper.IDENTIFIER_ADDED_MAP.get(identifier); + + if (event != null) event.invoker().onEntryAdded(rawId, id, object); + }); + + if (holder instanceof SyncedRegistry) { + ((SyncedRegistry) holder).fabric$getRegistryRemapCallback().register(changedIdsMap -> { + Event> event = (Event>) (Object) RegistryEventHelper.IDENTIFIER_REMAP_MAP.get(identifier); + + if (event != null) event.invoker().callback(changedIdsMap); + }); + } } public static void register(Registry registry, Identifier identifier, T value) { @@ -140,6 +173,12 @@ public static void readAndRemap(NbtCompound compound) { private static final Map BACKWARD_COMPATIBILITY = new HashMap<>(); static { BACKWARD_COMPATIBILITY.put("Items", RegistryIds.ITEMS.toString()); + BACKWARD_COMPATIBILITY.put("Blocks", RegistryIds.BLOCKS.toString()); + BACKWARD_COMPATIBILITY.put("Biomes", RegistryIds.BIOMES.toString()); + BACKWARD_COMPATIBILITY.put("BlockEntityTypes", RegistryIds.BLOCK_ENTITY_TYPES.toString()); + BACKWARD_COMPATIBILITY.put("Enchantments", RegistryIds.ENCHANTMENTS.toString()); + BACKWARD_COMPATIBILITY.put("EntityTypes", RegistryIds.ENTITY_TYPES.toString()); + BACKWARD_COMPATIBILITY.put("StatusEffects", RegistryIds.STATUS_EFFECTS.toString()); } public static NbtCompound toNbt() { From f314ddd1742bf1c2cfdab6883a3c0d3ac1775fa7 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 5 May 2024 22:53:55 +0200 Subject: [PATCH 12/36] Item registry is fully ported already --- .../legacyfabric/fabric/impl/registry/RegistryHelperImpl.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java index e1bf9f7c7..0b77016aa 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java @@ -31,8 +31,6 @@ import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; import net.minecraft.world.biome.Biome; import net.fabricmc.api.EnvType; @@ -45,7 +43,6 @@ import net.legacyfabric.fabric.impl.client.registry.sync.ClientRegistryRemapper; import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; import net.legacyfabric.fabric.impl.registry.sync.compat.RegistriesGetter; import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; From 7d4714cd7ac205e2a939c26d4087d6291ff139ff Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 00:39:11 +0200 Subject: [PATCH 13/36] Make it easier to set item texture in 1.7.10 --- legacy-fabric-item-api-v1/1.7.10/build.gradle | 3 ++ .../1.7.10/gradle.properties | 2 + .../impl/item/versioned/EarlyInitializer.java | 39 ++++++++++++++++ .../1.7.10/src/main/resources/fabric.mod.json | 44 +++++++++++++++++++ .../legacy-fabric-item-api-v1.mixins.json | 12 +++++ .../legacy-fabric-item-api.accesswidener | 3 ++ .../legacyfabric/fabric/testing/TestMod.java | 28 +++++------- .../src/testmod/resources/fabric.mod.json | 1 - .../testmod/resources/testmods.accesswidener | 3 -- 9 files changed, 114 insertions(+), 21 deletions(-) create mode 100644 legacy-fabric-item-api-v1/1.7.10/build.gradle create mode 100644 legacy-fabric-item-api-v1/1.7.10/gradle.properties create mode 100644 legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java create mode 100644 legacy-fabric-item-api-v1/1.7.10/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api-v1.mixins.json create mode 100644 legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api.accesswidener delete mode 100644 legacyfabric-api/1.7.10/src/testmod/resources/testmods.accesswidener diff --git a/legacy-fabric-item-api-v1/1.7.10/build.gradle b/legacy-fabric-item-api-v1/1.7.10/build.gradle new file mode 100644 index 000000000..66b589ecb --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/build.gradle @@ -0,0 +1,3 @@ +loom { + accessWidenerPath = file("src/main/resources/legacy-fabric-item-api.accesswidener") +} diff --git a/legacy-fabric-item-api-v1/1.7.10/gradle.properties b/legacy-fabric-item-api-v1/1.7.10/gradle.properties new file mode 100644 index 000000000..c6dcd9541 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.3 +maxVersionIncluded=1.7.10 diff --git a/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java b/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java new file mode 100644 index 000000000..b87b3583a --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.item.versioned; + +import net.minecraft.item.Item; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); + } + + private static void itemRegistryInit(Registry holder) { + Registry registry = (Registry) holder; + + + } +} diff --git a/legacy-fabric-item-api-v1/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..17176f15b --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/fabric.mod.json @@ -0,0 +1,44 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-item-api-v1", + "name": "Legacy Fabric Item API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Item utils", + "entrypoints": { + "preLaunch": [] + }, + "mixins": [ + "legacy-fabric-item-api-v1.mixins.json" + ], + "accessWidener": "legacy-fabric-item-api.accesswidener", + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api-v1.mixins.json b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api-v1.mixins.json new file mode 100644 index 000000000..86feace33 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api-v1.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.item", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + ], + "client": [ + ] +} diff --git a/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api.accesswidener b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api.accesswidener new file mode 100644 index 000000000..10be8bab6 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api.accesswidener @@ -0,0 +1,3 @@ +accessWidener v2 named + +transitive-accessible method net/minecraft/item/Item getFromId (Ljava/lang/String;)Lnet/minecraft/item/Item; diff --git a/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index e96611725..f9de833e2 100644 --- a/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -17,18 +17,13 @@ package net.legacyfabric.fabric.testing; -import java.util.concurrent.ThreadLocalRandom; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; import net.fabricmc.api.ModInitializer; import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; -import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; public class TestMod implements ModInitializer { @@ -38,18 +33,17 @@ public void onInitialize() { } private void registerItem() { - Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); - Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); - Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; - - for (Block block : blocks) { - Identifier identifier = new Identifier("legacy-fabric-api:conc_block_" + block.getMaterial().getColor().color); - RegistryHelper.registerBlock(block, identifier); - RegistryHelper.registerItem(new BlockItem(block), identifier); - } - - Item testItem = new Item().setItemGroup(ItemGroup.FOOD); +// Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); +// Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); +// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; +// +// for (Block block : blocks) { +// Identifier identifier = new Identifier("legacy-fabric-api:conc_block_" + block.getMaterial().getColor().color); +// RegistryHelper.registerBlock(block, identifier); +// RegistryHelper.registerItem(new BlockItem(block), identifier); +// } + + Item testItem = new Item().setItemGroup(ItemGroup.FOOD).getFromId("legacy-fabric-api:test_item"); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); - ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); } } diff --git a/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json index 4f47e2473..c7cf043bc 100644 --- a/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json +++ b/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json @@ -40,7 +40,6 @@ "net.legacyfabric.fabric.testing.TestMod" ] }, - "accessWidener": "testmods.accesswidener", "custom": { "modmenu": { "badges": [ "library" ] diff --git a/legacyfabric-api/1.7.10/src/testmod/resources/testmods.accesswidener b/legacyfabric-api/1.7.10/src/testmod/resources/testmods.accesswidener deleted file mode 100644 index 45ae69ced..000000000 --- a/legacyfabric-api/1.7.10/src/testmod/resources/testmods.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -accessWidener v2 named - -transitive-accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V From 76496568d0dd5d8b4a57e4acc833e32164be17c8 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 00:40:19 +0200 Subject: [PATCH 14/36] Fix item models being wrong after registry is remapped for 1.8+ --- .../impl/item/versioned/EarlyInitializer.java | 5 +- .../item/versioned/ItemModelsRemapper.java | 72 +++++++++++++++++++ .../item/versioned/ItemModelsAccessor.java | 32 +++++++++ .../mixin/item/versioned/ItemModelsMixin.java | 42 +++++++++++ .../legacy-fabric-item-api-v1.mixins.json | 2 + 5 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/ItemModelsRemapper.java create mode 100644 legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsAccessor.java create mode 100644 legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java index d8a9bfe22..1051fc0f0 100644 --- a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java @@ -25,6 +25,7 @@ import net.legacyfabric.fabric.api.registry.v2.RegistryIds; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; import net.legacyfabric.fabric.mixin.item.versioned.ItemAccessor; public class EarlyInitializer implements PreLaunchEntrypoint { @@ -34,12 +35,14 @@ public void onPreLaunch() { } private static void itemRegistryInit(Registry holder) { - Registry registry = (Registry) holder; + SyncedRegistry registry = (SyncedRegistry) holder; registry.fabric$getEntryAddedCallback().register((rawId, id, item) -> { if (item instanceof BlockItem) { ItemAccessor.getBLOCK_ITEMS().put(((BlockItem) item).getBlock(), item); } }); + + registry.fabric$getRegistryRemapCallback().register(new ItemModelsRemapper()); } } diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/ItemModelsRemapper.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/ItemModelsRemapper.java new file mode 100644 index 000000000..e82792a61 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/ItemModelsRemapper.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.item.versioned; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.item.ItemModels; +import net.minecraft.client.util.ModelIdentifier; +import net.minecraft.item.Item; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.mixin.item.versioned.ItemModelsAccessor; + +public class ItemModelsRemapper implements RegistryRemapCallback { + private static final Map> modelIds = new HashMap<>(); + + public static void registerModelId(Identifier id, int metadata, ModelIdentifier modelId) { + modelIds.computeIfAbsent(id, k -> new HashMap<>()) + .put(metadata, modelId); + } + + private int pack(int itemId, int metadata) { + return itemId << 16 | metadata; + } + + private ItemModels getModelRegistry() { + return MinecraftClient.getInstance().getItemRenderer().getModels(); + } + + @Override + public void callback(Map> changedIdsMap) { + ((ItemModelsAccessor) getModelRegistry()).getModelIds().clear(); + + for (Map.Entry> entry : modelIds.entrySet()) { + Identifier itemId = entry.getKey(); + + Item item = RegistryHelper.getValue(Item.REGISTRY, itemId); + int itemIndex = RegistryHelper.getRawId(Item.REGISTRY, item); + + if (changedIdsMap.containsKey(itemIndex)) { + itemIndex = changedIdsMap.get(itemIndex).getId(); + } + + for (Map.Entry modelIdEntry : entry.getValue().entrySet()) { + ((ItemModelsAccessor) getModelRegistry()).getModelIds() + .put(pack(itemIndex, modelIdEntry.getKey()), modelIdEntry.getValue()); + } + } + + getModelRegistry().reloadModels(); + } +} diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsAccessor.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsAccessor.java new file mode 100644 index 000000000..6e5e75d82 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsAccessor.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.item.versioned; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.client.render.item.ItemModels; +import net.minecraft.client.util.ModelIdentifier; + +@Mixin(ItemModels.class) +public interface ItemModelsAccessor { + @Accessor + Map getModelIds(); +} diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java new file mode 100644 index 000000000..b43463da3 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.item.versioned; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.render.item.ItemModels; +import net.minecraft.client.util.ModelIdentifier; +import net.minecraft.item.Item; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.item.versioned.ItemModelsRemapper; + +@Mixin(ItemModels.class) +public class ItemModelsMixin { + @Inject(method = "putModel", at = @At("RETURN")) + private void lf$registerModelId(Item item, int metadata, ModelIdentifier id, CallbackInfo ci) { + Identifier identifier = RegistryHelper.getId(Item.REGISTRY, item); + + if (identifier != null) ItemModelsRemapper.registerModelId(identifier, metadata, id); + else System.out.println(item + " " + metadata + " " + id); + } +} diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json index e79ed78b9..37ec3a268 100644 --- a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json @@ -9,5 +9,7 @@ "versioned.ItemAccessor" ], "client": [ + "versioned.ItemModelsAccessor", + "versioned.ItemModelsMixin" ] } From cbd3b5a48ff060b30a13d164b74ccf95f8f5b03f Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 00:41:07 +0200 Subject: [PATCH 15/36] Disable Block testmods as Block registry is not ported yet --- .../legacyfabric/fabric/testing/TestMod.java | 32 +++++++++---------- .../legacyfabric/fabric/testing/TestMod.java | 32 +++++++++---------- .../legacyfabric/fabric/testing/TestMod.java | 32 +++++++++---------- .../legacyfabric/fabric/testing/TestMod.java | 18 +++++------ .../legacyfabric/fabric/testing/TestMod.java | 18 +++++------ .../legacyfabric/fabric/testing/TestMod.java | 32 +++++++++---------- 6 files changed, 82 insertions(+), 82 deletions(-) diff --git a/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 332182e28..d6fe82092 100644 --- a/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -39,22 +39,22 @@ public void onInitialize() { } private void registerItem() { - Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); - Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); - Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; - - for (Block block : blocks) { - int color = 1644825; - - if (block == concBlock2) { - color = 3361970; - } - - Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); - - net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); - net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); - } +// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); +// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); +// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; +// +// for (Block block : blocks) { +// int color = 1644825; +// +// if (block == concBlock2) { +// color = 3361970; +// } +// +// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); +// +// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); +// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); +// } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); diff --git a/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index dd6cb8e7b..18b068df9 100644 --- a/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -39,22 +39,22 @@ public void onInitialize() { } private void registerItem() { - Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); - Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); - Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; - - for (Block block : blocks) { - int color = 1644825; - - if (block == concBlock2) { - color = 3361970; - } - - Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); - - net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); - net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); - } +// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); +// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); +// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; +// +// for (Block block : blocks) { +// int color = 1644825; +// +// if (block == concBlock2) { +// color = 3361970; +// } +// +// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); +// +// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); +// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); +// } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.register( diff --git a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index dd6cb8e7b..18b068df9 100644 --- a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -39,22 +39,22 @@ public void onInitialize() { } private void registerItem() { - Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); - Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); - Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; - - for (Block block : blocks) { - int color = 1644825; - - if (block == concBlock2) { - color = 3361970; - } - - Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); - - net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); - net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); - } +// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); +// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); +// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; +// +// for (Block block : blocks) { +// int color = 1644825; +// +// if (block == concBlock2) { +// color = 3361970; +// } +// +// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); +// +// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); +// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); +// } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.register( diff --git a/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 80cf2d90e..6a9be55a9 100644 --- a/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -39,15 +39,15 @@ public void onInitialize() { } private void registerItem() { - Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); - Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); - Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; - - for (Block block : blocks) { - Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + block.getMaterialColor(block.getDefaultState()).color); - RegistryHelper.registerBlock(block, identifier); - RegistryHelper.registerItem(new BlockItem(block), identifier); - } +// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); +// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); +// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; +// +// for (Block block : blocks) { +// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + block.getMaterialColor(block.getDefaultState()).color); +// RegistryHelper.registerBlock(block, identifier); +// RegistryHelper.registerItem(new BlockItem(block), identifier); +// } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); diff --git a/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index e96611725..2ad9f9792 100644 --- a/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -38,15 +38,15 @@ public void onInitialize() { } private void registerItem() { - Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); - Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); - Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; - - for (Block block : blocks) { - Identifier identifier = new Identifier("legacy-fabric-api:conc_block_" + block.getMaterial().getColor().color); - RegistryHelper.registerBlock(block, identifier); - RegistryHelper.registerItem(new BlockItem(block), identifier); - } +// Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); +// Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); +// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; +// +// for (Block block : blocks) { +// Identifier identifier = new Identifier("legacy-fabric-api:conc_block_" + block.getMaterial().getColor().color); +// RegistryHelper.registerBlock(block, identifier); +// RegistryHelper.registerItem(new BlockItem(block), identifier); +// } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); diff --git a/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index f0f18e18a..b4bcb41c6 100644 --- a/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -39,22 +39,22 @@ public void onInitialize() { } private void registerItem() { - Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); - Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); - Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; - - for (Block block : blocks) { - int color = 1644825; - - if (block == concBlock2) { - color = 3361970; - } - - Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); - - RegistryHelper.registerBlock(block, identifier); - RegistryHelper.registerItem(new BlockItem(block), identifier); - } +// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); +// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); +// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; +// +// for (Block block : blocks) { +// int color = 1644825; +// +// if (block == concBlock2) { +// color = 3361970; +// } +// +// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); +// +// RegistryHelper.registerBlock(block, identifier); +// RegistryHelper.registerItem(new BlockItem(block), identifier); +// } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); From 648e61013eafddbc5c641bd386096b28518c5b40 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 00:41:54 +0200 Subject: [PATCH 16/36] Fix a few possible crashes when using registries --- .../mixin/registry/sync/versioned/SimpleRegistryMixin.java | 6 +++++- .../registry/sync/versioned/SimpleRegistryMixinV2.java | 6 +++++- .../registry/sync/versioned/SimpleRegistryMixinV2.java | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java index 5423f2924..7fad490e3 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java @@ -72,7 +72,11 @@ public abstract class SimpleRegistryMixin implements SyncedRegistry, Sy @Override public Identifier fabric$getId(V value) { - return new Identifier(getIdentifier(value)); + K vanillaId = getIdentifier(value); + + if (vanillaId == null) return null; + + return new Identifier(vanillaId); } @Override diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java index fe060410e..07eacb02c 100644 --- a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java @@ -70,7 +70,11 @@ public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, Syn @Override public Identifier fabric$getId(V value) { - return new Identifier(getId(value)); + String vanillaId = getId(value); + + if (vanillaId == null) return null; + + return new Identifier(vanillaId); } @Override diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java index 0cffc2b81..428b915ca 100644 --- a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java @@ -71,7 +71,11 @@ public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, @Override public Identifier fabric$getId(V value) { - return new Identifier(getIdentifier(value)); + K vanillaId = getIdentifier(value); + + if (vanillaId == null) return null; + + return new Identifier(vanillaId); } @Override From b6cbf787ec1fa7884faccd73c046ca87be45c6eb Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 00:43:02 +0200 Subject: [PATCH 17/36] Add more useful methods to RegistryHelper --- .../api/registry/v2/RegistryHelper.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java index d9053b4a5..37cfda2eb 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java @@ -20,9 +20,11 @@ import java.util.function.Function; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; + public class RegistryHelper { public static void register(Registry registry, Identifier identifier, T value) { RegistryHelperImplementation.register(registry, identifier, value); @@ -56,4 +58,24 @@ public static T getValue(Identifier registryId, Identifier identifier) { public static T getValue(Registry registry, Identifier identifier) { return registry.fabric$getValue(identifier); } + + public static Identifier getId(Registry registry, T object) { + return registry.fabric$getId(object); + } + + public static Identifier getId(Identifier registryId, T object) { + return getId(RegistryHelperImplementation.getRegistry(registryId), object); + } + + public static int getRawId(Registry registry, T object) { + if (!(registry instanceof SyncedRegistry)) { + throw new IllegalArgumentException("Cannot get raw id of " + object + " of non synced registry " + registry.fabric$getId()); + } + + return ((SyncedRegistry) registry).fabric$getRawId(object); + } + + public static int getRawId(Identifier registryId, T object) { + return getRawId(RegistryHelperImplementation.getRegistry(registryId), object); + } } From 2bd406dc2f8ee81da104967202c82583eec96dac Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 00:44:42 +0200 Subject: [PATCH 18/36] Fix style --- .../java/net/legacyfabric/fabric/testing/TestMod.java | 5 ----- .../java/net/legacyfabric/fabric/testing/TestMod.java | 5 ----- .../java/net/legacyfabric/fabric/testing/TestMod.java | 5 ----- .../java/net/legacyfabric/fabric/testing/TestMod.java | 5 ----- .../java/net/legacyfabric/fabric/testing/TestMod.java | 4 ---- .../java/net/legacyfabric/fabric/testing/TestMod.java | 5 ----- 6 files changed, 29 deletions(-) diff --git a/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index d6fe82092..a4880c24d 100644 --- a/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -17,12 +17,7 @@ package net.legacyfabric.fabric.testing; -import java.util.concurrent.ThreadLocalRandom; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.block.material.MaterialColor; -import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; diff --git a/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 18b068df9..d6be83ef4 100644 --- a/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -17,12 +17,7 @@ package net.legacyfabric.fabric.testing; -import java.util.concurrent.ThreadLocalRandom; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.block.material.MaterialColor; -import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; diff --git a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 18b068df9..d6be83ef4 100644 --- a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -17,12 +17,7 @@ package net.legacyfabric.fabric.testing; -import java.util.concurrent.ThreadLocalRandom; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.block.material.MaterialColor; -import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; diff --git a/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 6a9be55a9..e8cf76499 100644 --- a/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -17,12 +17,7 @@ package net.legacyfabric.fabric.testing; -import java.util.concurrent.ThreadLocalRandom; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.block.material.MaterialColor; -import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; diff --git a/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 2ad9f9792..5eff69729 100644 --- a/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -17,11 +17,7 @@ package net.legacyfabric.fabric.testing; -import java.util.concurrent.ThreadLocalRandom; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; diff --git a/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index b4bcb41c6..e848e7a88 100644 --- a/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -17,12 +17,7 @@ package net.legacyfabric.fabric.testing; -import java.util.concurrent.ThreadLocalRandom; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.block.material.MaterialColor; -import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; From 49679c59d832ba68f01b64951ef48088addd9893 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 17:12:47 +0200 Subject: [PATCH 19/36] Fix Item registry being registered before vanilla items initialisation --- .../main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java index b0c379210..915f9423c 100644 --- a/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java +++ b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java @@ -37,7 +37,7 @@ public class ItemMixin { @Final public static SimpleRegistry REGISTRY; - @Inject(method = "", at = @At("RETURN")) + @Inject(method = "setup", at = @At("RETURN")) private static void registerRegistry(CallbackInfo ci) { RegistryHelper.addRegistry(RegistryIds.ITEMS, (Registry) REGISTRY); } From 2226ba659d1c97703d356afe6be2340ac33289ec Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 19:38:03 +0200 Subject: [PATCH 20/36] Remove block related fixes from item modules --- .../fabric/impl/item/versioned/EarlyInitializer.java | 8 -------- .../main/resources/legacy-fabric-item-api-v1.mixins.json | 1 - 2 files changed, 9 deletions(-) diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java index 1051fc0f0..17d33b408 100644 --- a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java @@ -17,7 +17,6 @@ package net.legacyfabric.fabric.impl.item.versioned; -import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; @@ -26,7 +25,6 @@ import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; -import net.legacyfabric.fabric.mixin.item.versioned.ItemAccessor; public class EarlyInitializer implements PreLaunchEntrypoint { @Override @@ -37,12 +35,6 @@ public void onPreLaunch() { private static void itemRegistryInit(Registry holder) { SyncedRegistry registry = (SyncedRegistry) holder; - registry.fabric$getEntryAddedCallback().register((rawId, id, item) -> { - if (item instanceof BlockItem) { - ItemAccessor.getBLOCK_ITEMS().put(((BlockItem) item).getBlock(), item); - } - }); - registry.fabric$getRegistryRemapCallback().register(new ItemModelsRemapper()); } } diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json index 37ec3a268..8882e989a 100644 --- a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json @@ -6,7 +6,6 @@ "defaultRequire": 1 }, "mixins": [ - "versioned.ItemAccessor" ], "client": [ "versioned.ItemModelsAccessor", From e3850eb4dfdd25f4298054f48764435c19228e1e Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 19:39:58 +0200 Subject: [PATCH 21/36] New Block module --- gradle.properties | 1 + .../1.12.2/build.gradle | 0 .../1.12.2/gradle.properties | 2 + .../block/versioned/BlockStateRemapper.java | 69 +++++++++++++++++++ .../block/versioned/EarlyInitializer.java | 62 +++++++++++++++++ .../mixin/block/versioned/BlockAccessor.java | 24 +++---- .../mixin/block/versioned}/BlockMixin.java | 30 ++++---- .../mixin/block}/versioned/ItemAccessor.java | 2 +- .../1.12.2/src/main/resources/fabric.mod.json | 45 ++++++++++++ .../legacy-fabric-block-api-v1.mixins.json | 15 ++++ .../1.7.10/build.gradle | 3 + .../1.7.10/gradle.properties | 2 + .../block/versioned/EarlyInitializer.java | 38 ++++++++++ .../block/versioned/BlockItemAccessor.java | 25 ++----- .../mixin/block/versioned/BlockMixin.java | 68 ++++++++++++++++++ .../mixin/block/versioned/ItemMixin.java | 48 +++++++++++++ .../1.7.10/src/main/resources/fabric.mod.json | 46 +++++++++++++ .../legacy-fabric-block-api-v1.accesswidener | 0 .../legacy-fabric-block-api-v1.mixins.json | 15 ++++ legacy-fabric-block-api-v1/common.gradle | 7 ++ .../common/build.gradle | 0 .../common/gradle.properties | 2 + .../fabric/impl/block/EarlyInitializer.java | 39 +++++++++++ .../common/src/main/resources/fabric.mod.json | 45 ++++++++++++ ...acy-fabric-block-api-v1-common.mixins.json | 12 ++++ .../mixin/registry/sync/BlockMixin.java | 43 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../mixin/registry/sync/BlockMixin.java | 43 ------------ .../fabric/mixin/registry/sync/ItemMixin.java | 41 ----------- ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../1.7.10/build.gradle | 4 +- .../1.7.10/src/main/resources/fabric.mod.json | 1 - .../mixin/registry/sync/BlockMixin.java | 43 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../mixin/registry/sync/BlockMixin.java | 43 ------------ .../fabric/mixin/registry/sync/ItemMixin.java | 41 ----------- ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../mixin/registry/sync/BlockMixin.java | 43 ------------ .../fabric/mixin/registry/sync/ItemMixin.java | 41 ----------- ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../impl/registry/RegistryHelperImpl.java | 16 ----- ...ic-registry-sync-api-v1-common.mixins.json | 1 - .../legacyfabric/fabric/testing/TestMod.java | 38 +++++----- .../legacyfabric/fabric/testing/TestMod.java | 38 +++++----- .../legacyfabric/fabric/testing/TestMod.java | 38 +++++----- .../legacyfabric/fabric/testing/TestMod.java | 23 ++++--- .../legacyfabric/fabric/testing/TestMod.java | 24 ++++--- .../legacyfabric/fabric/testing/TestMod.java | 23 ++++--- .../1.8/src/testmod/resources/fabric.mod.json | 1 - .../testmod/resources/testmods.accesswidener | 3 - .../legacyfabric/fabric/testing/TestMod.java | 38 +++++----- legacyfabric-api/common.gradle | 1 + settings.gradle | 1 + 53 files changed, 682 insertions(+), 516 deletions(-) create mode 100644 legacy-fabric-block-api-v1/1.12.2/build.gradle create mode 100644 legacy-fabric-block-api-v1/1.12.2/gradle.properties create mode 100644 legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/BlockStateRemapper.java create mode 100644 legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java rename legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java => legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java (60%) rename {legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry => legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned}/BlockMixin.java (59%) rename {legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item => legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block}/versioned/ItemAccessor.java (94%) create mode 100644 legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.mixins.json create mode 100644 legacy-fabric-block-api-v1/1.7.10/build.gradle create mode 100644 legacy-fabric-block-api-v1/1.7.10/gradle.properties create mode 100644 legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java rename legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java => legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockItemAccessor.java (60%) create mode 100644 legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java create mode 100644 legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemMixin.java create mode 100644 legacy-fabric-block-api-v1/1.7.10/src/main/resources/fabric.mod.json rename legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener => legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener (100%) create mode 100644 legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.mixins.json create mode 100644 legacy-fabric-block-api-v1/common.gradle create mode 100644 legacy-fabric-block-api-v1/common/build.gradle create mode 100644 legacy-fabric-block-api-v1/common/gradle.properties create mode 100644 legacy-fabric-block-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/EarlyInitializer.java create mode 100644 legacy-fabric-block-api-v1/common/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-block-api-v1/common/src/main/resources/legacy-fabric-block-api-v1-common.mixins.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java delete mode 100644 legacyfabric-api/1.8/src/testmod/resources/testmods.accesswidener diff --git a/gradle.properties b/gradle.properties index a11e1db1e..3275caaf0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,5 +21,6 @@ legacy-fabric-permissions-api-v1.version = 1.0.1 legacy-fabric-registry-sync-api-v1.version = 2.2.0 legacy-fabric-registry-sync-api-v2.version = 1.0.0 legacy-fabric-item-api-v1.version = 1.0.0 +legacy-fabric-block-api-v1.version = 1.0.0 legacy-fabric-rendering-api-v1.version = 1.0.0 legacy-fabric-resource-loader-v1.version = 2.1.1 diff --git a/legacy-fabric-block-api-v1/1.12.2/build.gradle b/legacy-fabric-block-api-v1/1.12.2/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-block-api-v1/1.12.2/gradle.properties b/legacy-fabric-block-api-v1/1.12.2/gradle.properties new file mode 100644 index 000000000..7d5606688 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.8 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/BlockStateRemapper.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/BlockStateRemapper.java new file mode 100644 index 000000000..d1f6010ce --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/BlockStateRemapper.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.block.versioned; + +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.util.collection.IdList; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.api.util.VersionUtils; +import net.legacyfabric.fabric.mixin.block.versioned.BlockAccessor; + +public class BlockStateRemapper implements RegistryRemapCallback { + private static final boolean hasSpecialCase = VersionUtils.matches(">1.8.9"); + private static final Identifier specialCaseId = new Identifier("tripwire"); + + @Override + public void callback(Map> changedIdsMap) { + IdsHolder newList = Block.BLOCK_STATES.fabric$new(); + + for (Block block : Block.REGISTRY) { + int blockRawId = RegistryHelper.getRawId(Block.REGISTRY, block); + + if (changedIdsMap.containsKey(blockRawId)) { + blockRawId = changedIdsMap.get(blockRawId).getId(); + } + + Identifier blockId = RegistryHelper.getId(Block.REGISTRY, block); + + if (blockId.equals(specialCaseId) && hasSpecialCase) { + for (int i = 0; i < 15; ++i) { + int blockStateId = blockRawId << 4 | i; + BlockState state = block.stateFromData(i); + + newList.fabric$setValue(state, blockStateId); + } + } else { + for (BlockState state : block.getStateManager().getBlockStates()) { + int blockStateId = blockRawId << 4 | block.getData(state); + + newList.fabric$setValue(state, blockStateId); + } + } + } + + BlockAccessor.setBLOCK_STATES((IdList) newList); + } +} diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java new file mode 100644 index 000000000..f3c5d9b09 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.block.versioned; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.mixin.block.versioned.ItemAccessor; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.BLOCKS).register(EarlyInitializer::blockRegistryInit); + RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); + } + + private static void blockRegistryInit(Registry holder) { + SyncedRegistry registry = (SyncedRegistry) holder; + + registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> { + for (BlockState blockState : block.getStateManager().getBlockStates()) { + int i = rawId << 4 | block.getData(blockState); + Block.BLOCK_STATES.set(blockState, i); + } + }); + + registry.fabric$getRegistryRemapCallback().register(new BlockStateRemapper()); + } + + private static void itemRegistryInit(Registry holder) { + SyncedRegistry registry = (SyncedRegistry) holder; + + registry.fabric$getEntryAddedCallback().register((rawId, id, item) -> { + if (item instanceof BlockItem) { + ItemAccessor.getBLOCK_ITEMS().put(((BlockItem) item).getBlock(), item); + } + }); + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java similarity index 60% rename from legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java rename to legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java index a51824472..924029309 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java @@ -15,27 +15,19 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.block.versioned; -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.gen.Accessor; import net.minecraft.block.Block; -import net.minecraft.item.Item; - -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; +import net.minecraft.block.BlockState; +import net.minecraft.util.collection.IdList; -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; +@Mixin(Block.class) +public interface BlockAccessor { + @Accessor + static void setBLOCK_STATES(IdList blockStates) { - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; } } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java similarity index 59% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java rename to legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java index b7f06b894..6bd40b175 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java @@ -15,34 +15,30 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync.registry; +package net.legacyfabric.fabric.mixin.block.versioned; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.block.Block; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.BiDefaultedRegistry; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockRegistryRemapper; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; @Mixin(Block.class) public class BlockMixin { - @Inject(method = "setup", at = @At("RETURN")) - private static void initRegistryRemapper(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(BlockRegistryRemapper::new); - - if (!RegistryHelperImpl.bootstrap) { - try { - Class.forName(StatusEffect.class.getName()); + @Shadow + @Final + public static BiDefaultedRegistry REGISTRY; - Class.forName(Enchantment.class.getName()); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } + @Inject(method = "setup", at = @At("RETURN")) + private static void registerRegistry(CallbackInfo ci) { + RegistryHelper.addRegistry(RegistryIds.BLOCKS, REGISTRY); } } diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemAccessor.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemAccessor.java similarity index 94% rename from legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemAccessor.java rename to legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemAccessor.java index 37bcb308f..290aa26b3 100644 --- a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemAccessor.java +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemAccessor.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.item.versioned; +package net.legacyfabric.fabric.mixin.block.versioned; import java.util.Map; diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..818b9ad13 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json @@ -0,0 +1,45 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-api-v1", + "name": "Legacy Fabric Block API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.block.versioned.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-block-api-v1.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.mixins.json b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.mixins.json new file mode 100644 index 000000000..6368baf84 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.block.versioned", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "BlockAccessor", + "BlockMixin", + "ItemAccessor" + ], + "client": [ + ] +} diff --git a/legacy-fabric-block-api-v1/1.7.10/build.gradle b/legacy-fabric-block-api-v1/1.7.10/build.gradle new file mode 100644 index 000000000..306a9d690 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/build.gradle @@ -0,0 +1,3 @@ +loom { + accessWidenerPath = file("src/main/resources/legacy-fabric-block-api-v1.accesswidener") +} diff --git a/legacy-fabric-block-api-v1/1.7.10/gradle.properties b/legacy-fabric-block-api-v1/1.7.10/gradle.properties new file mode 100644 index 000000000..c01c52c6b --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.7.10 diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java new file mode 100644 index 000000000..dc3f4a4e0 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.block.versioned; + +import net.minecraft.block.Block; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.BLOCKS).register(EarlyInitializer::blockRegistryInit); + } + + private static void blockRegistryInit(Registry holder) { + SyncedRegistry registry = (SyncedRegistry) holder; + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockItemAccessor.java similarity index 60% rename from legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java rename to legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockItemAccessor.java index a51824472..aaad9cbfb 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockItemAccessor.java @@ -15,27 +15,16 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.block.versioned; -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.gen.Accessor; import net.minecraft.block.Block; -import net.minecraft.item.Item; - -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; - -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; +import net.minecraft.item.BlockItem; - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; - } +@Mixin(BlockItem.class) +public interface BlockItemAccessor { + @Accessor + Block getBlock(); } diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java new file mode 100644 index 000000000..7b959d0aa --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.block.versioned; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.util.registry.SimpleRegistry; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.util.Identifier; + +@Mixin(Block.class) +public class BlockMixin { + @Shadow + @Final + public static SimpleRegistry REGISTRY; + + @Inject(method = "setup", at = @At("RETURN")) + private static void registerRegistry(CallbackInfo ci) { + RegistryHelper.addRegistry(RegistryIds.BLOCKS, REGISTRY); + } + + @Inject(method = "getBlockFromItem", at = @At("HEAD"), cancellable = true) + private static void fixBlockFromItem(Item item, CallbackInfoReturnable cir) { + if (item instanceof BlockItem) { + cir.setReturnValue(((BlockItemAccessor) item).getBlock()); + return; + } + + Identifier identifier = RegistryHelper.getId(Item.REGISTRY, item); + + if (identifier != null) { + Block blockFromId = RegistryHelper.getValue(REGISTRY, identifier); + + if (blockFromId != null) { + cir.setReturnValue(blockFromId); + return; + } + } + + cir.setReturnValue(null); + } +} diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemMixin.java b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemMixin.java new file mode 100644 index 000000000..da5fd6879 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemMixin.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.block.versioned; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.util.Identifier; + +@Mixin(Item.class) +public class ItemMixin { + @Inject(method = "fromBlock", at = @At("HEAD"), cancellable = true) + private static void fixItemFromBlock(Block block, CallbackInfoReturnable cir) { + Identifier identifier = RegistryHelper.getId(Block.REGISTRY, block); + + if (identifier != null) { + Item item = RegistryHelper.getValue(Item.REGISTRY, identifier); + + if (item != null) { + cir.setReturnValue(item); + return; + } + } + + cir.setReturnValue(null); + } +} diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..b018250ea --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/fabric.mod.json @@ -0,0 +1,46 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-api-v1", + "name": "Legacy Fabric Block API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.block.versioned.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-block-api-v1.mixins.json" + ], + "accessWidener": "legacy-fabric-block-api-v1.accesswidener", + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener similarity index 100% rename from legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener rename to legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.mixins.json b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.mixins.json new file mode 100644 index 000000000..0fbf43835 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.block.versioned", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "BlockItemAccessor", + "BlockMixin", + "ItemMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-block-api-v1/common.gradle b/legacy-fabric-block-api-v1/common.gradle new file mode 100644 index 000000000..7102014bf --- /dev/null +++ b/legacy-fabric-block-api-v1/common.gradle @@ -0,0 +1,7 @@ +moduleDependencies(project, [ + "legacy-fabric-api-base", + "legacy-fabric-networking-api-v1", + "legacy-fabric-resource-loader-v1", + "legacy-fabric-registry-sync-api-v2", + "legacy-fabric-item-api-v1" +]) diff --git a/legacy-fabric-block-api-v1/common/build.gradle b/legacy-fabric-block-api-v1/common/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-block-api-v1/common/gradle.properties b/legacy-fabric-block-api-v1/common/gradle.properties new file mode 100644 index 000000000..a499ab733 --- /dev/null +++ b/legacy-fabric-block-api-v1/common/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-block-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/EarlyInitializer.java b/legacy-fabric-block-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/EarlyInitializer.java new file mode 100644 index 000000000..9039efbc3 --- /dev/null +++ b/legacy-fabric-block-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/EarlyInitializer.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.block; + +import net.minecraft.block.Block; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.BLOCKS).register(EarlyInitializer::blockRegistryInit); + } + + private static void blockRegistryInit(Registry holder) { + Registry registry = (Registry) holder; + + registry.fabric$getBeforeAddedCallback().register((rawId, id, block) -> block.setTranslationKey(id.toTranslationKey())); + } +} diff --git a/legacy-fabric-block-api-v1/common/src/main/resources/fabric.mod.json b/legacy-fabric-block-api-v1/common/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..39d3627f1 --- /dev/null +++ b/legacy-fabric-block-api-v1/common/src/main/resources/fabric.mod.json @@ -0,0 +1,45 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-api-v1-common", + "name": "Legacy Fabric Block API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.block.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-block-api-v1-common.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-block-api-v1/common/src/main/resources/legacy-fabric-block-api-v1-common.mixins.json b/legacy-fabric-block-api-v1/common/src/main/resources/legacy-fabric-block-api-v1-common.mixins.json new file mode 100644 index 000000000..4c2ea7c54 --- /dev/null +++ b/legacy-fabric-block-api-v1/common/src/main/resources/legacy-fabric-block-api-v1-common.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.block", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java deleted file mode 100644 index ce4eecb72..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.impl.registry.sync.compat.BlockCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -@Mixin(Block.class) -public class BlockMixin implements BlockCompat { - @Mutable - @Shadow - @Final - public static IdList BLOCK_STATES; - - @Override - public void setBLOCK_STATES(IdListCompat block_states) { - BLOCK_STATES = (IdList) block_states; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index fb5274ab6..5493ef74a 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,8 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "class_2929Mixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java deleted file mode 100644 index ce4eecb72..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.impl.registry.sync.compat.BlockCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -@Mixin(Block.class) -public class BlockMixin implements BlockCompat { - @Mutable - @Shadow - @Final - public static IdList BLOCK_STATES; - - @Override - public void setBLOCK_STATES(IdListCompat block_states) { - BLOCK_STATES = (IdList) block_states; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java deleted file mode 100644 index a51824472..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; - -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; - -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; - - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 28dbfae1b..aeb78a447 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,8 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "class_2929Mixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/build.gradle b/legacy-fabric-registry-sync-api-v1/1.7.10/build.gradle index 5058a1900..8b1378917 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/build.gradle +++ b/legacy-fabric-registry-sync-api-v1/1.7.10/build.gradle @@ -1,3 +1 @@ -loom { - accessWidenerPath = file("src/main/resources/registrysync.accesswidener") -} + diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json index 909da100a..ac4e75d72 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json +++ b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json @@ -28,7 +28,6 @@ "mixins": [ "legacy-fabric-registry-sync-api-v1.mixins.json" ], - "accessWidener": "registrysync.accesswidener", "custom": { "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java deleted file mode 100644 index ce4eecb72..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.impl.registry.sync.compat.BlockCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -@Mixin(Block.class) -public class BlockMixin implements BlockCompat { - @Mutable - @Shadow - @Final - public static IdList BLOCK_STATES; - - @Override - public void setBLOCK_STATES(IdListCompat block_states) { - BLOCK_STATES = (IdList) block_states; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index eae009f7d..1a5914904 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -7,8 +7,6 @@ }, "mixins": [ "SimpleRegistryMixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java deleted file mode 100644 index 80b003f7d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.impl.registry.sync.compat.BlockCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -@Mixin(Block.class) -public class BlockMixin implements BlockCompat { - @Mutable - @Shadow - @Final - public static IdList BLOCK_STATES; - - @Override - public void setBLOCK_STATES(IdListCompat block_states) { - BLOCK_STATES = (IdList) block_states; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java deleted file mode 100644 index a51824472..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; - -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; - -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; - - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index eae009f7d..1a5914904 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -7,8 +7,6 @@ }, "mixins": [ "SimpleRegistryMixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java deleted file mode 100644 index ce4eecb72..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.impl.registry.sync.compat.BlockCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -@Mixin(Block.class) -public class BlockMixin implements BlockCompat { - @Mutable - @Shadow - @Final - public static IdList BLOCK_STATES; - - @Override - public void setBLOCK_STATES(IdListCompat block_states) { - BLOCK_STATES = (IdList) block_states; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java deleted file mode 100644 index a51824472..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; - -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; - -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; - - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index fb5274ab6..5493ef74a 100644 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,8 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "class_2929Mixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java index 0b77016aa..ddc5417e3 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java @@ -25,8 +25,6 @@ import com.google.common.collect.HashBiMap; import org.jetbrains.annotations.ApiStatus; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.Entity; @@ -83,20 +81,6 @@ public static T register(RegistryHelper.EntryCreator entryCreator, Identi return instance; } - public static Block registerBlock(Block block, Identifier id) { - block.setTranslationKey(formatTranslationKey(id)); - int rawId = register(block, id, RegistryIds.BLOCKS); - - if (hasFlatteningBegun) { - for (BlockState blockState : block.getStateManager().getBlockStates()) { - int i = rawId << 4 | block.getData(blockState); - Block.BLOCK_STATES.set(blockState, i); - } - } - - return block; - } - public static Class registerBlockEntityType(Class blockEntityClass, Identifier id) { register(blockEntityClass, id, RegistryIds.BLOCK_ENTITY_TYPES); diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json index c3ad0db1e..554285579 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json @@ -8,7 +8,6 @@ "mixins": [ "MinecraftServerMixin", "IdListMixin", - "registry.BlockMixin", "registry.BlockEntityMixin", "registry.StatusEffectMixin", "registry.EnchantmentMixin", diff --git a/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index a4880c24d..0b2e631a3 100644 --- a/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -18,6 +18,12 @@ package net.legacyfabric.fabric.testing; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialColor; +import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; @@ -34,22 +40,22 @@ public void onInitialize() { } private void registerItem() { -// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); -// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); -// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; -// -// for (Block block : blocks) { -// int color = 1644825; -// -// if (block == concBlock2) { -// color = 3361970; -// } -// -// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); -// -// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); -// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); -// } + Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); + Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); + Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; + + for (Block block : blocks) { + int color = 1644825; + + if (block == concBlock2) { + color = 3361970; + } + + Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); + + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); + } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); diff --git a/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index d6be83ef4..e337ff849 100644 --- a/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -18,6 +18,12 @@ package net.legacyfabric.fabric.testing; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialColor; +import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; @@ -34,22 +40,22 @@ public void onInitialize() { } private void registerItem() { -// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); -// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); -// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; -// -// for (Block block : blocks) { -// int color = 1644825; -// -// if (block == concBlock2) { -// color = 3361970; -// } -// -// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); -// -// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); -// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); -// } + Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); + Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); + Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; + + for (Block block : blocks) { + int color = 1644825; + + if (block == concBlock2) { + color = 3361970; + } + + Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); + + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); + } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.register( diff --git a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index d6be83ef4..e337ff849 100644 --- a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -18,6 +18,12 @@ package net.legacyfabric.fabric.testing; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialColor; +import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; @@ -34,22 +40,22 @@ public void onInitialize() { } private void registerItem() { -// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); -// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); -// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; -// -// for (Block block : blocks) { -// int color = 1644825; -// -// if (block == concBlock2) { -// color = 3361970; -// } -// -// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); -// -// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); -// net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); -// } + Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); + Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); + Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; + + for (Block block : blocks) { + int color = 1644825; + + if (block == concBlock2) { + color = 3361970; + } + + Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); + + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); + } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.register( diff --git a/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index f9de833e2..0c8506f82 100644 --- a/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -18,6 +18,11 @@ package net.legacyfabric.fabric.testing; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; @@ -33,15 +38,15 @@ public void onInitialize() { } private void registerItem() { -// Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); -// Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); -// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; -// -// for (Block block : blocks) { -// Identifier identifier = new Identifier("legacy-fabric-api:conc_block_" + block.getMaterial().getColor().color); -// RegistryHelper.registerBlock(block, identifier); -// RegistryHelper.registerItem(new BlockItem(block), identifier); -// } + Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); + Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); + Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; + + for (Block block : blocks) { + Identifier identifier = new Identifier("legacy-fabric-api:conc_block_" + block.getMaterial().getColor().color); + RegistryHelper.registerBlock(block, identifier); + RegistryHelper.registerItem(new BlockItem(block), identifier); + } Item testItem = new Item().setItemGroup(ItemGroup.FOOD).getFromId("legacy-fabric-api:test_item"); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); diff --git a/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index e8cf76499..d338c86fe 100644 --- a/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -18,6 +18,12 @@ package net.legacyfabric.fabric.testing; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialColor; +import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; @@ -34,15 +40,15 @@ public void onInitialize() { } private void registerItem() { -// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); -// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); -// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; -// -// for (Block block : blocks) { -// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + block.getMaterialColor(block.getDefaultState()).color); -// RegistryHelper.registerBlock(block, identifier); -// RegistryHelper.registerItem(new BlockItem(block), identifier); -// } + Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); + Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); + Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; + + for (Block block : blocks) { + Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + block.getMaterialColor(block.getDefaultState()).color); + RegistryHelper.registerBlock(block, identifier); + RegistryHelper.registerItem(new BlockItem(block), identifier); + } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); diff --git a/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 5eff69729..1b356eef7 100644 --- a/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -18,6 +18,11 @@ package net.legacyfabric.fabric.testing; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; @@ -34,15 +39,15 @@ public void onInitialize() { } private void registerItem() { -// Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); -// Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); -// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; -// -// for (Block block : blocks) { -// Identifier identifier = new Identifier("legacy-fabric-api:conc_block_" + block.getMaterial().getColor().color); -// RegistryHelper.registerBlock(block, identifier); -// RegistryHelper.registerItem(new BlockItem(block), identifier); -// } + Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); + Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); + Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; + + for (Block block : blocks) { + Identifier identifier = new Identifier("legacy-fabric-api:conc_block_" + block.getMaterial().getColor().color); + RegistryHelper.registerBlock(block, identifier); + RegistryHelper.registerItem(new BlockItem(block), identifier); + } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); diff --git a/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json index 4f47e2473..c7cf043bc 100644 --- a/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json +++ b/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json @@ -40,7 +40,6 @@ "net.legacyfabric.fabric.testing.TestMod" ] }, - "accessWidener": "testmods.accesswidener", "custom": { "modmenu": { "badges": [ "library" ] diff --git a/legacyfabric-api/1.8/src/testmod/resources/testmods.accesswidener b/legacyfabric-api/1.8/src/testmod/resources/testmods.accesswidener deleted file mode 100644 index 8f8db9c23..000000000 --- a/legacyfabric-api/1.8/src/testmod/resources/testmods.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -accessWidener v2 named - -accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V diff --git a/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index e848e7a88..970a1a683 100644 --- a/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -18,6 +18,12 @@ package net.legacyfabric.fabric.testing; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialColor; +import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; @@ -34,22 +40,22 @@ public void onInitialize() { } private void registerItem() { -// Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); -// Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); -// Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; -// -// for (Block block : blocks) { -// int color = 1644825; -// -// if (block == concBlock2) { -// color = 3361970; -// } -// -// Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); -// -// RegistryHelper.registerBlock(block, identifier); -// RegistryHelper.registerItem(new BlockItem(block), identifier); -// } + Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); + Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); + Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; + + for (Block block : blocks) { + int color = 1644825; + + if (block == concBlock2) { + color = 3361970; + } + + Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); + + RegistryHelper.registerBlock(block, identifier); + RegistryHelper.registerItem(new BlockItem(block), identifier); + } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); diff --git a/legacyfabric-api/common.gradle b/legacyfabric-api/common.gradle index 1ec69e2e6..9598864ea 100644 --- a/legacyfabric-api/common.gradle +++ b/legacyfabric-api/common.gradle @@ -12,6 +12,7 @@ moduleDependencies(project, [ "legacy-fabric-registry-sync-api-v1", "legacy-fabric-registry-sync-api-v2", "legacy-fabric-item-api-v1", + "legacy-fabric-block-api-v1", "legacy-fabric-rendering-api-v1", "legacy-fabric-crash-report-info-v1", "legacy-fabric-command-api-v2" diff --git a/settings.gradle b/settings.gradle index 669e4b740..8384c772b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -39,6 +39,7 @@ loadProject("legacy-fabric-permissions-api-v1") loadProject("legacy-fabric-registry-sync-api-v1") loadProject("legacy-fabric-registry-sync-api-v2") loadProject("legacy-fabric-item-api-v1") +loadProject("legacy-fabric-block-api-v1") loadProject("legacy-fabric-rendering-api-v1") loadProject("legacy-fabric-crash-report-info-v1") loadProject("legacy-fabric-command-api-v2") From f0259fa262da4b9e55c1343cd4f524f77736f089 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 20:59:24 +0200 Subject: [PATCH 22/36] Fix whether to use neighbour light for Modded blocks --- .../1.12.2/build.gradle | 3 +++ .../block/versioned/EarlyInitializer.java | 27 +++++++++++++++++++ .../1.12.2/src/main/resources/fabric.mod.json | 1 + .../legacy-fabric-block-api-v1.accesswidener | 6 +++++ .../block/versioned/EarlyInitializer.java | 24 +++++++++++++++++ .../legacy-fabric-block-api-v1.accesswidener | 3 +++ 6 files changed, 64 insertions(+) create mode 100644 legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.accesswidener diff --git a/legacy-fabric-block-api-v1/1.12.2/build.gradle b/legacy-fabric-block-api-v1/1.12.2/build.gradle index e69de29bb..306a9d690 100644 --- a/legacy-fabric-block-api-v1/1.12.2/build.gradle +++ b/legacy-fabric-block-api-v1/1.12.2/build.gradle @@ -0,0 +1,3 @@ +loom { + accessWidenerPath = file("src/main/resources/legacy-fabric-block-api-v1.accesswidener") +} diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java index f3c5d9b09..eb2820a14 100644 --- a/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java @@ -19,18 +19,25 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.SlabBlock; +import net.minecraft.block.StairsBlock; +import net.minecraft.block.material.Material; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; import net.legacyfabric.fabric.api.registry.v2.RegistryIds; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.api.util.VersionUtils; import net.legacyfabric.fabric.mixin.block.versioned.ItemAccessor; public class EarlyInitializer implements PreLaunchEntrypoint { + private static final boolean checkGrass = VersionUtils.matches(">1.8.9"); @Override public void onPreLaunch() { RegistryInitializedEvent.event(RegistryIds.BLOCKS).register(EarlyInitializer::blockRegistryInit); @@ -48,6 +55,26 @@ private static void blockRegistryInit(Registry holder) { }); registry.fabric$getRegistryRemapCallback().register(new BlockStateRemapper()); + + registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> { + if (block.material == Material.AIR) { + block.useNeighbourLight = false; + } else { + boolean var12 = false; + boolean var13 = block instanceof StairsBlock; + boolean var14 = block instanceof SlabBlock; + boolean var15 = block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("farmland")) + || (checkGrass && block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("grass_path"))); + boolean var16 = block.transluscent; + boolean var17 = block.opacity == 0; + + if (var13 || var14 || var15 || var16 || var17) { + var12 = true; + } + + block.useNeighbourLight = var12; + } + }); } private static void itemRegistryInit(Registry holder) { diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json index 818b9ad13..b018250ea 100644 --- a/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json @@ -28,6 +28,7 @@ "mixins": [ "legacy-fabric-block-api-v1.mixins.json" ], + "accessWidener": "legacy-fabric-block-api-v1.accesswidener", "custom": { "loom:injected_interfaces": { }, diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.accesswidener b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.accesswidener new file mode 100644 index 000000000..b3e9ad4a4 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.accesswidener @@ -0,0 +1,6 @@ +accessWidener v2 named + +accessible field net/minecraft/block/Block useNeighbourLight Z +accessible field net/minecraft/block/Block transluscent Z +accessible field net/minecraft/block/Block material Lnet/minecraft/block/material/Material; +accessible field net/minecraft/block/Block opacity I diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java index dc3f4a4e0..f97bb4994 100644 --- a/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java @@ -18,13 +18,18 @@ package net.legacyfabric.fabric.impl.block.versioned; import net.minecraft.block.Block; +import net.minecraft.block.SlabBlock; +import net.minecraft.block.material.Material; +import net.minecraft.item.Item; import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; import net.legacyfabric.fabric.api.registry.v2.RegistryIds; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.util.Identifier; public class EarlyInitializer implements PreLaunchEntrypoint { @Override @@ -34,5 +39,24 @@ public void onPreLaunch() { private static void blockRegistryInit(Registry holder) { SyncedRegistry registry = (SyncedRegistry) holder; + + registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> { + if (block.getMaterial() == Material.AIR) { + block.useNeighbourLight = false; + } else { + boolean var12 = false; + boolean var13 = block.getBlockType() == 10; + boolean var14 = block instanceof SlabBlock; + boolean var15 = block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("farmland")); + boolean var16 = block.transluscent; + boolean var17 = block.getOpacity() == 0; + + if (var13 || var14 || var15 || var16 || var17) { + var12 = true; + } + + block.useNeighbourLight = var12; + } + }); } } diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener index 45ae69ced..55067474a 100644 --- a/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener @@ -1,3 +1,6 @@ accessWidener v2 named transitive-accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V + +accessible field net/minecraft/block/Block useNeighbourLight Z +accessible field net/minecraft/block/Block transluscent Z From b2266b75fc7c565d3ce87e43dfa5fcc85bc01f18 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:06:11 +0200 Subject: [PATCH 23/36] Make vanilla registries first assignable id 1 instead of 0 --- .../fabric/mixin/registry/sync/versioned/OtherIdListMixin.java | 2 +- .../legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java index d01f6ea1c..fa8fff420 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java @@ -47,7 +47,7 @@ public abstract class OtherIdListMixin implements IdsHolder { @Override public int fabric$nextId() { - int id = 0; + int id = 1; while (this.getById(id) != null) id++; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java index 77720f077..5ebaec0c2 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java @@ -49,7 +49,7 @@ public abstract class IdListMixinV2 implements IdsHolder { @Override public int fabric$nextId() { - int id = 0; + int id = 1; while (this.fromId(id) != null) id++; From f47b8e23b0d9e93400103d2f2e48b595b23721d9 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:08:04 +0200 Subject: [PATCH 24/36] Some improvements and bug fixes. --- .../sync/versioned/OtherIdListMixin.java | 5 ++++ .../v2/registry/RegistrableRegistry.java | 24 +++++++++++++++++++ ...ry.java => SyncedRegistrableRegistry.java} | 2 +- .../registry/v2/registry/holder/Registry.java | 2 +- .../v2/registry/registrable/IdsHolder.java | 2 ++ .../RegistryHelperImplementation.java | 10 ++++---- .../impl/registry/RegistryRemapper.java | 22 ++++++++--------- .../mixin/registry/sync/IdListMixinV2.java | 21 +++++++++------- .../registry/sync/MutableRegistryMixinV2.java | 4 ++-- .../registry/sync/SimpleRegistryMixinV2.java | 4 ++-- 10 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java rename legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/{SyncedRegistry.java => SyncedRegistrableRegistry.java} (83%) diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java index fa8fff420..f6faa63d7 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java @@ -68,4 +68,9 @@ public abstract class OtherIdListMixin implements IdsHolder { public int fabric$getId(T value) { return getId(value); } + + @Override + public T fabric$getValue(int rawId) { + return this.getById(rawId); + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java new file mode 100644 index 000000000..d3201800c --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry; + +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; + +public interface RegistrableRegistry extends Registry, Registrable { +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistrableRegistry.java similarity index 83% rename from legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistrableRegistry.java index b91b65820..25e5c5767 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistrableRegistry.java @@ -19,5 +19,5 @@ import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; -public interface SyncedRegistry extends net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry, SyncedRegistrable { +public interface SyncedRegistrableRegistry extends net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry, SyncedRegistrable { } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java index a81c3a986..0882fc172 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java @@ -30,7 +30,7 @@ public interface Registry extends Iterable { Event> fabric$getEntryAddedCallback(); Event> fabric$getBeforeAddedCallback(); - K fabric$toKeyType(Object o); + K fabric$toKeyType(Identifier identifier); T fabric$getValue(Identifier id); Identifier fabric$getId(T value); diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java index 6abd3ae1b..eefefc030 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java @@ -28,4 +28,6 @@ public interface IdsHolder extends Iterable { default boolean fabric$contains(T value) { return fabric$getId(value) != -1; } + + T fabric$getValue(int rawId); } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java index c1c87e670..d9aa8889d 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java @@ -35,7 +35,7 @@ import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; -import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistrableRegistry; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; @@ -88,8 +88,8 @@ public static void registerRegistry(Identifier identifier, Registry holde if (holder instanceof RegistryIdSetter) ((RegistryIdSetter) holder).fabric$setId(identifier); - if (holder instanceof SyncedRegistry) { - REMAPPERS.put(identifier, new RegistryRemapper<>((SyncedRegistry) holder)); + if (holder instanceof SyncedRegistrableRegistry) { + REMAPPERS.put(identifier, new RegistryRemapper<>((SyncedRegistrableRegistry) holder)); } REGISTRY_REGISTERED.forEach(c -> c.accept(identifier)); @@ -108,8 +108,8 @@ public static void registerRegistry(Identifier identifier, Registry holde if (event != null) event.invoker().onEntryAdded(rawId, id, object); }); - if (holder instanceof SyncedRegistry) { - ((SyncedRegistry) holder).fabric$getRegistryRemapCallback().register(changedIdsMap -> { + if (holder instanceof SyncedRegistrableRegistry) { + ((SyncedRegistrableRegistry) holder).fabric$getRegistryRemapCallback().register(changedIdsMap -> { Event> event = (Event>) (Object) RegistryEventHelper.IDENTIFIER_REMAP_MAP.get(identifier); if (event != null) event.invoker().callback(changedIdsMap); diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java index e5e03c1a5..166c5624b 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java @@ -28,7 +28,7 @@ import net.minecraft.nbt.NbtCompound; import net.legacyfabric.fabric.api.logger.v1.Logger; -import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistrableRegistry; import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; import net.legacyfabric.fabric.api.util.Identifier; @@ -36,11 +36,11 @@ public class RegistryRemapper { protected static final Logger LOGGER = Logger.get(LoggerImpl.API, "RegistryRemapper"); - private final SyncedRegistry registry; + private final SyncedRegistrableRegistry registry; private BiMap entryDump; private BiMap missingMap = HashBiMap.create(); - public RegistryRemapper(SyncedRegistry registry) { + public RegistryRemapper(SyncedRegistrableRegistry registry) { this.registry = registry; } @@ -127,10 +127,10 @@ private IntSupplier normalizeEntryList(IdsHolder ids) { if (this.missingMap.isEmpty()) { throw new IllegalStateException("Registry size increased from " + previousSize.getAsInt() + " to " + currentSize.getAsInt() + " after remapping! This is not possible!"); } - } else if (currentSize.getAsInt() < previousSize.getAsInt()) { - addNewEntries(ids, currentSize, previousSize); } + addNewEntries(ids); + if (currentSize.getAsInt() != previousSize.getAsInt() && this.missingMap.isEmpty()) { throw new IllegalStateException("An error occured during remapping"); } @@ -138,8 +138,8 @@ private IntSupplier normalizeEntryList(IdsHolder ids) { return previousSize; } - private void addNewEntries(IdsHolder newList, IntSupplier currentSize, IntSupplier previousSize) { - LOGGER.info("Adding " + (previousSize.getAsInt() - currentSize.getAsInt()) + " missing entries to registry"); + private void addNewEntries(IdsHolder newList) { + LOGGER.info("Checking for missing entries in registry"); this.registry.stream() .filter(obj -> !newList.fabric$contains(obj)) @@ -149,7 +149,7 @@ private void addNewEntries(IdsHolder newList, IntSupplier currentSize, IntSup newList.fabric$setValue(missingEntry, newId); - LOGGER.info("Adding %s %s with numerical id %d to registry", this.registry.fabric$getId(), this.registry.fabric$getId(missingEntry), newId); + LOGGER.info("Adding %s with numerical id %d to registry %s", this.registry.fabric$getId(missingEntry), newId, this.registry.fabric$getId()); }); } @@ -186,17 +186,17 @@ private static class RegistryEntryImpl implements RegistryEntry { @Override public int getId() { - return 0; + return this.id; } @Override public Identifier getIdentifier() { - return null; + return this.identifier; } @Override public T getValue() { - return null; + return this.value; } } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java index 5ebaec0c2..a7c3ac826 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java @@ -17,7 +17,7 @@ package net.legacyfabric.fabric.mixin.registry.sync; -import java.util.IdentityHashMap; +import java.util.List; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -30,17 +30,17 @@ @Mixin(IdList.class) public abstract class IdListMixinV2 implements IdsHolder { @Shadow - public abstract Object fromId(int index); + public abstract T fromId(int index); @Shadow - public abstract void set(Object value, int index); + public abstract void set(T value, int index); @Shadow - @Final - private IdentityHashMap idMap; + public abstract int getId(T value); @Shadow - public abstract int getId(T value); + @Final + private List list; @Override public IdsHolder fabric$new() { @@ -51,7 +51,7 @@ public abstract class IdListMixinV2 implements IdsHolder { public int fabric$nextId() { int id = 1; - while (this.fromId(id) != null) id++; + while (this.fabric$getValue(id) != null) id++; return id; } @@ -63,7 +63,12 @@ public abstract class IdListMixinV2 implements IdsHolder { @Override public int fabric$size() { - return idMap.size(); + return list.size(); + } + + @Override + public T fabric$getValue(int rawId) { + return this.fromId(rawId); } @Override diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixinV2.java index d904555cc..096c664b1 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixinV2.java @@ -97,8 +97,8 @@ public abstract class MutableRegistryMixinV2 implements net.legacyfabric.f } @Override - public K fabric$toKeyType(Object o) { - return RegistryHelperImplementation.hasFlatteningBegun ? (K) new net.minecraft.util.Identifier(o.toString()) : (K) o.toString(); + public K fabric$toKeyType(Identifier identifier) { + return RegistryHelperImplementation.hasFlatteningBegun ? (K) new net.minecraft.util.Identifier(identifier.toString()) : (K) identifier.toString(); } @Override diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java index c857f6477..5aab49407 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java @@ -21,8 +21,8 @@ import net.minecraft.util.registry.SimpleRegistry; -import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistrableRegistry; @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixinV2 implements SyncedRegistry { +public abstract class SimpleRegistryMixinV2 implements SyncedRegistrableRegistry { } From 2ac36afcbb3b0bb7ffaa2ec0bdb47b02a29c8f61 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:08:41 +0200 Subject: [PATCH 25/36] Create a default implementation of IdsHolder and SyncedRegistrableRegistry. --- .../fabric/impl/registry/IdsHolderImpl.java | 81 ++++++++++ .../SyncedRegistrableRegistryImpl.java | 152 ++++++++++++++++++ 2 files changed, 233 insertions(+) create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/SyncedRegistrableRegistryImpl.java diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java new file mode 100644 index 000000000..9024ef4c8 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.registry; + +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.List; + +import com.google.common.base.Predicates; +import com.google.common.collect.Iterators; +import com.google.common.collect.Lists; +import org.jetbrains.annotations.NotNull; + +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; + +public class IdsHolderImpl implements IdsHolder { + private final IdentityHashMap valueToId = new IdentityHashMap<>(512); + private final List values = Lists.newArrayList(); + + @Override + public IdsHolder fabric$new() { + return new IdsHolderImpl<>(); + } + + @Override + public int fabric$nextId() { + int id = 0; + + while (this.fabric$getValue(id) != null) id++; + + return id; + } + + @Override + public void fabric$setValue(T value, int index) { + this.valueToId.put(value, index); + + while (this.values.size() <= index) { + this.values.add(null); + } + + this.values.set(index, value); + } + + @Override + public int fabric$size() { + return values.size(); + } + + @Override + public int fabric$getId(T value) { + Integer integer = this.valueToId.get(value); + return integer == null ? -1 : integer; + } + + @Override + public T fabric$getValue(int rawId) { + return rawId >= 0 && rawId < this.values.size() ? this.values.get(rawId) : null; + } + + @NotNull + @Override + public Iterator iterator() { + return Iterators.filter(this.values.iterator(), Predicates.notNull()); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/SyncedRegistrableRegistryImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/SyncedRegistrableRegistryImpl.java new file mode 100644 index 000000000..8e3926453 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/SyncedRegistrableRegistryImpl.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.registry; + +import java.util.Iterator; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import org.apache.commons.lang3.Validate; +import org.jetbrains.annotations.NotNull; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.event.EventFactory; +import net.legacyfabric.fabric.api.logger.v1.Logger; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistrableRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; +import net.legacyfabric.fabric.api.util.Identifier; + +public class SyncedRegistrableRegistryImpl implements SyncedRegistrableRegistry { + private static final Logger LOGGER = Logger.get("LegacyFabricAPI", "SyncedRegistryImpl"); + protected final BiMap valueMap = HashBiMap.create(); + protected IdsHolder idsHolder = new IdsHolderImpl<>(); + protected final BiMap idMap = valueMap.inverse(); + + private final Event> addObjectEvent = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryEntryAddedCallback callback : callbacks) { + callback.onEntryAdded(rawId, id, object); + } + } + ); + private final Event> beforeAddObjectEvent = EventFactory.createArrayBacked(RegistryBeforeAddCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryBeforeAddCallback callback : callbacks) { + callback.onEntryAdding(rawId, id, object); + } + } + ); + private final Event> remapCallbackEvent = EventFactory.createArrayBacked(RegistryRemapCallback.class, + (callbacks) -> (changedMap) -> { + for (RegistryRemapCallback callback : callbacks) { + callback.callback(changedMap); + } + } + ); + + private final Identifier identifier; + + public SyncedRegistrableRegistryImpl(Identifier id) { + this.identifier = id; + } + + private void put(Identifier key, V value) { + Validate.notNull(key); + Validate.notNull(value); + + if (this.valueMap.containsKey(key)) { + LOGGER.debug("Adding duplicate key '" + key + "' to registry"); + } + + this.valueMap.put(key, value); + } + + @Override + public int fabric$getRawId(V value) { + return this.idsHolder.fabric$getId(value); + } + + @Override + public V fabric$getValue(int rawId) { + return this.idsHolder.fabric$getValue(rawId); + } + + @Override + public Event> fabric$getRegistryRemapCallback() { + return remapCallbackEvent; + } + + @Override + public Identifier fabric$getId() { + return this.identifier; + } + + @Override + public Event> fabric$getEntryAddedCallback() { + return addObjectEvent; + } + + @Override + public Event> fabric$getBeforeAddedCallback() { + return beforeAddObjectEvent; + } + + @Override + public Identifier fabric$toKeyType(Identifier identifier) { + return identifier; + } + + @Override + public V fabric$getValue(Identifier id) { + return valueMap.get(id); + } + + @Override + public Identifier fabric$getId(V value) { + return idMap.get(value); + } + + @NotNull + @Override + public Iterator iterator() { + return this.idsHolder.iterator(); + } + + @Override + public IdsHolder fabric$getIdsHolder() { + return this.idsHolder; + } + + @Override + public void fabric$updateRegistry(IdsHolder ids) { + this.idsHolder = ids; + } + + @Override + public void fabric$register(int rawId, Identifier identifier, V value) { + beforeAddObjectEvent.invoker().onEntryAdding(rawId, identifier, value); + + this.idsHolder.fabric$setValue(value, rawId); + this.put(identifier, value); + + addObjectEvent.invoker().onEntryAdded(rawId, identifier, value); + } +} From 5cb14928cccde4d1115f789dec9853de67fc81b5 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:09:38 +0200 Subject: [PATCH 26/36] Start working on wrapper for non-standard registry forms --- .../registry/wrapper/MapRegistryWrapper.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/MapRegistryWrapper.java diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/MapRegistryWrapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/MapRegistryWrapper.java new file mode 100644 index 000000000..39704d72a --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/MapRegistryWrapper.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.registry.wrapper; + +import java.util.Iterator; +import java.util.Map; +import java.util.function.Function; + +import org.jetbrains.annotations.NotNull; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.RegistrableRegistry; +import net.legacyfabric.fabric.api.util.Identifier; + +public class MapRegistryWrapper implements RegistrableRegistry { + private final Identifier id; + private final Map idToValue; + private final Map valueToId; + private final Function toMapKey; + private final Function fromMapKey; + + public MapRegistryWrapper(Identifier id, Map idToValue, Map valueToId, Function toMapKey, Function fromMapKey) { + this.id = id; + this.idToValue = idToValue; + this.valueToId = valueToId; + this.toMapKey = toMapKey; + this.fromMapKey = fromMapKey; + } + + @Override + public Identifier fabric$getId() { + return this.id; + } + + @Override + public Event> fabric$getEntryAddedCallback() { + return null; + } + + @Override + public Event> fabric$getBeforeAddedCallback() { + return null; + } + + @Override + public K fabric$toKeyType(Identifier identifier) { + return toMapKey.apply(identifier); + } + + @Override + public V fabric$getValue(Identifier id) { + return this.idToValue.get(this.fabric$toKeyType(id)); + } + + @Override + public Identifier fabric$getId(V value) { + K key = this.valueToId.get(value); + + if (key == null) return null; + + return fromMapKey.apply(key); + } + + @NotNull + @Override + public Iterator iterator() { + return this.idToValue.values().iterator(); + } + + @Override + public void fabric$register(int rawId, Identifier identifier, V value) { + fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); + + this.idToValue.put(this.fabric$toKeyType(identifier), value); + this.valueToId.put(value, this.fabric$toKeyType(identifier)); + + fabric$getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); + } +} From c44ee86a21e686c1438aa37ce07863677994ed67 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:15:07 +0200 Subject: [PATCH 27/36] Clean up and fix style --- .../registry/BackwardCompatibilityHelper.java | 2 +- .../registry/sync/MinecraftServerMixin.java | 31 ------------ .../sync/client/MinecraftClientMixin.java | 35 -------------- .../registry/sync/registry/BlockMixin.java | 48 ------------------- ...ic-registry-sync-api-v1-common.mixins.json | 3 -- .../api/registry/v2/RegistryHelper.java | 1 - 6 files changed, 1 insertion(+), 119 deletions(-) delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java index 7fd019ec9..57b3f5bc3 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java @@ -67,7 +67,7 @@ private static void initCallback(Identifier identifier) { entry.getValue().getId(), entry.getValue().getIdentifier(), entry.getValue().getValue() - ); + ); } }); } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java deleted file mode 100644 index c66b93cff..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Mixin; - -import net.minecraft.server.MinecraftServer; - - -@Mixin(MinecraftServer.class) -public class MinecraftServerMixin { -// @Inject(method = "", at = @At("RETURN")) -// private static void remapperInit(CallbackInfo ci) { -// ServerRegistryRemapper.getInstance(); -// } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java deleted file mode 100644 index 9aa0aed9a..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync.client; - -import org.spongepowered.asm.mixin.Mixin; - -import net.minecraft.client.MinecraftClient; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - - -@Environment(EnvType.CLIENT) -@Mixin(MinecraftClient.class) -public class MinecraftClientMixin { -// @Inject(method = "", at = @At("RETURN")) -// private static void remapperInit(CallbackInfo ci) { -// ClientRegistryRemapper.getInstance(); -// } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java deleted file mode 100644 index b7f06b894..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync.registry; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.block.Block; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.effect.StatusEffect; - -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockRegistryRemapper; - -@Mixin(Block.class) -public class BlockMixin { - @Inject(method = "setup", at = @At("RETURN")) - private static void initRegistryRemapper(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(BlockRegistryRemapper::new); - - if (!RegistryHelperImpl.bootstrap) { - try { - Class.forName(StatusEffect.class.getName()); - - Class.forName(Enchantment.class.getName()); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json index c3ad0db1e..017961d1e 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json @@ -6,9 +6,7 @@ "defaultRequire": 1 }, "mixins": [ - "MinecraftServerMixin", "IdListMixin", - "registry.BlockMixin", "registry.BlockEntityMixin", "registry.StatusEffectMixin", "registry.EnchantmentMixin", @@ -16,6 +14,5 @@ "registry.EntityTypeMixin" ], "client": [ - "client.MinecraftClientMixin" ] } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java index 37cfda2eb..f2ee7b69b 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java @@ -24,7 +24,6 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; - public class RegistryHelper { public static void register(Registry registry, Identifier identifier, T value) { RegistryHelperImplementation.register(registry, identifier, value); From a87e0f84ec6c4d15ea72f5d0ee5fb4d6be03196a Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:18:53 +0200 Subject: [PATCH 28/36] Clean up and fix style --- .../fabric/mixin/item/versioned/ItemModelsMixin.java | 1 - .../fabric/impl/item/versioned/EarlyInitializer.java | 2 -- 2 files changed, 3 deletions(-) diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java index b43463da3..e09f4b938 100644 --- a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java @@ -37,6 +37,5 @@ public class ItemModelsMixin { Identifier identifier = RegistryHelper.getId(Item.REGISTRY, item); if (identifier != null) ItemModelsRemapper.registerModelId(identifier, metadata, id); - else System.out.println(item + " " + metadata + " " + id); } } diff --git a/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java b/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java index b87b3583a..79448f1eb 100644 --- a/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java +++ b/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java @@ -33,7 +33,5 @@ public void onPreLaunch() { private static void itemRegistryInit(Registry holder) { Registry registry = (Registry) holder; - - } } From 8d574264dcda843b56ff23139b9cf9fed189e810 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:22:52 +0200 Subject: [PATCH 29/36] Clean up and fix style --- .../legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java index 924029309..836e1105d 100644 --- a/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java @@ -28,6 +28,5 @@ public interface BlockAccessor { @Accessor static void setBLOCK_STATES(IdList blockStates) { - } } From daa73b142e119dc4239d8871e7b48105b2186e33 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 23:58:33 +0200 Subject: [PATCH 30/36] New Block Entity module --- gradle.properties | 1 + .../1.10.2/build.gradle | 0 .../1.10.2/gradle.properties | 2 + .../mixin/block/entity/BlockEntityMixin.java | 76 +++++++++++++++++++ .../1.10.2/src/main/resources/fabric.mod.json | 44 +++++++++++ ...acy-fabric-block-entity-api-v1.mixins.json | 13 ++++ .../1.12.2/build.gradle | 0 .../1.12.2/gradle.properties | 2 + .../mixin/block/entity}/BlockEntityMixin.java | 18 +++-- .../1.12.2/src/main/resources/fabric.mod.json | 44 +++++++++++ ...acy-fabric-block-entity-api-v1.mixins.json | 13 ++++ .../1.8.9/build.gradle | 0 .../1.8.9/gradle.properties | 2 + .../mixin/block/entity/BlockEntityMixin.java | 76 +++++++++++++++++++ .../1.8.9/src/main/resources/fabric.mod.json | 44 +++++++++++ ...acy-fabric-block-entity-api-v1.mixins.json | 13 ++++ .../common.gradle | 8 ++ .../common/build.gradle | 0 .../common/gradle.properties | 2 + .../block/entity/v1/BlockEntityTypeIds.java | 58 ++++++++++++++ .../impl/block/entity/BlockEntityUtils.java | 55 ++++++++++++++ .../common/src/main/resources/fabric.mod.json | 43 +++++++++++ .../sync/RegistrySyncEarlyInitializer.java | 13 ++-- .../registry/sync/BlockEntityAccessor.java | 38 ---------- .../mixin/registry/sync/BlockEntityMixin.java | 48 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../sync/RegistrySyncEarlyInitializer.java | 4 +- .../registry/sync/BlockEntityAccessor.java | 33 -------- ...cy-fabric-registry-sync-api-v1.mixins.json | 1 - .../sync/RegistrySyncEarlyInitializer.java | 13 ++-- .../registry/sync/BlockEntityAccessor.java | 38 ---------- .../mixin/registry/sync/BlockEntityMixin.java | 48 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../sync/RegistrySyncEarlyInitializer.java | 13 ++-- .../registry/sync/BlockEntityAccessor.java | 38 ---------- .../mixin/registry/sync/BlockEntityMixin.java | 48 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../sync/RegistrySyncEarlyInitializer.java | 13 ++-- .../registry/sync/BlockEntityAccessor.java | 38 ---------- .../mixin/registry/sync/BlockEntityMixin.java | 48 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../sync/RegistrySyncEarlyInitializer.java | 12 +-- .../registry/sync/BlockEntityAccessor.java | 38 ---------- .../mixin/registry/sync/BlockEntityMixin.java | 48 ------------ ...cy-fabric-registry-sync-api-v1.mixins.json | 2 - .../common.gradle | 3 +- .../api/registry/v1/BlockEntityTypeIds.java | 54 ++++++------- .../impl/registry/RegistryHelperImpl.java | 7 -- ...ic-registry-sync-api-v1-common.mixins.json | 1 - .../legacyfabric/fabric/testing/TestMod.java | 45 +++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 43 +++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 42 ++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 48 ++++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 50 ++++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 50 ++++++++++++ .../legacyfabric/fabric/testing/TestMod.java | 54 +++++++++++++ legacyfabric-api/common.gradle | 1 + settings.gradle | 1 + 58 files changed, 902 insertions(+), 553 deletions(-) create mode 100644 legacy-fabric-block-entity-api-v1/1.10.2/build.gradle create mode 100644 legacy-fabric-block-entity-api-v1/1.10.2/gradle.properties create mode 100644 legacy-fabric-block-entity-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java create mode 100644 legacy-fabric-block-entity-api-v1/1.10.2/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-block-entity-api-v1/1.10.2/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json create mode 100644 legacy-fabric-block-entity-api-v1/1.12.2/build.gradle create mode 100644 legacy-fabric-block-entity-api-v1/1.12.2/gradle.properties rename {legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry => legacy-fabric-block-entity-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity}/BlockEntityMixin.java (63%) create mode 100644 legacy-fabric-block-entity-api-v1/1.12.2/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-block-entity-api-v1/1.12.2/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json create mode 100644 legacy-fabric-block-entity-api-v1/1.8.9/build.gradle create mode 100644 legacy-fabric-block-entity-api-v1/1.8.9/gradle.properties create mode 100644 legacy-fabric-block-entity-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java create mode 100644 legacy-fabric-block-entity-api-v1/1.8.9/src/main/resources/fabric.mod.json create mode 100644 legacy-fabric-block-entity-api-v1/1.8.9/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json create mode 100644 legacy-fabric-block-entity-api-v1/common.gradle create mode 100644 legacy-fabric-block-entity-api-v1/common/build.gradle create mode 100644 legacy-fabric-block-entity-api-v1/common/gradle.properties create mode 100644 legacy-fabric-block-entity-api-v1/common/src/main/java/net/legacyfabric/fabric/api/block/entity/v1/BlockEntityTypeIds.java create mode 100644 legacy-fabric-block-entity-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/entity/BlockEntityUtils.java create mode 100644 legacy-fabric-block-entity-api-v1/common/src/main/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java diff --git a/gradle.properties b/gradle.properties index 3275caaf0..ad9246777 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,5 +22,6 @@ legacy-fabric-registry-sync-api-v1.version = 2.2.0 legacy-fabric-registry-sync-api-v2.version = 1.0.0 legacy-fabric-item-api-v1.version = 1.0.0 legacy-fabric-block-api-v1.version = 1.0.0 +legacy-fabric-block-entity-api-v1.version = 1.0.0 legacy-fabric-rendering-api-v1.version = 1.0.0 legacy-fabric-resource-loader-v1.version = 2.1.1 diff --git a/legacy-fabric-block-entity-api-v1/1.10.2/build.gradle b/legacy-fabric-block-entity-api-v1/1.10.2/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-block-entity-api-v1/1.10.2/gradle.properties b/legacy-fabric-block-entity-api-v1/1.10.2/gradle.properties new file mode 100644 index 000000000..649cef215 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.10.2/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.10.2 +maxVersionIncluded=1.10.2 diff --git a/legacy-fabric-block-entity-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java b/legacy-fabric-block-entity-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java new file mode 100644 index 000000000..461f18fb2 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.block.entity; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.block.entity.BlockEntity; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.block.entity.BlockEntityUtils; +import net.legacyfabric.fabric.impl.registry.wrapper.MapRegistryWrapper; + +@Mixin(BlockEntity.class) +public class BlockEntityMixin { + @Shadow + @Final + private static Map> stringClassMap; + @Shadow + @Final + private static Map, String> classStringMap; + @Unique + private static Registry> BLOCK_ENTITY_TYPE_REGISTRY; + + @Inject(method = "", at = @At("RETURN")) + private static void registerRegistry(CallbackInfo ci) { + BLOCK_ENTITY_TYPE_REGISTRY = new MapRegistryWrapper<>( + RegistryIds.BLOCK_ENTITY_TYPES, stringClassMap, classStringMap, + identifier -> BlockEntityUtils.ID_TO_OLD.getOrDefault(identifier, identifier.toString()), + string -> BlockEntityUtils.OLD_TO_ID.getOrDefault(string, new Identifier(string)) + ); + + RegistryHelper.addRegistry(RegistryIds.BLOCK_ENTITY_TYPES, BLOCK_ENTITY_TYPE_REGISTRY); + } + + /* + Previous version of LFAPI used to transform vanilla names to id. + We don't do that anymore, so we still check for id versions to not break old saves. + */ + @ModifyArg(method = "create", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) + private static Object fixOldSaves(Object oldKey) { + Identifier asId = new Identifier(oldKey); + + if (BlockEntityUtils.ID_TO_OLD.containsKey(asId)) { + return BlockEntityUtils.ID_TO_OLD.get(asId); + } + + return oldKey; + } +} diff --git a/legacy-fabric-block-entity-api-v1/1.10.2/src/main/resources/fabric.mod.json b/legacy-fabric-block-entity-api-v1/1.10.2/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..9df4134a7 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.10.2/src/main/resources/fabric.mod.json @@ -0,0 +1,44 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-entity-api-v1", + "name": "Legacy Fabric Block Entity API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block Entity utils", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + "legacy-fabric-block-entity-api-v1.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-block-entity-api-v1/1.10.2/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json b/legacy-fabric-block-entity-api-v1/1.10.2/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json new file mode 100644 index 000000000..627ad7fa6 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.10.2/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.block.entity", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "BlockEntityMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-block-entity-api-v1/1.12.2/build.gradle b/legacy-fabric-block-entity-api-v1/1.12.2/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-block-entity-api-v1/1.12.2/gradle.properties b/legacy-fabric-block-entity-api-v1/1.12.2/gradle.properties new file mode 100644 index 000000000..ccf915102 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.12.2/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.11 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockEntityMixin.java b/legacy-fabric-block-entity-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java similarity index 63% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockEntityMixin.java rename to legacy-fabric-block-entity-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java index badf89b9a..bbd3ff464 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockEntityMixin.java +++ b/legacy-fabric-block-entity-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java @@ -15,22 +15,30 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync.registry; +package net.legacyfabric.fabric.mixin.block.entity; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.SimpleRegistry; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockEntityTypeRegistryRemapper; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; @Mixin(BlockEntity.class) public class BlockEntityMixin { + @Shadow + @Final + private static SimpleRegistry> BLOCK_ENTITY; + @Inject(method = "", at = @At("RETURN")) - private static void initRegistryRemapper(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(BlockEntityTypeRegistryRemapper::new); + private static void registerRegistry(CallbackInfo ci) { + RegistryHelper.addRegistry(RegistryIds.BLOCK_ENTITY_TYPES, BLOCK_ENTITY); } } diff --git a/legacy-fabric-block-entity-api-v1/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-block-entity-api-v1/1.12.2/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..9df4134a7 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.12.2/src/main/resources/fabric.mod.json @@ -0,0 +1,44 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-entity-api-v1", + "name": "Legacy Fabric Block Entity API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block Entity utils", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + "legacy-fabric-block-entity-api-v1.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-block-entity-api-v1/1.12.2/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json b/legacy-fabric-block-entity-api-v1/1.12.2/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json new file mode 100644 index 000000000..627ad7fa6 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.12.2/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.block.entity", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "BlockEntityMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-block-entity-api-v1/1.8.9/build.gradle b/legacy-fabric-block-entity-api-v1/1.8.9/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-block-entity-api-v1/1.8.9/gradle.properties b/legacy-fabric-block-entity-api-v1/1.8.9/gradle.properties new file mode 100644 index 000000000..c0fb44439 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.8.9/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.9.4 diff --git a/legacy-fabric-block-entity-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java b/legacy-fabric-block-entity-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java new file mode 100644 index 000000000..80a2ca0b6 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.block.entity; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.block.entity.BlockEntity; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.block.entity.BlockEntityUtils; +import net.legacyfabric.fabric.impl.registry.wrapper.MapRegistryWrapper; + +@Mixin(BlockEntity.class) +public class BlockEntityMixin { + @Shadow + @Final + private static Map> stringClassMap; + @Shadow + @Final + private static Map, String> classStringMap; + @Unique + private static Registry> BLOCK_ENTITY_TYPE_REGISTRY; + + @Inject(method = "", at = @At("RETURN")) + private static void registerRegistry(CallbackInfo ci) { + BLOCK_ENTITY_TYPE_REGISTRY = new MapRegistryWrapper<>( + RegistryIds.BLOCK_ENTITY_TYPES, stringClassMap, classStringMap, + identifier -> BlockEntityUtils.ID_TO_OLD.getOrDefault(identifier, identifier.toString()), + string -> BlockEntityUtils.OLD_TO_ID.getOrDefault(string, new Identifier(string)) + ); + + RegistryHelper.addRegistry(RegistryIds.BLOCK_ENTITY_TYPES, BLOCK_ENTITY_TYPE_REGISTRY); + } + + /* + Previous version of LFAPI used to transform vanilla names to id. + We don't do that anymore, so we still check for id versions to not break old saves. + */ + @ModifyArg(method = "createFromNbt", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) + private static Object fixOldSaves(Object oldKey) { + Identifier asId = new Identifier(oldKey); + + if (BlockEntityUtils.ID_TO_OLD.containsKey(asId)) { + return BlockEntityUtils.ID_TO_OLD.get(asId); + } + + return oldKey; + } +} diff --git a/legacy-fabric-block-entity-api-v1/1.8.9/src/main/resources/fabric.mod.json b/legacy-fabric-block-entity-api-v1/1.8.9/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..9df4134a7 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.8.9/src/main/resources/fabric.mod.json @@ -0,0 +1,44 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-entity-api-v1", + "name": "Legacy Fabric Block Entity API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block Entity utils", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + "legacy-fabric-block-entity-api-v1.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-block-entity-api-v1/1.8.9/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json b/legacy-fabric-block-entity-api-v1/1.8.9/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json new file mode 100644 index 000000000..627ad7fa6 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/1.8.9/src/main/resources/legacy-fabric-block-entity-api-v1.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.block.entity", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "BlockEntityMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-block-entity-api-v1/common.gradle b/legacy-fabric-block-entity-api-v1/common.gradle new file mode 100644 index 000000000..13fb589b0 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/common.gradle @@ -0,0 +1,8 @@ +moduleDependencies(project, [ + "legacy-fabric-api-base", + "legacy-fabric-networking-api-v1", + "legacy-fabric-resource-loader-v1", + "legacy-fabric-registry-sync-api-v2", + "legacy-fabric-item-api-v1", + "legacy-fabric-block-api-v1" +]) diff --git a/legacy-fabric-block-entity-api-v1/common/build.gradle b/legacy-fabric-block-entity-api-v1/common/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-block-entity-api-v1/common/gradle.properties b/legacy-fabric-block-entity-api-v1/common/gradle.properties new file mode 100644 index 000000000..a499ab733 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/common/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-block-entity-api-v1/common/src/main/java/net/legacyfabric/fabric/api/block/entity/v1/BlockEntityTypeIds.java b/legacy-fabric-block-entity-api-v1/common/src/main/java/net/legacyfabric/fabric/api/block/entity/v1/BlockEntityTypeIds.java new file mode 100644 index 000000000..33718fb55 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/common/src/main/java/net/legacyfabric/fabric/api/block/entity/v1/BlockEntityTypeIds.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.block.entity.v1; + +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.api.util.SinceMC; + +public class BlockEntityTypeIds { + public static final Identifier FURNACE = id("furnace"); + public static final Identifier CHEST = id("chest"); + public static final Identifier ENDER_CHEST = id("ender_chest"); + public static final Identifier JUKEBOX = id("jukebox"); + public static final Identifier DISPENSER = id("dispenser"); + public static final Identifier DROPPER = id("dropper"); + public static final Identifier SIGN = id("sign"); + public static final Identifier MOB_SPAWNER = id("mob_spawner"); + public static final Identifier NOTEBLOCK = id("noteblock"); + public static final Identifier PISTON = id("piston"); + public static final Identifier BREWING_STAND = id("brewing_stand"); + public static final Identifier ENCHANTING_TABLE = id("enchanting_table"); + public static final Identifier END_PORTAL = id("end_portal"); + public static final Identifier BEACON = id("beacon"); + public static final Identifier SKULL = id("skull"); + public static final Identifier DAYLIGHT_DETECTOR = id("daylight_detector"); + public static final Identifier HOPPER = id("hopper"); + public static final Identifier COMPARATOR = id("comparator"); + public static final Identifier FLOWER_POT = id("flower_pot"); + @SinceMC("1.8") + public static final Identifier BANNER = id("banner"); + @SinceMC("1.9.4") + public static final Identifier STRUCTURE_BLOCK = id("structure_block"); + @SinceMC("1.9.4") + public static final Identifier END_GATEWAY = id("end_gateway"); + public static final Identifier COMMAND_BLOCK = id("command_block"); + @SinceMC("1.11.2") + public static final Identifier SHULKER_BOX = id("shulker_box"); + @SinceMC("1.12.2") + public static final Identifier BED = id("bed"); + + private static Identifier id(String path) { + return new Identifier(path); + } +} diff --git a/legacy-fabric-block-entity-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/entity/BlockEntityUtils.java b/legacy-fabric-block-entity-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/entity/BlockEntityUtils.java new file mode 100644 index 000000000..6944aac48 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/entity/BlockEntityUtils.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.block.entity; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +import net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds; +import net.legacyfabric.fabric.api.util.Identifier; + +public class BlockEntityUtils { + public static final BiMap OLD_TO_ID = HashBiMap.create(); + public static final BiMap ID_TO_OLD = OLD_TO_ID.inverse(); + + static { + OLD_TO_ID.put("Furnace", BlockEntityTypeIds.FURNACE); + OLD_TO_ID.put("Chest", BlockEntityTypeIds.CHEST); + OLD_TO_ID.put("EnderChest", BlockEntityTypeIds.ENDER_CHEST); + OLD_TO_ID.put("RecordPlayer", BlockEntityTypeIds.JUKEBOX); + OLD_TO_ID.put("Trap", BlockEntityTypeIds.DISPENSER); + OLD_TO_ID.put("Dropper", BlockEntityTypeIds.DROPPER); + OLD_TO_ID.put("Sign", BlockEntityTypeIds.SIGN); + OLD_TO_ID.put("MobSpawner", BlockEntityTypeIds.MOB_SPAWNER); + OLD_TO_ID.put("Music", BlockEntityTypeIds.NOTEBLOCK); + OLD_TO_ID.put("Piston", BlockEntityTypeIds.PISTON); + OLD_TO_ID.put("Cauldron", BlockEntityTypeIds.BREWING_STAND); + OLD_TO_ID.put("EnchantTable", BlockEntityTypeIds.ENCHANTING_TABLE); + OLD_TO_ID.put("Airportal", BlockEntityTypeIds.END_PORTAL); + OLD_TO_ID.put("Control", BlockEntityTypeIds.COMMAND_BLOCK); + OLD_TO_ID.put("Beacon", BlockEntityTypeIds.BEACON); + OLD_TO_ID.put("Skull", BlockEntityTypeIds.SKULL); + OLD_TO_ID.put("DLDetector", BlockEntityTypeIds.DAYLIGHT_DETECTOR); + OLD_TO_ID.put("Hopper", BlockEntityTypeIds.HOPPER); + OLD_TO_ID.put("Comparator", BlockEntityTypeIds.COMPARATOR); + OLD_TO_ID.put("FlowerPot", BlockEntityTypeIds.FLOWER_POT); + OLD_TO_ID.put("Banner", BlockEntityTypeIds.BANNER); + OLD_TO_ID.put("Structure", BlockEntityTypeIds.STRUCTURE_BLOCK); + OLD_TO_ID.put("EndGateway", BlockEntityTypeIds.END_GATEWAY); + } +} diff --git a/legacy-fabric-block-entity-api-v1/common/src/main/resources/fabric.mod.json b/legacy-fabric-block-entity-api-v1/common/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..f7f623bc5 --- /dev/null +++ b/legacy-fabric-block-entity-api-v1/common/src/main/resources/fabric.mod.json @@ -0,0 +1,43 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-entity-api-v1-common", + "name": "Legacy Fabric Block Entity API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block Entity utils", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java index 6e5e698e2..34f301196 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java @@ -38,13 +38,11 @@ import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; import net.legacyfabric.fabric.api.registry.v1.RegistryIds; import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.registries.OldBlockEntityRegistry; import net.legacyfabric.fabric.impl.registry.registries.OldEntityTypeRegistry; import net.legacyfabric.fabric.impl.registry.sync.compat.RegistriesGetter; import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; import net.legacyfabric.fabric.mixin.registry.sync.BiomeAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.BlockEntityAccessor; import net.legacyfabric.fabric.mixin.registry.sync.EntityTypeAccessor; import net.legacyfabric.fabric.mixin.registry.sync.SpawnEggDataAccessor; @@ -67,11 +65,12 @@ public SimpleRegistryCompat getItemRegistry() { @Override public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } - - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; +// if (BLOCK_ENTITY_REGISTRY == null) { +// BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); +// } +// +// return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; + return null; } @Override diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java deleted file mode 100644 index 7d37e7f9e..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import java.util.Map; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.block.entity.BlockEntity; - -@Mixin(BlockEntity.class) -public interface BlockEntityAccessor { - @Accessor - static Map getStringClassMap() { - return null; - } - - @Accessor - static Map getClassStringMap() { - return null; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java deleted file mode 100644 index 68c5e8fbb..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -import net.minecraft.block.entity.BlockEntity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockEntityTypeRegistryRemapper; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.MapBasedRegistry; - -@Mixin(BlockEntity.class) -public class BlockEntityMixin { - @ModifyArg(method = "create", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private static Object replaceVanillaId(Object oldKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getNewKey(oldKey.toString()); - } - - @ModifyArg(method = "method_11648", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 5493ef74a..577058066 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -10,8 +10,6 @@ "class_2929Mixin", "PacketByteBufMixin", "MutableRegistryMixin", - "BlockEntityAccessor", - "BlockEntityMixin", "BiomeAccessor", "EntityTypeAccessor", "EntityTypeMixin", diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java index 45221b48a..d15994975 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java @@ -37,7 +37,6 @@ import net.legacyfabric.fabric.impl.registry.sync.compat.RegistriesGetter; import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.mixin.registry.sync.BiomeAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.BlockEntityAccessor; import net.legacyfabric.fabric.mixin.registry.sync.EntityTypeAccessor; public class RegistrySyncEarlyInitializer implements PreLaunchEntrypoint { @@ -56,7 +55,8 @@ public SimpleRegistryCompat getItemRegistry() { @Override public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - return (SimpleRegistryCompat>) BlockEntityAccessor.getBLOCK_ENTITY(); +// return (SimpleRegistryCompat>) BlockEntityAccessor.getBLOCK_ENTITY(); + return null; } @Override diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java deleted file mode 100644 index 53c6422bf..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.SimpleRegistry; - -@Mixin(BlockEntity.class) -public interface BlockEntityAccessor { - @Accessor - static SimpleRegistry> getBLOCK_ENTITY() { - return null; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index aeb78a447..f0d42d8e6 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -10,7 +10,6 @@ "class_2929Mixin", "PacketByteBufMixin", "MutableRegistryMixin", - "BlockEntityAccessor", "BiomeAccessor", "EntityTypeAccessor" ], diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java index 376d9e10d..134f2e883 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java @@ -38,7 +38,6 @@ import net.legacyfabric.fabric.api.registry.v1.RegistryIds; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.registries.OldBlockEntityRegistry; import net.legacyfabric.fabric.impl.registry.registries.OldEntityTypeRegistry; import net.legacyfabric.fabric.impl.registry.registries.ReallyOldBiomeRegistry; import net.legacyfabric.fabric.impl.registry.registries.ReallyOldEnchantmentRegistry; @@ -47,7 +46,6 @@ import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; import net.legacyfabric.fabric.mixin.registry.sync.BiomeAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.BlockEntityAccessor; import net.legacyfabric.fabric.mixin.registry.sync.EnchantmentAccessor; import net.legacyfabric.fabric.mixin.registry.sync.EntityTypeAccessor; import net.legacyfabric.fabric.mixin.registry.sync.StatusEffectAccessor; @@ -74,11 +72,12 @@ public SimpleRegistryCompat getItemRegistry() { @Override public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } - - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; +// if (BLOCK_ENTITY_REGISTRY == null) { +// BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); +// } +// +// return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; + return null; } @Override diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java deleted file mode 100644 index 7d37e7f9e..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import java.util.Map; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.block.entity.BlockEntity; - -@Mixin(BlockEntity.class) -public interface BlockEntityAccessor { - @Accessor - static Map getStringClassMap() { - return null; - } - - @Accessor - static Map getClassStringMap() { - return null; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java deleted file mode 100644 index 99d7a4f3e..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -import net.minecraft.block.entity.BlockEntity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockEntityTypeRegistryRemapper; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.MapBasedRegistry; - -@Mixin(BlockEntity.class) -public class BlockEntityMixin { - @ModifyArg(method = "createFromNbt", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private static Object replaceVanillaId(Object oldKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getNewKey(oldKey.toString()); - } - - @ModifyArg(method = "toNbt", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 2b3435c36..1bc673749 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,8 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "PacketByteBufMixin", - "BlockEntityAccessor", - "BlockEntityMixin", "StatusEffectAccessor", "EnchantmentAccessor", "BiomeAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java index 1bb4e0e56..dafa4b6d6 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java @@ -39,7 +39,6 @@ import net.legacyfabric.fabric.api.registry.v1.RegistryIds; import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; import net.legacyfabric.fabric.impl.registry.registries.OldBiomeRegistry; -import net.legacyfabric.fabric.impl.registry.registries.OldBlockEntityRegistry; import net.legacyfabric.fabric.impl.registry.registries.OldEnchantmentRegistry; import net.legacyfabric.fabric.impl.registry.registries.OldEntityTypeRegistry; import net.legacyfabric.fabric.impl.registry.registries.OldStatusEffectRegistry; @@ -47,7 +46,6 @@ import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; import net.legacyfabric.fabric.mixin.registry.sync.BiomeAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.BlockEntityAccessor; import net.legacyfabric.fabric.mixin.registry.sync.EnchantmentAccessor; import net.legacyfabric.fabric.mixin.registry.sync.EntityTypeAccessor; import net.legacyfabric.fabric.mixin.registry.sync.StatusEffectAccessor; @@ -74,11 +72,12 @@ public SimpleRegistryCompat getItemRegistry() { @Override public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } - - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; +// if (BLOCK_ENTITY_REGISTRY == null) { +// BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); +// } +// +// return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; + return null; } @Override diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java deleted file mode 100644 index 7d37e7f9e..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import java.util.Map; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.block.entity.BlockEntity; - -@Mixin(BlockEntity.class) -public interface BlockEntityAccessor { - @Accessor - static Map getStringClassMap() { - return null; - } - - @Accessor - static Map getClassStringMap() { - return null; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java deleted file mode 100644 index 99d7a4f3e..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -import net.minecraft.block.entity.BlockEntity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockEntityTypeRegistryRemapper; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.MapBasedRegistry; - -@Mixin(BlockEntity.class) -public class BlockEntityMixin { - @ModifyArg(method = "createFromNbt", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private static Object replaceVanillaId(Object oldKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getNewKey(oldKey.toString()); - } - - @ModifyArg(method = "toNbt", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 1a5914904..30f3b5602 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -9,8 +9,6 @@ "SimpleRegistryMixin", "PacketByteBufMixin", "MutableRegistryMixin", - "BlockEntityAccessor", - "BlockEntityMixin", "StatusEffectAccessor", "EnchantmentAccessor", "BiomeAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java index 1bb4e0e56..dafa4b6d6 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java @@ -39,7 +39,6 @@ import net.legacyfabric.fabric.api.registry.v1.RegistryIds; import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; import net.legacyfabric.fabric.impl.registry.registries.OldBiomeRegistry; -import net.legacyfabric.fabric.impl.registry.registries.OldBlockEntityRegistry; import net.legacyfabric.fabric.impl.registry.registries.OldEnchantmentRegistry; import net.legacyfabric.fabric.impl.registry.registries.OldEntityTypeRegistry; import net.legacyfabric.fabric.impl.registry.registries.OldStatusEffectRegistry; @@ -47,7 +46,6 @@ import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; import net.legacyfabric.fabric.mixin.registry.sync.BiomeAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.BlockEntityAccessor; import net.legacyfabric.fabric.mixin.registry.sync.EnchantmentAccessor; import net.legacyfabric.fabric.mixin.registry.sync.EntityTypeAccessor; import net.legacyfabric.fabric.mixin.registry.sync.StatusEffectAccessor; @@ -74,11 +72,12 @@ public SimpleRegistryCompat getItemRegistry() { @Override public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } - - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; +// if (BLOCK_ENTITY_REGISTRY == null) { +// BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); +// } +// +// return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; + return null; } @Override diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java deleted file mode 100644 index 7d37e7f9e..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import java.util.Map; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.block.entity.BlockEntity; - -@Mixin(BlockEntity.class) -public interface BlockEntityAccessor { - @Accessor - static Map getStringClassMap() { - return null; - } - - @Accessor - static Map getClassStringMap() { - return null; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java deleted file mode 100644 index 99d7a4f3e..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -import net.minecraft.block.entity.BlockEntity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockEntityTypeRegistryRemapper; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.MapBasedRegistry; - -@Mixin(BlockEntity.class) -public class BlockEntityMixin { - @ModifyArg(method = "createFromNbt", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private static Object replaceVanillaId(Object oldKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getNewKey(oldKey.toString()); - } - - @ModifyArg(method = "toNbt", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 1a5914904..30f3b5602 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -9,8 +9,6 @@ "SimpleRegistryMixin", "PacketByteBufMixin", "MutableRegistryMixin", - "BlockEntityAccessor", - "BlockEntityMixin", "StatusEffectAccessor", "EnchantmentAccessor", "BiomeAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java index 6e5e698e2..81f3f7e66 100644 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java @@ -38,13 +38,11 @@ import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; import net.legacyfabric.fabric.api.registry.v1.RegistryIds; import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.registries.OldBlockEntityRegistry; import net.legacyfabric.fabric.impl.registry.registries.OldEntityTypeRegistry; import net.legacyfabric.fabric.impl.registry.sync.compat.RegistriesGetter; import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; import net.legacyfabric.fabric.mixin.registry.sync.BiomeAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.BlockEntityAccessor; import net.legacyfabric.fabric.mixin.registry.sync.EntityTypeAccessor; import net.legacyfabric.fabric.mixin.registry.sync.SpawnEggDataAccessor; @@ -67,11 +65,13 @@ public SimpleRegistryCompat getItemRegistry() { @Override public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } +// if (BLOCK_ENTITY_REGISTRY == null) { +// BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); +// } +// +// return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; + return null; } @Override diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java deleted file mode 100644 index 7d37e7f9e..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import java.util.Map; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.block.entity.BlockEntity; - -@Mixin(BlockEntity.class) -public interface BlockEntityAccessor { - @Accessor - static Map getStringClassMap() { - return null; - } - - @Accessor - static Map getClassStringMap() { - return null; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java deleted file mode 100644 index 0e68f2ee3..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -import net.minecraft.block.entity.BlockEntity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockEntityTypeRegistryRemapper; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.MapBasedRegistry; - -@Mixin(BlockEntity.class) -public class BlockEntityMixin { - @ModifyArg(method = "createFromNbt", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private static Object replaceVanillaId(Object oldKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getNewKey(oldKey.toString()); - } - - @ModifyArg(method = "method_11648", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - BlockEntityTypeRegistryRemapper registryRemapper = (BlockEntityTypeRegistryRemapper) RegistryRemapper.>getRegistryRemapper(RegistryIds.BLOCK_ENTITY_TYPES); - MapBasedRegistry> registry = (MapBasedRegistry>) registryRemapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 5493ef74a..577058066 100644 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -10,8 +10,6 @@ "class_2929Mixin", "PacketByteBufMixin", "MutableRegistryMixin", - "BlockEntityAccessor", - "BlockEntityMixin", "BiomeAccessor", "EntityTypeAccessor", "EntityTypeMixin", diff --git a/legacy-fabric-registry-sync-api-v1/common.gradle b/legacy-fabric-registry-sync-api-v1/common.gradle index 561f4dfa6..8b8c20daa 100644 --- a/legacy-fabric-registry-sync-api-v1/common.gradle +++ b/legacy-fabric-registry-sync-api-v1/common.gradle @@ -3,5 +3,6 @@ moduleDependencies(project, [ "legacy-fabric-networking-api-v1", "legacy-fabric-resource-loader-v1", "legacy-fabric-registry-sync-api-v2", - "legacy-fabric-item-api-v2" + "legacy-fabric-item-api-v2", + "legacy-fabric-block-entity-api-v1" ]) diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BlockEntityTypeIds.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BlockEntityTypeIds.java index 594cd5a4d..f267f81c0 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BlockEntityTypeIds.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BlockEntityTypeIds.java @@ -21,38 +21,34 @@ import net.legacyfabric.fabric.api.util.SinceMC; public class BlockEntityTypeIds { - public static final Identifier FURNACE = id("furnace"); - public static final Identifier CHEST = id("chest"); - public static final Identifier ENDER_CHEST = id("ender_chest"); - public static final Identifier JUKEBOX = id("jukebox"); - public static final Identifier DISPENSER = id("dispenser"); - public static final Identifier DROPPER = id("dropper"); - public static final Identifier SIGN = id("sign"); - public static final Identifier MOB_SPAWNER = id("mob_spawner"); - public static final Identifier NOTEBLOCK = id("noteblock"); - public static final Identifier PISTON = id("piston"); - public static final Identifier BREWING_STAND = id("brewing_stand"); - public static final Identifier ENCHANTING_TABLE = id("enchanting_table"); - public static final Identifier END_PORTAL = id("end_portal"); - public static final Identifier BEACON = id("beacon"); - public static final Identifier SKULL = id("skull"); - public static final Identifier DAYLIGHT_DETECTOR = id("daylight_detector"); - public static final Identifier HOPPER = id("hopper"); - public static final Identifier COMPARATOR = id("comparator"); - public static final Identifier FLOWER_POT = id("flower_pot"); + public static final Identifier FURNACE = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.FURNACE; + public static final Identifier CHEST = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.CHEST; + public static final Identifier ENDER_CHEST = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.ENDER_CHEST; + public static final Identifier JUKEBOX = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.JUKEBOX; + public static final Identifier DISPENSER = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.DISPENSER; + public static final Identifier DROPPER = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.DROPPER; + public static final Identifier SIGN = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.SIGN; + public static final Identifier MOB_SPAWNER = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.MOB_SPAWNER; + public static final Identifier NOTEBLOCK = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.NOTEBLOCK; + public static final Identifier PISTON = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.PISTON; + public static final Identifier BREWING_STAND = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.BREWING_STAND; + public static final Identifier ENCHANTING_TABLE = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.ENCHANTING_TABLE; + public static final Identifier END_PORTAL = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.END_PORTAL; + public static final Identifier BEACON = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.BEACON; + public static final Identifier SKULL = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.SKULL; + public static final Identifier DAYLIGHT_DETECTOR = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.DAYLIGHT_DETECTOR; + public static final Identifier HOPPER = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.HOPPER; + public static final Identifier COMPARATOR = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.COMPARATOR; + public static final Identifier FLOWER_POT = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.FLOWER_POT; @SinceMC("1.8") - public static final Identifier BANNER = id("banner"); + public static final Identifier BANNER = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.BANNER; @SinceMC("1.9.4") - public static final Identifier STRUCTURE_BLOCK = id("structure_block"); + public static final Identifier STRUCTURE_BLOCK = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.STRUCTURE_BLOCK; @SinceMC("1.9.4") - public static final Identifier END_GATEWAY = id("end_gateway"); - public static final Identifier COMMAND_BLOCK = id("command_block"); + public static final Identifier END_GATEWAY = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.END_GATEWAY; + public static final Identifier COMMAND_BLOCK = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.COMMAND_BLOCK; @SinceMC("1.11.2") - public static final Identifier SHULKER_BOX = id("shulker_box"); + public static final Identifier SHULKER_BOX = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.SHULKER_BOX; @SinceMC("1.12.2") - public static final Identifier BED = id("bed"); - - private static Identifier id(String path) { - return new Identifier(path); - } + public static final Identifier BED = net.legacyfabric.fabric.api.block.entity.v1.BlockEntityTypeIds.BED; } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java index ddc5417e3..529ec9a69 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java @@ -25,7 +25,6 @@ import com.google.common.collect.HashBiMap; import org.jetbrains.annotations.ApiStatus; -import net.minecraft.block.entity.BlockEntity; import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.StatusEffect; @@ -81,12 +80,6 @@ public static T register(RegistryHelper.EntryCreator entryCreator, Identi return instance; } - public static Class registerBlockEntityType(Class blockEntityClass, Identifier id) { - register(blockEntityClass, id, RegistryIds.BLOCK_ENTITY_TYPES); - - return blockEntityClass; - } - public static Class registerEntityType(Class entityTypeClass, Identifier id) { register(entityTypeClass, id, RegistryIds.ENTITY_TYPES); diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json index 017961d1e..01e3f8ad1 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json @@ -7,7 +7,6 @@ }, "mixins": [ "IdListMixin", - "registry.BlockEntityMixin", "registry.StatusEffectMixin", "registry.EnchantmentMixin", "registry.BiomeMixin", diff --git a/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 0b2e631a3..6d4c2304d 100644 --- a/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -20,12 +20,24 @@ import java.util.concurrent.ThreadLocalRandom; +import org.jetbrains.annotations.Nullable; + import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.material.Material; import net.minecraft.block.material.MaterialColor; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.item.itemgroup.ItemGroup; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; import net.fabricmc.api.ModInitializer; @@ -34,6 +46,7 @@ import net.legacyfabric.fabric.api.util.Identifier; public class TestMod implements ModInitializer { + static Identifier blockEntityTestId = new Identifier("legacy-fabric-api:test_block_entity"); @Override public void onInitialize() { registerItem(); @@ -60,5 +73,37 @@ private void registerItem() { Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); + + Block blockWithEntity = new TestBlockWithEntity(Material.DIRT).setItemGroup(ItemGroup.FOOD); + RegistryHelper.registerBlock(blockWithEntity, blockEntityTestId); + RegistryHelper.registerItem(new BlockItem(blockWithEntity), blockEntityTestId); + RegistryHelper.registerBlockEntityType(TestBlockEntity.class, blockEntityTestId); + } + + public static class TestBlockWithEntity extends BlockWithEntity { + protected TestBlockWithEntity(Material material) { + super(material); + } + + @Override + public BlockEntity createBlockEntity(World world, int id) { + return new TestBlockEntity(); + } + + @Override + public boolean method_421(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity, Hand hand, @Nullable ItemStack itemStack, Direction direction, float f, float g, float h) { + if (!world.isClient) { + BlockEntity entity = world.getBlockEntity(blockPos); + + if (entity instanceof TestBlockEntity) { + playerEntity.sendMessage(new LiteralText(entity + " at " + blockPos.toString())); + } + } + + return true; + } + } + + public static class TestBlockEntity extends BlockEntity { } } diff --git a/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index e337ff849..78389f41f 100644 --- a/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -21,11 +21,20 @@ import java.util.concurrent.ThreadLocalRandom; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.material.Material; import net.minecraft.block.material.MaterialColor; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; import net.fabricmc.api.ModInitializer; @@ -33,7 +42,9 @@ import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; + public class TestMod implements ModInitializer { + static Identifier blockEntityTestId = new Identifier("legacy-fabric-api:test_block_entity"); @Override public void onInitialize() { registerItem(); @@ -63,5 +74,37 @@ private void registerItem() { new Identifier("legacy-fabric-api", "test_item"), testItem ); ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); + + Block blockWithEntity = new TestBlockWithEntity(Material.DIRT).setItemGroup(ItemGroup.FOOD); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(blockWithEntity, blockEntityTestId); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(blockWithEntity), blockEntityTestId); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlockEntityType(TestBlockEntity.class, blockEntityTestId); + } + + public static class TestBlockWithEntity extends BlockWithEntity { + protected TestBlockWithEntity(Material material) { + super(material); + } + + @Override + public BlockEntity createBlockEntity(World world, int id) { + return new TestBlockEntity(); + } + + @Override + public boolean use(World world, BlockPos pos, BlockState state, PlayerEntity player, Hand hand, Direction direction, float f, float g, float h) { + if (!world.isClient) { + BlockEntity entity = world.getBlockEntity(pos); + + if (entity instanceof TestBlockEntity) { + player.sendMessage(new LiteralText(entity + " at " + pos.toString())); + } + } + + return true; + } + } + + public static class TestBlockEntity extends BlockEntity { } } diff --git a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index e337ff849..d37ede9e1 100644 --- a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -21,11 +21,20 @@ import java.util.concurrent.ThreadLocalRandom; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.material.Material; import net.minecraft.block.material.MaterialColor; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; import net.fabricmc.api.ModInitializer; @@ -34,6 +43,7 @@ import net.legacyfabric.fabric.api.util.Identifier; public class TestMod implements ModInitializer { + static Identifier blockEntityTestId = new Identifier("legacy-fabric-api:test_block_entity"); @Override public void onInitialize() { registerItem(); @@ -63,5 +73,37 @@ private void registerItem() { new Identifier("legacy-fabric-api", "test_item"), testItem ); ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); + + Block blockWithEntity = new TestBlockWithEntity(Material.DIRT).setItemGroup(ItemGroup.FOOD); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(blockWithEntity, blockEntityTestId); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(blockWithEntity), blockEntityTestId); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlockEntityType(TestBlockEntity.class, blockEntityTestId); + } + + public static class TestBlockWithEntity extends BlockWithEntity { + protected TestBlockWithEntity(Material material) { + super(material); + } + + @Override + public BlockEntity createBlockEntity(World world, int id) { + return new TestBlockEntity(); + } + + @Override + public boolean use(World world, BlockPos pos, BlockState state, PlayerEntity player, Hand hand, Direction direction, float f, float g, float h) { + if (!world.isClient) { + BlockEntity entity = world.getBlockEntity(pos); + + if (entity instanceof TestBlockEntity) { + player.sendMessage(new LiteralText(entity + " at " + pos.toString())); + } + } + + return true; + } + } + + public static class TestBlockEntity extends BlockEntity { } } diff --git a/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 0c8506f82..7b1ebd7bb 100644 --- a/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -21,17 +21,27 @@ import java.util.concurrent.ThreadLocalRandom; import net.minecraft.block.Block; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.material.Material; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; +import net.minecraft.text.LiteralText; +import net.minecraft.world.World; import net.fabricmc.api.ModInitializer; import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.util.Identifier; public class TestMod implements ModInitializer { + static Identifier blockEntityTestId = new Identifier("legacy-fabric-api:test_block_entity"); + @Override public void onInitialize() { registerItem(); @@ -50,5 +60,43 @@ private void registerItem() { Item testItem = new Item().setItemGroup(ItemGroup.FOOD).getFromId("legacy-fabric-api:test_item"); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); + + Block blockWithEntity = new TestBlockWithEntity(Material.DIRT).setItemGroup(ItemGroup.FOOD); + RegistryHelper.registerBlock(blockWithEntity, blockEntityTestId); + RegistryHelper.registerItem(new BlockItem(blockWithEntity), blockEntityTestId); + + RegistryInitializedEvent.event(RegistryIds.BLOCK_ENTITY_TYPES).register(this::registerBlockEntity); + } + + public void registerBlockEntity(Registry registry) { + System.err.println("Registering block entity"); + RegistryHelper.registerBlockEntityType(TestBlockEntity.class, blockEntityTestId); + } + + public static class TestBlockWithEntity extends BlockWithEntity { + protected TestBlockWithEntity(Material material) { + super(material); + } + + @Override + public BlockEntity createBlockEntity(World world, int id) { + return new TestBlockEntity(); + } + + @Override + public boolean onActivated(World world, int x, int y, int z, PlayerEntity player, int i, float f, float g, float h) { + if (!world.isClient) { + BlockEntity entity = world.getBlockEntity(x, y, z); + + if (entity instanceof TestBlockEntity) { + player.sendMessage(new LiteralText(entity + " at " + x + "," + y + "," + z)); + } + } + + return true; + } + } + + public static class TestBlockEntity extends BlockEntity { } } diff --git a/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index d338c86fe..7f905ea5b 100644 --- a/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -21,19 +21,31 @@ import java.util.concurrent.ThreadLocalRandom; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.material.Material; import net.minecraft.block.material.MaterialColor; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; +import net.minecraft.text.LiteralText; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; import net.fabricmc.api.ModInitializer; import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; public class TestMod implements ModInitializer { + static Identifier blockEntityTestId = new Identifier("legacy-fabric-api:test_block_entity"); @Override public void onInitialize() { registerItem(); @@ -53,5 +65,43 @@ private void registerItem() { Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); + + Block blockWithEntity = new TestBlockWithEntity(Material.DIRT).setItemGroup(ItemGroup.FOOD); + RegistryHelper.registerBlock(blockWithEntity, blockEntityTestId); + RegistryHelper.registerItem(new BlockItem(blockWithEntity), blockEntityTestId); + + RegistryInitializedEvent.event(RegistryIds.BLOCK_ENTITY_TYPES).register(this::registerBlockEntity); + } + + public void registerBlockEntity(Registry registry) { + System.err.println("Registering block entity"); + RegistryHelper.registerBlockEntityType(TestBlockEntity.class, blockEntityTestId); + } + + public static class TestBlockWithEntity extends BlockWithEntity { + protected TestBlockWithEntity(Material material) { + super(material); + } + + @Override + public BlockEntity createBlockEntity(World world, int id) { + return new TestBlockEntity(); + } + + @Override + public boolean onUse(World world, BlockPos pos, BlockState state, PlayerEntity player, Direction direction, float posX, float posY, float posZ) { + if (!world.isClient) { + BlockEntity entity = world.getBlockEntity(pos); + + if (entity instanceof TestBlockEntity) { + player.sendMessage(new LiteralText(entity + " at " + pos.toString())); + } + } + + return true; + } + } + + public static class TestBlockEntity extends BlockEntity { } } diff --git a/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 1b356eef7..869d24436 100644 --- a/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -21,18 +21,30 @@ import java.util.concurrent.ThreadLocalRandom; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.material.Material; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; +import net.minecraft.text.LiteralText; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; import net.fabricmc.api.ModInitializer; import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; public class TestMod implements ModInitializer { + static Identifier blockEntityTestId = new Identifier("legacy-fabric-api:test_block_entity"); @Override public void onInitialize() { registerItem(); @@ -52,5 +64,43 @@ private void registerItem() { Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); + + Block blockWithEntity = new TestBlockWithEntity(Material.DIRT).setItemGroup(ItemGroup.FOOD); + RegistryHelper.registerBlock(blockWithEntity, blockEntityTestId); + RegistryHelper.registerItem(new BlockItem(blockWithEntity), blockEntityTestId); + + RegistryInitializedEvent.event(RegistryIds.BLOCK_ENTITY_TYPES).register(this::registerBlockEntity); + } + + public void registerBlockEntity(Registry registry) { + System.err.println("Registering block entity"); + RegistryHelper.registerBlockEntityType(TestBlockEntity.class, blockEntityTestId); + } + + public static class TestBlockWithEntity extends BlockWithEntity { + protected TestBlockWithEntity(Material material) { + super(material); + } + + @Override + public BlockEntity createBlockEntity(World world, int id) { + return new TestBlockEntity(); + } + + @Override + public boolean onUse(World world, BlockPos pos, BlockState state, PlayerEntity player, Direction direction, float posX, float posY, float posZ) { + if (!world.isClient) { + BlockEntity entity = world.getBlockEntity(pos); + + if (entity instanceof TestBlockEntity) { + player.sendMessage(new LiteralText(entity + " at " + pos.toString())); + } + } + + return true; + } + } + + public static class TestBlockEntity extends BlockEntity { } } diff --git a/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 970a1a683..026c6c66b 100644 --- a/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java +++ b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -20,20 +20,36 @@ import java.util.concurrent.ThreadLocalRandom; +import org.jetbrains.annotations.Nullable; + import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.material.Material; import net.minecraft.block.material.MaterialColor; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.item.itemgroup.ItemGroup; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; import net.fabricmc.api.ModInitializer; import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; public class TestMod implements ModInitializer { + static Identifier blockEntityTestId = new Identifier("legacy-fabric-api:test_block_entity"); @Override public void onInitialize() { registerItem(); @@ -60,5 +76,43 @@ private void registerItem() { Item testItem = new Item().setItemGroup(ItemGroup.FOOD); RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); + + Block blockWithEntity = new TestBlockWithEntity(Material.DIRT).setItemGroup(ItemGroup.FOOD); + RegistryHelper.registerBlock(blockWithEntity, blockEntityTestId); + RegistryHelper.registerItem(new BlockItem(blockWithEntity), blockEntityTestId); + + RegistryInitializedEvent.event(RegistryIds.BLOCK_ENTITY_TYPES).register(this::registerBlockEntity); + } + + public void registerBlockEntity(Registry registry) { + System.err.println("Registering block entity"); + RegistryHelper.registerBlockEntityType(TestBlockEntity.class, blockEntityTestId); + } + + public static class TestBlockWithEntity extends BlockWithEntity { + protected TestBlockWithEntity(Material material) { + super(material); + } + + @Override + public BlockEntity createBlockEntity(World world, int id) { + return new TestBlockEntity(); + } + + @Override + public boolean method_421(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity, Hand hand, @Nullable ItemStack itemStack, Direction direction, float f, float g, float h) { + if (!world.isClient) { + BlockEntity entity = world.getBlockEntity(blockPos); + + if (entity instanceof TestBlockEntity) { + playerEntity.sendMessage(new LiteralText(entity + " at " + blockPos.toString())); + } + } + + return true; + } + } + + public static class TestBlockEntity extends BlockEntity { } } diff --git a/legacyfabric-api/common.gradle b/legacyfabric-api/common.gradle index 9598864ea..e2834bcdd 100644 --- a/legacyfabric-api/common.gradle +++ b/legacyfabric-api/common.gradle @@ -13,6 +13,7 @@ moduleDependencies(project, [ "legacy-fabric-registry-sync-api-v2", "legacy-fabric-item-api-v1", "legacy-fabric-block-api-v1", + "legacy-fabric-block-entity-api-v1", "legacy-fabric-rendering-api-v1", "legacy-fabric-crash-report-info-v1", "legacy-fabric-command-api-v2" diff --git a/settings.gradle b/settings.gradle index 8384c772b..ab580d7eb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -40,6 +40,7 @@ loadProject("legacy-fabric-registry-sync-api-v1") loadProject("legacy-fabric-registry-sync-api-v2") loadProject("legacy-fabric-item-api-v1") loadProject("legacy-fabric-block-api-v1") +loadProject("legacy-fabric-block-entity-api-v1") loadProject("legacy-fabric-rendering-api-v1") loadProject("legacy-fabric-crash-report-info-v1") loadProject("legacy-fabric-command-api-v2") From 10d7cbda7c2319e4beba651798b6e95063de4cc9 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 23:59:38 +0200 Subject: [PATCH 31/36] Fix missing events in MapRegistryWrapper --- .../registry/wrapper/MapRegistryWrapper.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/MapRegistryWrapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/MapRegistryWrapper.java index 39704d72a..6aa7e5cb0 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/MapRegistryWrapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/MapRegistryWrapper.java @@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull; import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.event.EventFactory; import net.legacyfabric.fabric.api.registry.v2.event.RegistryBeforeAddCallback; import net.legacyfabric.fabric.api.registry.v2.event.RegistryEntryAddedCallback; import net.legacyfabric.fabric.api.registry.v2.registry.RegistrableRegistry; @@ -36,6 +37,21 @@ public class MapRegistryWrapper implements RegistrableRegistry { private final Function toMapKey; private final Function fromMapKey; + private final Event> addObjectEvent = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryEntryAddedCallback callback : callbacks) { + callback.onEntryAdded(rawId, id, object); + } + } + ); + private final Event> beforeAddObjectEvent = EventFactory.createArrayBacked(RegistryBeforeAddCallback.class, + (callbacks) -> (rawId, id, object) -> { + for (RegistryBeforeAddCallback callback : callbacks) { + callback.onEntryAdding(rawId, id, object); + } + } + ); + public MapRegistryWrapper(Identifier id, Map idToValue, Map valueToId, Function toMapKey, Function fromMapKey) { this.id = id; this.idToValue = idToValue; @@ -51,12 +67,12 @@ public MapRegistryWrapper(Identifier id, Map idToValue, Map valueToI @Override public Event> fabric$getEntryAddedCallback() { - return null; + return this.addObjectEvent; } @Override public Event> fabric$getBeforeAddedCallback() { - return null; + return this.beforeAddObjectEvent; } @Override From 4caee9f821c51aad1d043d86ebe574c3c2c10566 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 9 May 2024 00:01:59 +0200 Subject: [PATCH 32/36] Avoid using sysout --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 73756e661..d93894ddd 100644 --- a/build.gradle +++ b/build.gradle @@ -445,7 +445,7 @@ def addPomMetadataInformation(Project project, MavenPom pom) { def modJsonFile = project.file("src/main/resources/fabric.mod.json") if (!modJsonFile.exists()) { - System.out.println("Can't find fabric.mod.json at ${modJsonFile.toString()}!") + logger.error("Can't find fabric.mod.json at ${modJsonFile.toString()}!") return; } From bca9170f5ccd005be01d0cb2c463763858d7611e Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 9 May 2024 00:28:19 +0200 Subject: [PATCH 33/36] Block entity registry doesn't need to be synchronized --- .../fabric/mixin/block/entity/BlockEntityMixin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/legacy-fabric-block-entity-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java b/legacy-fabric-block-entity-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java index bbd3ff464..122d2de17 100644 --- a/legacy-fabric-block-entity-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java +++ b/legacy-fabric-block-entity-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.java @@ -30,6 +30,7 @@ import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.DesynchronizeableRegistrable; @Mixin(BlockEntity.class) public class BlockEntityMixin { @@ -39,6 +40,7 @@ public class BlockEntityMixin { @Inject(method = "", at = @At("RETURN")) private static void registerRegistry(CallbackInfo ci) { + ((DesynchronizeableRegistrable) BLOCK_ENTITY).setSynchronize(false); RegistryHelper.addRegistry(RegistryIds.BLOCK_ENTITY_TYPES, BLOCK_ENTITY); } } From da6916ff1b93088bc138656074d725dd4fcf5b05 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 9 May 2024 00:29:21 +0200 Subject: [PATCH 34/36] Allow Synchronized Registry to declare themselves not to be synchronized --- .../sync/versioned/SimpleRegistryMixin.java | 25 ++++++++++++++++-- .../sync/versioned/SimpleRegistryMixinV2.java | 25 ++++++++++++++++-- .../sync/versioned/SimpleRegistryMixinV2.java | 25 ++++++++++++++++-- .../DesynchronizeableRegistrable.java | 26 +++++++++++++++++++ .../RegistryHelperImplementation.java | 19 +++++++++++--- .../registry/sync/SimpleRegistryMixinV2.java | 3 ++- 6 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java index 7fad490e3..985b37aa2 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java @@ -24,18 +24,20 @@ import org.spongepowered.asm.mixin.Unique; import net.minecraft.class_2929; +import net.minecraft.util.registry.MutableRegistry; import net.minecraft.util.registry.SimpleRegistry; import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.event.EventFactory; import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.DesynchronizeableRegistrable; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements SyncedRegistry, SyncedRegistrable { +public abstract class SimpleRegistryMixin implements SyncedRegistry, SyncedRegistrable, DesynchronizeableRegistrable { // 1.8+ @Shadow public abstract void add(int id, K identifier, V object); @@ -58,10 +60,29 @@ public abstract class SimpleRegistryMixin implements SyncedRegistry, Sy @Shadow public abstract Object getByRawId(int index); + @Unique + private boolean synchronize = true; + + @Override + public void setSynchronize(boolean isSynchronize) { + this.synchronize = isSynchronize; + } + + @Override + public boolean canSynchronize() { + return this.synchronize; + } + @Override public void fabric$register(int rawId, Identifier identifier, V value) { fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); - add(rawId, fabric$toKeyType(identifier), value); + + if (this.synchronize) { + add(rawId, fabric$toKeyType(identifier), value); + } else { + ((MutableRegistry) (Object) this).put(fabric$toKeyType(identifier), value); + } + fabric$getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); } diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java index 07eacb02c..7e5fe7799 100644 --- a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java @@ -24,18 +24,20 @@ import org.spongepowered.asm.mixin.Unique; import net.minecraft.util.collection.IdList; +import net.minecraft.util.registry.MutableRegistry; import net.minecraft.util.registry.SimpleRegistry; import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.event.EventFactory; import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.DesynchronizeableRegistrable; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, SyncedRegistrable { +public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, SyncedRegistrable, DesynchronizeableRegistrable { // 1.8+ @Shadow public abstract void add(int id, String identifier, Object object); @@ -56,10 +58,29 @@ public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, Syn @Shadow public abstract String getId(Object par1); + @Unique + private boolean synchronize = true; + + @Override + public void setSynchronize(boolean isSynchronize) { + this.synchronize = isSynchronize; + } + + @Override + public boolean canSynchronize() { + return this.synchronize; + } + @Override public void fabric$register(int rawId, Identifier identifier, V value) { fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); - add(rawId, fabric$toKeyType(identifier), value); + + if (this.synchronize) { + add(rawId, fabric$toKeyType(identifier), value); + } else { + ((MutableRegistry) (Object) this).put(fabric$toKeyType(identifier), value); + } + fabric$getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); } diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java index 428b915ca..f46c98c00 100644 --- a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java @@ -24,18 +24,20 @@ import org.spongepowered.asm.mixin.Unique; import net.minecraft.util.collection.IdList; +import net.minecraft.util.registry.MutableRegistry; import net.minecraft.util.registry.SimpleRegistry; import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.event.EventFactory; import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.DesynchronizeableRegistrable; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, SyncedRegistrable { +public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, SyncedRegistrable, DesynchronizeableRegistrable { // 1.8+ @Shadow public abstract void add(int id, K identifier, V object); @@ -57,10 +59,29 @@ public abstract class SimpleRegistryMixinV2 implements SyncedRegistry, @Final protected IdList ids; + @Unique + private boolean synchronize = true; + + @Override + public void setSynchronize(boolean isSynchronize) { + this.synchronize = isSynchronize; + } + + @Override + public boolean canSynchronize() { + return this.synchronize; + } + @Override public void fabric$register(int rawId, Identifier identifier, V value) { fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); - add(rawId, fabric$toKeyType(identifier), value); + + if (this.synchronize) { + add(rawId, fabric$toKeyType(identifier), value); + } else { + ((MutableRegistry) (Object) this).put(fabric$toKeyType(identifier), value); + } + fabric$getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java new file mode 100644 index 000000000..9194d63fc --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; + +public interface DesynchronizeableRegistrable { + default boolean canSynchronize() { + return true; + } + + void setSynchronize(boolean synchronize); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java index d9aa8889d..53052a06d 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java @@ -37,6 +37,7 @@ import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistrableRegistry; import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.DesynchronizeableRegistrable; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; @@ -88,7 +89,13 @@ public static void registerRegistry(Identifier identifier, Registry holde if (holder instanceof RegistryIdSetter) ((RegistryIdSetter) holder).fabric$setId(identifier); - if (holder instanceof SyncedRegistrableRegistry) { + boolean remappable = true; + + if (holder instanceof DesynchronizeableRegistrable) { + remappable = ((DesynchronizeableRegistrable) holder).canSynchronize(); + } + + if (holder instanceof SyncedRegistrableRegistry && remappable) { REMAPPERS.put(identifier, new RegistryRemapper<>((SyncedRegistrableRegistry) holder)); } @@ -108,7 +115,7 @@ public static void registerRegistry(Identifier identifier, Registry holde if (event != null) event.invoker().onEntryAdded(rawId, id, object); }); - if (holder instanceof SyncedRegistrableRegistry) { + if (holder instanceof SyncedRegistrableRegistry && remappable) { ((SyncedRegistrableRegistry) holder).fabric$getRegistryRemapCallback().register(changedIdsMap -> { Event> event = (Event>) (Object) RegistryEventHelper.IDENTIFIER_REMAP_MAP.get(identifier); @@ -124,7 +131,13 @@ public static void register(Registry registry, Identifier identifier, T v Registrable registrable = (Registrable) registry; int computedId = -1; - if (registry instanceof SyncedRegistrable) { + boolean remappable = true; + + if (registry instanceof DesynchronizeableRegistrable) { + remappable = ((DesynchronizeableRegistrable) registry).canSynchronize(); + } + + if (registry instanceof SyncedRegistrable && remappable) { computedId = ((SyncedRegistrable) registrable).fabric$nextId(); } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java index 5aab49407..5977956c1 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java @@ -22,7 +22,8 @@ import net.minecraft.util.registry.SimpleRegistry; import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistrableRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.DesynchronizeableRegistrable; @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixinV2 implements SyncedRegistrableRegistry { +public abstract class SimpleRegistryMixinV2 implements SyncedRegistrableRegistry, DesynchronizeableRegistrable { } From b1ff8b812b5445ca6d5d65bbe49ff7f023ee06f9 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 6 Jun 2024 22:48:24 +0200 Subject: [PATCH 35/36] Allow setting the min id possible of a registry --- .../fabric/impl/registry/IdsHolderImpl.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java index 9024ef4c8..c83167389 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java @@ -32,14 +32,24 @@ public class IdsHolderImpl implements IdsHolder { private final IdentityHashMap valueToId = new IdentityHashMap<>(512); private final List values = Lists.newArrayList(); + private final int minId; + + public IdsHolderImpl(int minId) { + this.minId = minId; + } + + public IdsHolderImpl() { + this(0); + } + @Override public IdsHolder fabric$new() { - return new IdsHolderImpl<>(); + return new IdsHolderImpl<>(this.minId); } @Override public int fabric$nextId() { - int id = 0; + int id = this.minId; while (this.fabric$getValue(id) != null) id++; @@ -70,7 +80,7 @@ public class IdsHolderImpl implements IdsHolder { @Override public T fabric$getValue(int rawId) { - return rawId >= 0 && rawId < this.values.size() ? this.values.get(rawId) : null; + return rawId >= this.minId && rawId < this.values.size() ? this.values.get(rawId) : null; } @NotNull From b7a8575b20876bd5c313360030bc216bb391705a Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 6 Jun 2024 22:48:44 +0200 Subject: [PATCH 36/36] Fix entry count in IdsHolder --- .../mixin/registry/sync/versioned/OtherIdListMixin.java | 6 +++--- .../legacyfabric/fabric/impl/registry/IdsHolderImpl.java | 2 +- .../legacyfabric/fabric/impl/registry/RegistryRemapper.java | 2 +- .../fabric/mixin/registry/sync/IdListMixinV2.java | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java index f6faa63d7..08d5ed10d 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java @@ -35,10 +35,10 @@ public abstract class OtherIdListMixin implements IdsHolder { public abstract void add(T value, int id); @Shadow - private T[] field_14375; + public abstract int getId(T value); @Shadow - public abstract int getId(T value); + public abstract int size(); @Override public IdsHolder fabric$new() { @@ -61,7 +61,7 @@ public abstract class OtherIdListMixin implements IdsHolder { @Override public int fabric$size() { - return this.field_14375.length; + return this.size(); } @Override diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java index c83167389..da31e5450 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java @@ -69,7 +69,7 @@ public IdsHolderImpl() { @Override public int fabric$size() { - return values.size(); + return this.valueToId.size(); } @Override diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java index 166c5624b..382757f25 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java @@ -132,7 +132,7 @@ private IntSupplier normalizeEntryList(IdsHolder ids) { addNewEntries(ids); if (currentSize.getAsInt() != previousSize.getAsInt() && this.missingMap.isEmpty()) { - throw new IllegalStateException("An error occured during remapping"); + throw new IllegalStateException("An error occurred during remapping"); } return previousSize; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java index a7c3ac826..8a7d3f42a 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java @@ -17,6 +17,7 @@ package net.legacyfabric.fabric.mixin.registry.sync; +import java.util.IdentityHashMap; import java.util.List; import org.spongepowered.asm.mixin.Final; @@ -40,7 +41,7 @@ public abstract class IdListMixinV2 implements IdsHolder { @Shadow @Final - private List list; + private IdentityHashMap idMap; @Override public IdsHolder fabric$new() { @@ -63,7 +64,7 @@ public abstract class IdListMixinV2 implements IdsHolder { @Override public int fabric$size() { - return list.size(); + return idMap.size(); } @Override