From ec8fbe722453b00b0e6401220f9bccff80fee0ae Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 17 Mar 2024 18:38:28 +0100 Subject: [PATCH 01/31] 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 ab1434761..e4f7994e1 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.2 legacy-fabric-permissions-api-v1.version = 1.1.0 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.2.2 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 58f6a5239e1ed4bc8a5cc2fdd149f13539c06208 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sat, 23 Mar 2024 19:47:33 +0100 Subject: [PATCH 02/31] 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 78d80a4d7..72be17e65 100644 --- a/build.gradle +++ b/build.gradle @@ -290,6 +290,10 @@ allprojects { useLegacyMixinAp = true } + interfaceInjection { + enableDependencyInterfaceInjection = true + } + runs { "testModClient$mcVersion" { client() @@ -451,7 +455,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 2b0538bb47ddfae444d9b7454031f36baf525d84 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 24 Mar 2024 17:26:03 +0100 Subject: [PATCH 03/31] 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 aa17b4ab6f2df944c2b530db5a78868ab74657f1 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 24 Apr 2024 18:24:17 +0200 Subject: [PATCH 04/31] 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 69b1df9c7a30a2e259caf1c135f3d153c5816d35 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 5 May 2024 21:52:46 +0200 Subject: [PATCH 05/31] 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 10653d66578aa4d2c1d8d2cbe4e200262a75b9d9 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 5 May 2024 22:51:53 +0200 Subject: [PATCH 06/31] 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 7f883347e5b082c5191184a351c985695e5561ee Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 00:41:54 +0200 Subject: [PATCH 07/31] 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 285e4a97caef385b4ec718e267596f38011d52fe Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 00:43:02 +0200 Subject: [PATCH 08/31] 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 40eff6fbbcb3e9b71448e2a65c513cc9ae9331f9 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:06:11 +0200 Subject: [PATCH 09/31] 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 612a85d0be64537548686847ea4cee6bfebdb5e2 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:08:04 +0200 Subject: [PATCH 10/31] 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 1f29898fea62f689ffe77bb6d1cfdf0efb09df6b Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:08:41 +0200 Subject: [PATCH 11/31] 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 f5d879fbc362aca68513b7929372db6eee5ccf16 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:09:38 +0200 Subject: [PATCH 12/31] 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 134b16d254abdb7f597c266368a7a193e24c6102 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 21:15:07 +0200 Subject: [PATCH 13/31] 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 3664dd944b5aee666d8397b33ae5302bee1884ab Mon Sep 17 00:00:00 2001 From: Cat Core Date: Wed, 8 May 2024 23:59:38 +0200 Subject: [PATCH 14/31] 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 a8f6652333802d3f0f8a289e74769bcfd555b90e Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 9 May 2024 00:01:59 +0200 Subject: [PATCH 15/31] Avoid using sysout --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 72be17e65..b6f110bbf 100644 --- a/build.gradle +++ b/build.gradle @@ -455,7 +455,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 fd13568b7241bb6cf41feb2a5927f9d24764bd19 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 9 May 2024 00:29:21 +0200 Subject: [PATCH 16/31] 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 719d9cb33a5ee64bf7505e69ba610927ad10bab8 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 6 Jun 2024 22:48:24 +0200 Subject: [PATCH 17/31] 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 fc96dd5745c5c422d5c101100a295ffecbef81d9 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 6 Jun 2024 22:48:44 +0200 Subject: [PATCH 18/31] 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 From d4057612af43db105e66b39216ac8cc510f490f4 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 29 Aug 2024 22:08:01 +0200 Subject: [PATCH 19/31] SyncedArrayMapRegistryWrapper --- .../fabric/api/registry/v2/RegistryIds.java | 3 + .../SyncedArrayMapRegistryWrapper.java | 164 ++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java 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 index 83f11fba7..9301737a7 100644 --- 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 @@ -18,6 +18,7 @@ package net.legacyfabric.fabric.api.registry.v2; import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.api.util.SinceMC; public class RegistryIds { public static final Identifier ITEMS = new Identifier("items"); @@ -27,4 +28,6 @@ public class RegistryIds { 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"); + @SinceMC("1.9") + public static final Identifier POTIONS = new Identifier("potions"); } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java new file mode 100644 index 000000000..d85b8eb8d --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java @@ -0,0 +1,164 @@ +/* + * 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.function.Consumer; +import java.util.function.Function; + +import com.google.common.collect.BiMap; +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.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; +import net.legacyfabric.fabric.impl.registry.IdsHolderImpl; + +public class SyncedArrayMapRegistryWrapper implements SyncedRegistrableRegistry { + private IdsHolder idsHolder = new IdsHolderImpl<>(); + + private final Identifier id; + private final BiMap keyToValue; + private final boolean updateMap; + private final BiMap valueToKey; + private final Function toMapKey; + private final Function fromMapKey; + private final Consumer> arraySetter; + + 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); + } + } + ); + + public SyncedArrayMapRegistryWrapper(Identifier id, V[] array, BiMap keyToValue, boolean updateMap, Function toMapKey, Function fromMapKey, Consumer> arraySetter) { + this.id = id; + this.keyToValue = keyToValue; + this.updateMap = updateMap; + this.valueToKey = this.keyToValue.inverse(); + this.toMapKey = toMapKey; + this.fromMapKey = fromMapKey; + this.arraySetter = arraySetter; + + for (int i = 0; i < array.length; i++) { + V value = array[i]; + + if (value != null) { + idsHolder.fabric$setValue(value, i); + } + } + } + + @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.id; + } + + @Override + public Event> fabric$getEntryAddedCallback() { + return addObjectEvent; + } + + @Override + public Event> fabric$getBeforeAddedCallback() { + return beforeAddObjectEvent; + } + + @Override + public K fabric$toKeyType(Identifier identifier) { + return toMapKey.apply(identifier); + } + + @Override + public V fabric$getValue(Identifier id) { + return this.keyToValue.get(this.fabric$toKeyType(id)); + } + + @Override + public Identifier fabric$getId(V value) { + K key = this.valueToKey.get(value); + + if (key == null) return null; + + return fromMapKey.apply(key); + } + + @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; + + this.arraySetter.accept(this.idsHolder); + } + + @Override + public void fabric$register(int rawId, Identifier identifier, V value) { + beforeAddObjectEvent.invoker().onEntryAdding(rawId, identifier, value); + + this.idsHolder.fabric$setValue(value, rawId); + if (updateMap) this.keyToValue.put(this.fabric$toKeyType(identifier), value); + + addObjectEvent.invoker().onEntryAdded(rawId, identifier, value); + } +} From 4cf43de81b408469384dc0754a984475d33c03d4 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 6 Jun 2024 22:52:58 +0200 Subject: [PATCH 20/31] Make Map+Array-based registry min id be 1 instead of 0 --- .../impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java index d85b8eb8d..03b543d57 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java @@ -35,7 +35,7 @@ import net.legacyfabric.fabric.impl.registry.IdsHolderImpl; public class SyncedArrayMapRegistryWrapper implements SyncedRegistrableRegistry { - private IdsHolder idsHolder = new IdsHolderImpl<>(); + private IdsHolder idsHolder = new IdsHolderImpl<>(1); private final Identifier id; private final BiMap keyToValue; From 8b549854a9a5187d3e448360eb1e3104488297ed Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 29 Aug 2024 22:09:38 +0200 Subject: [PATCH 21/31] SyncedArrayRegistryWrapper --- .../SyncedArrayMapRegistryWrapper.java | 2 + .../wrapper/SyncedArrayRegistryWrapper.java | 161 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java index 03b543d57..086b26d35 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java @@ -160,5 +160,7 @@ public Iterator iterator() { if (updateMap) this.keyToValue.put(this.fabric$toKeyType(identifier), value); addObjectEvent.invoker().onEntryAdded(rawId, identifier, value); + + this.arraySetter.accept(this.idsHolder); } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java new file mode 100644 index 000000000..9f613babc --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java @@ -0,0 +1,161 @@ +package net.legacyfabric.fabric.impl.registry.wrapper; + +import com.google.common.collect.BiMap; + +import com.google.common.collect.HashBiMap; + +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.SyncedRegistrableRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.registry.IdsHolderImpl; + +import org.jetbrains.annotations.NotNull; + +import java.util.Iterator; +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; + +public class SyncedArrayRegistryWrapper implements SyncedRegistrableRegistry { + private IdsHolder idsHolder = new IdsHolderImpl<>(1); + + private final Identifier id; + private final BiMap keyToValue = HashBiMap.create(); + private final BiMap valueToKey = keyToValue.inverse(); + private final Consumer> arraySetter; + 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); + } + } + ); + private final Event> remapCallbackEvent = EventFactory.createArrayBacked(RegistryRemapCallback.class, + (callbacks) -> (changedMap) -> { + for (RegistryRemapCallback callback : callbacks) { + callback.callback(changedMap); + } + } + ); + + public SyncedArrayRegistryWrapper(Identifier id, V[] array, Map defaultIds, Function toMapKey, Function fromMapKey, Consumer> arraySetter) { + this.id = id; + this.arraySetter = arraySetter; + this.toMapKey = toMapKey; + this.fromMapKey = fromMapKey; + + for (int i = 0; i < array.length; i++) { + V value = array[i]; + + if (value != null) { + Identifier key = defaultIds.get(i); + + if (key == null) { + idsHolder.fabric$setValue(value, i); + } else { + this.registerWithoutEvents(i, key, value); + } + } + } + + this.arraySetter.accept(this.idsHolder); + } + + @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.id; + } + + @Override + public Event> fabric$getEntryAddedCallback() { + return addObjectEvent; + } + + @Override + public Event> fabric$getBeforeAddedCallback() { + return beforeAddObjectEvent; + } + + @Override + public K fabric$toKeyType(Identifier identifier) { + return toMapKey.apply(identifier); + } + + @Override + public V fabric$getValue(Identifier id) { + return this.keyToValue.get(this.fabric$toKeyType(id)); + } + + @Override + public Identifier fabric$getId(V value) { + K key = this.valueToKey.get(value); + + if (key == null) return null; + + return fromMapKey.apply(key); + } + + @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; + + this.arraySetter.accept(this.idsHolder); + } + + @Override + public void fabric$register(int rawId, Identifier identifier, V value) { + beforeAddObjectEvent.invoker().onEntryAdding(rawId, identifier, value); + + this.registerWithoutEvents(rawId, identifier, value); + + addObjectEvent.invoker().onEntryAdded(rawId, identifier, value); + + this.arraySetter.accept(this.idsHolder); + } + + private void registerWithoutEvents(int rawId, Identifier identifier, V value) { + this.idsHolder.fabric$setValue(value, rawId); + this.keyToValue.put(this.fabric$toKeyType(identifier), value); + } +} From 79f885139dfb16d460d012f74fd9243e61259e34 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 29 Aug 2024 22:11:44 +0200 Subject: [PATCH 22/31] RegistryWrapper Improvements --- .../registry/wrapper/SyncedArrayMapRegistryWrapper.java | 7 ++++++- .../impl/registry/wrapper/SyncedArrayRegistryWrapper.java | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java index 086b26d35..77fb6e349 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java @@ -35,7 +35,7 @@ import net.legacyfabric.fabric.impl.registry.IdsHolderImpl; public class SyncedArrayMapRegistryWrapper implements SyncedRegistrableRegistry { - private IdsHolder idsHolder = new IdsHolderImpl<>(1); + private IdsHolder idsHolder; private final Identifier id; private final BiMap keyToValue; @@ -68,6 +68,11 @@ public class SyncedArrayMapRegistryWrapper implements SyncedRegistrableReg ); public SyncedArrayMapRegistryWrapper(Identifier id, V[] array, BiMap keyToValue, boolean updateMap, Function toMapKey, Function fromMapKey, Consumer> arraySetter) { + this(id, array, keyToValue, updateMap, toMapKey, fromMapKey, arraySetter, 0); + } + + public SyncedArrayMapRegistryWrapper(Identifier id, V[] array, BiMap keyToValue, boolean updateMap, Function toMapKey, Function fromMapKey, Consumer> arraySetter, int minId) { + this.idsHolder = new IdsHolderImpl<>(minId); this.id = id; this.keyToValue = keyToValue; this.updateMap = updateMap; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java index 9f613babc..3fa07d0bc 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java @@ -22,7 +22,7 @@ import java.util.function.Function; public class SyncedArrayRegistryWrapper implements SyncedRegistrableRegistry { - private IdsHolder idsHolder = new IdsHolderImpl<>(1); + private IdsHolder idsHolder; private final Identifier id; private final BiMap keyToValue = HashBiMap.create(); @@ -54,6 +54,11 @@ public class SyncedArrayRegistryWrapper implements SyncedRegistrableRegist ); public SyncedArrayRegistryWrapper(Identifier id, V[] array, Map defaultIds, Function toMapKey, Function fromMapKey, Consumer> arraySetter) { + this(id, array, defaultIds, toMapKey, fromMapKey, arraySetter, 0); + } + + public SyncedArrayRegistryWrapper(Identifier id, V[] array, Map defaultIds, Function toMapKey, Function fromMapKey, Consumer> arraySetter, int minId) { + this.idsHolder = new IdsHolderImpl<>(minId); this.id = id; this.arraySetter = arraySetter; this.toMapKey = toMapKey; From 22fc4f2f26b1d26dc2b9fa5fe82bfe34a870cac0 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sun, 7 Jul 2024 00:49:07 +0200 Subject: [PATCH 23/31] Fix defaulted registries default value not being interpreted as entry missing when it should. --- .../versioned/BiDefaultedRegistryMixin.java | 49 +++++++++++++++++ ...cy-fabric-registry-sync-api-v2.mixins.json | 1 + .../versioned/BiDefaultedRegistryMixin.java | 52 +++++++++++++++++++ ...cy-fabric-registry-sync-api-v2.mixins.json | 1 + .../versioned/BiDefaultedRegistryMixin.java | 49 +++++++++++++++++ ...cy-fabric-registry-sync-api-v2.mixins.json | 1 + 6 files changed, 153 insertions(+) create mode 100644 legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java create mode 100644 legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java create mode 100644 legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java new file mode 100644 index 000000000..a1048b269 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -0,0 +1,49 @@ +/* + * 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.Shadow; + +import net.minecraft.util.registry.BiDefaultedRegistry; + +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.SyncedRegistrable; +import net.legacyfabric.fabric.api.util.Identifier; + +@Mixin(BiDefaultedRegistry.class) +public abstract class BiDefaultedRegistryMixin implements SyncedRegistry, SyncedRegistrable, DesynchronizeableRegistrable { + @Shadow + private V defaultValue; + + @Shadow + @Final + private K defaultKey; + + @Override + public V fabric$getValue(Identifier id) { + K key = (K) fabric$toKeyType(id); + V value = ((BiDefaultedRegistry)(Object) this).get(key); + + if (value == this.defaultValue && this.defaultKey != key) return null; + + return value; + } +} 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 f2e024e25..231708e9e 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": [ + "versioned.BiDefaultedRegistryMixin", "versioned.OtherIdListMixin", "versioned.PlayerManagerMixin", "versioned.SimpleRegistryMixin" diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java new file mode 100644 index 000000000..cc23020be --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -0,0 +1,52 @@ +/* + * 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 java.util.Objects; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.util.registry.BiDefaultedRegistry; +import net.minecraft.util.registry.SimpleRegistry; + +import net.legacyfabric.fabric.api.util.Identifier; + +@Mixin(BiDefaultedRegistry.class) +public abstract class BiDefaultedRegistryMixin extends SimpleRegistry { + @Shadow + private Object defaultValue; + + @Shadow + @Final + private String field_8395; + + @Shadow + public abstract Object get(String par1); + + @Override + public Object fabric$getValue(Identifier id) { + String key = (String) fabric$toKeyType(id); + Object value = get(key); + + if (value == this.defaultValue && !Objects.equals(this.field_8395, key)) return null; + + return value; + } +} 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 index 9298f31f9..b120e9059 100644 --- 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 @@ -6,6 +6,7 @@ "defaultRequire": 1 }, "mixins": [ + "versioned.BiDefaultedRegistryMixin", "versioned.PlayerManagerMixin", "versioned.SimpleRegistryMixinV2" ], diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java new file mode 100644 index 000000000..a1048b269 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -0,0 +1,49 @@ +/* + * 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.Shadow; + +import net.minecraft.util.registry.BiDefaultedRegistry; + +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.SyncedRegistrable; +import net.legacyfabric.fabric.api.util.Identifier; + +@Mixin(BiDefaultedRegistry.class) +public abstract class BiDefaultedRegistryMixin implements SyncedRegistry, SyncedRegistrable, DesynchronizeableRegistrable { + @Shadow + private V defaultValue; + + @Shadow + @Final + private K defaultKey; + + @Override + public V fabric$getValue(Identifier id) { + K key = (K) fabric$toKeyType(id); + V value = ((BiDefaultedRegistry)(Object) this).get(key); + + if (value == this.defaultValue && this.defaultKey != key) return null; + + return value; + } +} 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 index 9298f31f9..b120e9059 100644 --- 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 @@ -6,6 +6,7 @@ "defaultRequire": 1 }, "mixins": [ + "versioned.BiDefaultedRegistryMixin", "versioned.PlayerManagerMixin", "versioned.SimpleRegistryMixinV2" ], From 4954eaef7be2761eec9d7eaae5f5d8f4c60e0c7d Mon Sep 17 00:00:00 2001 From: Cat Core Date: Tue, 9 Jul 2024 22:32:40 +0200 Subject: [PATCH 24/31] Fix defaulted registries default value not being interpreted as entry missing when it should. (again) --- .../registry/sync/versioned/BiDefaultedRegistryMixin.java | 4 +++- .../registry/sync/versioned/BiDefaultedRegistryMixin.java | 4 +++- 2 files changed, 6 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/BiDefaultedRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java index a1048b269..407cb98ab 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -28,6 +28,8 @@ import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; +import java.util.Objects; + @Mixin(BiDefaultedRegistry.class) public abstract class BiDefaultedRegistryMixin implements SyncedRegistry, SyncedRegistrable, DesynchronizeableRegistrable { @Shadow @@ -42,7 +44,7 @@ public abstract class BiDefaultedRegistryMixin implements SyncedRegistry)(Object) this).get(key); - if (value == this.defaultValue && this.defaultKey != key) return null; + if (value == this.defaultValue && !Objects.equals(this.defaultKey.toString(), key.toString())) return null; return value; } diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java index a1048b269..407cb98ab 100644 --- a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -28,6 +28,8 @@ import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; +import java.util.Objects; + @Mixin(BiDefaultedRegistry.class) public abstract class BiDefaultedRegistryMixin implements SyncedRegistry, SyncedRegistrable, DesynchronizeableRegistrable { @Shadow @@ -42,7 +44,7 @@ public abstract class BiDefaultedRegistryMixin implements SyncedRegistry)(Object) this).get(key); - if (value == this.defaultValue && this.defaultKey != key) return null; + if (value == this.defaultValue && !Objects.equals(this.defaultKey.toString(), key.toString())) return null; return value; } From ea04cdbb4d98ff04ca4efe94c318f61b95ad4b10 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 29 Aug 2024 22:13:55 +0200 Subject: [PATCH 25/31] Allow registering multiple entries together with a defined offset between their numerical ids. --- .../api/registry/v2/RegistryHelper.java | 27 +++++++++ .../registrable/RegistryEntryCreator.java | 9 +++ .../registry/RegistryEntryCreatorImpl.java | 39 +++++++++++++ .../impl/registry/RegistryEntryImpl.java | 31 ++++++++++ .../RegistryHelperImplementation.java | 56 +++++++++++++++++++ .../impl/registry/RegistryRemapper.java | 26 --------- 6 files changed, 162 insertions(+), 26 deletions(-) create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/RegistryEntryCreator.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryCreatorImpl.java create mode 100644 legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java 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 f2ee7b69b..b600f464d 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 @@ -17,10 +17,13 @@ package net.legacyfabric.fabric.api.registry.v2; +import java.util.List; import java.util.function.Function; 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.registry.v2.registry.registrable.RegistryEntryCreator; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @@ -77,4 +80,28 @@ public static int getRawId(Registry registry, T object) { public static int getRawId(Identifier registryId, T object) { return getRawId(RegistryHelperImplementation.getRegistry(registryId), object); } + + public static RegistryEntryCreator createEntryCreator(Identifier identifier, Function valueConstructor, int offset) { + return RegistryHelperImplementation.createEntryCreator(identifier, valueConstructor, offset); + } + + public static RegistryEntryCreator createEntryCreator(Identifier identifier, T value, int offset) { + return createEntryCreator(identifier, (id) -> value, offset); + } + + public static RegistryEntryCreator createEntryCreator(Identifier identifier, Function valueConstructor) { + return createEntryCreator(identifier, valueConstructor, 0); + } + + public static RegistryEntryCreator createEntryCreator(Identifier identifier, T value) { + return createEntryCreator(identifier, value, 0); + } + + public static List> registerMultiple(Registry registry, RegistryEntryCreator... creators) { + return RegistryHelperImplementation.register(registry, creators); + } + + public static List> registerMultiple(Identifier registryId, RegistryEntryCreator... creators) { + return registerMultiple(RegistryHelperImplementation.getRegistry(registryId), creators); + } } diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/RegistryEntryCreator.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/RegistryEntryCreator.java new file mode 100644 index 000000000..bcad2a56d --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/RegistryEntryCreator.java @@ -0,0 +1,9 @@ +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; + +import net.legacyfabric.fabric.api.util.Identifier; + +public interface RegistryEntryCreator { + T getValue(int id); + Identifier getIdentifier(); + int getIdOffset(); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryCreatorImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryCreatorImpl.java new file mode 100644 index 000000000..8930ff5fc --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryCreatorImpl.java @@ -0,0 +1,39 @@ +package net.legacyfabric.fabric.impl.registry; + +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.RegistryEntryCreator; +import net.legacyfabric.fabric.api.util.Identifier; + +import java.util.function.Function; + +public class RegistryEntryCreatorImpl implements RegistryEntryCreator { + private final Identifier identifier; + private final int offset; + private final Function valueGetter; + + private T value; + + public RegistryEntryCreatorImpl(Identifier identifier, int offset, Function valueGetter) { + this.identifier = identifier; + this.offset = offset; + this.valueGetter = valueGetter; + } + + @Override + public T getValue(int id) { + if (this.value == null) { + this.value = this.valueGetter.apply(id); + } + + return this.value; + } + + @Override + public Identifier getIdentifier() { + return this.identifier; + } + + @Override + public int getIdOffset() { + return this.offset; + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java new file mode 100644 index 000000000..ef613aa85 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java @@ -0,0 +1,31 @@ +package net.legacyfabric.fabric.impl.registry; + +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; +import net.legacyfabric.fabric.api.util.Identifier; + +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 this.id; + } + + @Override + public Identifier getIdentifier() { + return this.identifier; + } + + @Override + public T getValue() { + return this.value; + } +} 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 53052a06d..623484bae 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,6 +24,10 @@ import java.util.function.Consumer; import java.util.function.Function; +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.registry.v2.registry.registrable.RegistryEntryCreator; + import net.minecraft.nbt.NbtCompound; import net.minecraft.util.PacketByteBuf; @@ -158,6 +162,58 @@ public static T register(Registry registry, Identifier identifier, Functi return value; } + public static RegistryEntryCreator createEntryCreator(Identifier identifier, Function valueConstructor, int offset) { + return new RegistryEntryCreatorImpl<>(identifier, offset, valueConstructor); + } + + @SafeVarargs + public static List> register(Registry registry, RegistryEntryCreator... entryCreators) { + if (entryCreators.length < 1) throw new IllegalArgumentException("Can't register nothing to a registry!"); + if (registry == null) throw new IllegalArgumentException("Can't register to a null registry!"); + if (!(registry instanceof SyncedRegistrable) || !(registry instanceof SyncedRegistry)) throw new IllegalArgumentException("Can't register object to non registrable registry " + registry.fabric$getId()); + + SyncedRegistrableRegistry registrable = (SyncedRegistrableRegistry) registry; + int baseComputedId = registrable.fabric$nextId(); + + Map computedIdsMap = new HashMap<>(); + + boolean matchPredicate = false; + + while (!matchPredicate) { + for (RegistryEntryCreator creator : entryCreators) { + int offset = creator.getIdOffset(); + int offsetId = baseComputedId + offset; + + if (registrable.fabric$getValue(offsetId) == null) { + matchPredicate = true; + computedIdsMap.put(offset, offsetId); + } else { + matchPredicate = false; + computedIdsMap.clear(); + + do { + baseComputedId++; + } while (registrable.fabric$getValue(baseComputedId) != null); + + break; + } + } + } + + List> entries = new ArrayList<>(); + + for (RegistryEntryCreator creator : entryCreators) { + int computedId = computedIdsMap.get(creator.getIdOffset()); + + RegistryEntry registryEntry = new RegistryEntryImpl<>(computedId, creator.getIdentifier(), creator.getValue(computedId)); + entries.add(registryEntry); + + registrable.fabric$register(registryEntry.getId(), registryEntry.getIdentifier(), registryEntry.getValue()); + } + + return entries; + } + public static void remapRegistries() { for (RegistryRemapper remapper : REMAPPERS.values()) { remapper.remap(); 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 382757f25..19fc6afc3 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 @@ -173,30 +173,4 @@ 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 this.id; - } - - @Override - public Identifier getIdentifier() { - return this.identifier; - } - - @Override - public T getValue() { - return this.value; - } - } } From 38665026d834e9c828655ef37a573812ef9b3150 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sat, 20 Jul 2024 12:51:42 +0200 Subject: [PATCH 26/31] Fix missing ids being taken over by new entries when entering an existing world --- .../legacyfabric/fabric/impl/registry/RegistryRemapper.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 19fc6afc3..0f87d3446 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 @@ -64,6 +64,8 @@ public void dump() { LOGGER.debug("[%s] %s %s %s", this.registry.fabric$getId(), entry.getKey(), entry.getValue(), value); this.entryDump.put(entry.getKey(), entry.getValue()); }); + + this.entryDump.putAll(this.missingMap); } public NbtCompound toNbt() { @@ -105,6 +107,8 @@ public void remap() { private IdsHolder getDumpIds() { IdsHolder ids = this.registry.fabric$getIdsHolder().fabric$new(); + this.missingMap.clear(); + this.entryDump.forEach((id, rawId) -> { T value = this.registry.fabric$getValue(id); @@ -147,6 +151,8 @@ private void addNewEntries(IdsHolder newList) { .forEach(missingEntry -> { int newId = newList.fabric$nextId(); + while (this.missingMap.containsValue(newId) || newList.fabric$getValue(newId) != null) newId++; + newList.fabric$setValue(missingEntry, newId); LOGGER.info("Adding %s with numerical id %d to registry %s", this.registry.fabric$getId(missingEntry), newId, this.registry.fabric$getId()); From 32e56668590e28578b6c85b8eca6be80f672f009 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 29 Aug 2024 22:14:52 +0200 Subject: [PATCH 27/31] Fix style --- .../versioned/BiDefaultedRegistryMixin.java | 4 +-- .../versioned/BiDefaultedRegistryMixin.java | 4 +-- .../registrable/RegistryEntryCreator.java | 17 ++++++++++ .../registry/RegistryEntryCreatorImpl.java | 21 +++++++++++-- .../impl/registry/RegistryEntryImpl.java | 17 ++++++++++ .../RegistryHelperImplementation.java | 7 ++--- .../wrapper/SyncedArrayRegistryWrapper.java | 31 ++++++++++++++----- .../mixin/registry/sync/IdListMixinV2.java | 1 - 8 files changed, 83 insertions(+), 19 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java index 407cb98ab..6930c90b5 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -17,6 +17,8 @@ package net.legacyfabric.fabric.mixin.registry.sync.versioned; +import java.util.Objects; + import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -28,8 +30,6 @@ import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; -import java.util.Objects; - @Mixin(BiDefaultedRegistry.class) public abstract class BiDefaultedRegistryMixin implements SyncedRegistry, SyncedRegistrable, DesynchronizeableRegistrable { @Shadow diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java index 407cb98ab..6930c90b5 100644 --- a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -17,6 +17,8 @@ package net.legacyfabric.fabric.mixin.registry.sync.versioned; +import java.util.Objects; + import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -28,8 +30,6 @@ import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; -import java.util.Objects; - @Mixin(BiDefaultedRegistry.class) public abstract class BiDefaultedRegistryMixin implements SyncedRegistry, SyncedRegistrable, DesynchronizeableRegistrable { @Shadow diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/RegistryEntryCreator.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/RegistryEntryCreator.java index bcad2a56d..9a0c19df4 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/RegistryEntryCreator.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/RegistryEntryCreator.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.api.registry.v2.registry.registrable; import net.legacyfabric.fabric.api.util.Identifier; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryCreatorImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryCreatorImpl.java index 8930ff5fc..0c9e4f9eb 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryCreatorImpl.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryCreatorImpl.java @@ -1,10 +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.impl.registry; +import java.util.function.Function; + import net.legacyfabric.fabric.api.registry.v2.registry.registrable.RegistryEntryCreator; import net.legacyfabric.fabric.api.util.Identifier; -import java.util.function.Function; - public class RegistryEntryCreatorImpl implements RegistryEntryCreator { private final Identifier identifier; private final int offset; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java index ef613aa85..09cdd6615 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.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; import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; 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 623484bae..7989c7b3d 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,10 +24,6 @@ import java.util.function.Consumer; import java.util.function.Function; -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.registry.v2.registry.registrable.RegistryEntryCreator; - import net.minecraft.nbt.NbtCompound; import net.minecraft.util.PacketByteBuf; @@ -41,8 +37,11 @@ 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.holder.RegistryEntry; +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.Registrable; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.RegistryEntryCreator; import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.VersionUtils; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java index 3fa07d0bc..2a0ea154c 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java @@ -1,8 +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.impl.registry.wrapper; -import com.google.common.collect.BiMap; +import java.util.Iterator; +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; +import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import org.jetbrains.annotations.NotNull; import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.event.EventFactory; @@ -14,13 +36,6 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.IdsHolderImpl; -import org.jetbrains.annotations.NotNull; - -import java.util.Iterator; -import java.util.Map; -import java.util.function.Consumer; -import java.util.function.Function; - public class SyncedArrayRegistryWrapper implements SyncedRegistrableRegistry { private IdsHolder idsHolder; 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 8a7d3f42a..35170c1a1 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 @@ -18,7 +18,6 @@ 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; From 8b323b79ca66a9b88adb2de19ab786d5545cfc32 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 29 Aug 2024 22:15:22 +0200 Subject: [PATCH 28/31] Fix style and compiling errors --- .../mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java | 2 +- .../mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java | 2 +- .../net/legacyfabric/fabric/impl/registry/RegistryRemapper.java | 1 - 3 files changed, 2 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/BiDefaultedRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java index 6930c90b5..ade73e2d8 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -42,7 +42,7 @@ public abstract class BiDefaultedRegistryMixin implements SyncedRegistry)(Object) this).get(key); + V value = ((BiDefaultedRegistry) (Object) this).get(key); if (value == this.defaultValue && !Objects.equals(this.defaultKey.toString(), key.toString())) return null; diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java index 6930c90b5..ade73e2d8 100644 --- a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -42,7 +42,7 @@ public abstract class BiDefaultedRegistryMixin implements SyncedRegistry)(Object) this).get(key); + V value = ((BiDefaultedRegistry) (Object) this).get(key); if (value == this.defaultValue && !Objects.equals(this.defaultKey.toString(), key.toString())) return null; 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 0f87d3446..65353a884 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 @@ -178,5 +178,4 @@ private void invokeListeners(IdsHolder ids) { private void updateRegistry(IdsHolder ids) { this.registry.fabric$updateRegistry(ids); } - } From d5e2551d4e050f747dc76de658c408dc5af409cc Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 29 Aug 2024 22:16:19 +0200 Subject: [PATCH 29/31] Disable complex registering for now --- .../fabric/api/registry/v2/RegistryHelper.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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 b600f464d..81375fe83 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 @@ -17,11 +17,9 @@ package net.legacyfabric.fabric.api.registry.v2; -import java.util.List; import java.util.function.Function; 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.registry.v2.registry.registrable.RegistryEntryCreator; import net.legacyfabric.fabric.api.util.Identifier; @@ -97,11 +95,12 @@ public static RegistryEntryCreator createEntryCreator(Identifier identifi return createEntryCreator(identifier, value, 0); } - public static List> registerMultiple(Registry registry, RegistryEntryCreator... creators) { - return RegistryHelperImplementation.register(registry, creators); - } - - public static List> registerMultiple(Identifier registryId, RegistryEntryCreator... creators) { - return registerMultiple(RegistryHelperImplementation.getRegistry(registryId), creators); - } + // TODO Finish remapping part of it + // public static List> registerMultiple(Registry registry, RegistryEntryCreator... creators) { + // return RegistryHelperImplementation.register(registry, creators); + // } + // + // public static List> registerMultiple(Identifier registryId, RegistryEntryCreator... creators) { + // return registerMultiple(RegistryHelperImplementation.getRegistry(registryId), creators); + // } } From 3a74c69a5adc898eddc5c477119e6b3a2fd9273f Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 29 Aug 2024 22:22:26 +0200 Subject: [PATCH 30/31] Clean up registry-sync-v1 --- .../1.10.2/build.gradle | 0 .../1.10.2/gradle.properties | 2 - .../sync/RegistrySyncEarlyInitializer.java | 131 --------- .../mixin/registry/sync/BiomeAccessor.java | 29 -- .../registry/sync/BlockEntityAccessor.java | 38 --- .../mixin/registry/sync/BlockEntityMixin.java | 48 --- .../mixin/registry/sync/BlockMixin.java | 43 --- .../mixin/registry/sync/EntityMixin.java | 58 ---- .../registry/sync/EntityTypeAccessor.java | 73 ----- .../mixin/registry/sync/EntityTypeMixin.java | 99 ------- .../fabric/mixin/registry/sync/ItemMixin.java | 41 --- .../registry/sync/MutableRegistryMixin.java | 40 --- .../registry/sync/PacketByteBufMixin.java | 37 --- .../registry/sync/SimpleRegistryMixin.java | 102 ------- .../registry/sync/SpawnEggDataAccessor.java | 31 -- .../mixin/registry/sync/class_2929Mixin.java | 89 ------ .../resources/assets/legacy-fabric/icon.png | Bin 1579 -> 0 bytes .../1.10.2/src/main/resources/fabric.mod.json | 43 --- ...cy-fabric-registry-sync-api-v1.mixins.json | 25 -- .../fabric/test/registry/RegistryTest.java | 59 ---- .../src/testmod/resources/fabric.mod.json | 14 - .../1.12.2/build.gradle | 0 .../1.12.2/gradle.properties | 2 - .../sync/RegistrySyncEarlyInitializer.java | 118 -------- .../mixin/registry/sync/BiomeAccessor.java | 29 -- .../registry/sync/BlockEntityAccessor.java | 33 --- .../mixin/registry/sync/BlockMixin.java | 43 --- .../registry/sync/EntityTypeAccessor.java | 33 --- .../fabric/mixin/registry/sync/ItemMixin.java | 41 --- .../registry/sync/MutableRegistryMixin.java | 40 --- .../registry/sync/PacketByteBufMixin.java | 37 --- .../registry/sync/SimpleRegistryMixin.java | 102 ------- .../mixin/registry/sync/class_2929Mixin.java | 89 ------ .../resources/assets/legacy-fabric/icon.png | Bin 1579 -> 0 bytes .../1.12.2/src/main/resources/fabric.mod.json | 43 --- ...cy-fabric-registry-sync-api-v1.mixins.json | 21 -- .../fabric/test/registry/RegistryTest.java | 59 ---- .../src/testmod/resources/fabric.mod.json | 14 - .../1.7.10/build.gradle | 3 - .../1.7.10/gradle.properties | 2 - .../sync/RegistrySyncEarlyInitializer.java | 189 ------------ .../mixin/registry/sync/BiomeAccessor.java | 41 --- .../registry/sync/BlockEntityAccessor.java | 38 --- .../mixin/registry/sync/BlockEntityMixin.java | 48 --- .../registry/sync/EnchantmentAccessor.java | 41 --- .../mixin/registry/sync/EntityMixin.java | 58 ---- .../registry/sync/EntityTypeAccessor.java | 73 ----- .../mixin/registry/sync/EntityTypeMixin.java | 41 --- .../registry/sync/PacketByteBufMixin.java | 38 --- .../registry/sync/SimpleRegistryMixin.java | 115 -------- .../registry/sync/SpawnEggItemMixin.java | 43 --- .../registry/sync/StatusEffectAccessor.java | 36 --- .../icon.png | Bin 1579 -> 0 bytes .../1.7.10/src/main/resources/fabric.mod.json | 44 --- ...cy-fabric-registry-sync-api-v1.mixins.json | 23 -- .../main/resources/registrysync.accesswidener | 3 - .../fabric/test/registry/RegistryTest.java | 45 --- .../src/testmod/resources/fabric.mod.json | 14 - .../1.8.9/build.gradle | 0 .../1.8.9/gradle.properties | 2 - .../sync/RegistrySyncEarlyInitializer.java | 196 ------------ .../mixin/registry/sync/BiomeAccessor.java | 48 --- .../registry/sync/BlockEntityAccessor.java | 38 --- .../mixin/registry/sync/BlockEntityMixin.java | 48 --- .../mixin/registry/sync/BlockMixin.java | 43 --- .../registry/sync/EnchantmentAccessor.java | 59 ---- .../mixin/registry/sync/EntityMixin.java | 58 ---- .../registry/sync/EntityTypeAccessor.java | 73 ----- .../mixin/registry/sync/EntityTypeMixin.java | 99 ------- .../fabric/mixin/registry/sync/ItemMixin.java | 41 --- .../registry/sync/MutableRegistryMixin.java | 40 --- .../registry/sync/PacketByteBufMixin.java | 38 --- .../registry/sync/SimpleRegistryMixin.java | 102 ------- .../registry/sync/SpawnEggItemMixin.java | 43 --- .../registry/sync/StatusEffectAccessor.java | 49 --- .../icon.png | Bin 1579 -> 0 bytes .../1.8.9/src/main/resources/fabric.mod.json | 43 --- ...cy-fabric-registry-sync-api-v1.mixins.json | 26 -- .../fabric/test/registry/RegistryTest.java | 52 ---- .../src/testmod/resources/fabric.mod.json | 14 - .../1.8/build.gradle | 3 - .../1.8/gradle.properties | 2 - .../sync/RegistrySyncEarlyInitializer.java | 196 ------------ .../mixin/registry/sync/BiomeAccessor.java | 48 --- .../registry/sync/BlockEntityAccessor.java | 38 --- .../mixin/registry/sync/BlockEntityMixin.java | 48 --- .../mixin/registry/sync/BlockMixin.java | 43 --- .../registry/sync/EnchantmentAccessor.java | 58 ---- .../mixin/registry/sync/EntityMixin.java | 58 ---- .../registry/sync/EntityTypeAccessor.java | 73 ----- .../mixin/registry/sync/EntityTypeMixin.java | 99 ------- .../fabric/mixin/registry/sync/ItemMixin.java | 41 --- .../registry/sync/MutableRegistryMixin.java | 40 --- .../registry/sync/PacketByteBufMixin.java | 38 --- .../registry/sync/SimpleRegistryMixin.java | 102 ------- .../registry/sync/SpawnEggItemMixin.java | 43 --- .../registry/sync/StatusEffectAccessor.java | 49 --- .../icon.png | Bin 1579 -> 0 bytes .../1.8/src/main/resources/fabric.mod.json | 44 --- ...cy-fabric-registry-sync-api-v1.mixins.json | 26 -- .../main/resources/registrysync.accesswidener | 3 - .../fabric/test/registry/RegistryTest.java | 51 ---- .../1.8/src/testmod/resources/fabric.mod.json | 14 - .../1.9.4/build.gradle | 0 .../1.9.4/gradle.properties | 2 - .../sync/RegistrySyncEarlyInitializer.java | 131 --------- .../mixin/registry/sync/BiomeAccessor.java | 29 -- .../registry/sync/BlockEntityAccessor.java | 38 --- .../mixin/registry/sync/BlockEntityMixin.java | 48 --- .../mixin/registry/sync/BlockMixin.java | 43 --- .../mixin/registry/sync/EntityMixin.java | 58 ---- .../registry/sync/EntityTypeAccessor.java | 73 ----- .../mixin/registry/sync/EntityTypeMixin.java | 99 ------- .../fabric/mixin/registry/sync/ItemMixin.java | 41 --- .../registry/sync/MutableRegistryMixin.java | 40 --- .../registry/sync/PacketByteBufMixin.java | 37 --- .../registry/sync/SimpleRegistryMixin.java | 102 ------- .../registry/sync/SpawnEggDataAccessor.java | 31 -- .../mixin/registry/sync/class_2929Mixin.java | 89 ------ .../icon.png | Bin 1579 -> 0 bytes .../1.9.4/src/main/resources/fabric.mod.json | 43 --- ...cy-fabric-registry-sync-api-v1.mixins.json | 25 -- .../fabric/test/registry/RegistryTest.java | 59 ---- .../src/testmod/resources/fabric.mod.json | 14 - .../fabric/api/registry/v1/BiomeIds.java | 1 + .../api/registry/v1/BlockEntityTypeIds.java | 1 + .../fabric/api/registry/v1/BlockIds.java | 1 + .../api/registry/v1/EnchantmentIds.java | 1 + .../fabric/api/registry/v1/EntityTypeIds.java | 1 + .../fabric/api/registry/v1/ItemIds.java | 1 + .../registry/v1/RegistryEntryAddCallback.java | 1 + .../v1/RegistryEntryRemapCallback.java | 1 + .../api/registry/v1/RegistryHelper.java | 12 +- .../fabric/api/registry/v1/RegistryIds.java | 1 + .../api/registry/v1/StatusEffectIds.java | 1 + .../registry/sync/ClientRegistryRemapper.java | 47 --- .../registry/sync/ClientRemapInitializer.java | 48 --- .../impl/registry/RegistryHelperImpl.java | 278 ------------------ .../registry/registries/OldBiomeRegistry.java | 106 ------- .../registries/OldBlockEntityRegistry.java | 100 ------- .../registries/OldEnchantmentRegistry.java | 31 -- .../registries/OldEntityTypeRegistry.java | 224 -------------- .../registries/OldStatusEffectRegistry.java | 36 --- .../registries/ReallyOldBiomeRegistry.java | 102 ------- .../ReallyOldEnchantmentRegistry.java | 64 ---- .../ReallyOldStatusEffectRegistry.java | 63 ---- .../registries/RegistryRemapperRegistry.java | 33 --- .../registry/sync/RegistryRemapperAccess.java | 68 ----- .../registry/sync/ServerRegistryRemapper.java | 51 ---- .../registry/sync/compat/BlockCompat.java | 24 -- .../registry/sync/compat/IdListCompat.java | 37 --- .../impl/registry/sync/compat/ItemCompat.java | 27 -- .../sync/compat/PacketByteBufCompat.java | 25 -- .../sync/compat/RegistriesGetter.java | 36 --- .../sync/compat/SimpleRegistryCompat.java | 68 ----- .../sync/remappers/BiomeRegistryRemapper.java | 29 -- .../BlockEntityTypeRegistryRemapper.java | 29 -- .../sync/remappers/BlockRegistryRemapper.java | 89 ------ .../EnchantmentRegistryRemapper.java | 29 -- .../remappers/EntityTypeRegistryRemapper.java | 34 --- .../sync/remappers/ItemRegistryRemapper.java | 34 --- .../sync/remappers/RegistryRemapper.java | 260 ---------------- .../RegistryRemapperRegistryRemapper.java | 27 -- .../StatusEffectRegistryRemapper.java | 34 --- .../util/ArrayAndMapBasedRegistry.java | 146 --------- .../registry/util/ArrayBasedRegistry.java | 45 --- .../fabric/impl/registry/util/BiomePair.java | 1 + .../impl/registry/util/MapBasedRegistry.java | 119 -------- .../impl/registry/util/NumericalIdPair.java | 35 --- .../registry/util/OldRemappedRegistry.java | 70 ----- .../registry/util/RegistryEventsHolder.java | 1 + .../registry/util/VanillaLikeRegistry.java | 116 -------- .../mixin/registry/sync/IdListMixin.java | 80 ----- .../registry/sync/registry/BiomeMixin.java | 36 --- .../sync/registry/BlockEntityMixin.java | 36 --- .../sync/registry/EnchantmentMixin.java | 36 --- .../sync/registry/EntityTypeMixin.java | 36 --- .../sync/registry/StatusEffectMixin.java | 36 --- .../common/src/main/resources/fabric.mod.json | 7 +- ...ic-registry-sync-api-v1-common.mixins.json | 18 -- 180 files changed, 26 insertions(+), 8679 deletions(-) delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/build.gradle delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/gradle.properties delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java 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.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggDataAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/assets/legacy-fabric/icon.png delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java 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/build.gradle delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/gradle.properties delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.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.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/EntityTypeAccessor.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.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/assets/legacy-fabric/icon.png delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java 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/build.gradle delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/gradle.properties delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.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.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener delete mode 100644 legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java 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/build.gradle delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/gradle.properties delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.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.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/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/MutableRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java 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/build.gradle delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/gradle.properties delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.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.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/EnchantmentAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.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.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener delete mode 100644 legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java 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/build.gradle delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/gradle.properties delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.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 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/EntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.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 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggDataAccessor.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java delete mode 100644 legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/resources/fabric.mod.json delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/client/registry/sync/ClientRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/client/registry/sync/ClientRemapInitializer.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldBiomeRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldBlockEntityRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldEnchantmentRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldEntityTypeRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldStatusEffectRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldBiomeRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldEnchantmentRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldStatusEffectRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/RegistryRemapperRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistryRemapperAccess.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/ServerRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/BlockCompat.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/IdListCompat.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/ItemCompat.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/PacketByteBufCompat.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/RegistriesGetter.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/SimpleRegistryCompat.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BiomeRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BlockEntityTypeRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BlockRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/EnchantmentRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/EntityTypeRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/ItemRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/RegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/RegistryRemapperRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/StatusEffectRegistryRemapper.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/ArrayAndMapBasedRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/ArrayBasedRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/MapBasedRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/NumericalIdPair.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/OldRemappedRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/VanillaLikeRegistry.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BiomeMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockEntityMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/EnchantmentMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/EntityTypeMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/StatusEffectMixin.java delete mode 100644 legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/build.gradle b/legacy-fabric-registry-sync-api-v1/1.10.2/build.gradle deleted file mode 100644 index e69de29bb..000000000 diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/gradle.properties b/legacy-fabric-registry-sync-api-v1/1.10.2/gradle.properties deleted file mode 100644 index 2108465ed..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -minVersionExcluded=1.9.4 -maxVersionIncluded=1.10.2 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 deleted file mode 100644 index 6e5e698e2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ /dev/null @@ -1,131 +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.impl.registry.sync; - -import java.util.Map; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; - -import net.minecraft.block.Block; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.item.Item; -import net.minecraft.util.Identifier; -import net.minecraft.world.biome.Biome; - -import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; - -import net.legacyfabric.fabric.api.registry.v1.RegistryEntryAddCallback; -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; - -public class RegistrySyncEarlyInitializer implements PreLaunchEntrypoint { - private static SimpleRegistryCompat> BLOCK_ENTITY_REGISTRY; - private static OldRemappedRegistry> ENTITY_TYPE_REGISTRY; - - @Override - public void onPreLaunch() { - RegistryHelperImpl.registriesGetter = new RegistriesGetter() { - @Override - public SimpleRegistryCompat getBlockRegistry() { - return (SimpleRegistryCompat) Block.REGISTRY; - } - - @Override - public SimpleRegistryCompat getItemRegistry() { - return (SimpleRegistryCompat) Item.REGISTRY; - } - - @Override - public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } - - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; - } - - @Override - public SimpleRegistryCompat getStatusEffectRegistry() { - return (SimpleRegistryCompat) StatusEffect.REGISTRY; - } - - @Override - public SimpleRegistryCompat getEnchantmentRegistry() { - return (SimpleRegistryCompat) Enchantment.REGISTRY; - } - - @Override - public SimpleRegistryCompat getBiomeRegistry() { - return (SimpleRegistryCompat) Biome.REGISTRY; - } - - @Override - public SimpleRegistryCompat> getEntityTypeRegistry() { - if (ENTITY_TYPE_REGISTRY == null) { - BiMap> NAME_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_CLASS_MAP()); - EntityTypeAccessor.setNAME_CLASS_MAP(NAME_CLASS_MAP); - EntityTypeAccessor.setCLASS_NAME_MAP(NAME_CLASS_MAP.inverse()); - - BiMap> ID_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getID_CLASS_MAP()); - EntityTypeAccessor.setID_CLASS_MAP(ID_CLASS_MAP); - EntityTypeAccessor.setCLASS_ID_MAP(ID_CLASS_MAP.inverse()); - - BiMap NAME_ID_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_ID_MAP()); - EntityTypeAccessor.setNAME_ID_MAP(NAME_ID_MAP); - - ENTITY_TYPE_REGISTRY = new OldEntityTypeRegistry(NAME_CLASS_MAP, ID_CLASS_MAP, NAME_ID_MAP); - } - - return (SimpleRegistryCompat>) ENTITY_TYPE_REGISTRY; - } - }; - - RegistryHelper.onRegistryInitialized(RegistryIds.BIOMES).register(() -> { - RegistryEntryAddCallback.event(RegistryIds.BIOMES).register((rawId, id, biome) -> { - if (biome.isMutatedBiome()) { - Biome.biomeList.set(biome, Biome.getBiomeIndex(Biome.REGISTRY.get(new Identifier(((BiomeAccessor) biome).getParent())))); - } - }); - }); - - RegistryHelper.onRegistryInitialized(RegistryIds.ENTITY_TYPES).register(() -> { - for (Map.Entry entry : EntityTypeAccessor.getNAME_ID_MAP().entrySet()) { - if (EntityType.SPAWN_EGGS.containsKey(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey()))) { - EntityType.SpawnEggData data = EntityType.SPAWN_EGGS.remove(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey())); - ((SpawnEggDataAccessor) data).setName(entry.getKey()); - EntityType.SPAWN_EGGS.put(entry.getKey(), data); - } - } - }); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java deleted file mode 100644 index 5cf98a69d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java +++ /dev/null @@ -1,29 +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.world.biome.Biome; - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor - String getParent(); -} 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/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/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java deleted file mode 100644 index 335f5c36f..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java +++ /dev/null @@ -1,58 +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.entity.Entity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(Entity.class) -public class EntityMixin { - @ModifyArg(method = "getTranslationKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/CommonI18n;translate(Ljava/lang/String;)Ljava/lang/String;")) - private String remapTranslationKey(String key) { - String newKey = key; - - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - if (key.contains("minecraft:")) { - String entityId = key.replace("entity.", "").replace(".name", ""); - - newKey = "entity." + registry.getOldKey(entityId) + ".name"; - } else if (key.contains(":")) { - newKey = key.replace(":", "."); - } - - return newKey; - } - - @ModifyArg(method = {"saveSelfToNbt", "saveToNbt"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java deleted file mode 100644 index 3880c4ca2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java +++ /dev/null @@ -1,73 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Mutable - @Accessor - static Map> getNAME_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setNAME_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_NAME_MAP(Map, String> map) { - } - - @Mutable - @Accessor - static Map> getID_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setID_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_ID_MAP(Map, Integer> map) { - } - - @Mutable - @Accessor - static Map getNAME_ID_MAP() { - return null; - } - - @Mutable - @Accessor - static void setNAME_ID_MAP(Map map) { - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java deleted file mode 100644 index 5f7ceed05..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java +++ /dev/null @@ -1,99 +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.List; - -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.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LightningBoltEntity; -import net.minecraft.entity.player.PlayerEntity; - -import net.legacyfabric.fabric.api.registry.v1.EntityTypeIds; -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(EntityType.class) -public abstract class EntityTypeMixin { - @Shadow - public static String getEntityName(Entity entity) { - return null; - } - - @ModifyArg(method = {"createInstanceFromName", "createInstanceFromNbt", "getIdByName"}, - at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;", remap = false)) - private static Object remap$createInstanceFromName(Object key) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - return registry.getNewKey(key.toString()); - } - - @Inject(method = "getEntityNames", at = @At("RETURN")) - private static void remap$getEntityNames(CallbackInfoReturnable> cir) { - List list = cir.getReturnValue(); - list.remove("LightningBolt"); - list.add(EntityTypeIds.LIGHTNING_BOLT.toString()); - } - - @Inject(method = "equals", at = @At("RETURN"), cancellable = true) - private static void remap$equals(Entity entity, String string, CallbackInfoReturnable cir) { - if (!cir.getReturnValue()) { - String string2 = getEntityName(entity); - - if (string2 == null) { - if (entity instanceof PlayerEntity) { - string2 = EntityTypeIds.PLAYER.toString(); - } else { - if (!(entity instanceof LightningBoltEntity)) { - cir.setReturnValue(false); - } - - string2 = EntityTypeIds.LIGHTNING_BOLT.toString(); - } - } - - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - cir.setReturnValue(registry.getNewKey(string).equals(string2)); - } - } - - @ModifyArg(method = "isEntityRegistered", at = @At(value = "INVOKE", target = "Ljava/util/List;contains(Ljava/lang/Object;)Z", remap = false)) - private static Object remap$isEntityRegistered(Object key) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - return registry.getNewKey(key.toString()); - } - - @Inject(method = "isEntityRegistered", cancellable = true, at = @At("RETURN")) - private static void remap$isEntityRegistered(String name, CallbackInfoReturnable cir) { - if (!cir.getReturnValue()) { - cir.setReturnValue(name.equals(EntityTypeIds.PLAYER.toString())); - } - } -} 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-registry-sync-api-v1/1.10.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.10.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.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java deleted file mode 100644 index 4475180c2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java +++ /dev/null @@ -1,40 +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.util.registry.MutableRegistry; - -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -@Mixin(MutableRegistry.class) -public abstract class MutableRegistryMixin implements SimpleRegistryCompat { - @Shadow - @Final - protected Map map; - - @Override - public V getValue(Object key) { - return this.map.get(this.toKeyType(key)); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java deleted file mode 100644 index 30b30ca2c..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java +++ /dev/null @@ -1,37 +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.Shadow; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.PacketByteBuf; - -import net.legacyfabric.fabric.impl.registry.sync.compat.PacketByteBufCompat; - -@Mixin(PacketByteBuf.class) -public abstract class PacketByteBufMixin implements PacketByteBufCompat { - @Shadow - public abstract PacketByteBuf writeNbtCompound(NbtCompound par1); - - @Override - public PacketByteBuf writeCompound(NbtCompound compound) { - return this.writeNbtCompound(compound); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java deleted file mode 100644 index f85602e03..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java +++ /dev/null @@ -1,102 +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.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.class_2929; -import net.minecraft.util.registry.SimpleRegistry; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; -import net.legacyfabric.fabric.impl.registry.util.RegistryEventsHolder; - -@Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements SimpleRegistryCompat { - @Shadow - @Final - protected Map objects; - - @Mutable - @Shadow - @Final - protected class_2929 field_13718; - private RegistryEventsHolder registryEventsHolder; - - @Shadow - public abstract int getRawId(Object par1); - - @Shadow - public abstract K getIdentifier(V id); - - @Shadow - public abstract void add(int id, K identifier, V object); - - @Override - public IdListCompat getIds() { - return (IdListCompat) this.field_13718; - } - - @Override - public Map getObjects() { - return this.objects; - } - - @Override - public void setIds(IdListCompat idList) { - this.field_13718 = (class_2929) idList; - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new class_2929(256); - } - - @Override - public int getRawID(V object) { - return this.getRawId(object); - } - - @Override - public K getKey(V object) { - return this.getIdentifier(object); - } - - @Override - public V register(int i, Object key, V value) { - this.add(i, this.toKeyType(key), value); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(i, new Identifier(key), value); - return value; - } - - @Override - public RegistryEventsHolder getEventHolder() { - return this.registryEventsHolder; - } - - @Override - public void setEventHolder(RegistryEventsHolder registryEventsHolder) { - this.registryEventsHolder = registryEventsHolder; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggDataAccessor.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggDataAccessor.java deleted file mode 100644 index 5ca5d86af..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggDataAccessor.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 org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.EntityType; - -@Mixin(EntityType.SpawnEggData.class) -public interface SpawnEggDataAccessor { - @Mutable - @Accessor - void setName(String name); -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java deleted file mode 100644 index 408e79a2a..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java +++ /dev/null @@ -1,89 +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.IdentityHashMap; -import java.util.List; - -import com.google.common.collect.Lists; -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.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -@Mixin(class_2929.class) -public abstract class class_2929Mixin implements IdListCompat { - @Shadow - public abstract void add(V object, int i); - - @Shadow - @Nullable - public abstract V getById(int i); - - @Shadow - public abstract int getId(V object); - - @Shadow - private V[] field_14375; - - @Override - public IdentityHashMap getIdMap(SimpleRegistryCompat simpleRegistry) { - IdentityHashMap idMap = new IdentityHashMap<>(512); - - for (int i = 0; i < this.field_14375.length; i++) { - V value = this.field_14375[i]; - - if (value == null) { - continue; - } - - idMap.put(value, i); - } - - return idMap; - } - - @Override - public List getList() { - return Lists.newArrayList(this.field_14375); - } - - @Override - public V fromInt(int index) { - return this.getById(index); - } - - @Override - public void setValue(V value, int index) { - this.add(value, index); - } - - @Override - public int getInt(V value) { - return this.getId(value); - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new class_2929(256); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/assets/legacy-fabric/icon.png b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/assets/legacy-fabric/icon.png deleted file mode 100644 index 2931efbf610873c0084debb8690902b0103d27fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1579 zcmbVMTWB0r7@iGm)TAXsYw<=rnU=;v=W=GRbL=!tc4Brl6GO7t2vVJ$IlDV#XU;e? z+r2ymsZdMQqAyaFLLUo;RumtE8Z@?uf_*4nP^4;o6fOFoSkN+o1$K?f2nE9_*b5G-l)AV)k5Qhb^- zU{V4ZnTKgnmXdpcB*Kg!W(1hvM2N&RO30x1u~eI9meGQGe@_?PDQq%q1CiV$8~M7 z?MQ_mOdqCh^a65Sv|ntwSXjV5se1;VK1|Kr8G7TQoQL&*ctt{L{fClG}xPK5k^yK3%T69N6J=>3jBqc zDNvZsrJ-yOXI^^mWf1cmY^XST)CVzIGjvEPENowmy}ax zvJ8_(Cf#+H-dBlH53`_u-~6BVAMz|(g?jCVdBWNZ(+A}(pFV7>S3QgPiQcMaflkIC z-3Ti|VT~{au*vq0ts9O&m$p&Gl=L6+q6_m$IcVq}o~+Pl{g>1esQp4%wp~|*zk1n` zZ7T6Toc4`y88s}riCP|ZXrJ?FLz@^KTcyqLjey zu95Yz%F&S{<0~f)Iomek?+hQ%MhCu%T^zsg>C_L`1`Br`xNY&))k9yTQb$JC>)w_f zpU(^tu^Q)y%W~lVz`jz;_ jF?g&s@Y=Qe&c#kW|JbvqK0Y=Rw)4XDoVqsk_>;c_`@;F@ diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/fabric.mod.json deleted file mode 100644 index c4d681021..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync 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": "Registry hooks", - "entrypoints": { - "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" - ] - }, - "mixins": [ - "legacy-fabric-registry-sync-api-v1.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-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 deleted file mode 100644 index fb5274ab6..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "class_2929Mixin", - "BlockMixin", - "ItemMixin", - "PacketByteBufMixin", - "MutableRegistryMixin", - "BlockEntityAccessor", - "BlockEntityMixin", - "BiomeAccessor", - "EntityTypeAccessor", - "EntityTypeMixin", - "EntityMixin", - "SpawnEggDataAccessor" - ], - "client": [ - ] -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java deleted file mode 100644 index 3d72858aa..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ /dev/null @@ -1,59 +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.test.registry; - -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.v1.RegistryHelper; -import net.legacyfabric.fabric.api.resource.ItemModelRegistry; -import net.legacyfabric.fabric.api.util.Identifier; - -public class RegistryTest implements ModInitializer { - @Override - public void onInitialize() { - 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")); - ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); - } -} 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/build.gradle b/legacy-fabric-registry-sync-api-v1/1.12.2/build.gradle deleted file mode 100644 index e69de29bb..000000000 diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/gradle.properties b/legacy-fabric-registry-sync-api-v1/1.12.2/gradle.properties deleted file mode 100644 index a104a3a86..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -minVersionExcluded=1.10.2 -maxVersionIncluded=1.12.2 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 deleted file mode 100644 index 45221b48a..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ /dev/null @@ -1,118 +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.impl.registry.sync; - -import net.minecraft.block.Block; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.item.Item; -import net.minecraft.util.Identifier; -import net.minecraft.world.biome.Biome; - -import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; - -import net.legacyfabric.fabric.api.registry.v1.RegistryEntryAddCallback; -import net.legacyfabric.fabric.api.registry.v1.RegistryEntryRemapCallback; -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.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 { - @Override - public void onPreLaunch() { - RegistryHelperImpl.registriesGetter = new RegistriesGetter() { - @Override - public SimpleRegistryCompat getBlockRegistry() { - return (SimpleRegistryCompat) Block.REGISTRY; - } - - @Override - public SimpleRegistryCompat getItemRegistry() { - return (SimpleRegistryCompat) Item.REGISTRY; - } - - @Override - public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - return (SimpleRegistryCompat>) BlockEntityAccessor.getBLOCK_ENTITY(); - } - - @Override - public SimpleRegistryCompat getStatusEffectRegistry() { - return (SimpleRegistryCompat) StatusEffect.REGISTRY; - } - - @Override - public SimpleRegistryCompat getEnchantmentRegistry() { - return (SimpleRegistryCompat) Enchantment.REGISTRY; - } - - @Override - public SimpleRegistryCompat getBiomeRegistry() { - return (SimpleRegistryCompat) Biome.REGISTRY; - } - - @Override - public SimpleRegistryCompat> getEntityTypeRegistry() { - return (SimpleRegistryCompat>) EntityType.REGISTRY; - } - }; - - RegistryHelper.onRegistryInitialized(RegistryIds.BIOMES).register(() -> { - RegistryEntryAddCallback.event(RegistryIds.BIOMES).register((rawId, id, biome) -> { - if (biome.isMutatedBiome()) { - Biome.biomeList.set(biome, Biome.getBiomeIndex(Biome.REGISTRY.get(new Identifier(((BiomeAccessor) biome).getParent())))); - } - }); - }); - - RegistryHelper.onRegistryInitialized(RegistryIds.ENTITY_TYPES).register(() -> { - RegistryEntryAddCallback.>event(RegistryIds.ENTITY_TYPES).register((rawId, key, object) -> { - EntityType.IDENTIFIERS.add(new Identifier(key.toString())); - - while (EntityTypeAccessor.getNAMES().size() <= rawId) { - EntityTypeAccessor.getNAMES().add(null); - } - - EntityTypeAccessor.getNAMES().set(rawId, key.getNamespace() + "." + key.getPath()); - }); - - RegistryEntryRemapCallback.>event(RegistryIds.ENTITY_TYPES).register((oldId, newId, key, object) -> { - while (EntityTypeAccessor.getNAMES().size() <= oldId || EntityTypeAccessor.getNAMES().size() <= newId) { - EntityTypeAccessor.getNAMES().add(null); - } - - String name = EntityTypeAccessor.getNAMES().get(oldId); - - if (name.isEmpty()) { - name = key.getNamespace() + "." + key.getPath(); - } - - EntityTypeAccessor.getNAMES().set(oldId, null); - EntityTypeAccessor.getNAMES().set(newId, name); - }); - }); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java deleted file mode 100644 index 5cf98a69d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java +++ /dev/null @@ -1,29 +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.world.biome.Biome; - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor - String getParent(); -} 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/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/EntityTypeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java deleted file mode 100644 index 0f96333a5..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.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 java.util.List; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.EntityType; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Accessor - static List getNAMES() { - return null; - } -} 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/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java deleted file mode 100644 index 4475180c2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java +++ /dev/null @@ -1,40 +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.util.registry.MutableRegistry; - -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -@Mixin(MutableRegistry.class) -public abstract class MutableRegistryMixin implements SimpleRegistryCompat { - @Shadow - @Final - protected Map map; - - @Override - public V getValue(Object key) { - return this.map.get(this.toKeyType(key)); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java deleted file mode 100644 index 30b30ca2c..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java +++ /dev/null @@ -1,37 +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.Shadow; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.PacketByteBuf; - -import net.legacyfabric.fabric.impl.registry.sync.compat.PacketByteBufCompat; - -@Mixin(PacketByteBuf.class) -public abstract class PacketByteBufMixin implements PacketByteBufCompat { - @Shadow - public abstract PacketByteBuf writeNbtCompound(NbtCompound par1); - - @Override - public PacketByteBuf writeCompound(NbtCompound compound) { - return this.writeNbtCompound(compound); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java deleted file mode 100644 index f85602e03..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java +++ /dev/null @@ -1,102 +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.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.class_2929; -import net.minecraft.util.registry.SimpleRegistry; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; -import net.legacyfabric.fabric.impl.registry.util.RegistryEventsHolder; - -@Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements SimpleRegistryCompat { - @Shadow - @Final - protected Map objects; - - @Mutable - @Shadow - @Final - protected class_2929 field_13718; - private RegistryEventsHolder registryEventsHolder; - - @Shadow - public abstract int getRawId(Object par1); - - @Shadow - public abstract K getIdentifier(V id); - - @Shadow - public abstract void add(int id, K identifier, V object); - - @Override - public IdListCompat getIds() { - return (IdListCompat) this.field_13718; - } - - @Override - public Map getObjects() { - return this.objects; - } - - @Override - public void setIds(IdListCompat idList) { - this.field_13718 = (class_2929) idList; - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new class_2929(256); - } - - @Override - public int getRawID(V object) { - return this.getRawId(object); - } - - @Override - public K getKey(V object) { - return this.getIdentifier(object); - } - - @Override - public V register(int i, Object key, V value) { - this.add(i, this.toKeyType(key), value); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(i, new Identifier(key), value); - return value; - } - - @Override - public RegistryEventsHolder getEventHolder() { - return this.registryEventsHolder; - } - - @Override - public void setEventHolder(RegistryEventsHolder registryEventsHolder) { - this.registryEventsHolder = registryEventsHolder; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java deleted file mode 100644 index 408e79a2a..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java +++ /dev/null @@ -1,89 +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.IdentityHashMap; -import java.util.List; - -import com.google.common.collect.Lists; -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.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -@Mixin(class_2929.class) -public abstract class class_2929Mixin implements IdListCompat { - @Shadow - public abstract void add(V object, int i); - - @Shadow - @Nullable - public abstract V getById(int i); - - @Shadow - public abstract int getId(V object); - - @Shadow - private V[] field_14375; - - @Override - public IdentityHashMap getIdMap(SimpleRegistryCompat simpleRegistry) { - IdentityHashMap idMap = new IdentityHashMap<>(512); - - for (int i = 0; i < this.field_14375.length; i++) { - V value = this.field_14375[i]; - - if (value == null) { - continue; - } - - idMap.put(value, i); - } - - return idMap; - } - - @Override - public List getList() { - return Lists.newArrayList(this.field_14375); - } - - @Override - public V fromInt(int index) { - return this.getById(index); - } - - @Override - public void setValue(V value, int index) { - this.add(value, index); - } - - @Override - public int getInt(V value) { - return this.getId(value); - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new class_2929(256); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/assets/legacy-fabric/icon.png b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/assets/legacy-fabric/icon.png deleted file mode 100644 index 2931efbf610873c0084debb8690902b0103d27fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1579 zcmbVMTWB0r7@iGm)TAXsYw<=rnU=;v=W=GRbL=!tc4Brl6GO7t2vVJ$IlDV#XU;e? z+r2ymsZdMQqAyaFLLUo;RumtE8Z@?uf_*4nP^4;o6fOFoSkN+o1$K?f2nE9_*b5G-l)AV)k5Qhb^- zU{V4ZnTKgnmXdpcB*Kg!W(1hvM2N&RO30x1u~eI9meGQGe@_?PDQq%q1CiV$8~M7 z?MQ_mOdqCh^a65Sv|ntwSXjV5se1;VK1|Kr8G7TQoQL&*ctt{L{fClG}xPK5k^yK3%T69N6J=>3jBqc zDNvZsrJ-yOXI^^mWf1cmY^XST)CVzIGjvEPENowmy}ax zvJ8_(Cf#+H-dBlH53`_u-~6BVAMz|(g?jCVdBWNZ(+A}(pFV7>S3QgPiQcMaflkIC z-3Ti|VT~{au*vq0ts9O&m$p&Gl=L6+q6_m$IcVq}o~+Pl{g>1esQp4%wp~|*zk1n` zZ7T6Toc4`y88s}riCP|ZXrJ?FLz@^KTcyqLjey zu95Yz%F&S{<0~f)Iomek?+hQ%MhCu%T^zsg>C_L`1`Br`xNY&))k9yTQb$JC>)w_f zpU(^tu^Q)y%W~lVz`jz;_ jF?g&s@Y=Qe&c#kW|JbvqK0Y=Rw)4XDoVqsk_>;c_`@;F@ diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/fabric.mod.json deleted file mode 100644 index c4d681021..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync 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": "Registry hooks", - "entrypoints": { - "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" - ] - }, - "mixins": [ - "legacy-fabric-registry-sync-api-v1.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-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 deleted file mode 100644 index 28dbfae1b..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "class_2929Mixin", - "BlockMixin", - "ItemMixin", - "PacketByteBufMixin", - "MutableRegistryMixin", - "BlockEntityAccessor", - "BiomeAccessor", - "EntityTypeAccessor" - ], - "client": [ - ] -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java deleted file mode 100644 index 3d72858aa..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ /dev/null @@ -1,59 +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.test.registry; - -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.v1.RegistryHelper; -import net.legacyfabric.fabric.api.resource.ItemModelRegistry; -import net.legacyfabric.fabric.api.util.Identifier; - -public class RegistryTest implements ModInitializer { - @Override - public void onInitialize() { - 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")); - ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); - } -} 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/build.gradle b/legacy-fabric-registry-sync-api-v1/1.7.10/build.gradle deleted file mode 100644 index 5058a1900..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -loom { - accessWidenerPath = file("src/main/resources/registrysync.accesswidener") -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/gradle.properties b/legacy-fabric-registry-sync-api-v1/1.7.10/gradle.properties deleted file mode 100644 index c01c52c6b..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -minVersionIncluded=1.7 -maxVersionIncluded=1.7.10 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 deleted file mode 100644 index 376d9e10d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ /dev/null @@ -1,189 +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.impl.registry.sync; - -import java.util.ArrayList; -import java.util.List; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; - -import net.minecraft.block.Block; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.Entity; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.item.Item; -import net.minecraft.world.biome.Biome; - -import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; - -import net.legacyfabric.fabric.api.registry.v1.RegistryEntryRemapCallback; -import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; -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; -import net.legacyfabric.fabric.impl.registry.registries.ReallyOldStatusEffectRegistry; -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.EnchantmentAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.EntityTypeAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.StatusEffectAccessor; - -public class RegistrySyncEarlyInitializer implements PreLaunchEntrypoint { - private static SimpleRegistryCompat> BLOCK_ENTITY_REGISTRY; - private static SimpleRegistryCompat STATUS_EFFECT_REGISTRY; - private static SimpleRegistryCompat ENCHANTMENT_REGISTRY; - private static SimpleRegistryCompat BIOME_REGISTRY; - private static OldRemappedRegistry> ENTITY_TYPE_REGISTRY; - - @Override - public void onPreLaunch() { - RegistryHelperImpl.registriesGetter = new RegistriesGetter() { - @Override - public SimpleRegistryCompat getBlockRegistry() { - return (SimpleRegistryCompat) Block.REGISTRY; - } - - @Override - public SimpleRegistryCompat getItemRegistry() { - return (SimpleRegistryCompat) Item.REGISTRY; - } - - @Override - public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } - - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; - } - - @Override - public SimpleRegistryCompat getStatusEffectRegistry() { - if (STATUS_EFFECT_REGISTRY == null) { - STATUS_EFFECT_REGISTRY = new ReallyOldStatusEffectRegistry(StatusEffect.STATUS_EFFECTS) { - @Override - public void updateArray() { - StatusEffectAccessor.setSTATUS_EFFECTS(this.getArray()); - } - }; - } - - return (SimpleRegistryCompat) STATUS_EFFECT_REGISTRY; - } - - @Override - public SimpleRegistryCompat getEnchantmentRegistry() { - if (ENCHANTMENT_REGISTRY == null) { - ENCHANTMENT_REGISTRY = new ReallyOldEnchantmentRegistry(Enchantment.ALL_ENCHANTMENTS) { - @Override - public void updateArray() { - EnchantmentAccessor.setALL_ENCHANTMENTS(this.getArray()); - - List enchantments = new ArrayList<>(); - - for (Enchantment enchantment : Enchantment.ALL_ENCHANTMENTS) { - if (enchantment != null) { - enchantments.add(enchantment); - } - } - - EnchantmentAccessor.setField_5457(enchantments.toArray(new Enchantment[0])); - } - }; - } - - return (SimpleRegistryCompat) ENCHANTMENT_REGISTRY; - } - - @Override - public SimpleRegistryCompat getBiomeRegistry() { - if (BIOME_REGISTRY == null) { - BIOME_REGISTRY = new ReallyOldBiomeRegistry(BiomeAccessor.getBIOMES()) { - @Override - public void updateArray() { - BiomeAccessor.setBIOMES(this.getArray()); - } - }; - } - - return (SimpleRegistryCompat) BIOME_REGISTRY; - } - - @Override - public SimpleRegistryCompat> getEntityTypeRegistry() { - if (ENTITY_TYPE_REGISTRY == null) { - BiMap> NAME_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_CLASS_MAP()); - EntityTypeAccessor.setNAME_CLASS_MAP(NAME_CLASS_MAP); - EntityTypeAccessor.setCLASS_NAME_MAP(NAME_CLASS_MAP.inverse()); - - BiMap> ID_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getID_CLASS_MAP()); - EntityTypeAccessor.setID_CLASS_MAP(ID_CLASS_MAP); - EntityTypeAccessor.setCLASS_ID_MAP(ID_CLASS_MAP.inverse()); - - BiMap NAME_ID_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_ID_MAP()); - EntityTypeAccessor.setNAME_ID_MAP(NAME_ID_MAP); - - ENTITY_TYPE_REGISTRY = new OldEntityTypeRegistry(NAME_CLASS_MAP, ID_CLASS_MAP, NAME_ID_MAP); - } - - return (SimpleRegistryCompat>) ENTITY_TYPE_REGISTRY; - } - }; - - RegistryHelper.onRegistryInitialized(RegistryIds.BIOMES).register(() -> { - RegistryEntryRemapCallback.event(RegistryIds.BIOMES).register((oldId, newId, key, biome) -> { - if (biome.id != newId) { - ((BiomeAccessor) biome).setId(newId); - } - }); - }); - - RegistryHelper.onRegistryInitialized(RegistryIds.ENCHANTMENTS).register(() -> { - RegistryEntryRemapCallback.event(RegistryIds.ENCHANTMENTS).register((oldId, newId, key, enchantment) -> { - if (enchantment.id != newId) { - ((EnchantmentAccessor) enchantment).setId(newId); - } - }); - }); - - RegistryHelper.onRegistryInitialized(RegistryIds.STATUS_EFFECTS).register(() -> { - RegistryEntryRemapCallback.event(RegistryIds.STATUS_EFFECTS).register((oldId, newId, key, statusEffect) -> { - if (statusEffect.id != newId) { - ((StatusEffectAccessor) statusEffect).setId(newId); - } - }); - }); - - // RegistryHelper.onRegistryInitialized(RegistryIds.ENTITY_TYPES).register(() -> { - // for (Map.Entry entry : EntityTypeAccessor.getNAME_ID_MAP().entrySet()) { - // if (EntityType.SPAWN_EGGS.containsKey(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey()))) { - // EntityType.SPAWN_EGGS.put(entry.getKey(), EntityType.SPAWN_EGGS.remove(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey()))); - // } - // } - // }); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java deleted file mode 100644 index cdff0c76c..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.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 org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.world.biome.Biome; - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor - static Biome[] getBIOMES() { - return new Biome[0]; - } - - @Mutable - @Accessor - static void setBIOMES(Biome[] biomes) { - } - - @Mutable - @Accessor - void setId(int id); -} 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/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.java deleted file mode 100644 index 00e555796..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.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 org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.enchantment.Enchantment; - -@Mixin(Enchantment.class) -public interface EnchantmentAccessor { - @Mutable - @Accessor - static void setALL_ENCHANTMENTS(Enchantment[] enchantments) { - } - - @Mutable - @Accessor - static void setField_5457(Enchantment[] enchantments) { - } - - @Mutable - @Accessor - void setId(int id); -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java deleted file mode 100644 index 335f5c36f..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java +++ /dev/null @@ -1,58 +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.entity.Entity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(Entity.class) -public class EntityMixin { - @ModifyArg(method = "getTranslationKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/CommonI18n;translate(Ljava/lang/String;)Ljava/lang/String;")) - private String remapTranslationKey(String key) { - String newKey = key; - - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - if (key.contains("minecraft:")) { - String entityId = key.replace("entity.", "").replace(".name", ""); - - newKey = "entity." + registry.getOldKey(entityId) + ".name"; - } else if (key.contains(":")) { - newKey = key.replace(":", "."); - } - - return newKey; - } - - @ModifyArg(method = {"saveSelfToNbt", "saveToNbt"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java deleted file mode 100644 index 0be3513a6..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java +++ /dev/null @@ -1,73 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Mutable - @Accessor - static Map> getNAME_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setNAME_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_NAME_MAP(Map, String> map) { - } - - @Mutable - @Accessor - static Map> getID_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setID_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_ID_MAP(Map, Integer> map) { - } - - @Mutable - @Accessor("field_3272") - static Map getNAME_ID_MAP() { - return null; - } - - @Mutable - @Accessor("field_3272") - static void setNAME_ID_MAP(Map map) { - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java deleted file mode 100644 index 7ad175b6b..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.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 org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(EntityType.class) -public abstract class EntityTypeMixin { - @ModifyArg(method = {"createInstanceFromName", "createInstanceFromNbt"}, - at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;", remap = false)) - private static Object remap$createInstanceFromName(Object key) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - return registry.getNewKey(key.toString()); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java deleted file mode 100644 index 4a0a4298d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.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 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.registry.sync.compat.PacketByteBufCompat; - -@Mixin(PacketByteBuf.class) -public abstract class PacketByteBufMixin implements PacketByteBufCompat { - @Shadow - public abstract void writeNbtCompound(NbtCompound nbt); - - @Override - public PacketByteBuf writeCompound(NbtCompound compound) { - this.writeNbtCompound(compound); - return (PacketByteBuf) (Object) this; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java deleted file mode 100644 index 7a1b5368a..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java +++ /dev/null @@ -1,115 +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.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.util.collection.IdList; -import net.minecraft.util.registry.SimpleRegistry; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; -import net.legacyfabric.fabric.impl.registry.util.RegistryEventsHolder; - -@Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements SimpleRegistryCompat { - @Mutable - @Shadow - @Final - protected IdList ids; - - @Shadow - @Final - protected Map objects; - private RegistryEventsHolder registryEventsHolder; - - @Shadow - public abstract Object get(String par1); - - @Shadow - public abstract int getRawId(Object object); - - @Shadow - public abstract String getId(Object object); - - @Shadow - public abstract void add(int rawId, String id, Object object); - - @Override - public IdListCompat getIds() { - return (IdListCompat) this.ids; - } - - @Override - public Map getObjects() { - return this.objects; - } - - @Override - public void setIds(IdListCompat idList) { - this.ids = (IdList) idList; - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new IdList(); - } - - @Override - public int getRawID(V object) { - return this.getRawId(object); - } - - @Override - public K getKey(V object) { - return (K) this.getId(object); - } - - @Override - public V getValue(Object key) { - return (V) this.get((String) this.toKeyType(key)); - } - - @Override - public V register(int i, Object key, V value) { - this.add(i, (String) this.toKeyType(key), value); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(i, new Identifier(key), value); - return value; - } - - @Override - public KeyType getKeyType() { - return KeyType.JAVA; - } - - @Override - public RegistryEventsHolder getEventHolder() { - return this.registryEventsHolder; - } - - @Override - public void setEventHolder(RegistryEventsHolder registryEventsHolder) { - this.registryEventsHolder = registryEventsHolder; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.java deleted file mode 100644 index 557e1b71b..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.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.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.item.SpawnEggItem; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(SpawnEggItem.class) -public class SpawnEggItemMixin { - @Redirect(method = "getDisplayName", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;getEntityName(I)Ljava/lang/String;")) - private String saveAsVanillaId(int id) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - if (remapper == null) return EntityType.getEntityName(id); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - return registry.getOldKey(EntityType.getEntityName(id)); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java deleted file mode 100644 index aab241c2c..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java +++ /dev/null @@ -1,36 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.effect.StatusEffect; - -@Mixin(StatusEffect.class) -public interface StatusEffectAccessor { - @Mutable - @Accessor - static void setSTATUS_EFFECTS(StatusEffect[] effects) { - } - - @Mutable - @Accessor - void setId(int id); -} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png deleted file mode 100644 index 2931efbf610873c0084debb8690902b0103d27fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1579 zcmbVMTWB0r7@iGm)TAXsYw<=rnU=;v=W=GRbL=!tc4Brl6GO7t2vVJ$IlDV#XU;e? z+r2ymsZdMQqAyaFLLUo;RumtE8Z@?uf_*4nP^4;o6fOFoSkN+o1$K?f2nE9_*b5G-l)AV)k5Qhb^- zU{V4ZnTKgnmXdpcB*Kg!W(1hvM2N&RO30x1u~eI9meGQGe@_?PDQq%q1CiV$8~M7 z?MQ_mOdqCh^a65Sv|ntwSXjV5se1;VK1|Kr8G7TQoQL&*ctt{L{fClG}xPK5k^yK3%T69N6J=>3jBqc zDNvZsrJ-yOXI^^mWf1cmY^XST)CVzIGjvEPENowmy}ax zvJ8_(Cf#+H-dBlH53`_u-~6BVAMz|(g?jCVdBWNZ(+A}(pFV7>S3QgPiQcMaflkIC z-3Ti|VT~{au*vq0ts9O&m$p&Gl=L6+q6_m$IcVq}o~+Pl{g>1esQp4%wp~|*zk1n` zZ7T6Toc4`y88s}riCP|ZXrJ?FLz@^KTcyqLjey zu95Yz%F&S{<0~f)Iomek?+hQ%MhCu%T^zsg>C_L`1`Br`xNY&))k9yTQb$JC>)w_f zpU(^tu^Q)y%W~lVz`jz;_ jF?g&s@Y=Qe&c#kW|JbvqK0Y=Rw)4XDoVqsk_>;c_`@;F@ 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 deleted file mode 100644 index 909da100a..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync 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": "Registry hooks", - "entrypoints": { - "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" - ] - }, - "mixins": [ - "legacy-fabric-registry-sync-api-v1.mixins.json" - ], - "accessWidener": "registrysync.accesswidener", - "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-registry-sync-api-v1/icon.png" - } - } - } -} 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 deleted file mode 100644 index 2b3435c36..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "PacketByteBufMixin", - "BlockEntityAccessor", - "BlockEntityMixin", - "StatusEffectAccessor", - "EnchantmentAccessor", - "BiomeAccessor", - "EntityTypeAccessor", - "EntityTypeMixin", - "EntityMixin", - "SpawnEggItemMixin" - ], - "client": [ - ] -} 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 deleted file mode 100644 index 45ae69ced..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -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.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java deleted file mode 100644 index d44e15cdf..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ /dev/null @@ -1,45 +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.test.registry; - -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.itemgroup.ItemGroup; - -import net.fabricmc.api.ModInitializer; - -import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; -import net.legacyfabric.fabric.api.util.Identifier; - -public class RegistryTest implements ModInitializer { - @Override - public void onInitialize() { - 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); - } - } -} 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/build.gradle b/legacy-fabric-registry-sync-api-v1/1.8.9/build.gradle deleted file mode 100644 index e69de29bb..000000000 diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/gradle.properties b/legacy-fabric-registry-sync-api-v1/1.8.9/gradle.properties deleted file mode 100644 index 770b8d576..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -minVersionIncluded=1.8.9 -maxVersionIncluded=1.8.9 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 deleted file mode 100644 index 1bb4e0e56..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ /dev/null @@ -1,196 +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.impl.registry.sync; - -import java.util.ArrayList; -import java.util.List; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; - -import net.minecraft.block.Block; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.Entity; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.item.Item; -import net.minecraft.util.Identifier; -import net.minecraft.world.biome.Biome; - -import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; - -import net.legacyfabric.fabric.api.registry.v1.RegistryEntryRemapCallback; -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.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; -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.EnchantmentAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.EntityTypeAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.StatusEffectAccessor; - -public class RegistrySyncEarlyInitializer implements PreLaunchEntrypoint { - private static SimpleRegistryCompat> BLOCK_ENTITY_REGISTRY; - private static SimpleRegistryCompat STATUS_EFFECT_REGISTRY; - private static SimpleRegistryCompat ENCHANTMENT_REGISTRY; - private static SimpleRegistryCompat BIOME_REGISTRY; - private static OldRemappedRegistry> ENTITY_TYPE_REGISTRY; - - @Override - public void onPreLaunch() { - RegistryHelperImpl.registriesGetter = new RegistriesGetter() { - @Override - public SimpleRegistryCompat getBlockRegistry() { - return (SimpleRegistryCompat) Block.REGISTRY; - } - - @Override - public SimpleRegistryCompat getItemRegistry() { - return (SimpleRegistryCompat) Item.REGISTRY; - } - - @Override - public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } - - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; - } - - @Override - public SimpleRegistryCompat getStatusEffectRegistry() { - if (STATUS_EFFECT_REGISTRY == null) { - BiMap biMap = HashBiMap.create(StatusEffectAccessor.getSTATUS_EFFECTS_BY_ID()); - StatusEffectAccessor.setSTATUS_EFFECTS_BY_ID(biMap); - - STATUS_EFFECT_REGISTRY = new OldStatusEffectRegistry(StatusEffect.STATUS_EFFECTS, biMap) { - @Override - public void updateArray() { - StatusEffectAccessor.setSTATUS_EFFECTS(this.getArray()); - } - }; - } - - return (SimpleRegistryCompat) STATUS_EFFECT_REGISTRY; - } - - @Override - public SimpleRegistryCompat getEnchantmentRegistry() { - if (ENCHANTMENT_REGISTRY == null) { - BiMap map = HashBiMap.create(EnchantmentAccessor.getENCHANTMENT_MAP()); - EnchantmentAccessor.setENCHANTMENT_MAP(map); - ENCHANTMENT_REGISTRY = new OldEnchantmentRegistry(EnchantmentAccessor.getENCHANTMENTS(), map) { - @Override - public void updateArray() { - EnchantmentAccessor.setENCHANTMENTS(this.getArray()); - - List enchantments = new ArrayList<>(); - - for (Enchantment enchantment : EnchantmentAccessor.getENCHANTMENTS()) { - if (enchantment != null) { - enchantments.add(enchantment); - } - } - - EnchantmentAccessor.setALL_ENCHANTMENTS(enchantments.toArray(new Enchantment[0])); - } - }; - } - - return (SimpleRegistryCompat) ENCHANTMENT_REGISTRY; - } - - @Override - public SimpleRegistryCompat getBiomeRegistry() { - if (BIOME_REGISTRY == null) { - BiMap map = HashBiMap.create(Biome.MUTATED_BIOMES); - BiomeAccessor.setMUTATED_BIOMES(map); - BIOME_REGISTRY = new OldBiomeRegistry(BiomeAccessor.getBIOMES(), map) { - @Override - public void updateArray() { - BiomeAccessor.setBIOMES(this.getArray()); - } - }; - } - - return (SimpleRegistryCompat) BIOME_REGISTRY; - } - - @Override - public SimpleRegistryCompat> getEntityTypeRegistry() { - if (ENTITY_TYPE_REGISTRY == null) { - BiMap> NAME_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_CLASS_MAP()); - EntityTypeAccessor.setNAME_CLASS_MAP(NAME_CLASS_MAP); - EntityTypeAccessor.setCLASS_NAME_MAP(NAME_CLASS_MAP.inverse()); - - BiMap> ID_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getID_CLASS_MAP()); - EntityTypeAccessor.setID_CLASS_MAP(ID_CLASS_MAP); - EntityTypeAccessor.setCLASS_ID_MAP(ID_CLASS_MAP.inverse()); - - BiMap NAME_ID_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_ID_MAP()); - EntityTypeAccessor.setNAME_ID_MAP(NAME_ID_MAP); - - ENTITY_TYPE_REGISTRY = new OldEntityTypeRegistry(NAME_CLASS_MAP, ID_CLASS_MAP, NAME_ID_MAP); - } - - return (SimpleRegistryCompat>) ENTITY_TYPE_REGISTRY; - } - }; - - RegistryHelper.onRegistryInitialized(RegistryIds.BIOMES).register(() -> { - RegistryEntryRemapCallback.event(RegistryIds.BIOMES).register((oldId, newId, key, biome) -> { - if (biome.id != newId) { - ((BiomeAccessor) biome).setId(newId); - } - }); - }); - - RegistryHelper.onRegistryInitialized(RegistryIds.ENCHANTMENTS).register(() -> { - RegistryEntryRemapCallback.event(RegistryIds.ENCHANTMENTS).register((oldId, newId, key, enchantment) -> { - if (enchantment.id != newId) { - ((EnchantmentAccessor) enchantment).setId(newId); - } - }); - }); - - RegistryHelper.onRegistryInitialized(RegistryIds.STATUS_EFFECTS).register(() -> { - RegistryEntryRemapCallback.event(RegistryIds.STATUS_EFFECTS).register((oldId, newId, key, statusEffect) -> { - if (statusEffect.id != newId) { - ((StatusEffectAccessor) statusEffect).setId(newId); - } - }); - }); - - // RegistryHelper.onRegistryInitialized(RegistryIds.ENTITY_TYPES).register(() -> { - // for (Map.Entry entry : EntityTypeAccessor.getNAME_ID_MAP().entrySet()) { - // if (EntityType.SPAWN_EGGS.containsKey(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey()))) { - // EntityType.SPAWN_EGGS.put(entry.getKey(), EntityType.SPAWN_EGGS.remove(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey()))); - // } - // } - // }); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java deleted file mode 100644 index a1f795731..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.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 java.util.Map; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.world.biome.Biome; - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor - static Biome[] getBIOMES() { - return new Biome[0]; - } - - @Mutable - @Accessor - static void setBIOMES(Biome[] biomes) { - } - - @Mutable - @Accessor - static void setMUTATED_BIOMES(Map map) { - } - - @Mutable - @Accessor - void setId(int id); -} 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/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/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.java deleted file mode 100644 index f6b8e5ef3..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.java +++ /dev/null @@ -1,59 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.enchantment.Enchantment; -import net.minecraft.util.Identifier; - -@Mixin(Enchantment.class) -public interface EnchantmentAccessor { - @Mutable - @Accessor - static void setALL_ENCHANTMENTS(Enchantment[] enchantments) { - } - - @Mutable - @Accessor - static void setENCHANTMENTS(Enchantment[] enchantments) { - } - - @Accessor - static Enchantment[] getENCHANTMENTS() { - return new Enchantment[0]; - } - - @Accessor - static Map getENCHANTMENT_MAP() { - return null; - } - - @Mutable - @Accessor - static void setENCHANTMENT_MAP(Map map) { - } - - @Mutable - @Accessor - void setId(int id); -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java deleted file mode 100644 index 335f5c36f..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java +++ /dev/null @@ -1,58 +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.entity.Entity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(Entity.class) -public class EntityMixin { - @ModifyArg(method = "getTranslationKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/CommonI18n;translate(Ljava/lang/String;)Ljava/lang/String;")) - private String remapTranslationKey(String key) { - String newKey = key; - - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - if (key.contains("minecraft:")) { - String entityId = key.replace("entity.", "").replace(".name", ""); - - newKey = "entity." + registry.getOldKey(entityId) + ".name"; - } else if (key.contains(":")) { - newKey = key.replace(":", "."); - } - - return newKey; - } - - @ModifyArg(method = {"saveSelfToNbt", "saveToNbt"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java deleted file mode 100644 index 3880c4ca2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java +++ /dev/null @@ -1,73 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Mutable - @Accessor - static Map> getNAME_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setNAME_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_NAME_MAP(Map, String> map) { - } - - @Mutable - @Accessor - static Map> getID_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setID_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_ID_MAP(Map, Integer> map) { - } - - @Mutable - @Accessor - static Map getNAME_ID_MAP() { - return null; - } - - @Mutable - @Accessor - static void setNAME_ID_MAP(Map map) { - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java deleted file mode 100644 index 5f7ceed05..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java +++ /dev/null @@ -1,99 +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.List; - -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.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LightningBoltEntity; -import net.minecraft.entity.player.PlayerEntity; - -import net.legacyfabric.fabric.api.registry.v1.EntityTypeIds; -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(EntityType.class) -public abstract class EntityTypeMixin { - @Shadow - public static String getEntityName(Entity entity) { - return null; - } - - @ModifyArg(method = {"createInstanceFromName", "createInstanceFromNbt", "getIdByName"}, - at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;", remap = false)) - private static Object remap$createInstanceFromName(Object key) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - return registry.getNewKey(key.toString()); - } - - @Inject(method = "getEntityNames", at = @At("RETURN")) - private static void remap$getEntityNames(CallbackInfoReturnable> cir) { - List list = cir.getReturnValue(); - list.remove("LightningBolt"); - list.add(EntityTypeIds.LIGHTNING_BOLT.toString()); - } - - @Inject(method = "equals", at = @At("RETURN"), cancellable = true) - private static void remap$equals(Entity entity, String string, CallbackInfoReturnable cir) { - if (!cir.getReturnValue()) { - String string2 = getEntityName(entity); - - if (string2 == null) { - if (entity instanceof PlayerEntity) { - string2 = EntityTypeIds.PLAYER.toString(); - } else { - if (!(entity instanceof LightningBoltEntity)) { - cir.setReturnValue(false); - } - - string2 = EntityTypeIds.LIGHTNING_BOLT.toString(); - } - } - - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - cir.setReturnValue(registry.getNewKey(string).equals(string2)); - } - } - - @ModifyArg(method = "isEntityRegistered", at = @At(value = "INVOKE", target = "Ljava/util/List;contains(Ljava/lang/Object;)Z", remap = false)) - private static Object remap$isEntityRegistered(Object key) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - return registry.getNewKey(key.toString()); - } - - @Inject(method = "isEntityRegistered", cancellable = true, at = @At("RETURN")) - private static void remap$isEntityRegistered(String name, CallbackInfoReturnable cir) { - if (!cir.getReturnValue()) { - cir.setReturnValue(name.equals(EntityTypeIds.PLAYER.toString())); - } - } -} 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-registry-sync-api-v1/1.8.9/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.9/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.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java deleted file mode 100644 index 4475180c2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java +++ /dev/null @@ -1,40 +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.util.registry.MutableRegistry; - -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -@Mixin(MutableRegistry.class) -public abstract class MutableRegistryMixin implements SimpleRegistryCompat { - @Shadow - @Final - protected Map map; - - @Override - public V getValue(Object key) { - return this.map.get(this.toKeyType(key)); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java deleted file mode 100644 index 4a0a4298d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.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 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.registry.sync.compat.PacketByteBufCompat; - -@Mixin(PacketByteBuf.class) -public abstract class PacketByteBufMixin implements PacketByteBufCompat { - @Shadow - public abstract void writeNbtCompound(NbtCompound nbt); - - @Override - public PacketByteBuf writeCompound(NbtCompound compound) { - this.writeNbtCompound(compound); - return (PacketByteBuf) (Object) this; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java deleted file mode 100644 index 69252b979..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java +++ /dev/null @@ -1,102 +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.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.util.collection.IdList; -import net.minecraft.util.registry.SimpleRegistry; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; -import net.legacyfabric.fabric.impl.registry.util.RegistryEventsHolder; - -@Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements SimpleRegistryCompat { - @Mutable - @Shadow - @Final - protected IdList ids; - - @Shadow - @Final - protected Map objects; - private RegistryEventsHolder registryEventsHolder; - - @Shadow - public abstract K getIdentifier(V id); - - @Shadow - public abstract void add(int id, K identifier, V object); - - @Shadow - public abstract int getRawId(Object object); - - @Override - public IdListCompat getIds() { - return (IdListCompat) this.ids; - } - - @Override - public Map getObjects() { - return this.objects; - } - - @Override - public void setIds(IdListCompat idList) { - this.ids = (IdList) idList; - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new IdList(); - } - - @Override - public int getRawID(V object) { - return this.getRawId(object); - } - - @Override - public K getKey(V object) { - return this.getIdentifier(object); - } - - @Override - public V register(int i, Object key, V value) { - this.add(i, this.toKeyType(key), value); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(i, new Identifier(key), value); - return value; - } - - @Override - public RegistryEventsHolder getEventHolder() { - return this.registryEventsHolder; - } - - @Override - public void setEventHolder(RegistryEventsHolder registryEventsHolder) { - this.registryEventsHolder = registryEventsHolder; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.java deleted file mode 100644 index 557e1b71b..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.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.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.item.SpawnEggItem; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(SpawnEggItem.class) -public class SpawnEggItemMixin { - @Redirect(method = "getDisplayName", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;getEntityName(I)Ljava/lang/String;")) - private String saveAsVanillaId(int id) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - if (remapper == null) return EntityType.getEntityName(id); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - return registry.getOldKey(EntityType.getEntityName(id)); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java deleted file mode 100644 index 89f01c085..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java +++ /dev/null @@ -1,49 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.util.Identifier; - -@Mixin(StatusEffect.class) -public interface StatusEffectAccessor { - @Mutable - @Accessor - static void setSTATUS_EFFECTS(StatusEffect[] effects) { - } - - @Accessor - static Map getSTATUS_EFFECTS_BY_ID() { - return null; - } - - @Mutable - @Accessor - static void setSTATUS_EFFECTS_BY_ID(Map map) { - } - - @Mutable - @Accessor - void setId(int id); -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png deleted file mode 100644 index 2931efbf610873c0084debb8690902b0103d27fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1579 zcmbVMTWB0r7@iGm)TAXsYw<=rnU=;v=W=GRbL=!tc4Brl6GO7t2vVJ$IlDV#XU;e? z+r2ymsZdMQqAyaFLLUo;RumtE8Z@?uf_*4nP^4;o6fOFoSkN+o1$K?f2nE9_*b5G-l)AV)k5Qhb^- zU{V4ZnTKgnmXdpcB*Kg!W(1hvM2N&RO30x1u~eI9meGQGe@_?PDQq%q1CiV$8~M7 z?MQ_mOdqCh^a65Sv|ntwSXjV5se1;VK1|Kr8G7TQoQL&*ctt{L{fClG}xPK5k^yK3%T69N6J=>3jBqc zDNvZsrJ-yOXI^^mWf1cmY^XST)CVzIGjvEPENowmy}ax zvJ8_(Cf#+H-dBlH53`_u-~6BVAMz|(g?jCVdBWNZ(+A}(pFV7>S3QgPiQcMaflkIC z-3Ti|VT~{au*vq0ts9O&m$p&Gl=L6+q6_m$IcVq}o~+Pl{g>1esQp4%wp~|*zk1n` zZ7T6Toc4`y88s}riCP|ZXrJ?FLz@^KTcyqLjey zu95Yz%F&S{<0~f)Iomek?+hQ%MhCu%T^zsg>C_L`1`Br`xNY&))k9yTQb$JC>)w_f zpU(^tu^Q)y%W~lVz`jz;_ jF?g&s@Y=Qe&c#kW|JbvqK0Y=Rw)4XDoVqsk_>;c_`@;F@ diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/fabric.mod.json deleted file mode 100644 index ac4e75d72..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync 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": "Registry hooks", - "entrypoints": { - "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" - ] - }, - "mixins": [ - "legacy-fabric-registry-sync-api-v1.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-registry-sync-api-v1/icon.png" - } - } - } -} 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 deleted file mode 100644 index eae009f7d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "BlockMixin", - "ItemMixin", - "PacketByteBufMixin", - "MutableRegistryMixin", - "BlockEntityAccessor", - "BlockEntityMixin", - "StatusEffectAccessor", - "EnchantmentAccessor", - "BiomeAccessor", - "EntityTypeAccessor", - "EntityTypeMixin", - "EntityMixin", - "SpawnEggItemMixin" - ], - "client": [ - ] -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java deleted file mode 100644 index 903995adf..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ /dev/null @@ -1,52 +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.test.registry; - -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.v1.RegistryHelper; -import net.legacyfabric.fabric.api.resource.ItemModelRegistry; -import net.legacyfabric.fabric.api.util.Identifier; - -public class RegistryTest implements ModInitializer { - @Override - public void onInitialize() { - 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")); - ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); - } -} 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/build.gradle b/legacy-fabric-registry-sync-api-v1/1.8/build.gradle deleted file mode 100644 index 5058a1900..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -loom { - accessWidenerPath = file("src/main/resources/registrysync.accesswidener") -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/gradle.properties b/legacy-fabric-registry-sync-api-v1/1.8/gradle.properties deleted file mode 100644 index 8dcacbf34..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -minVersionIncluded=1.8 -maxVersionIncluded=1.8 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 deleted file mode 100644 index 1bb4e0e56..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ /dev/null @@ -1,196 +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.impl.registry.sync; - -import java.util.ArrayList; -import java.util.List; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; - -import net.minecraft.block.Block; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.Entity; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.item.Item; -import net.minecraft.util.Identifier; -import net.minecraft.world.biome.Biome; - -import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; - -import net.legacyfabric.fabric.api.registry.v1.RegistryEntryRemapCallback; -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.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; -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.EnchantmentAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.EntityTypeAccessor; -import net.legacyfabric.fabric.mixin.registry.sync.StatusEffectAccessor; - -public class RegistrySyncEarlyInitializer implements PreLaunchEntrypoint { - private static SimpleRegistryCompat> BLOCK_ENTITY_REGISTRY; - private static SimpleRegistryCompat STATUS_EFFECT_REGISTRY; - private static SimpleRegistryCompat ENCHANTMENT_REGISTRY; - private static SimpleRegistryCompat BIOME_REGISTRY; - private static OldRemappedRegistry> ENTITY_TYPE_REGISTRY; - - @Override - public void onPreLaunch() { - RegistryHelperImpl.registriesGetter = new RegistriesGetter() { - @Override - public SimpleRegistryCompat getBlockRegistry() { - return (SimpleRegistryCompat) Block.REGISTRY; - } - - @Override - public SimpleRegistryCompat getItemRegistry() { - return (SimpleRegistryCompat) Item.REGISTRY; - } - - @Override - public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } - - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; - } - - @Override - public SimpleRegistryCompat getStatusEffectRegistry() { - if (STATUS_EFFECT_REGISTRY == null) { - BiMap biMap = HashBiMap.create(StatusEffectAccessor.getSTATUS_EFFECTS_BY_ID()); - StatusEffectAccessor.setSTATUS_EFFECTS_BY_ID(biMap); - - STATUS_EFFECT_REGISTRY = new OldStatusEffectRegistry(StatusEffect.STATUS_EFFECTS, biMap) { - @Override - public void updateArray() { - StatusEffectAccessor.setSTATUS_EFFECTS(this.getArray()); - } - }; - } - - return (SimpleRegistryCompat) STATUS_EFFECT_REGISTRY; - } - - @Override - public SimpleRegistryCompat getEnchantmentRegistry() { - if (ENCHANTMENT_REGISTRY == null) { - BiMap map = HashBiMap.create(EnchantmentAccessor.getENCHANTMENT_MAP()); - EnchantmentAccessor.setENCHANTMENT_MAP(map); - ENCHANTMENT_REGISTRY = new OldEnchantmentRegistry(EnchantmentAccessor.getENCHANTMENTS(), map) { - @Override - public void updateArray() { - EnchantmentAccessor.setENCHANTMENTS(this.getArray()); - - List enchantments = new ArrayList<>(); - - for (Enchantment enchantment : EnchantmentAccessor.getENCHANTMENTS()) { - if (enchantment != null) { - enchantments.add(enchantment); - } - } - - EnchantmentAccessor.setALL_ENCHANTMENTS(enchantments.toArray(new Enchantment[0])); - } - }; - } - - return (SimpleRegistryCompat) ENCHANTMENT_REGISTRY; - } - - @Override - public SimpleRegistryCompat getBiomeRegistry() { - if (BIOME_REGISTRY == null) { - BiMap map = HashBiMap.create(Biome.MUTATED_BIOMES); - BiomeAccessor.setMUTATED_BIOMES(map); - BIOME_REGISTRY = new OldBiomeRegistry(BiomeAccessor.getBIOMES(), map) { - @Override - public void updateArray() { - BiomeAccessor.setBIOMES(this.getArray()); - } - }; - } - - return (SimpleRegistryCompat) BIOME_REGISTRY; - } - - @Override - public SimpleRegistryCompat> getEntityTypeRegistry() { - if (ENTITY_TYPE_REGISTRY == null) { - BiMap> NAME_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_CLASS_MAP()); - EntityTypeAccessor.setNAME_CLASS_MAP(NAME_CLASS_MAP); - EntityTypeAccessor.setCLASS_NAME_MAP(NAME_CLASS_MAP.inverse()); - - BiMap> ID_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getID_CLASS_MAP()); - EntityTypeAccessor.setID_CLASS_MAP(ID_CLASS_MAP); - EntityTypeAccessor.setCLASS_ID_MAP(ID_CLASS_MAP.inverse()); - - BiMap NAME_ID_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_ID_MAP()); - EntityTypeAccessor.setNAME_ID_MAP(NAME_ID_MAP); - - ENTITY_TYPE_REGISTRY = new OldEntityTypeRegistry(NAME_CLASS_MAP, ID_CLASS_MAP, NAME_ID_MAP); - } - - return (SimpleRegistryCompat>) ENTITY_TYPE_REGISTRY; - } - }; - - RegistryHelper.onRegistryInitialized(RegistryIds.BIOMES).register(() -> { - RegistryEntryRemapCallback.event(RegistryIds.BIOMES).register((oldId, newId, key, biome) -> { - if (biome.id != newId) { - ((BiomeAccessor) biome).setId(newId); - } - }); - }); - - RegistryHelper.onRegistryInitialized(RegistryIds.ENCHANTMENTS).register(() -> { - RegistryEntryRemapCallback.event(RegistryIds.ENCHANTMENTS).register((oldId, newId, key, enchantment) -> { - if (enchantment.id != newId) { - ((EnchantmentAccessor) enchantment).setId(newId); - } - }); - }); - - RegistryHelper.onRegistryInitialized(RegistryIds.STATUS_EFFECTS).register(() -> { - RegistryEntryRemapCallback.event(RegistryIds.STATUS_EFFECTS).register((oldId, newId, key, statusEffect) -> { - if (statusEffect.id != newId) { - ((StatusEffectAccessor) statusEffect).setId(newId); - } - }); - }); - - // RegistryHelper.onRegistryInitialized(RegistryIds.ENTITY_TYPES).register(() -> { - // for (Map.Entry entry : EntityTypeAccessor.getNAME_ID_MAP().entrySet()) { - // if (EntityType.SPAWN_EGGS.containsKey(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey()))) { - // EntityType.SPAWN_EGGS.put(entry.getKey(), EntityType.SPAWN_EGGS.remove(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey()))); - // } - // } - // }); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java deleted file mode 100644 index a1f795731..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.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 java.util.Map; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.world.biome.Biome; - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor - static Biome[] getBIOMES() { - return new Biome[0]; - } - - @Mutable - @Accessor - static void setBIOMES(Biome[] biomes) { - } - - @Mutable - @Accessor - static void setMUTATED_BIOMES(Map map) { - } - - @Mutable - @Accessor - void setId(int id); -} 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/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/EnchantmentAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.java deleted file mode 100644 index 934548d96..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EnchantmentAccessor.java +++ /dev/null @@ -1,58 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.enchantment.Enchantment; - -@Mixin(Enchantment.class) -public interface EnchantmentAccessor { - @Mutable - @Accessor - static void setALL_ENCHANTMENTS(Enchantment[] enchantments) { - } - - @Mutable - @Accessor - static void setENCHANTMENTS(Enchantment[] enchantments) { - } - - @Accessor - static Enchantment[] getENCHANTMENTS() { - return new Enchantment[0]; - } - - @Accessor - static Map getENCHANTMENT_MAP() { - return null; - } - - @Mutable - @Accessor - static void setENCHANTMENT_MAP(Map map) { - } - - @Mutable - @Accessor - void setId(int id); -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java deleted file mode 100644 index 335f5c36f..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java +++ /dev/null @@ -1,58 +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.entity.Entity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(Entity.class) -public class EntityMixin { - @ModifyArg(method = "getTranslationKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/CommonI18n;translate(Ljava/lang/String;)Ljava/lang/String;")) - private String remapTranslationKey(String key) { - String newKey = key; - - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - if (key.contains("minecraft:")) { - String entityId = key.replace("entity.", "").replace(".name", ""); - - newKey = "entity." + registry.getOldKey(entityId) + ".name"; - } else if (key.contains(":")) { - newKey = key.replace(":", "."); - } - - return newKey; - } - - @ModifyArg(method = {"saveSelfToNbt", "saveToNbt"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java deleted file mode 100644 index 3880c4ca2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java +++ /dev/null @@ -1,73 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Mutable - @Accessor - static Map> getNAME_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setNAME_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_NAME_MAP(Map, String> map) { - } - - @Mutable - @Accessor - static Map> getID_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setID_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_ID_MAP(Map, Integer> map) { - } - - @Mutable - @Accessor - static Map getNAME_ID_MAP() { - return null; - } - - @Mutable - @Accessor - static void setNAME_ID_MAP(Map map) { - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java deleted file mode 100644 index 5f7ceed05..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java +++ /dev/null @@ -1,99 +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.List; - -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.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LightningBoltEntity; -import net.minecraft.entity.player.PlayerEntity; - -import net.legacyfabric.fabric.api.registry.v1.EntityTypeIds; -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(EntityType.class) -public abstract class EntityTypeMixin { - @Shadow - public static String getEntityName(Entity entity) { - return null; - } - - @ModifyArg(method = {"createInstanceFromName", "createInstanceFromNbt", "getIdByName"}, - at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;", remap = false)) - private static Object remap$createInstanceFromName(Object key) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - return registry.getNewKey(key.toString()); - } - - @Inject(method = "getEntityNames", at = @At("RETURN")) - private static void remap$getEntityNames(CallbackInfoReturnable> cir) { - List list = cir.getReturnValue(); - list.remove("LightningBolt"); - list.add(EntityTypeIds.LIGHTNING_BOLT.toString()); - } - - @Inject(method = "equals", at = @At("RETURN"), cancellable = true) - private static void remap$equals(Entity entity, String string, CallbackInfoReturnable cir) { - if (!cir.getReturnValue()) { - String string2 = getEntityName(entity); - - if (string2 == null) { - if (entity instanceof PlayerEntity) { - string2 = EntityTypeIds.PLAYER.toString(); - } else { - if (!(entity instanceof LightningBoltEntity)) { - cir.setReturnValue(false); - } - - string2 = EntityTypeIds.LIGHTNING_BOLT.toString(); - } - } - - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - cir.setReturnValue(registry.getNewKey(string).equals(string2)); - } - } - - @ModifyArg(method = "isEntityRegistered", at = @At(value = "INVOKE", target = "Ljava/util/List;contains(Ljava/lang/Object;)Z", remap = false)) - private static Object remap$isEntityRegistered(Object key) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - return registry.getNewKey(key.toString()); - } - - @Inject(method = "isEntityRegistered", cancellable = true, at = @At("RETURN")) - private static void remap$isEntityRegistered(String name, CallbackInfoReturnable cir) { - if (!cir.getReturnValue()) { - cir.setReturnValue(name.equals(EntityTypeIds.PLAYER.toString())); - } - } -} 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/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java deleted file mode 100644 index 4475180c2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java +++ /dev/null @@ -1,40 +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.util.registry.MutableRegistry; - -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -@Mixin(MutableRegistry.class) -public abstract class MutableRegistryMixin implements SimpleRegistryCompat { - @Shadow - @Final - protected Map map; - - @Override - public V getValue(Object key) { - return this.map.get(this.toKeyType(key)); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java deleted file mode 100644 index 4a0a4298d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.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 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.registry.sync.compat.PacketByteBufCompat; - -@Mixin(PacketByteBuf.class) -public abstract class PacketByteBufMixin implements PacketByteBufCompat { - @Shadow - public abstract void writeNbtCompound(NbtCompound nbt); - - @Override - public PacketByteBuf writeCompound(NbtCompound compound) { - this.writeNbtCompound(compound); - return (PacketByteBuf) (Object) this; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java deleted file mode 100644 index 1c5811c27..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java +++ /dev/null @@ -1,102 +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.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.util.collection.IdList; -import net.minecraft.util.registry.SimpleRegistry; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; -import net.legacyfabric.fabric.impl.registry.util.RegistryEventsHolder; - -@Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements SimpleRegistryCompat { - @Mutable - @Shadow - @Final - protected IdList ids; - - @Shadow - @Final - protected Map objects; - private RegistryEventsHolder registryEventsHolder; - - @Shadow - public abstract K getIdentifier(V id); - - @Shadow - public abstract void add(int id, K identifier, V object); - - @Shadow - public abstract int getRawId(Object object); - - @Override - public IdListCompat getIds() { - return (IdListCompat) this.ids; - } - - @Override - public Map getObjects() { - return this.objects; - } - - @Override - public void setIds(IdListCompat idList) { - this.ids = (IdList) idList; - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new IdList(); - } - - @Override - public int getRawID(V object) { - return this.getRawId(object); - } - - @Override - public K getKey(V object) { - return this.getIdentifier(object); - } - - @Override - public V register(int i, Object key, V value) { - this.add(i, this.toKeyType(key), value); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(i, new Identifier(key), value); - return value; - } - - @Override - public RegistryEventsHolder getEventHolder() { - return this.registryEventsHolder; - } - - @Override - public void setEventHolder(RegistryEventsHolder registryEventsHolder) { - this.registryEventsHolder = registryEventsHolder; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.java deleted file mode 100644 index 557e1b71b..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggItemMixin.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.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.item.SpawnEggItem; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(SpawnEggItem.class) -public class SpawnEggItemMixin { - @Redirect(method = "getDisplayName", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;getEntityName(I)Ljava/lang/String;")) - private String saveAsVanillaId(int id) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - if (remapper == null) return EntityType.getEntityName(id); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - return registry.getOldKey(EntityType.getEntityName(id)); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java b/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java deleted file mode 100644 index 89f01c085..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/StatusEffectAccessor.java +++ /dev/null @@ -1,49 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.util.Identifier; - -@Mixin(StatusEffect.class) -public interface StatusEffectAccessor { - @Mutable - @Accessor - static void setSTATUS_EFFECTS(StatusEffect[] effects) { - } - - @Accessor - static Map getSTATUS_EFFECTS_BY_ID() { - return null; - } - - @Mutable - @Accessor - static void setSTATUS_EFFECTS_BY_ID(Map map) { - } - - @Mutable - @Accessor - void setId(int id); -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png deleted file mode 100644 index 2931efbf610873c0084debb8690902b0103d27fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1579 zcmbVMTWB0r7@iGm)TAXsYw<=rnU=;v=W=GRbL=!tc4Brl6GO7t2vVJ$IlDV#XU;e? z+r2ymsZdMQqAyaFLLUo;RumtE8Z@?uf_*4nP^4;o6fOFoSkN+o1$K?f2nE9_*b5G-l)AV)k5Qhb^- zU{V4ZnTKgnmXdpcB*Kg!W(1hvM2N&RO30x1u~eI9meGQGe@_?PDQq%q1CiV$8~M7 z?MQ_mOdqCh^a65Sv|ntwSXjV5se1;VK1|Kr8G7TQoQL&*ctt{L{fClG}xPK5k^yK3%T69N6J=>3jBqc zDNvZsrJ-yOXI^^mWf1cmY^XST)CVzIGjvEPENowmy}ax zvJ8_(Cf#+H-dBlH53`_u-~6BVAMz|(g?jCVdBWNZ(+A}(pFV7>S3QgPiQcMaflkIC z-3Ti|VT~{au*vq0ts9O&m$p&Gl=L6+q6_m$IcVq}o~+Pl{g>1esQp4%wp~|*zk1n` zZ7T6Toc4`y88s}riCP|ZXrJ?FLz@^KTcyqLjey zu95Yz%F&S{<0~f)Iomek?+hQ%MhCu%T^zsg>C_L`1`Br`xNY&))k9yTQb$JC>)w_f zpU(^tu^Q)y%W~lVz`jz;_ jF?g&s@Y=Qe&c#kW|JbvqK0Y=Rw)4XDoVqsk_>;c_`@;F@ diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/fabric.mod.json deleted file mode 100644 index 909da100a..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync 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": "Registry hooks", - "entrypoints": { - "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" - ] - }, - "mixins": [ - "legacy-fabric-registry-sync-api-v1.mixins.json" - ], - "accessWidener": "registrysync.accesswidener", - "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-registry-sync-api-v1/icon.png" - } - } - } -} 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 deleted file mode 100644 index eae009f7d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "BlockMixin", - "ItemMixin", - "PacketByteBufMixin", - "MutableRegistryMixin", - "BlockEntityAccessor", - "BlockEntityMixin", - "StatusEffectAccessor", - "EnchantmentAccessor", - "BiomeAccessor", - "EntityTypeAccessor", - "EntityTypeMixin", - "EntityMixin", - "SpawnEggItemMixin" - ], - "client": [ - ] -} 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 deleted file mode 100644 index 45ae69ced..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -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/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java deleted file mode 100644 index 987555b4e..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ /dev/null @@ -1,51 +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.test.registry; - -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 { - @Override - public void onInitialize() { - 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")); - ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); - } -} 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/build.gradle b/legacy-fabric-registry-sync-api-v1/1.9.4/build.gradle deleted file mode 100644 index e69de29bb..000000000 diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/gradle.properties b/legacy-fabric-registry-sync-api-v1/1.9.4/gradle.properties deleted file mode 100644 index 34201081c..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -minVersionExcluded=1.8.9 -maxVersionIncluded=1.9.4 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 deleted file mode 100644 index 6e5e698e2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistrySyncEarlyInitializer.java +++ /dev/null @@ -1,131 +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.impl.registry.sync; - -import java.util.Map; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; - -import net.minecraft.block.Block; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.item.Item; -import net.minecraft.util.Identifier; -import net.minecraft.world.biome.Biome; - -import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; - -import net.legacyfabric.fabric.api.registry.v1.RegistryEntryAddCallback; -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; - -public class RegistrySyncEarlyInitializer implements PreLaunchEntrypoint { - private static SimpleRegistryCompat> BLOCK_ENTITY_REGISTRY; - private static OldRemappedRegistry> ENTITY_TYPE_REGISTRY; - - @Override - public void onPreLaunch() { - RegistryHelperImpl.registriesGetter = new RegistriesGetter() { - @Override - public SimpleRegistryCompat getBlockRegistry() { - return (SimpleRegistryCompat) Block.REGISTRY; - } - - @Override - public SimpleRegistryCompat getItemRegistry() { - return (SimpleRegistryCompat) Item.REGISTRY; - } - - @Override - public SimpleRegistryCompat> getBlockEntityTypeRegistry() { - if (BLOCK_ENTITY_REGISTRY == null) { - BLOCK_ENTITY_REGISTRY = new OldBlockEntityRegistry(BlockEntityAccessor.getStringClassMap(), BlockEntityAccessor.getClassStringMap()); - } - - return (SimpleRegistryCompat>) BLOCK_ENTITY_REGISTRY; - } - - @Override - public SimpleRegistryCompat getStatusEffectRegistry() { - return (SimpleRegistryCompat) StatusEffect.REGISTRY; - } - - @Override - public SimpleRegistryCompat getEnchantmentRegistry() { - return (SimpleRegistryCompat) Enchantment.REGISTRY; - } - - @Override - public SimpleRegistryCompat getBiomeRegistry() { - return (SimpleRegistryCompat) Biome.REGISTRY; - } - - @Override - public SimpleRegistryCompat> getEntityTypeRegistry() { - if (ENTITY_TYPE_REGISTRY == null) { - BiMap> NAME_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_CLASS_MAP()); - EntityTypeAccessor.setNAME_CLASS_MAP(NAME_CLASS_MAP); - EntityTypeAccessor.setCLASS_NAME_MAP(NAME_CLASS_MAP.inverse()); - - BiMap> ID_CLASS_MAP = HashBiMap.create(EntityTypeAccessor.getID_CLASS_MAP()); - EntityTypeAccessor.setID_CLASS_MAP(ID_CLASS_MAP); - EntityTypeAccessor.setCLASS_ID_MAP(ID_CLASS_MAP.inverse()); - - BiMap NAME_ID_MAP = HashBiMap.create(EntityTypeAccessor.getNAME_ID_MAP()); - EntityTypeAccessor.setNAME_ID_MAP(NAME_ID_MAP); - - ENTITY_TYPE_REGISTRY = new OldEntityTypeRegistry(NAME_CLASS_MAP, ID_CLASS_MAP, NAME_ID_MAP); - } - - return (SimpleRegistryCompat>) ENTITY_TYPE_REGISTRY; - } - }; - - RegistryHelper.onRegistryInitialized(RegistryIds.BIOMES).register(() -> { - RegistryEntryAddCallback.event(RegistryIds.BIOMES).register((rawId, id, biome) -> { - if (biome.isMutatedBiome()) { - Biome.biomeList.set(biome, Biome.getBiomeIndex(Biome.REGISTRY.get(new Identifier(((BiomeAccessor) biome).getParent())))); - } - }); - }); - - RegistryHelper.onRegistryInitialized(RegistryIds.ENTITY_TYPES).register(() -> { - for (Map.Entry entry : EntityTypeAccessor.getNAME_ID_MAP().entrySet()) { - if (EntityType.SPAWN_EGGS.containsKey(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey()))) { - EntityType.SpawnEggData data = EntityType.SPAWN_EGGS.remove(ENTITY_TYPE_REGISTRY.getOldKey(entry.getKey())); - ((SpawnEggDataAccessor) data).setName(entry.getKey()); - EntityType.SPAWN_EGGS.put(entry.getKey(), data); - } - } - }); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java deleted file mode 100644 index 5cf98a69d..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java +++ /dev/null @@ -1,29 +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.world.biome.Biome; - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor - String getParent(); -} 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/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/EntityMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java deleted file mode 100644 index 335f5c36f..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityMixin.java +++ /dev/null @@ -1,58 +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.entity.Entity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(Entity.class) -public class EntityMixin { - @ModifyArg(method = "getTranslationKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/CommonI18n;translate(Ljava/lang/String;)Ljava/lang/String;")) - private String remapTranslationKey(String key) { - String newKey = key; - - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - if (key.contains("minecraft:")) { - String entityId = key.replace("entity.", "").replace(".name", ""); - - newKey = "entity." + registry.getOldKey(entityId) + ".name"; - } else if (key.contains(":")) { - newKey = key.replace(":", "."); - } - - return newKey; - } - - @ModifyArg(method = {"saveSelfToNbt", "saveToNbt"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;putString(Ljava/lang/String;Ljava/lang/String;)V"), index = 1) - private String saveAsVanillaId(String newKey) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - return registry.getOldKey(newKey); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java deleted file mode 100644 index 3880c4ca2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeAccessor.java +++ /dev/null @@ -1,73 +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.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Mutable - @Accessor - static Map> getNAME_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setNAME_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_NAME_MAP(Map, String> map) { - } - - @Mutable - @Accessor - static Map> getID_CLASS_MAP() { - return null; - } - - @Mutable - @Accessor - static void setID_CLASS_MAP(Map> map) { - } - - @Mutable - @Accessor - static void setCLASS_ID_MAP(Map, Integer> map) { - } - - @Mutable - @Accessor - static Map getNAME_ID_MAP() { - return null; - } - - @Mutable - @Accessor - static void setNAME_ID_MAP(Map map) { - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java deleted file mode 100644 index 5f7ceed05..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/EntityTypeMixin.java +++ /dev/null @@ -1,99 +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.List; - -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.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LightningBoltEntity; -import net.minecraft.entity.player.PlayerEntity; - -import net.legacyfabric.fabric.api.registry.v1.EntityTypeIds; -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -@Mixin(EntityType.class) -public abstract class EntityTypeMixin { - @Shadow - public static String getEntityName(Entity entity) { - return null; - } - - @ModifyArg(method = {"createInstanceFromName", "createInstanceFromNbt", "getIdByName"}, - at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;", remap = false)) - private static Object remap$createInstanceFromName(Object key) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - return registry.getNewKey(key.toString()); - } - - @Inject(method = "getEntityNames", at = @At("RETURN")) - private static void remap$getEntityNames(CallbackInfoReturnable> cir) { - List list = cir.getReturnValue(); - list.remove("LightningBolt"); - list.add(EntityTypeIds.LIGHTNING_BOLT.toString()); - } - - @Inject(method = "equals", at = @At("RETURN"), cancellable = true) - private static void remap$equals(Entity entity, String string, CallbackInfoReturnable cir) { - if (!cir.getReturnValue()) { - String string2 = getEntityName(entity); - - if (string2 == null) { - if (entity instanceof PlayerEntity) { - string2 = EntityTypeIds.PLAYER.toString(); - } else { - if (!(entity instanceof LightningBoltEntity)) { - cir.setReturnValue(false); - } - - string2 = EntityTypeIds.LIGHTNING_BOLT.toString(); - } - } - - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - - cir.setReturnValue(registry.getNewKey(string).equals(string2)); - } - } - - @ModifyArg(method = "isEntityRegistered", at = @At(value = "INVOKE", target = "Ljava/util/List;contains(Ljava/lang/Object;)Z", remap = false)) - private static Object remap$isEntityRegistered(Object key) { - RegistryRemapper> remapper = RegistryHelperImpl.getRegistryRemapper(RegistryIds.ENTITY_TYPES); - OldRemappedRegistry> registry = (OldRemappedRegistry>) remapper.getRegistry(); - return registry.getNewKey(key.toString()); - } - - @Inject(method = "isEntityRegistered", cancellable = true, at = @At("RETURN")) - private static void remap$isEntityRegistered(String name, CallbackInfoReturnable cir) { - if (!cir.getReturnValue()) { - cir.setReturnValue(name.equals(EntityTypeIds.PLAYER.toString())); - } - } -} 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/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java deleted file mode 100644 index 4475180c2..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixin.java +++ /dev/null @@ -1,40 +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.util.registry.MutableRegistry; - -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -@Mixin(MutableRegistry.class) -public abstract class MutableRegistryMixin implements SimpleRegistryCompat { - @Shadow - @Final - protected Map map; - - @Override - public V getValue(Object key) { - return this.map.get(this.toKeyType(key)); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java deleted file mode 100644 index 30b30ca2c..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java +++ /dev/null @@ -1,37 +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.Shadow; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.PacketByteBuf; - -import net.legacyfabric.fabric.impl.registry.sync.compat.PacketByteBufCompat; - -@Mixin(PacketByteBuf.class) -public abstract class PacketByteBufMixin implements PacketByteBufCompat { - @Shadow - public abstract PacketByteBuf writeNbtCompound(NbtCompound par1); - - @Override - public PacketByteBuf writeCompound(NbtCompound compound) { - return this.writeNbtCompound(compound); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java deleted file mode 100644 index f85602e03..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixin.java +++ /dev/null @@ -1,102 +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.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.class_2929; -import net.minecraft.util.registry.SimpleRegistry; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; -import net.legacyfabric.fabric.impl.registry.util.RegistryEventsHolder; - -@Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements SimpleRegistryCompat { - @Shadow - @Final - protected Map objects; - - @Mutable - @Shadow - @Final - protected class_2929 field_13718; - private RegistryEventsHolder registryEventsHolder; - - @Shadow - public abstract int getRawId(Object par1); - - @Shadow - public abstract K getIdentifier(V id); - - @Shadow - public abstract void add(int id, K identifier, V object); - - @Override - public IdListCompat getIds() { - return (IdListCompat) this.field_13718; - } - - @Override - public Map getObjects() { - return this.objects; - } - - @Override - public void setIds(IdListCompat idList) { - this.field_13718 = (class_2929) idList; - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new class_2929(256); - } - - @Override - public int getRawID(V object) { - return this.getRawId(object); - } - - @Override - public K getKey(V object) { - return this.getIdentifier(object); - } - - @Override - public V register(int i, Object key, V value) { - this.add(i, this.toKeyType(key), value); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(i, new Identifier(key), value); - return value; - } - - @Override - public RegistryEventsHolder getEventHolder() { - return this.registryEventsHolder; - } - - @Override - public void setEventHolder(RegistryEventsHolder registryEventsHolder) { - this.registryEventsHolder = registryEventsHolder; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggDataAccessor.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggDataAccessor.java deleted file mode 100644 index 5ca5d86af..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SpawnEggDataAccessor.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 org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.entity.EntityType; - -@Mixin(EntityType.SpawnEggData.class) -public interface SpawnEggDataAccessor { - @Mutable - @Accessor - void setName(String name); -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java deleted file mode 100644 index 408e79a2a..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java +++ /dev/null @@ -1,89 +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.IdentityHashMap; -import java.util.List; - -import com.google.common.collect.Lists; -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.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -@Mixin(class_2929.class) -public abstract class class_2929Mixin implements IdListCompat { - @Shadow - public abstract void add(V object, int i); - - @Shadow - @Nullable - public abstract V getById(int i); - - @Shadow - public abstract int getId(V object); - - @Shadow - private V[] field_14375; - - @Override - public IdentityHashMap getIdMap(SimpleRegistryCompat simpleRegistry) { - IdentityHashMap idMap = new IdentityHashMap<>(512); - - for (int i = 0; i < this.field_14375.length; i++) { - V value = this.field_14375[i]; - - if (value == null) { - continue; - } - - idMap.put(value, i); - } - - return idMap; - } - - @Override - public List getList() { - return Lists.newArrayList(this.field_14375); - } - - @Override - public V fromInt(int index) { - return this.getById(index); - } - - @Override - public void setValue(V value, int index) { - this.add(value, index); - } - - @Override - public int getInt(V value) { - return this.getId(value); - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new class_2929(256); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png deleted file mode 100644 index 2931efbf610873c0084debb8690902b0103d27fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1579 zcmbVMTWB0r7@iGm)TAXsYw<=rnU=;v=W=GRbL=!tc4Brl6GO7t2vVJ$IlDV#XU;e? z+r2ymsZdMQqAyaFLLUo;RumtE8Z@?uf_*4nP^4;o6fOFoSkN+o1$K?f2nE9_*b5G-l)AV)k5Qhb^- zU{V4ZnTKgnmXdpcB*Kg!W(1hvM2N&RO30x1u~eI9meGQGe@_?PDQq%q1CiV$8~M7 z?MQ_mOdqCh^a65Sv|ntwSXjV5se1;VK1|Kr8G7TQoQL&*ctt{L{fClG}xPK5k^yK3%T69N6J=>3jBqc zDNvZsrJ-yOXI^^mWf1cmY^XST)CVzIGjvEPENowmy}ax zvJ8_(Cf#+H-dBlH53`_u-~6BVAMz|(g?jCVdBWNZ(+A}(pFV7>S3QgPiQcMaflkIC z-3Ti|VT~{au*vq0ts9O&m$p&Gl=L6+q6_m$IcVq}o~+Pl{g>1esQp4%wp~|*zk1n` zZ7T6Toc4`y88s}riCP|ZXrJ?FLz@^KTcyqLjey zu95Yz%F&S{<0~f)Iomek?+hQ%MhCu%T^zsg>C_L`1`Br`xNY&))k9yTQb$JC>)w_f zpU(^tu^Q)y%W~lVz`jz;_ jF?g&s@Y=Qe&c#kW|JbvqK0Y=Rw)4XDoVqsk_>;c_`@;F@ diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/fabric.mod.json deleted file mode 100644 index ac4e75d72..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync 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": "Registry hooks", - "entrypoints": { - "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" - ] - }, - "mixins": [ - "legacy-fabric-registry-sync-api-v1.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-registry-sync-api-v1/icon.png" - } - } - } -} 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 deleted file mode 100644 index fb5274ab6..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "class_2929Mixin", - "BlockMixin", - "ItemMixin", - "PacketByteBufMixin", - "MutableRegistryMixin", - "BlockEntityAccessor", - "BlockEntityMixin", - "BiomeAccessor", - "EntityTypeAccessor", - "EntityTypeMixin", - "EntityMixin", - "SpawnEggDataAccessor" - ], - "client": [ - ] -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java deleted file mode 100644 index 3d72858aa..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ /dev/null @@ -1,59 +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.test.registry; - -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.v1.RegistryHelper; -import net.legacyfabric.fabric.api.resource.ItemModelRegistry; -import net.legacyfabric.fabric.api.util.Identifier; - -public class RegistryTest implements ModInitializer { - @Override - public void onInitialize() { - 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")); - ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); - } -} 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/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BiomeIds.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BiomeIds.java index b7d1aef42..3bc5bd9e9 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BiomeIds.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BiomeIds.java @@ -20,6 +20,7 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.SinceMC; +@Deprecated public class BiomeIds { public static final Identifier OCEAN = id("ocean"); public static final Identifier PLAINS = id("plains"); 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..2c0579cb0 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 @@ -20,6 +20,7 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.SinceMC; +@Deprecated public class BlockEntityTypeIds { public static final Identifier FURNACE = id("furnace"); public static final Identifier CHEST = id("chest"); diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BlockIds.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BlockIds.java index 4764d8645..7d62acbce 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BlockIds.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/BlockIds.java @@ -20,6 +20,7 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.SinceMC; +@Deprecated public class BlockIds { public static final Identifier AIR = id("air"); public static final Identifier STONE = id("stone"); diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/EnchantmentIds.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/EnchantmentIds.java index e5980eaa1..9d3518d35 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/EnchantmentIds.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/EnchantmentIds.java @@ -20,6 +20,7 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.SinceMC; +@Deprecated public class EnchantmentIds { public static final Identifier PROTECTION = id("protection"); public static final Identifier FIRE_PROTECTION = id("fire_protection"); diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/EntityTypeIds.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/EntityTypeIds.java index 3325f4bd4..e0ac10af8 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/EntityTypeIds.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/EntityTypeIds.java @@ -21,6 +21,7 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.SinceMC; +@Deprecated public class EntityTypeIds { public static final Identifier ITEM = id("item"); public static final Identifier XP_ORB = id("xp_orb"); diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/ItemIds.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/ItemIds.java index 0170074d4..ad7e02d69 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/ItemIds.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/ItemIds.java @@ -21,6 +21,7 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.SinceMC; +@Deprecated public class ItemIds { // Block Items @SinceMC("1.11") 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 55023e78d..ed9f0785b 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 @@ -21,6 +21,7 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.BackwardCompatibilityHelper; +@Deprecated @FunctionalInterface public interface RegistryEntryAddCallback { void onEntryAdded(int rawId, Identifier key, T object); 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 c947e5f4d..7ba3c7c19 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 @@ -21,6 +21,7 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.impl.registry.BackwardCompatibilityHelper; +@Deprecated @FunctionalInterface public interface RegistryEntryRemapCallback { void onEntryAdded(int oldId, int newId, Identifier key, T object); 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 d9179d2b5..841c7f323 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 @@ -20,6 +20,8 @@ import java.util.HashMap; import java.util.Map; +import org.apache.commons.lang3.NotImplementedException; + import net.minecraft.block.Block; import net.minecraft.block.entity.BlockEntity; import net.minecraft.enchantment.Enchantment; @@ -33,12 +35,12 @@ import net.legacyfabric.fabric.api.util.BeforeMC; import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.SinceMC; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; import net.legacyfabric.fabric.impl.registry.util.BiomePair; /** * Allows registration of Blocks, Items, Block Entity Classes, Status Effects and Enchantments. */ +@Deprecated public final class RegistryHelper { public static final Map> IDENTIFIER_EVENT_MAP = new HashMap<>(); @@ -251,7 +253,13 @@ public static BiomePair registerBiomeWithMutatedVariant( EntryCreator parentBiome, Identifier parentId, EntryCreator mutatedBiome, Identifier mutatedId ) { - return RegistryHelperImpl.registerBiomeWithMutatedVariant(parentBiome, parentId, mutatedBiome, mutatedId); + // List> list = BiomeHelper.registerBiomeWithParent( + // parentId, parentBiome::create, + // mutatedId, (id, biome) -> mutatedBiome.create(id) + // ); + // + // return new BiomePair(list.get(0).getValue(), list.get(1).getValue()); + throw new NotImplementedException("Registering biome with parent is currently not implemented before 1.9"); } public static Biome getBiome(Identifier id) { 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 9fd34e60e..f4cb55ff8 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 @@ -19,6 +19,7 @@ import net.legacyfabric.fabric.api.util.Identifier; +@Deprecated 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 = net.legacyfabric.fabric.api.registry.v2.RegistryIds.ITEMS; diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/StatusEffectIds.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/StatusEffectIds.java index 6b9347be3..3e3014119 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/StatusEffectIds.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/StatusEffectIds.java @@ -20,6 +20,7 @@ import net.legacyfabric.fabric.api.util.Identifier; import net.legacyfabric.fabric.api.util.SinceMC; +@Deprecated public class StatusEffectIds { public static final Identifier SPEED = id("speed"); public static final Identifier SLOWNESS = id("slowness"); diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/client/registry/sync/ClientRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/client/registry/sync/ClientRegistryRemapper.java deleted file mode 100644 index 5424d2cca..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/client/registry/sync/ClientRegistryRemapper.java +++ /dev/null @@ -1,47 +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.impl.client.registry.sync; - -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapperRegistryRemapper; - -public class ClientRegistryRemapper implements RegistryRemapperAccess { - private static final RegistryRemapperAccess INSTANCE = new ClientRegistryRemapper(); - - private final RegistryRemapper> REGISTRY_REMAPPER; - - @Override - public RegistryRemapper> getRegistryRemapperRegistryRemapper() { - return REGISTRY_REMAPPER; - } - - @Override - public void registrerRegistryRemapper(RegistryRemapper registryRemapper) { - RegistryHelperImpl.registerRegistryRemapper(REGISTRY_REMAPPER, registryRemapper); - } - - public static RegistryRemapperAccess getInstance() { - return INSTANCE; - } - - private ClientRegistryRemapper() { - REGISTRY_REMAPPER = new RegistryRemapperRegistryRemapper(); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/client/registry/sync/ClientRemapInitializer.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/client/registry/sync/ClientRemapInitializer.java deleted file mode 100644 index ded3d09bb..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/client/registry/sync/ClientRemapInitializer.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.impl.client.registry.sync; - -import java.io.IOException; -import java.io.UncheckedIOException; - -import net.minecraft.nbt.NbtCompound; - -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -import net.legacyfabric.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; - -@Environment(EnvType.CLIENT) -public class ClientRemapInitializer implements ClientModInitializer { - @Override - public void onInitializeClient() { - ClientPlayNetworking.registerGlobalReceiver(RegistryRemapperAccess.PACKET_ID, (client, handler, buf, responseSender) -> { - NbtCompound nbt; - - try { - nbt = buf.readNbtCompound(); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - - client.submit(() -> ClientRegistryRemapper.getInstance().readAndRemap(nbt)); - }); - } -} 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 deleted file mode 100644 index 4ad5ae3c0..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java +++ /dev/null @@ -1,278 +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.impl.registry; - -import java.util.IdentityHashMap; -import java.util.function.Consumer; -import java.util.function.Supplier; - -import com.google.common.collect.BiMap; -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; -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; -import net.fabricmc.loader.api.FabricLoader; - -import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.api.util.VersionUtils; -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; -import net.legacyfabric.fabric.impl.registry.util.ArrayAndMapBasedRegistry; -import net.legacyfabric.fabric.impl.registry.util.BiomePair; -import net.legacyfabric.fabric.impl.registry.util.NumericalIdPair; - -@ApiStatus.Internal -public class RegistryHelperImpl { - private static final boolean hasFlatteningBegun = VersionUtils.matches(">=1.8 <=1.12.2"); - public static final boolean bootstrap = VersionUtils.matches(">1.8.9"); - public static RegistriesGetter registriesGetter = null; - - public static int register(T object, Identifier id, Identifier registryId) { - RegistryRemapper remapper = RegistryRemapper.getRegistryRemapper(registryId); - int rawId = nextId(remapper.getRegistry()); - remapper.register(rawId, id, object); - - return rawId; - } - - public static T register(RegistryHelper.EntryCreator entryCreator, Identifier id, Identifier registryId) { - return register(entryCreator, id, registryId, instance -> { }); - } - - public static T register(RegistryHelper.EntryCreator entryCreator, Identifier id, Identifier registryId, Consumer beforeRegistration) { - RegistryRemapper remapper = RegistryRemapper.getRegistryRemapper(registryId); - SimpleRegistryCompat registry = remapper.getRegistry(); - int rawId = nextId(registry); - - if (registry instanceof ArrayAndMapBasedRegistry) ((ArrayAndMapBasedRegistry) registry).updateArrayLength(rawId); - - T instance = entryCreator.create(rawId); - beforeRegistration.accept(instance); - - remapper.register(rawId, id, instance); - - 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 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); - - return blockEntityClass; - } - - public static Class registerEntityType(Class entityTypeClass, Identifier id) { - register(entityTypeClass, id, RegistryIds.ENTITY_TYPES); - - return entityTypeClass; - } - - public static StatusEffect registerStatusEffect(StatusEffect statusEffect, Identifier id) { - statusEffect.setTranslationKey(formatTranslationKey(id)); - register(statusEffect, id, RegistryIds.STATUS_EFFECTS); - - return statusEffect; - } - - public static StatusEffect registerStatusEffect(RegistryHelper.EntryCreator statusEffectCreator, Identifier id) { - return register(statusEffectCreator, id, RegistryIds.STATUS_EFFECTS, effect -> effect.setTranslationKey(formatTranslationKey(id))); - } - - public static Enchantment registerEnchantment(Enchantment enchantment, Identifier id) { - enchantment.setName(formatTranslationKey(id)); - register(enchantment, id, RegistryIds.ENCHANTMENTS); - - return enchantment; - } - - public static Enchantment registerEnchantment(RegistryHelper.EntryCreator enchantmentCreator, Identifier id) { - return register(enchantmentCreator, id, RegistryIds.ENCHANTMENTS, enchantment -> enchantment.setName(formatTranslationKey(id))); - } - - public static Biome registerBiome(Biome biome, Identifier id) { - register(biome, id, RegistryIds.BIOMES); - - return biome; - } - - public static Biome registerBiome(RegistryHelper.EntryCreator biomeCreator, Identifier id) { - return register(biomeCreator, id, RegistryIds.BIOMES); - } - - public static BiomePair registerBiomeWithMutatedVariant( - RegistryHelper.EntryCreator parentBiomeCreator, Identifier parentId, - RegistryHelper.EntryCreator mutatedBiomeCreator, Identifier mutatedId - ) { - RegistryRemapper registryRemapper = RegistryRemapper.getRegistryRemapper(RegistryIds.BIOMES); - NumericalIdPair rawIds = nextIds(registryRemapper.getRegistry(), 128); - - ((ArrayAndMapBasedRegistry) registryRemapper.getRegistry()).updateArrayLength(rawIds.getSecondary()); - - Biome parentBiome = parentBiomeCreator.create(rawIds.getMain()); - registryRemapper.register(rawIds.getMain(), parentId, parentBiome); - - Biome mutatedBiome = mutatedBiomeCreator.create(rawIds.getSecondary()); - registryRemapper.register(rawIds.getSecondary(), mutatedId, mutatedBiome); - - return new BiomePair(parentBiome, mutatedBiome); - } - - public static V getValue(Identifier id, Identifier registryId) { - RegistryRemapper registryRemapper = RegistryRemapper.getRegistryRemapper(registryId); - return registryRemapper.getRegistry().getValue(id); - } - - public static RegistryRemapper registerRegistryRemapper(RegistryRemapper> registryRemapperRegistryRemapper, RegistryRemapper registryRemapper) { - int rawId = nextId(registryRemapperRegistryRemapper.getRegistry()); - registryRemapperRegistryRemapper.register(rawId, registryRemapper.registryId, registryRemapper); - - return registryRemapper; - } - - public static void registerRegistryRemapper(Supplier> remapperSupplier) { - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - ClientRegistryRemapper.getInstance().registrerRegistryRemapper(remapperSupplier.get()); - } - - ServerRegistryRemapper.getInstance().registrerRegistryRemapper(remapperSupplier.get()); - } - - public static RegistryRemapper getRegistryRemapper(Identifier identifier) { - return (RegistryRemapper) ServerRegistryRemapper.getInstance().getRegistryRemapperRegistryRemapper().getRegistry().getValue(identifier); - } - - private static String formatTranslationKey(Identifier key) { - return key.getNamespace() + "." + key.getPath(); - } - - public static int nextId(SimpleRegistryCompat registry) { - return nextId(registry.getIds(), registry); - } - - public static int nextId(SimpleRegistryCompat registry, int minId) { - return nextId(registry.getIds(), registry, minId); - } - - public static NumericalIdPair nextIds(SimpleRegistryCompat registry, int offset) { - int id = 0; - - RegistryRemapper registryRemapper = RegistryRemapper.getRegistryRemapper(registry); - - if (registryRemapper == null) { - registryRemapper = RegistryRemapper.DEFAULT_CLIENT_INSTANCE; - } - - while (id < registryRemapper.getMinId() - || !(getIdList(registry).fromInt(id) == null && getIdList(registry).fromInt(id + offset) == null) - ) { - id++; - } - - return new NumericalIdPair(id, id + offset); - } - - public static int nextId(IdListCompat idList, SimpleRegistryCompat registry, int minId) { - return nextId(idList, registry, HashBiMap.create(), minId); - } - - public static int nextId(IdListCompat idList, SimpleRegistryCompat registry) { - return nextId(idList, registry, 0); - } - - public static int nextId(IdListCompat idList, SimpleRegistryCompat registry, BiMap missingMap) { - return nextId(idList, registry, missingMap, 0); - } - - public static int nextId(IdListCompat idList, SimpleRegistryCompat registry, BiMap missingMap, int minId) { - int id = minId; - - RegistryRemapper registryRemapper = RegistryRemapper.getRegistryRemapper(registry); - - if (registryRemapper == null) { - registryRemapper = RegistryRemapper.DEFAULT_CLIENT_INSTANCE; - } - - while (idList.fromInt(id) != null - || id < registryRemapper.getMinId() - || missingMap.containsValue(id) - ) { - id++; - } - - return id; - } - - public static IdListCompat getIdList(SimpleRegistryCompat registry) { - return registry.getIds(); - } - - public static BiMap getObjects(SimpleRegistryCompat registry) { - return (BiMap) registry.getObjects(); - } - - public static IdentityHashMap getIdMap(IdListCompat idList, SimpleRegistryCompat registry) { - return idList.getIdMap(registry); - } - - public static IdentityHashMap getIdMap(SimpleRegistryCompat registry) { - return getIdMap(getIdList(registry), registry); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldBiomeRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldBiomeRegistry.java deleted file mode 100644 index 7f1fa2ce3..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldBiomeRegistry.java +++ /dev/null @@ -1,106 +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.impl.registry.registries; - -import com.google.common.collect.BiMap; - -import net.minecraft.world.biome.Biome; - -import net.legacyfabric.fabric.api.registry.v1.BiomeIds; -import net.legacyfabric.fabric.impl.registry.util.ArrayAndMapBasedRegistry; - -public abstract class OldBiomeRegistry extends ArrayAndMapBasedRegistry { - public OldBiomeRegistry(Biome[] valueArray, BiMap defaultMap) { - super(valueArray, defaultMap); - } - - @Override - public BiMap generateOldToNewKeyMap() { - BiMap map = super.generateOldToNewKeyMap(); - - map.put("Ocean", BiomeIds.OCEAN.toString()); - map.put("Plains", BiomeIds.PLAINS.toString()); - map.put("Desert", BiomeIds.DESERT.toString()); - map.put("Extreme Hills", BiomeIds.EXTREME_HILLS.toString()); - map.put("Forest", BiomeIds.FOREST.toString()); - map.put("Taiga", BiomeIds.TAIGA.toString()); - map.put("Swampland", BiomeIds.SWAMPLAND.toString()); - map.put("River", BiomeIds.RIVER.toString()); - map.put("Hell", BiomeIds.HELL.toString()); - map.put("The End", BiomeIds.THE_END.toString()); - map.put("FrozenOcean", BiomeIds.FROZEN_OCEAN.toString()); - map.put("FrozenRiver", BiomeIds.FROZEN_RIVER.toString()); - map.put("Ice Plains", BiomeIds.ICE_PLAINS.toString()); - map.put("Ice Mountains", BiomeIds.ICE_MOUNTAINS.toString()); - map.put("MushroomIsland", BiomeIds.MUSHROOM_ISLAND.toString()); - map.put("MushroomIslandShore", BiomeIds.MUSHROOM_ISLAND_SHORE.toString()); - map.put("Beach", BiomeIds.BEACH.toString()); - map.put("DesertHills", BiomeIds.DESERT_HILLS.toString()); - map.put("ForestHills", BiomeIds.FOREST_HILLS.toString()); - map.put("TaigaHills", BiomeIds.TAIGA_HILLS.toString()); - map.put("Extreme Hills Edge", BiomeIds.EXTREME_HILLS_EDGE.toString()); - map.put("Jungle", BiomeIds.JUNGLE.toString()); - map.put("JungleHills", BiomeIds.JUNGLE_HILLS.toString()); - map.put("JungleEdge", BiomeIds.JUNGLE_EDGE.toString()); - map.put("Deep Ocean", BiomeIds.DEEP_OCEAN.toString()); - map.put("Stone Beach", BiomeIds.STONE_BEACH.toString()); - map.put("Cold Beach", BiomeIds.COLD_BEACH.toString()); - map.put("Birch Forest", BiomeIds.BIRCH_FOREST.toString()); - map.put("Birch Forest Hills", BiomeIds.BIRCH_FOREST_HILLS.toString()); - map.put("Roofed Forest", BiomeIds.ROOFED_FOREST.toString()); - map.put("Cold Taiga", BiomeIds.COLD_TAIGA.toString()); - map.put("Cold Taiga Hills", BiomeIds.COLD_TAIGA_HILLS.toString()); - map.put("Mega Taiga", BiomeIds.MEGA_TAIGA.toString()); - map.put("Mega Taiga Hills", BiomeIds.MEGA_TAIGA_HILLS.toString()); - map.put("Extreme Hills+", BiomeIds.EXTREME_HILLS_PLUS.toString()); - map.put("Savanna", BiomeIds.SAVANNA.toString()); - map.put("Savanna Plateau", BiomeIds.SAVANNA_PLATEAU.toString()); - map.put("Mesa", BiomeIds.MESA.toString()); - map.put("Mesa Plateau F", BiomeIds.MESA_PLATEAU_F.toString()); - map.put("Mesa Plateau", BiomeIds.MESA_PLATEAU.toString()); - - map.put("Sunflower Plains", BiomeIds.SUNFLOWER_PLAINS.toString()); - map.put("Desert M", BiomeIds.MUTATED_DESERT.toString()); - map.put("Extreme Hills M", BiomeIds.MUTATED_EXTREME_HILLS.toString()); - map.put("Flower Forest", BiomeIds.FLOWER_FOREST.toString()); - map.put("Taiga M", BiomeIds.MUTATED_TAIGA.toString()); - map.put("Swampland M", BiomeIds.MUTATED_SWAMPLAND.toString()); - map.put("Ice Plains Spikes", BiomeIds.ICE_PLAINS_SPIKES.toString()); - map.put("Jungle M", BiomeIds.MUTATED_JUNGLE.toString()); - map.put("JungleEdge M", BiomeIds.MUTATED_JUNGLE_EDGE.toString()); - map.put("Birch Forest M", BiomeIds.MUTATED_BIRCH_FOREST.toString()); - map.put("Birch Forest Hills M", BiomeIds.MUTATED_BIRCH_FOREST_HILLS.toString()); - map.put("Roofed Forest M", BiomeIds.MUTATED_ROOFED_FOREST.toString()); - map.put("Cold Taiga M", BiomeIds.MUTATED_COLD_TAIGA.toString()); - map.put("Mega Spruce Taiga", BiomeIds.MEGA_SPRUCE_TAIGA.toString()); - map.put("Redwood Taiga Hills M", BiomeIds.MUTATED_REDWOOD_TAIGA_HILLS.toString()); - map.put("Extreme Hills+ M", BiomeIds.MUTATED_EXTREME_HILLS_PLUS.toString()); - map.put("Savanna M", BiomeIds.MUTATED_SAVANNA.toString()); - map.put("Savanna Plateau M", BiomeIds.MUTATED_SAVANNA_PLATEAU.toString()); - map.put("Mesa (Bryce)", BiomeIds.MESA_BRYCE.toString()); - map.put("Mesa Plateau F M", BiomeIds.MUTATED_MESA_PLATEAU_F.toString()); - map.put("Mesa Plateau M", BiomeIds.MUTATED_MESA_PLATEAU.toString()); - - return map; - } - - @Override - public KeyType getKeyType() { - return KeyType.JAVA; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldBlockEntityRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldBlockEntityRegistry.java deleted file mode 100644 index b60a6c1c0..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldBlockEntityRegistry.java +++ /dev/null @@ -1,100 +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.impl.registry.registries; - -import java.util.Map; - -import com.google.common.collect.BiMap; - -import net.minecraft.block.entity.BlockEntity; - -import net.legacyfabric.fabric.api.registry.v1.BlockEntityTypeIds; -import net.legacyfabric.fabric.impl.registry.util.MapBasedRegistry; - -public class OldBlockEntityRegistry extends MapBasedRegistry> { - public OldBlockEntityRegistry(Map> defaultMap, Map, String> invertedMap) { - super(defaultMap, invertedMap); - } - - @Override - public KeyType getKeyType() { - return KeyType.JAVA; - } - - @Override - public BiMap generateOldToNewKeyMap() { - BiMap map = super.generateOldToNewKeyMap(); - - map.put("Furnace", BlockEntityTypeIds.FURNACE.toString()); - map.put("Chest", BlockEntityTypeIds.CHEST.toString()); - map.put("EnderChest", BlockEntityTypeIds.ENDER_CHEST.toString()); - map.put("RecordPlayer", BlockEntityTypeIds.JUKEBOX.toString()); - map.put("Trap", BlockEntityTypeIds.DISPENSER.toString()); - map.put("Dropper", BlockEntityTypeIds.DROPPER.toString()); - map.put("Sign", BlockEntityTypeIds.SIGN.toString()); - map.put("MobSpawner", BlockEntityTypeIds.MOB_SPAWNER.toString()); - map.put("Music", BlockEntityTypeIds.NOTEBLOCK.toString()); - map.put("Piston", BlockEntityTypeIds.PISTON.toString()); - map.put("Cauldron", BlockEntityTypeIds.BREWING_STAND.toString()); - map.put("EnchantTable", BlockEntityTypeIds.ENCHANTING_TABLE.toString()); - map.put("Airportal", BlockEntityTypeIds.END_PORTAL.toString()); - map.put("Control", BlockEntityTypeIds.COMMAND_BLOCK.toString()); - map.put("Beacon", BlockEntityTypeIds.BEACON.toString()); - map.put("Skull", BlockEntityTypeIds.SKULL.toString()); - map.put("DLDetector", BlockEntityTypeIds.DAYLIGHT_DETECTOR.toString()); - map.put("Hopper", BlockEntityTypeIds.HOPPER.toString()); - map.put("Comparator", BlockEntityTypeIds.COMPARATOR.toString()); - map.put("FlowerPot", BlockEntityTypeIds.FLOWER_POT.toString()); - map.put("Banner", BlockEntityTypeIds.BANNER.toString()); - map.put("Structure", BlockEntityTypeIds.STRUCTURE_BLOCK.toString()); - map.put("EndGateway", BlockEntityTypeIds.END_GATEWAY.toString()); - - return map; - } - - @Override - public BiMap generateIdToKeyMap() { - BiMap map = super.generateIdToKeyMap(); - - map.put(0, "Furnace"); - map.put(1, "Chest"); - map.put(2, "EnderChest"); - map.put(3, "RecordPlayer"); - map.put(4, "Trap"); - map.put(5, "Dropper"); - map.put(6, "Sign"); - map.put(7, "MobSpawner"); - map.put(8, "Music"); - map.put(9, "Piston"); - map.put(10, "Cauldron"); - map.put(11, "EnchantTable"); - map.put(12, "Airportal"); - map.put(13, "Control"); - map.put(14, "Beacon"); - map.put(15, "Skull"); - map.put(16, "DLDetector"); - map.put(17, "Hopper"); - map.put(18, "Comparator"); - map.put(19, "FlowerPot"); - map.put(20, "Banner"); - map.put(21, "Structure"); - map.put(22, "EndGateway"); - - return map; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldEnchantmentRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldEnchantmentRegistry.java deleted file mode 100644 index 8a5661761..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldEnchantmentRegistry.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.impl.registry.registries; - -import com.google.common.collect.BiMap; - -import net.minecraft.enchantment.Enchantment; -import net.minecraft.util.Identifier; - -import net.legacyfabric.fabric.impl.registry.util.ArrayAndMapBasedRegistry; - -public abstract class OldEnchantmentRegistry extends ArrayAndMapBasedRegistry { - public OldEnchantmentRegistry(Enchantment[] valueArray, BiMap defaultMap) { - super(valueArray, defaultMap); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldEntityTypeRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldEntityTypeRegistry.java deleted file mode 100644 index 7eebd2172..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldEntityTypeRegistry.java +++ /dev/null @@ -1,224 +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.impl.registry.registries; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import com.google.common.collect.BiMap; -import org.jetbrains.annotations.NotNull; - -import net.minecraft.entity.Entity; -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.api.registry.v1.EntityTypeIds; -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.util.OldRemappedRegistry; - -public class OldEntityTypeRegistry extends OldRemappedRegistry> { - private final BiMap> stringClassBiMap; - private final BiMap> integerClassBiMap; - private final BiMap stringIntegerBiMap; - - private IdListCompat> IDLIST = (IdListCompat>) new IdList>(); - - public OldEntityTypeRegistry(BiMap> stringClassBiMap, - BiMap> integerClassBiMap, - BiMap stringIntegerBiMap) { - this.stringClassBiMap = stringClassBiMap; - this.integerClassBiMap = integerClassBiMap; - this.stringIntegerBiMap = stringIntegerBiMap; - - this.remapDefaultIds(); - } - - @Override - public void remapDefaultIds() { - List list = new ArrayList<>(); - - for (Map.Entry> entry : this.stringClassBiMap.entrySet()) { - if (!this.getNewKey(entry.getKey()).equals(entry.getKey())) { - list.add(entry.getKey()); - } - } - - for (String oldKey : list) { - if (this.getNewKey(oldKey) == null) continue; - - this.stringClassBiMap.put(this.getNewKey(oldKey), this.stringClassBiMap.remove(oldKey)); - this.stringIntegerBiMap.put(this.getNewKey(oldKey), this.stringIntegerBiMap.remove(oldKey)); - } - - this.stringIntegerBiMap.remove(null); - - for (Map.Entry> entry : this.integerClassBiMap.entrySet()) { - this.IDLIST.setValue(entry.getValue(), entry.getKey()); - } - } - - @Override - public BiMap generateOldToNewKeyMap() { - BiMap map = super.generateOldToNewKeyMap(); - - map.put("Item", EntityTypeIds.ITEM.toString()); - map.put("XPOrb", EntityTypeIds.XP_ORB.toString()); - map.put("AreaEffectCloud", EntityTypeIds.AREA_EFFECT_CLOUD.toString()); - map.put("ThrownEgg", EntityTypeIds.EGG.toString()); - map.put("LeashKnot", EntityTypeIds.LEASH_KNOT.toString()); - map.put("Painting", EntityTypeIds.PAINTING.toString()); - map.put("Arrow", EntityTypeIds.ARROW.toString()); - map.put("Snowball", EntityTypeIds.SNOWBALL.toString()); - map.put("Fireball", EntityTypeIds.FIREBALL.toString()); - map.put("SmallFireball", EntityTypeIds.SMALL_FIREBALL.toString()); - map.put("ThrownEnderpearl", EntityTypeIds.ENDER_PEARL.toString()); - map.put("EyeOfEnderSignal", EntityTypeIds.EYE_OF_ENDER.toString()); - map.put("ThrownPotion", EntityTypeIds.POTION.toString()); - map.put("ThrownExpBottle", EntityTypeIds.XP_BOTTLE.toString()); - map.put("ItemFrame", EntityTypeIds.ITEM_FRAME.toString()); - map.put("WitherSkull", EntityTypeIds.WITHER_SKULL.toString()); - map.put("PrimedTnt", EntityTypeIds.TNT.toString()); - map.put("FallingSand", EntityTypeIds.FALLING_BLOCK.toString()); - map.put("FireworksRocketEntity", EntityTypeIds.FIREWORKS_ROCKET.toString()); - map.put("SpectralArrow", EntityTypeIds.SPECTRAL_ARROW.toString()); - map.put("ShulkerBullet", EntityTypeIds.SHULKER_BULLET.toString()); - map.put("DragonFireball", EntityTypeIds.DRAGON_FIREBALL.toString()); - map.put("ArmorStand", EntityTypeIds.ARMOR_STAND.toString()); - map.put("MinecartCommandBlock", EntityTypeIds.COMMAND_BLOCK_MINECART.toString()); - map.put("Boat", EntityTypeIds.BOAT.toString()); - map.put("MinecartRideable", EntityTypeIds.MINECART.toString()); - map.put("MinecartChest", EntityTypeIds.CHEST_MINECART.toString()); - map.put("MinecartFurnace", EntityTypeIds.FURNACE_MINECART.toString()); - map.put("MinecartTNT", EntityTypeIds.TNT_MINECART.toString()); - map.put("MinecartHopper", EntityTypeIds.HOPPER_MINECART.toString()); - map.put("MinecartSpawner", EntityTypeIds.SPAWNER_MINECART.toString()); - map.put("Mob", EntityTypeIds.MOB.toString()); - map.put("Monster", EntityTypeIds.MONSTER.toString()); - map.put("Creeper", EntityTypeIds.CREEPER.toString()); - map.put("Skeleton", EntityTypeIds.SKELETON.toString()); - map.put("Spider", EntityTypeIds.SPIDER.toString()); - map.put("Giant", EntityTypeIds.GIANT.toString()); - map.put("Zombie", EntityTypeIds.ZOMBIE.toString()); - map.put("Slime", EntityTypeIds.SLIME.toString()); - map.put("Ghast", EntityTypeIds.GHAST.toString()); - map.put("PigZombie", EntityTypeIds.ZOMBIE_PIGMAN.toString()); - map.put("Enderman", EntityTypeIds.ENDERMAN.toString()); - map.put("CaveSpider", EntityTypeIds.CAVE_SPIDER.toString()); - map.put("Silverfish", EntityTypeIds.SILVERFISH.toString()); - map.put("Blaze", EntityTypeIds.BLAZE.toString()); - map.put("LavaSlime", EntityTypeIds.MAGMA_CUBE.toString()); - map.put("EnderDragon", EntityTypeIds.ENDER_DRAGON.toString()); - map.put("WitherBoss", EntityTypeIds.WITHER_BOSS.toString()); - map.put("Bat", EntityTypeIds.BAT.toString()); - map.put("Witch", EntityTypeIds.WITCH.toString()); - map.put("Endermite", EntityTypeIds.ENDERMITE.toString()); - map.put("Guardian", EntityTypeIds.GUARDIAN.toString()); - map.put("Shulker", EntityTypeIds.SHULKER.toString()); - map.put("Pig", EntityTypeIds.PIG.toString()); - map.put("Sheep", EntityTypeIds.SHEEP.toString()); - map.put("Cow", EntityTypeIds.COW.toString()); - map.put("Chicken", EntityTypeIds.CHICKEN.toString()); - map.put("Squid", EntityTypeIds.SQUID.toString()); - map.put("Wolf", EntityTypeIds.WOLF.toString()); - map.put("MushroomCow", EntityTypeIds.MOOSHROOM.toString()); - map.put("SnowMan", EntityTypeIds.SNOWMAN.toString()); - map.put("Ozelot", EntityTypeIds.OCELOT.toString()); - map.put("VillagerGolem", EntityTypeIds.IRON_GOLEM.toString()); - map.put("EntityHorse", EntityTypeIds.HORSE.toString()); - map.put("Rabbit", EntityTypeIds.RABBIT.toString()); - map.put("PolarBear", EntityTypeIds.POLAR_BEAR.toString()); - map.put("Villager", EntityTypeIds.VILLAGER.toString()); - map.put("EnderCrystal", EntityTypeIds.ENDER_CRYSTAL.toString()); - map.put("Player", EntityTypeIds.PLAYER.toString()); - map.put("LightningBolt", EntityTypeIds.LIGHTNING_BOLT.toString()); - - return map; - } - - @Override - public IdListCompat> getIds() { - return IDLIST; - } - - @Override - public Map, String> getObjects() { - return this.stringClassBiMap.inverse(); - } - - @Override - public void setIds(IdListCompat> idList) { - this.IDLIST = idList; - - BiMap, Integer> inversedMap = this.integerClassBiMap.inverse(); - BiMap, String> inversedMap2 = this.stringClassBiMap.inverse(); - - for (Class entityType : this.IDLIST.getList()) { - inversedMap.put(entityType, this.IDLIST.getInt(entityType)); - - this.stringIntegerBiMap.put(inversedMap2.get(entityType), this.IDLIST.getInt(entityType)); - } - - this.stringIntegerBiMap.remove(null); - } - - @Override - public IdListCompat> createIdList() { - return (IdListCompat>) new IdList>(); - } - - @Override - public int getRawID(Class object) { - return IDLIST.getInt(object); - } - - @Override - public String getKey(Class object) { - return this.stringClassBiMap.inverse().get(object); - } - - @Override - public Class getValue(Object key) { - return this.stringClassBiMap.get(this.toKeyType(key)); - } - - @Override - public Class register(int i, Object key, Class value) { - String nativeKey = this.toKeyType(key); - - this.stringClassBiMap.put(nativeKey, value); - this.integerClassBiMap.put(i, value); - this.stringIntegerBiMap.put(nativeKey, i); - - this.IDLIST.setValue(value, i); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(i, new Identifier(key), value); - return value; - } - - @Override - public KeyType getKeyType() { - return KeyType.JAVA; - } - - @NotNull - @Override - public Iterator> iterator() { - return this.IDLIST.iterator(); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldStatusEffectRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldStatusEffectRegistry.java deleted file mode 100644 index 836032380..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/OldStatusEffectRegistry.java +++ /dev/null @@ -1,36 +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.impl.registry.registries; - -import com.google.common.collect.BiMap; - -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.util.Identifier; - -import net.legacyfabric.fabric.impl.registry.util.ArrayAndMapBasedRegistry; - -public abstract class OldStatusEffectRegistry extends ArrayAndMapBasedRegistry { - public OldStatusEffectRegistry(StatusEffect[] valueArray, BiMap defaultMap) { - super(valueArray, defaultMap); - } - - @Override - public KeyType getKeyType() { - return KeyType.VANILLA; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldBiomeRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldBiomeRegistry.java deleted file mode 100644 index 669c04d8a..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldBiomeRegistry.java +++ /dev/null @@ -1,102 +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.impl.registry.registries; - -import com.google.common.collect.BiMap; - -import net.minecraft.world.biome.Biome; - -import net.legacyfabric.fabric.api.registry.v1.BiomeIds; -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.util.ArrayBasedRegistry; - -public abstract class ReallyOldBiomeRegistry extends ArrayBasedRegistry { - public ReallyOldBiomeRegistry(Biome[] valueArray) { - super(valueArray); - } - - @Override - public BiMap generateIdToKeyMap() { - BiMap map = super.generateIdToKeyMap(); - - map.put(0, BiomeIds.OCEAN); - map.put(1, BiomeIds.PLAINS); - map.put(2, BiomeIds.DESERT); - map.put(3, BiomeIds.EXTREME_HILLS); - map.put(4, BiomeIds.FOREST); - map.put(5, BiomeIds.TAIGA); - map.put(6, BiomeIds.SWAMPLAND); - map.put(7, BiomeIds.RIVER); - map.put(8, BiomeIds.HELL); - map.put(9, BiomeIds.THE_END); - map.put(10, BiomeIds.FROZEN_OCEAN); - map.put(11, BiomeIds.FROZEN_RIVER); - map.put(12, BiomeIds.ICE_PLAINS); - map.put(13, BiomeIds.ICE_MOUNTAINS); - map.put(14, BiomeIds.MUSHROOM_ISLAND); - map.put(15, BiomeIds.MUSHROOM_ISLAND_SHORE); - map.put(16, BiomeIds.BEACH); - map.put(17, BiomeIds.DESERT_HILLS); - map.put(18, BiomeIds.FOREST_HILLS); - map.put(19, BiomeIds.TAIGA_HILLS); - map.put(20, BiomeIds.EXTREME_HILLS_EDGE); - map.put(21, BiomeIds.JUNGLE); - map.put(22, BiomeIds.JUNGLE_HILLS); - map.put(23, BiomeIds.JUNGLE_EDGE); - map.put(24, BiomeIds.DEEP_OCEAN); - map.put(25, BiomeIds.STONE_BEACH); - map.put(26, BiomeIds.COLD_BEACH); - map.put(27, BiomeIds.BIRCH_FOREST); - map.put(28, BiomeIds.BIRCH_FOREST_HILLS); - map.put(29, BiomeIds.ROOFED_FOREST); - map.put(30, BiomeIds.COLD_TAIGA); - map.put(31, BiomeIds.COLD_TAIGA_HILLS); - map.put(32, BiomeIds.MEGA_TAIGA); - map.put(33, BiomeIds.MEGA_TAIGA_HILLS); - map.put(34, BiomeIds.EXTREME_HILLS_PLUS); - map.put(35, BiomeIds.SAVANNA); - map.put(36, BiomeIds.SAVANNA_PLATEAU); - map.put(37, BiomeIds.MESA); - map.put(38, BiomeIds.MESA_PLATEAU_F); - map.put(39, BiomeIds.MESA_PLATEAU); - - map.put(129, BiomeIds.SUNFLOWER_PLAINS); - map.put(130, BiomeIds.MUTATED_DESERT); - map.put(131, BiomeIds.MUTATED_EXTREME_HILLS); - map.put(132, BiomeIds.FLOWER_FOREST); - map.put(133, BiomeIds.MUTATED_TAIGA); - map.put(134, BiomeIds.MUTATED_SWAMPLAND); - map.put(140, BiomeIds.ICE_PLAINS_SPIKES); - map.put(149, BiomeIds.MUTATED_JUNGLE); - map.put(151, BiomeIds.MUTATED_JUNGLE_EDGE); - map.put(155, BiomeIds.MUTATED_BIRCH_FOREST); - map.put(156, BiomeIds.MUTATED_BIRCH_FOREST_HILLS); - map.put(157, BiomeIds.MUTATED_ROOFED_FOREST); - map.put(158, BiomeIds.MUTATED_COLD_TAIGA); - map.put(160, BiomeIds.MEGA_SPRUCE_TAIGA); - map.put(161, BiomeIds.MUTATED_REDWOOD_TAIGA_HILLS); - map.put(162, BiomeIds.MUTATED_EXTREME_HILLS_PLUS); - map.put(163, BiomeIds.MUTATED_SAVANNA); - map.put(164, BiomeIds.MUTATED_SAVANNA_PLATEAU); - map.put(165, BiomeIds.MESA_BRYCE); - map.put(166, BiomeIds.MUTATED_MESA_PLATEAU_F); - map.put(167, BiomeIds.MUTATED_MESA_PLATEAU); - - return map; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldEnchantmentRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldEnchantmentRegistry.java deleted file mode 100644 index d52309cc4..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldEnchantmentRegistry.java +++ /dev/null @@ -1,64 +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.impl.registry.registries; - -import com.google.common.collect.BiMap; - -import net.minecraft.enchantment.Enchantment; - -import net.legacyfabric.fabric.api.registry.v1.EnchantmentIds; -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.util.ArrayBasedRegistry; - -public abstract class ReallyOldEnchantmentRegistry extends ArrayBasedRegistry { - public ReallyOldEnchantmentRegistry(Enchantment[] valueArray) { - super(valueArray); - } - - @Override - public BiMap generateIdToKeyMap() { - BiMap map = super.generateIdToKeyMap(); - - map.put(0, EnchantmentIds.PROTECTION); - map.put(1, EnchantmentIds.FIRE_PROTECTION); - map.put(2, EnchantmentIds.FEATHER_FALLING); - map.put(3, EnchantmentIds.BLAST_PROTECTION); - map.put(4, EnchantmentIds.PROJECTILE_PROTECTION); - map.put(5, EnchantmentIds.RESPIRATION); - map.put(6, EnchantmentIds.AQUA_AFFINITY); - map.put(7, EnchantmentIds.THORNS); - map.put(16, EnchantmentIds.SHARPNESS); - map.put(17, EnchantmentIds.SMITE); - map.put(18, EnchantmentIds.BANE_OF_ARTHROPODS); - map.put(19, EnchantmentIds.KNOCKBACK); - map.put(20, EnchantmentIds.FIRE_ASPECT); - map.put(21, EnchantmentIds.LOOTING); - map.put(32, EnchantmentIds.EFFICIENCY); - map.put(33, EnchantmentIds.SILK_TOUCH); - map.put(34, EnchantmentIds.UNBREAKING); - map.put(35, EnchantmentIds.FORTUNE); - map.put(48, EnchantmentIds.POWER); - map.put(49, EnchantmentIds.PUNCH); - map.put(50, EnchantmentIds.FLAME); - map.put(51, EnchantmentIds.INFINITY); - map.put(61, EnchantmentIds.LUCK_OF_THE_SEA); - map.put(62, EnchantmentIds.LURE); - - return map; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldStatusEffectRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldStatusEffectRegistry.java deleted file mode 100644 index d02958552..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/ReallyOldStatusEffectRegistry.java +++ /dev/null @@ -1,63 +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.impl.registry.registries; - -import com.google.common.collect.BiMap; - -import net.minecraft.entity.effect.StatusEffect; - -import net.legacyfabric.fabric.api.registry.v1.StatusEffectIds; -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.util.ArrayBasedRegistry; - -public abstract class ReallyOldStatusEffectRegistry extends ArrayBasedRegistry { - public ReallyOldStatusEffectRegistry(StatusEffect[] valueArray) { - super(valueArray); - } - - @Override - public BiMap generateIdToKeyMap() { - BiMap map = super.generateIdToKeyMap(); - - map.put(1, StatusEffectIds.SPEED); - map.put(2, StatusEffectIds.SLOWNESS); - map.put(3, StatusEffectIds.HASTE); - map.put(4, StatusEffectIds.MINING_FATIGUE); - map.put(5, StatusEffectIds.STRENGTH); - map.put(6, StatusEffectIds.INSTANT_HEALTH); - map.put(7, StatusEffectIds.INSTANT_DAMAGE); - map.put(8, StatusEffectIds.JUMP_BOOST); - map.put(9, StatusEffectIds.NAUSEA); - map.put(10, StatusEffectIds.REGENERATION); - map.put(11, StatusEffectIds.RESISTANCE); - map.put(12, StatusEffectIds.FIRE_RESISTANCE); - map.put(13, StatusEffectIds.WATER_BREATHING); - map.put(14, StatusEffectIds.INVISIBILITY); - map.put(15, StatusEffectIds.BLINDNESS); - map.put(16, StatusEffectIds.NIGHT_VISION); - map.put(17, StatusEffectIds.HUNGER); - map.put(18, StatusEffectIds.WEAKNESS); - map.put(19, StatusEffectIds.POISON); - map.put(20, StatusEffectIds.WITHER); - map.put(21, StatusEffectIds.HEALTH_BOOST); - map.put(22, StatusEffectIds.ABSORPTION); - map.put(23, StatusEffectIds.SATURATION); - - return map; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/RegistryRemapperRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/RegistryRemapperRegistry.java deleted file mode 100644 index e6459eb7c..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/RegistryRemapperRegistry.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.impl.registry.registries; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.util.VanillaLikeRegistry; - -public class RegistryRemapperRegistry extends VanillaLikeRegistry> { - public RegistryRemapperRegistry() { - super(); - } - - @Override - public KeyType getKeyType() { - return KeyType.FABRIC; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistryRemapperAccess.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistryRemapperAccess.java deleted file mode 100644 index 581420eba..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/RegistryRemapperAccess.java +++ /dev/null @@ -1,68 +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.impl.registry.sync; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.PacketByteBuf; - -import net.legacyfabric.fabric.api.networking.v1.PacketByteBufs; -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.PacketByteBufCompat; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; - -public interface RegistryRemapperAccess { - Identifier PACKET_ID = new Identifier("legacy-fabric-api:registry_remap"); - - RegistryRemapper> getRegistryRemapperRegistryRemapper(); - - default void remap() { - this.getRegistryRemapperRegistryRemapper().remap(); - - for (RegistryRemapper registryRemapper : this.getRegistryRemapperRegistryRemapper().getRegistry()) { - registryRemapper.remap(); - } - } - - default void readAndRemap(NbtCompound nbt) { - this.getRegistryRemapperRegistryRemapper().readNbt(nbt.getCompound(this.getRegistryRemapperRegistryRemapper().nbtName)); - - for (RegistryRemapper registryRemapper : this.getRegistryRemapperRegistryRemapper().getRegistry()) { - registryRemapper.readNbt(nbt.getCompound(registryRemapper.nbtName)); - } - - this.remap(); - } - - default NbtCompound toNbtCompound() { - NbtCompound nbt = new NbtCompound(); - nbt.put(this.getRegistryRemapperRegistryRemapper().nbtName, this.getRegistryRemapperRegistryRemapper().toNbt()); - - for (RegistryRemapper registryRemapper : this.getRegistryRemapperRegistryRemapper().getRegistry()) { - nbt.put(registryRemapper.nbtName, registryRemapper.toNbt()); - } - - return nbt; - } - - default PacketByteBuf createBuf() { - PacketByteBuf buf = PacketByteBufs.create(); - return ((PacketByteBufCompat) buf).writeCompound(this.toNbtCompound()); - } - - void registrerRegistryRemapper(RegistryRemapper registryRemapper); -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/ServerRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/ServerRegistryRemapper.java deleted file mode 100644 index be28582fb..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/ServerRegistryRemapper.java +++ /dev/null @@ -1,51 +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.impl.registry.sync; - -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapperRegistryRemapper; - -public class ServerRegistryRemapper implements RegistryRemapperAccess { - private static final RegistryRemapperAccess INSTANCE = new ServerRegistryRemapper(); - - private final RegistryRemapper> REGISTRY_REMAPPER; - - @Override - public RegistryRemapper> getRegistryRemapperRegistryRemapper() { - return this.REGISTRY_REMAPPER; - } - - @Override - public void registrerRegistryRemapper(RegistryRemapper remapper) { - RegistryHelperImpl.registerRegistryRemapper(REGISTRY_REMAPPER, remapper); - RegistryRemapper.REMAPPER_MAP.put(remapper.registryId, remapper); - RegistryRemapper.REGISTRY_REMAPPER_MAP.put(remapper.getRegistry(), remapper); - } - - public static RegistryRemapperAccess getInstance() { - return INSTANCE; - } - - private ServerRegistryRemapper() { - REGISTRY_REMAPPER = new RegistryRemapperRegistryRemapper(); - - RegistryRemapper.REMAPPER_MAP.put(REGISTRY_REMAPPER.registryId, REGISTRY_REMAPPER); - RegistryRemapper.REGISTRY_REMAPPER_MAP.put(REGISTRY_REMAPPER.getRegistry(), REGISTRY_REMAPPER); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/BlockCompat.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/BlockCompat.java deleted file mode 100644 index da593b90f..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/BlockCompat.java +++ /dev/null @@ -1,24 +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.impl.registry.sync.compat; - -import net.minecraft.block.BlockState; - -public interface BlockCompat { - void setBLOCK_STATES(IdListCompat BLOCK_STATES); -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/IdListCompat.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/IdListCompat.java deleted file mode 100644 index 303337a3e..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/IdListCompat.java +++ /dev/null @@ -1,37 +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.impl.registry.sync.compat; - -import java.util.IdentityHashMap; -import java.util.List; - -import net.minecraft.util.collection.ObjectIdIterable; - -public interface IdListCompat extends ObjectIdIterable { - IdentityHashMap getIdMap(SimpleRegistryCompat simpleRegistry); - - List getList(); - - V fromInt(int index); - - void setValue(V value, int index); - - int getInt(V value); - - IdListCompat createIdList(); -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/ItemCompat.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/ItemCompat.java deleted file mode 100644 index 358e29aae..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/ItemCompat.java +++ /dev/null @@ -1,27 +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.impl.registry.sync.compat; - -import java.util.Map; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; - -public interface ItemCompat { - Map getBLOCK_ITEMS(); -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/PacketByteBufCompat.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/PacketByteBufCompat.java deleted file mode 100644 index 9b4421ce3..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/PacketByteBufCompat.java +++ /dev/null @@ -1,25 +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.impl.registry.sync.compat; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.PacketByteBuf; - -public interface PacketByteBufCompat { - PacketByteBuf writeCompound(NbtCompound compound); -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/RegistriesGetter.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/RegistriesGetter.java deleted file mode 100644 index 69d5378e9..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/RegistriesGetter.java +++ /dev/null @@ -1,36 +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.impl.registry.sync.compat; - -import net.minecraft.block.Block; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.Entity; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.item.Item; -import net.minecraft.world.biome.Biome; - -public interface RegistriesGetter { - SimpleRegistryCompat getBlockRegistry(); - SimpleRegistryCompat getItemRegistry(); - SimpleRegistryCompat> getBlockEntityTypeRegistry(); - SimpleRegistryCompat getStatusEffectRegistry(); - SimpleRegistryCompat getEnchantmentRegistry(); - SimpleRegistryCompat getBiomeRegistry(); - SimpleRegistryCompat> getEntityTypeRegistry(); -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/SimpleRegistryCompat.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/SimpleRegistryCompat.java deleted file mode 100644 index fe57e21b4..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/SimpleRegistryCompat.java +++ /dev/null @@ -1,68 +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.impl.registry.sync.compat; - -import java.util.Map; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.util.RegistryEventsHolder; - -public interface SimpleRegistryCompat extends Iterable { - RegistryEventsHolder getEventHolder(); - - void setEventHolder(RegistryEventsHolder eventsHolder); - - IdListCompat getIds(); - - Map getObjects(); - - void setIds(IdListCompat idList); - - IdListCompat createIdList(); - - int getRawID(V object); - - K getKey(V object); - - V getValue(Object key); - - V register(int i, Object key, V value); - - default KeyType getKeyType() { - return KeyType.VANILLA; - } - - default K toKeyType(Object key) { - switch (this.getKeyType()) { - case FABRIC: - return (K) (key instanceof Identifier ? key : new Identifier(key.toString())); - case JAVA: - return (K) key.toString(); - case VANILLA: - return (K) new net.minecraft.util.Identifier(key.toString()); - } - - return (K) key; - } - - enum KeyType { - FABRIC, - VANILLA, - JAVA - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BiomeRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BiomeRegistryRemapper.java deleted file mode 100644 index 7d1823ac5..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BiomeRegistryRemapper.java +++ /dev/null @@ -1,29 +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.impl.registry.sync.remappers; - -import net.minecraft.world.biome.Biome; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; - -public class BiomeRegistryRemapper extends RegistryRemapper { - public BiomeRegistryRemapper() { - super(RegistryHelperImpl.registriesGetter.getBiomeRegistry(), RegistryIds.BIOMES, "Biome", "Biomes"); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BlockEntityTypeRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BlockEntityTypeRegistryRemapper.java deleted file mode 100644 index 07faf46f5..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BlockEntityTypeRegistryRemapper.java +++ /dev/null @@ -1,29 +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.impl.registry.sync.remappers; - -import net.minecraft.block.entity.BlockEntity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; - -public class BlockEntityTypeRegistryRemapper extends RegistryRemapper> { - public BlockEntityTypeRegistryRemapper() { - super(RegistryHelperImpl.registriesGetter.getBlockEntityTypeRegistry(), RegistryIds.BLOCK_ENTITY_TYPES, "BlockEntityType", "BlockEntityTypes"); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BlockRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BlockRegistryRemapper.java deleted file mode 100644 index 79f14919b..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/BlockRegistryRemapper.java +++ /dev/null @@ -1,89 +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.impl.registry.sync.remappers; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.api.util.VersionUtils; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.compat.BlockCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -public class BlockRegistryRemapper extends RegistryRemapper { - public BlockRegistryRemapper() { - super(RegistryHelperImpl.registriesGetter.getBlockRegistry(), RegistryIds.BLOCKS, "Block", "Blocks"); - } - - private static final boolean hasBlockStateList = VersionUtils.matches(">=1.8"); - private static final boolean hasSpecialCase = VersionUtils.matches(">1.8.9"); - - @Override - public void remap() { - super.remap(); - - if (hasBlockStateList) { - IdListCompat oldStates = (IdListCompat) Block.BLOCK_STATES; - IdListCompat newStates = oldStates.createIdList(); - - for (Block block : this.registry) { - if (this.registry.getKey(block).equals(this.toKeyType("tripwire")) && hasSpecialCase) { - int newBlockId = this.registry.getRawID(block); - - for (int i = 0; i < 15; ++i) { - int newId = newBlockId << 4 | i; - BlockState state = block.stateFromData(i); - int oldId = oldStates.getInt(state); - - if (oldId == -1) { - LOGGER.info("New block state id %d for block %s", newId, this.registry.getKey(block).toString()); - } else if (oldId != newId) { - LOGGER.info("Migrating block state id %d of block %s to %d", - oldId, this.registry.getKey(block).toString(), newId); - } - - newStates.setValue(state, newId); - } - } else { - for (BlockState blockState : block.getStateManager().getBlockStates()) { - int newBlockId = this.registry.getRawID(block); - int newId = newBlockId << 4 | block.getData(blockState); - int oldId = oldStates.getInt(blockState); - - if (oldId == -1) { - LOGGER.info("New block state id %d for block %s", newId, this.registry.getKey(block).toString()); - } else if (oldId != newId) { - LOGGER.info("Migrating block state id %d of block %s to %d", - oldId, this.registry.getKey(block).toString(), newId); - } - - newStates.setValue(blockState, newId); - } - } - } - - ((BlockCompat) this.registry.getValue(this.toKeyType("air"))).setBLOCK_STATES(newStates); - } - } - - @Override - public int getMinId() { - return 256; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/EnchantmentRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/EnchantmentRegistryRemapper.java deleted file mode 100644 index 7ddb37208..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/EnchantmentRegistryRemapper.java +++ /dev/null @@ -1,29 +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.impl.registry.sync.remappers; - -import net.minecraft.enchantment.Enchantment; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; - -public class EnchantmentRegistryRemapper extends RegistryRemapper { - public EnchantmentRegistryRemapper() { - super(RegistryHelperImpl.registriesGetter.getEnchantmentRegistry(), RegistryIds.ENCHANTMENTS, "Enchantment", "Enchantments"); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/EntityTypeRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/EntityTypeRegistryRemapper.java deleted file mode 100644 index ffef7fedc..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/EntityTypeRegistryRemapper.java +++ /dev/null @@ -1,34 +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.impl.registry.sync.remappers; - -import net.minecraft.entity.Entity; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; - -public class EntityTypeRegistryRemapper extends RegistryRemapper> { - public EntityTypeRegistryRemapper() { - super(RegistryHelperImpl.registriesGetter.getEntityTypeRegistry(), RegistryIds.ENTITY_TYPES, "EntityType", "EntityTypes"); - } - - @Override - public int getMinId() { - return 210; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/ItemRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/ItemRegistryRemapper.java deleted file mode 100644 index 92a52812e..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/ItemRegistryRemapper.java +++ /dev/null @@ -1,34 +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.impl.registry.sync.remappers; - -import net.minecraft.item.Item; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; - -public class ItemRegistryRemapper extends RegistryRemapper { - public ItemRegistryRemapper() { - super(RegistryHelperImpl.registriesGetter.getItemRegistry(), RegistryIds.ITEMS, "Item", "Items"); - } - - @Override - public int getMinId() { - return 256; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/RegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/RegistryRemapper.java deleted file mode 100644 index cd7fab552..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/RegistryRemapper.java +++ /dev/null @@ -1,260 +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.impl.registry.sync.remappers; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.IntSupplier; -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.v1.RegistryHelper; -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.logger.LoggerImpl; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; -import net.legacyfabric.fabric.impl.registry.util.ArrayBasedRegistry; -import net.legacyfabric.fabric.impl.registry.util.RegistryEventsHolder; - -public class RegistryRemapper { - protected static final Logger LOGGER = Logger.get(LoggerImpl.API, "RegistryRemapper"); - protected final SimpleRegistryCompat registry; - protected BiMap entryDump; - protected BiMap missingMap = HashBiMap.create(); - public final Identifier registryId; - public final String type; - public final String nbtName; - - public static final Map, RegistryRemapper> REGISTRY_REMAPPER_MAP = new HashMap<>(); - public static final Map> REMAPPER_MAP = new HashMap<>(); - - public static RegistryRemapper> DEFAULT_CLIENT_INSTANCE = null; - - private static final Map> IDENTIFIER_EVENT_MAP = new HashMap<>(); - - public RegistryRemapper(SimpleRegistryCompat registry, Identifier registryId, String type, String nbtName) { - this.registry = registry; - this.registryId = registryId; - this.type = type; - this.nbtName = nbtName; - - if (this instanceof RegistryRemapperRegistryRemapper && DEFAULT_CLIENT_INSTANCE == null) { - DEFAULT_CLIENT_INSTANCE = (RegistryRemapper>) this; - } - - if (IDENTIFIER_EVENT_MAP.containsKey(this.registryId)) { - this.registry.setEventHolder((RegistryEventsHolder) IDENTIFIER_EVENT_MAP.get(this.registryId)); - } else { - this.registry.setEventHolder(new RegistryEventsHolder<>()); - } - - if (RegistryHelper.IDENTIFIER_EVENT_MAP.containsKey(registryId)) { - RegistryHelper.IDENTIFIER_EVENT_MAP.remove(registryId).invoker(); - } - } - - public void dump() { - this.entryDump = HashBiMap.create(); - LOGGER.debug("Dumping registry %s.", this.registryId); - RegistryHelperImpl.getIdMap(this.registry).forEach((value, id) -> { - Object key = RegistryHelperImpl.getObjects(this.registry).get(value); - LOGGER.debug("%s %s %d %s", this.type, key, id, value); - if (key != null) this.entryDump.put(new Identifier(key), id); - }); - - for (Map.Entry entry : this.missingMap.entrySet()) { - if (!this.entryDump.containsValue(entry.getValue())) { - this.entryDump.put(entry.getKey(), entry.getValue()); - } else { - LOGGER.warn("Tried to add missing entry %s at index %d, but it is already taken by %s", - entry.getKey(), entry.getValue(), this.entryDump.inverse().get(entry.getValue())); - } - } - } - - public NbtCompound toNbt() { - if (this.entryDump == null) { - 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); - } - } - - private IdListCompat getExistingFromDump() { - IdListCompat newList = this.registry.createIdList(); - - this.entryDump.forEach((id, rawId) -> { - V value = RegistryHelperImpl.getObjects(this.registry).inverse().get(this.registry.toKeyType(id)); - - if (value == null) { - newList.setValue(null, rawId); - LOGGER.warn("%s with id %s is missing!", this.type, id.toString()); - this.missingMap.put(id, rawId); - } else { - newList.setValue(value, rawId); - } - }); - - return newList; - } - - private void addNewEntries(IdListCompat newList, IntSupplier currentSize, IntSupplier previousSize) { - LOGGER.info("Adding " + (previousSize.getAsInt() - currentSize.getAsInt()) + " missing entries to registry"); - - RegistryHelperImpl.getObjects(this.registry) - .keySet().stream() - .filter(obj -> newList.getInt(obj) == -1) - .collect(Collectors.toList()) - .forEach(missingValue -> { - int newId = RegistryHelperImpl.nextId(newList, this.registry, this.missingMap); - - newList.setValue(missingValue, newId); - - LOGGER.info("Adding %s %s with numerical id %d to registry", this.type, this.registry.getKey(missingValue), newId); - }); - } - - private void invokeRemapListeners(IdListCompat newList) { - for (V value : newList) { - int oldId = this.registry.getIds().getInt(value); - int newId = newList.getInt(value); - - if (oldId != -1 && oldId != newId) { - LOGGER.info("Remapped %s %s from id %d to id %d", this.type, this.registry.getKey(value), oldId, newId); - this.registry.getEventHolder().getRemapEvent().invoker().onEntryAdded(oldId, newId, new Identifier(this.registry.getKey(value)), value); - } - } - } - - private void updateRegistry(IdListCompat newList) { - this.registry.setIds(newList); - - if (this.registry instanceof ArrayBasedRegistry) { - ((ArrayBasedRegistry) this.registry).syncArrayWithIdList(); - } - } - - private IntSupplier normalizeRegistryEntryList(IdListCompat newList) { - IntSupplier currentSize = () -> RegistryHelperImpl.getIdMap(newList, this.registry).size(); - IntSupplier previousSize = () -> RegistryHelperImpl.getObjects(this.registry).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(newList, currentSize, previousSize); - } - - if (currentSize.getAsInt() != previousSize.getAsInt() && this.missingMap.isEmpty()) { - throw new IllegalStateException("An error occured during remapping"); - } - - return previousSize; - } - - // Type erasure, ily - public void remap() { - LOGGER.info("Remapping registry %s", this.registryId.toString()); - - if (this.entryDump == null || this.entryDump.isEmpty()) { - this.dump(); - } - - IdListCompat newList = getExistingFromDump(); - - IntSupplier previousSize = normalizeRegistryEntryList(newList); - - invokeRemapListeners(newList); - - updateRegistry(newList); - - this.dump(); - LOGGER.info("Remapped " + previousSize.getAsInt() + " entries"); - } - - public static RegistryRemapper getRegistryRemapper(SimpleRegistryCompat simpleRegistry) { - return (RegistryRemapper) REGISTRY_REMAPPER_MAP.getOrDefault(simpleRegistry, null); - } - - public static RegistryRemapper getRegistryRemapper(Identifier identifier) { - RegistryRemapper remapper = (RegistryRemapper) REMAPPER_MAP.getOrDefault(identifier, null); - return remapper == null ? (RegistryRemapper) DEFAULT_CLIENT_INSTANCE : remapper; - } - - public static RegistryEventsHolder getEventsHolder(Identifier identifier) { - RegistryRemapper remapper = (RegistryRemapper) REMAPPER_MAP.getOrDefault(identifier, null); - - RegistryEventsHolder event; - - if (remapper == null) { - if (IDENTIFIER_EVENT_MAP.containsKey(identifier)) { - event = (RegistryEventsHolder) IDENTIFIER_EVENT_MAP.get(identifier); - } else { - event = new RegistryEventsHolder(); - IDENTIFIER_EVENT_MAP.put(identifier, event); - } - } else { - event = remapper.getRegistry().getEventHolder(); - } - - return event; - } - - public void addMissing(Identifier key, int id) { - this.missingMap.put(key, id); - } - - public V register(int i, Object key, V value) { - return this.registry.register(i, key, value); - } - - public SimpleRegistryCompat getRegistry() { - return this.registry; - } - - public Object toKeyType(Object id) { - return this.registry.toKeyType(id); - } - - public Identifier getIdentifier(V object) { - return new Identifier(this.registry.getKey(object).toString()); - } - - public int getMinId() { - return 0; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/RegistryRemapperRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/RegistryRemapperRegistryRemapper.java deleted file mode 100644 index a76f4dfb4..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/RegistryRemapperRegistryRemapper.java +++ /dev/null @@ -1,27 +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.impl.registry.sync.remappers; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.registries.RegistryRemapperRegistry; - -public class RegistryRemapperRegistryRemapper extends RegistryRemapper> { - public RegistryRemapperRegistryRemapper() { - super(new RegistryRemapperRegistry(), RegistryIds.REGISTRY_REMAPPER, "RegistryRemapper", "RegistryRemappers"); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/StatusEffectRegistryRemapper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/StatusEffectRegistryRemapper.java deleted file mode 100644 index 50a100436..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/remappers/StatusEffectRegistryRemapper.java +++ /dev/null @@ -1,34 +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.impl.registry.sync.remappers; - -import net.minecraft.entity.effect.StatusEffect; - -import net.legacyfabric.fabric.api.registry.v1.RegistryIds; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; - -public class StatusEffectRegistryRemapper extends RegistryRemapper { - public StatusEffectRegistryRemapper() { - super(RegistryHelperImpl.registriesGetter.getStatusEffectRegistry(), RegistryIds.STATUS_EFFECTS, "StatusEffect", "StatusEffects"); - } - - @Override - public int getMinId() { - return 1; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/ArrayAndMapBasedRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/ArrayAndMapBasedRegistry.java deleted file mode 100644 index 49b92155b..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/ArrayAndMapBasedRegistry.java +++ /dev/null @@ -1,146 +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.impl.registry.util; - -import java.lang.reflect.Array; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; - -import com.google.common.collect.BiMap; -import org.jetbrains.annotations.NotNull; - -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -public abstract class ArrayAndMapBasedRegistry extends OldRemappedRegistry { - private V[] valueArray; - private final Map defaultMap; - private final Map invertedMap; - private IdListCompat IDLIST = (IdListCompat) new IdList(); - - private boolean init = false; - - public ArrayAndMapBasedRegistry(V[] valueArray, BiMap defaultMap) { - this.valueArray = (V[]) Array.newInstance(valueArray.getClass().getComponentType(), valueArray.length + 1); - Arrays.fill(this.valueArray, null); - - this.defaultMap = defaultMap; - this.invertedMap = ((BiMap) this.defaultMap).inverse(); - - this.initRegistry(valueArray); - this.init = true; - - this.syncArrayWithIdList(); - } - - public void initRegistry(V[] originalValueArray) { - for (int i = 0; i < originalValueArray.length; i++) { - V value = originalValueArray[i]; - K key = this.invertedMap.remove(value); - - if (value == null) continue; - - K newKey = this.getNewKey(key); - - this.register(i, newKey, value); - } - } - - @Override - public IdListCompat getIds() { - return IDLIST; - } - - @Override - public Map getObjects() { - return this.invertedMap; - } - - @Override - public void setIds(IdListCompat idList) { - this.IDLIST = idList; - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new IdList(); - } - - @Override - public int getRawID(V object) { - return IDLIST.getInt(object); - } - - @Override - public K getKey(V object) { - return this.invertedMap.get(object); - } - - @Override - public V getValue(Object key) { - return this.defaultMap.get(this.toKeyType(key)); - } - - @NotNull - @Override - public Iterator iterator() { - return this.IDLIST.iterator(); - } - - @Override - public V register(int i, Object key, V value) { - this.defaultMap.put(this.toKeyType(key), value); - this.IDLIST.setValue(value, i); - - if (this.init) { - this.syncArrayWithIdList(); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(i, new Identifier(key), value); - } - - return value; - } - - public void updateArrayLength(int i) { - while (i >= this.valueArray.length) { - this.valueArray = Arrays.copyOf(this.valueArray, this.valueArray.length * 2); - } - - this.updateArray(); - } - - public void syncArrayWithIdList() { - Arrays.fill(this.valueArray, null); - - this.updateArrayLength(this.IDLIST.getIdMap(this).size() + 1); - - for (Map.Entry entry : this.IDLIST.getIdMap(this).entrySet()) { - this.valueArray[entry.getValue()] = entry.getKey(); - } - - this.updateArray(); - } - - public V[] getArray() { - return this.valueArray; - } - - public abstract void updateArray(); -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/ArrayBasedRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/ArrayBasedRegistry.java deleted file mode 100644 index 6b2400249..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/ArrayBasedRegistry.java +++ /dev/null @@ -1,45 +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.impl.registry.util; - -import com.google.common.collect.HashBiMap; - -import net.legacyfabric.fabric.api.util.Identifier; - -public abstract class ArrayBasedRegistry extends ArrayAndMapBasedRegistry { - public ArrayBasedRegistry(V[] valueArray) { - super(valueArray, HashBiMap.create()); - } - - @Override - public void initRegistry(V[] originalValueArray) { - for (int i = 0; i < originalValueArray.length; i++) { - V value = originalValueArray[i]; - Identifier key = this.getNewKey(i); - - if (value == null || key == null || this.getObjects().containsKey(value)) continue; - - this.register(i, key, value); - } - } - - @Override - public KeyType getKeyType() { - return KeyType.FABRIC; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/BiomePair.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/BiomePair.java index 8e420a379..ddd04937b 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/BiomePair.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/BiomePair.java @@ -19,6 +19,7 @@ import net.minecraft.world.biome.Biome; +@Deprecated public class BiomePair { private final Biome parent, mutated; diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/MapBasedRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/MapBasedRegistry.java deleted file mode 100644 index aec75500f..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/MapBasedRegistry.java +++ /dev/null @@ -1,119 +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.impl.registry.util; - -import java.util.Iterator; -import java.util.Map; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import org.jetbrains.annotations.NotNull; - -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -public class MapBasedRegistry extends OldRemappedRegistry { - private final Map defaultMap; - private final Map invertedMap; - - private IdListCompat IDLIST = (IdListCompat) new IdList(); - - public MapBasedRegistry(Map defaultMap, Map invertedMap) { - this.defaultMap = defaultMap; - this.invertedMap = invertedMap; - - this.remapDefaultIds(); - } - - @Override - public void remapDefaultIds() { - this.defaultMap.clear(); - - for (Map.Entry entry : this.invertedMap.entrySet()) { - this.defaultMap.put(this.getNewKey(entry.getValue()), entry.getKey()); - - this.IDLIST.setValue(entry.getKey(), this.getOldId(entry.getValue())); - } - - this.invertedMap.clear(); - - for (Map.Entry entry : this.defaultMap.entrySet()) { - this.invertedMap.put(entry.getValue(), entry.getKey()); - } - } - - @Override - public IdListCompat getIds() { - return IDLIST; - } - - @Override - public Map getObjects() { - if (this.invertedMap instanceof BiMap) { - return this.invertedMap; - } - - return HashBiMap.create(this.invertedMap); - } - - @Override - public void setIds(IdListCompat idList) { - this.IDLIST = idList; - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new IdList(); - } - - @Override - public int getRawID(V object) { - return IDLIST.getInt(object); - } - - @Override - public K getKey(V object) { - return this.invertedMap.get(object); - } - - @Override - public V getValue(Object key) { - return this.defaultMap.get(this.toKeyType(key)); - } - - @NotNull - @Override - public Iterator iterator() { - return this.IDLIST.iterator(); - } - - @Override - public V register(int i, Object key, V value) { - this.defaultMap.put(this.toKeyType(key), value); - - if (!this.invertedMap.containsKey(value)) { - this.invertedMap.put(value, this.toKeyType(key)); - } - - this.IDLIST.setValue(value, i); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(i, new Identifier(key), value); - return value; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/NumericalIdPair.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/NumericalIdPair.java deleted file mode 100644 index 43209445c..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/NumericalIdPair.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.impl.registry.util; - -public class NumericalIdPair { - private final int main, secondary; - - public NumericalIdPair(int main, int secondary) { - this.main = main; - this.secondary = secondary; - } - - public int getMain() { - return main; - } - - public int getSecondary() { - return secondary; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/OldRemappedRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/OldRemappedRegistry.java deleted file mode 100644 index b396eff49..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/OldRemappedRegistry.java +++ /dev/null @@ -1,70 +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.impl.registry.util; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; - -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -public abstract class OldRemappedRegistry implements SimpleRegistryCompat { - private final BiMap oldToNewKeyMap = this.generateOldToNewKeyMap(); - private final BiMap idToKeyMap = this.generateIdToKeyMap(); - - private RegistryEventsHolder registryEventsHolder; - - public OldRemappedRegistry() { - } - - public void remapDefaultIds() { - } - - public BiMap generateOldToNewKeyMap() { - return HashBiMap.create(); - } - - public BiMap generateIdToKeyMap() { - return HashBiMap.create(); - } - - public K getNewKey(K oldKey) { - return this.oldToNewKeyMap.getOrDefault(oldKey, oldKey); - } - - public K getOldKey(K newKey) { - return this.oldToNewKeyMap.inverse().getOrDefault(newKey, newKey); - } - - public K getNewKey(int oldId) { - return this.idToKeyMap.getOrDefault(oldId, null); - } - - public int getOldId(K newKey) { - return this.idToKeyMap.inverse().getOrDefault(newKey, -1); - } - - @Override - public RegistryEventsHolder getEventHolder() { - return this.registryEventsHolder; - } - - @Override - public void setEventHolder(RegistryEventsHolder registryEventsHolder) { - this.registryEventsHolder = registryEventsHolder; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/RegistryEventsHolder.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/RegistryEventsHolder.java index aa88f214a..9d81a3957 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/RegistryEventsHolder.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/RegistryEventsHolder.java @@ -22,6 +22,7 @@ import net.legacyfabric.fabric.api.registry.v1.RegistryEntryAddCallback; import net.legacyfabric.fabric.api.registry.v1.RegistryEntryRemapCallback; +@Deprecated public class RegistryEventsHolder { private final Event> ADD_EVENT = EventFactory.createArrayBacked(RegistryEntryAddCallback.class, (callbacks) -> (rawId, id, object) -> { diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/VanillaLikeRegistry.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/VanillaLikeRegistry.java deleted file mode 100644 index 9197e2eea..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/VanillaLikeRegistry.java +++ /dev/null @@ -1,116 +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.impl.registry.util; - -import java.util.Iterator; -import java.util.Map; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import org.apache.commons.lang3.Validate; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -public class VanillaLikeRegistry implements SimpleRegistryCompat { - private static final Logger LOGGER = LogManager.getLogger(); - protected final Map map = this.createMap(); - protected IdList ids = new IdList<>(); - protected final Map objects = ((BiMap) this.map).inverse(); - private RegistryEventsHolder registryEventsHolder; - - public VanillaLikeRegistry() { - } - - public void put(K key, V value) { - Validate.notNull(key); - Validate.notNull(value); - - if (this.map.containsKey(this.toKeyType(key))) { - LOGGER.debug("Adding duplicate key '{}' to registry", this.toKeyType(key)); - } - - this.map.put(this.toKeyType(key), value); - } - - protected Map createMap() { - return HashBiMap.create(); - } - - public Iterator iterator() { - return this.ids.iterator(); - } - - @Override - public IdListCompat getIds() { - return (IdListCompat) this.ids; - } - - @Override - public Map getObjects() { - return this.objects; - } - - @Override - public void setIds(IdListCompat idList) { - this.ids = (IdList) idList; - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new IdList(); - } - - @Override - public int getRawID(V object) { - return this.ids.getId(object); - } - - @Override - public K getKey(V id) { - return this.objects.get(id); - } - - @Override - public V getValue(Object key) { - return this.map.get(this.toKeyType(key)); - } - - @Override - public V register(int id, Object identifier, V object) { - this.ids.set(object, id); - this.put(this.toKeyType(identifier), object); - this.getEventHolder().getAddEvent().invoker().onEntryAdded(id, new Identifier(identifier), object); - return object; - } - - @Override - public RegistryEventsHolder getEventHolder() { - return this.registryEventsHolder; - } - - @Override - public void setEventHolder(RegistryEventsHolder registryEventsHolder) { - this.registryEventsHolder = registryEventsHolder; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixin.java deleted file mode 100644 index d4b23e6a3..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixin.java +++ /dev/null @@ -1,80 +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.IdentityHashMap; -import java.util.List; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; - -@Mixin(IdList.class) -public abstract class IdListMixin implements IdListCompat { - @Shadow - @Final - private IdentityHashMap idMap; - - @Shadow - @Final - private List list; - - @Shadow - public abstract V fromId(int index); - - @Shadow - public abstract void set(V value, int index); - - @Shadow - public abstract int getId(V value); - - @Override - public IdentityHashMap getIdMap(SimpleRegistryCompat simpleRegistry) { - return this.idMap; - } - - @Override - public List getList() { - return this.list; - } - - @Override - public V fromInt(int index) { - return this.fromId(index); - } - - @Override - public void setValue(V value, int index) { - this.set(value, index); - } - - @Override - public int getInt(V value) { - return this.getId(value); - } - - @Override - public IdListCompat createIdList() { - return (IdListCompat) new IdList(); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BiomeMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BiomeMixin.java deleted file mode 100644 index 2a8d9799c..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BiomeMixin.java +++ /dev/null @@ -1,36 +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.world.biome.Biome; - -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BiomeRegistryRemapper; - -@Mixin(Biome.class) -public class BiomeMixin { - @Inject(method = "", at = @At("RETURN")) - private static void initRegistryRemapper(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(BiomeRegistryRemapper::new); - } -} 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-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockEntityMixin.java deleted file mode 100644 index badf89b9a..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockEntityMixin.java +++ /dev/null @@ -1,36 +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.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockEntityTypeRegistryRemapper; - -@Mixin(BlockEntity.class) -public class BlockEntityMixin { - @Inject(method = "", at = @At("RETURN")) - private static void initRegistryRemapper(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(BlockEntityTypeRegistryRemapper::new); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/EnchantmentMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/EnchantmentMixin.java deleted file mode 100644 index bc908c198..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/EnchantmentMixin.java +++ /dev/null @@ -1,36 +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.enchantment.Enchantment; - -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.EnchantmentRegistryRemapper; - -@Mixin(Enchantment.class) -public class EnchantmentMixin { - @Inject(method = "", at = @At("RETURN")) - private static void initRegistryRemapper(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(EnchantmentRegistryRemapper::new); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/EntityTypeMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/EntityTypeMixin.java deleted file mode 100644 index 5d3db8e14..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/EntityTypeMixin.java +++ /dev/null @@ -1,36 +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.entity.EntityType; - -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.EntityTypeRegistryRemapper; - -@Mixin(EntityType.class) -public class EntityTypeMixin { - @Inject(method = "load", at = @At("RETURN")) - private static void initRegistry(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(EntityTypeRegistryRemapper::new); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/StatusEffectMixin.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/StatusEffectMixin.java deleted file mode 100644 index 1465f00a6..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/StatusEffectMixin.java +++ /dev/null @@ -1,36 +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.entity.effect.StatusEffect; - -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.StatusEffectRegistryRemapper; - -@Mixin(StatusEffect.class) -public class StatusEffectMixin { - @Inject(method = "", at = @At("RETURN")) - private static void initRegistryRemapper(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(StatusEffectRegistryRemapper::new); - } -} 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 99e4b85f7..e2bcf656d 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 @@ -1,6 +1,9 @@ { "schemaVersion": 1, "id": "legacy-fabric-registry-sync-api-v1-common", + "provides": [ + "legacy-fabric-registry-sync-api-v1" + ], "name": "Legacy Fabric Registry Sync API (V1)", "version": "${version}", "environment": "*", @@ -25,9 +28,7 @@ "net.legacyfabric.fabric.impl.registry.BackwardCompatibilityHelper" ] }, - "mixins": [ - "legacy-fabric-registry-sync-api-v1-common.mixins.json" - ], + "mixins": [], "custom": { "modmenu": { "badges": [ "library" ], 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 deleted file mode 100644 index 017961d1e..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "IdListMixin", - "registry.BlockEntityMixin", - "registry.StatusEffectMixin", - "registry.EnchantmentMixin", - "registry.BiomeMixin", - "registry.EntityTypeMixin" - ], - "client": [ - ] -} From f6a4d3cd5694d9fd16a3717eaa3bc53d6e7ad688 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Tue, 3 Sep 2024 19:20:26 +0200 Subject: [PATCH 31/31] apache commons lang3 isn't available in 1.7.10 --- .../legacyfabric/fabric/api/registry/v1/RegistryHelper.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 841c7f323..ec3533b25 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 @@ -20,8 +20,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.commons.lang3.NotImplementedException; - import net.minecraft.block.Block; import net.minecraft.block.entity.BlockEntity; import net.minecraft.enchantment.Enchantment; @@ -259,7 +257,7 @@ public static BiomePair registerBiomeWithMutatedVariant( // ); // // return new BiomePair(list.get(0).getValue(), list.get(1).getValue()); - throw new NotImplementedException("Registering biome with parent is currently not implemented before 1.9"); + throw new UnsupportedOperationException("Registering biome with parent is currently not implemented before 1.9"); } public static Biome getBiome(Identifier id) {