diff --git a/build.gradle b/build.gradle index 78d80a4d7..b6f110bbf 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") + logger.error("Can't find fabric.mod.json at ${modJsonFile.toString()}!") + return; } def modJson = new JsonSlurper().parse(modJsonFile) 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-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/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java similarity index 72% rename from legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java rename to legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java index 30b30ca2c..c6e206be2 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java +++ b/legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java @@ -15,23 +15,24 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +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.registry.sync.compat.PacketByteBufCompat; +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; @Mixin(PacketByteBuf.class) -public abstract class PacketByteBufMixin implements PacketByteBufCompat { +public abstract class PacketByteBufMixin implements PacketByteBufExtension { @Shadow - public abstract PacketByteBuf writeNbtCompound(NbtCompound par1); + public abstract PacketByteBuf writeNbtCompound(@Nullable NbtCompound nbt); @Override - public PacketByteBuf writeCompound(NbtCompound compound) { - return this.writeNbtCompound(compound); + 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-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java similarity index 76% rename from legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java rename to legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java index 4a0a4298d..d4611ec2b 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java +++ b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.networking.versioned; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -23,16 +23,16 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.util.PacketByteBuf; -import net.legacyfabric.fabric.impl.registry.sync.compat.PacketByteBufCompat; +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; @Mixin(PacketByteBuf.class) -public abstract class PacketByteBufMixin implements PacketByteBufCompat { +public abstract class PacketByteBufMixin implements PacketByteBufExtension { @Shadow - public abstract void writeNbtCompound(NbtCompound nbt); + public abstract void writeNbtCompound(NbtCompound par1); @Override - public PacketByteBuf writeCompound(NbtCompound compound) { - this.writeNbtCompound(compound); + 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-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java similarity index 76% rename from legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java rename to legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java index 4a0a4298d..d4611ec2b 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PacketByteBufMixin.java +++ b/legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.networking.versioned; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -23,16 +23,16 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.util.PacketByteBuf; -import net.legacyfabric.fabric.impl.registry.sync.compat.PacketByteBufCompat; +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; @Mixin(PacketByteBuf.class) -public abstract class PacketByteBufMixin implements PacketByteBufCompat { +public abstract class PacketByteBufMixin implements PacketByteBufExtension { @Shadow - public abstract void writeNbtCompound(NbtCompound nbt); + public abstract void writeNbtCompound(NbtCompound par1); @Override - public PacketByteBuf writeCompound(NbtCompound compound) { - this.writeNbtCompound(compound); + 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/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/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/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/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v1/1.10.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.10.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.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 2931efbf6..000000000 Binary files a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/assets/legacy-fabric/icon.png and /dev/null differ 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 9e64957e8..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,26 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "class_2929Mixin", - "PlayerManagerMixin", - "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/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/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/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 2931efbf6..000000000 Binary files a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/assets/legacy-fabric/icon.png and /dev/null differ 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 c95574ffd..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,22 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "class_2929Mixin", - "PlayerManagerMixin", - "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/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/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 2931efbf6..000000000 Binary files a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png and /dev/null differ 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 c1478703e..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,24 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "PlayerManagerMixin", - "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 be5a8fb24..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -accessWidener v1 named - -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/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/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/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 2931efbf6..000000000 Binary files a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png and /dev/null differ 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 cb9f7aaad..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,27 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "PlayerManagerMixin", - "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/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 2931efbf6..000000000 Binary files a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png and /dev/null differ 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 cb9f7aaad..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "PlayerManagerMixin", - "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 be5a8fb24..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -accessWidener v1 named - -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/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/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/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/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 2931efbf6..000000000 Binary files a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/assets/legacy-fabric-registry-sync-api-v1/icon.png and /dev/null differ 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 9e64957e8..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,26 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "SimpleRegistryMixin", - "class_2929Mixin", - "PlayerManagerMixin", - "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.gradle b/legacy-fabric-registry-sync-api-v1/common.gradle index 594e150a8..e139671fc 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-api-v2" ]) 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 47e70a0f9..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 @@ -19,13 +19,14 @@ 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; +@Deprecated @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..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 @@ -19,13 +19,14 @@ 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; +@Deprecated @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 3f18a60cc..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 @@ -33,12 +33,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<>(); @@ -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,11 +93,16 @@ 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); } /** @@ -103,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); } /** @@ -121,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; } /** @@ -135,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); } /** @@ -153,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; } /** @@ -167,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); } /** @@ -183,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; } /** @@ -195,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 + ); } /** @@ -212,11 +251,17 @@ 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 UnsupportedOperationException("Registering biome with parent is currently not implemented before 1.9"); } - 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); } /** @@ -227,11 +272,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..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,13 +19,14 @@ 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 = 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/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/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..57b3f5bc3 --- /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 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/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/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/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/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/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/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 9069ffca9..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.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; - -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(); - } -} 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 3f6281b9e..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java +++ /dev/null @@ -1,39 +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 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(); - } -} 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/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/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/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/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 261a4f9a4..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": "*", @@ -21,13 +24,11 @@ }, "description": "Registry hooks", "entrypoints": { - "client": [ - "net.legacyfabric.fabric.impl.client.registry.sync.ClientRemapInitializer" + "preLaunch": [ + "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 baf230136..000000000 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.registry.sync", - "compatibilityLevel": "JAVA_8", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "MinecraftServerMixin", - "WorldSaveHandlerMixin", - "IdListMixin", - "registry.ItemMixin", - "registry.BlockMixin", - "registry.BlockEntityMixin", - "registry.StatusEffectMixin", - "registry.EnchantmentMixin", - "registry.BiomeMixin", - "registry.EntityTypeMixin" - ], - "client": [ - "client.MinecraftClientMixin" - ] -} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/build.gradle b/legacy-fabric-registry-sync-api-v2/1.12.2/build.gradle similarity index 100% rename from legacy-fabric-registry-sync-api-v1/1.10.2/build.gradle rename to legacy-fabric-registry-sync-api-v2/1.12.2/build.gradle diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties similarity index 50% rename from legacy-fabric-registry-sync-api-v1/1.12.2/gradle.properties rename to legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties index a104a3a86..22c79abec 100644 --- a/legacy-fabric-registry-sync-api-v1/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/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..ade73e2d8 --- /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,51 @@ +/* + * 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.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 && !Objects.equals(this.defaultKey.toString(), key.toString())) return null; + + return value; + } +} 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 new file mode 100644 index 000000000..08d5ed10d --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.registry.sync.versioned; + +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 OtherIdListMixin implements IdsHolder { + @Shadow + @Nullable + public abstract T getById(int id); + + @Shadow + public abstract void add(T value, int id); + + @Shadow + public abstract int getId(T value); + + @Shadow + public abstract int size(); + + @Override + public IdsHolder fabric$new() { + return (IdsHolder) new class_2929<>(256); + } + + @Override + public int fabric$nextId() { + int id = 1; + + while (this.getById(id) != null) id++; + + return id; + } + + @Override + public void fabric$setValue(T value, int id) { + add(value, id); + } + + @Override + public int fabric$size() { + return this.size(); + } + + @Override + 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-v1/1.12.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.12.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.12.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 new file mode 100644 index 000000000..985b37aa2 --- /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,135 @@ +/* + * 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.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, DesynchronizeableRegistrable { + // 1.8+ + @Shadow + public abstract void add(int id, K identifier, V object); + + // 1.9+ + @Mutable + @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); + + @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); + + 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); + } + + @Override + public IdsHolder fabric$getIdsHolder() { + return (IdsHolder) field_13718; + } + + @Override + public Identifier fabric$getId(V value) { + K vanillaId = getIdentifier(value); + + if (vanillaId == null) return null; + + return new Identifier(vanillaId); + } + + @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.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-v1/1.10.2/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/fabric.mod.json similarity index 81% rename from legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/fabric.mod.json rename to legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/fabric.mod.json index c4d681021..1f20467ce 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/fabric.mod.json +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync API (V1)", + "id": "legacy-fabric-registry-sync-api-v2", + "name": "Legacy Fabric Registry Sync API (V2)", "version": "${version}", "environment": "*", "license": "Apache-2.0", @@ -22,11 +22,10 @@ "description": "Registry hooks", "entrypoints": { "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" ] }, "mixins": [ - "legacy-fabric-registry-sync-api-v1.mixins.json" + "legacy-fabric-registry-sync-api-v2.mixins.json" ], "custom": { "modmenu": { 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..231708e9e --- /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,16 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.BiDefaultedRegistryMixin", + "versioned.OtherIdListMixin", + "versioned.PlayerManagerMixin", + "versioned.SimpleRegistryMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/build.gradle b/legacy-fabric-registry-sync-api-v2/1.7.10/build.gradle similarity index 100% rename from legacy-fabric-registry-sync-api-v1/1.12.2/build.gradle rename to legacy-fabric-registry-sync-api-v2/1.7.10/build.gradle diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties similarity index 50% rename from legacy-fabric-registry-sync-api-v1/1.7.10/gradle.properties rename to legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties index c01c52c6b..af031afbf 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/gradle.properties +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties @@ -1,2 +1,2 @@ -minVersionIncluded=1.7 +minVersionIncluded=1.7.10 maxVersionIncluded=1.7.10 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-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java similarity index 53% rename from legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java rename to legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java index a51824472..cc23020be 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/BiDefaultedRegistryMixin.java @@ -15,27 +15,38 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.registry.sync.versioned; -import java.util.Map; +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.block.Block; -import net.minecraft.item.Item; +import net.minecraft.util.registry.BiDefaultedRegistry; +import net.minecraft.util.registry.SimpleRegistry; -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; +import net.legacyfabric.fabric.api.util.Identifier; + +@Mixin(BiDefaultedRegistry.class) +public abstract class BiDefaultedRegistryMixin extends SimpleRegistry { + @Shadow + private Object defaultValue; -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { @Shadow @Final - private static Map BLOCK_ITEMS; + private String field_8395; + + @Shadow + public abstract Object get(String par1); @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; + 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-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..7e5fe7799 --- /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,133 @@ +/* + * 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.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, DesynchronizeableRegistrable { + // 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); + + @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); + + 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); + } + + @Override + public IdsHolder fabric$getIdsHolder() { + return (IdsHolder) ids; + } + + @Override + public Identifier fabric$getId(V value) { + String vanillaId = getId(value); + + if (vanillaId == null) return null; + + return new Identifier(vanillaId); + } + + @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-v1/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/fabric.mod.json similarity index 81% rename from legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/fabric.mod.json rename to legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/fabric.mod.json index c4d681021..1f20467ce 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/fabric.mod.json +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync API (V1)", + "id": "legacy-fabric-registry-sync-api-v2", + "name": "Legacy Fabric Registry Sync API (V2)", "version": "${version}", "environment": "*", "license": "Apache-2.0", @@ -22,11 +22,10 @@ "description": "Registry hooks", "entrypoints": { "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" ] }, "mixins": [ - "legacy-fabric-registry-sync-api-v1.mixins.json" + "legacy-fabric-registry-sync-api-v2.mixins.json" ], "custom": { "modmenu": { 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..b120e9059 --- /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,15 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.BiDefaultedRegistryMixin", + "versioned.PlayerManagerMixin", + "versioned.SimpleRegistryMixinV2" + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/build.gradle b/legacy-fabric-registry-sync-api-v2/1.8.9/build.gradle similarity index 100% rename from legacy-fabric-registry-sync-api-v1/1.8.9/build.gradle rename to legacy-fabric-registry-sync-api-v2/1.8.9/build.gradle diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties similarity index 50% rename from legacy-fabric-registry-sync-api-v1/1.8.9/gradle.properties rename to legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties index 770b8d576..9056fbd37 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/gradle.properties +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties @@ -1,2 +1,2 @@ -minVersionIncluded=1.8.9 +minVersionIncluded=1.8 maxVersionIncluded=1.8.9 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..ade73e2d8 --- /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,51 @@ +/* + * 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.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 && !Objects.equals(this.defaultKey.toString(), key.toString())) return null; + + return value; + } +} 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..f46c98c00 --- /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,134 @@ +/* + * 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.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, DesynchronizeableRegistrable { + // 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; + + @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); + + 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); + } + + @Override + public IdsHolder fabric$getIdsHolder() { + return (IdsHolder) ids; + } + + @Override + public Identifier fabric$getId(V value) { + K vanillaId = getIdentifier(value); + + if (vanillaId == null) return null; + + return new Identifier(vanillaId); + } + + @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-v1/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 similarity index 76% rename from legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/fabric.mod.json rename to legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/fabric.mod.json index ac4e75d72..1f20467ce 100644 --- a/legacy-fabric-registry-sync-api-v1/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 @@ -1,7 +1,7 @@ { "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync API (V1)", + "id": "legacy-fabric-registry-sync-api-v2", + "name": "Legacy Fabric Registry Sync API (V2)", "version": "${version}", "environment": "*", "license": "Apache-2.0", @@ -22,11 +22,10 @@ "description": "Registry hooks", "entrypoints": { "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" ] }, "mixins": [ - "legacy-fabric-registry-sync-api-v1.mixins.json" + "legacy-fabric-registry-sync-api-v2.mixins.json" ], "custom": { "modmenu": { @@ -36,7 +35,7 @@ "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" + "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..b120e9059 --- /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,15 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.BiDefaultedRegistryMixin", + "versioned.PlayerManagerMixin", + "versioned.SimpleRegistryMixinV2" + ], + "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-v1/1.9.4/build.gradle b/legacy-fabric-registry-sync-api-v2/common/build.gradle similarity index 100% rename from legacy-fabric-registry-sync-api-v1/1.9.4/build.gradle rename to legacy-fabric-registry-sync-api-v2/common/build.gradle 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..81375fe83 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java @@ -0,0 +1,106 @@ +/* + * 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.Registry; +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; + +public class RegistryHelper { + public static void register(Registry registry, Identifier identifier, T value) { + RegistryHelperImplementation.register(registry, identifier, value); + } + + public static void register(Identifier registryId, Identifier identifier, T value) { + register(RegistryHelperImplementation.getRegistry(registryId), identifier, value); + } + + public static T register(Registry registry, Identifier identifier, Function valueConstructor) { + return RegistryHelperImplementation.register(registry, identifier, valueConstructor); + } + + public static T register(Identifier registryId, Identifier identifier, Function valueConstructor) { + return register(RegistryHelperImplementation.getRegistry(registryId), identifier, valueConstructor); + } + + public static void addRegistry(Identifier identifier, Registry registry) { + RegistryHelperImplementation.registerRegistry(identifier, registry); + } + + public static Registry 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(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); + } + + 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); + } + + // 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); + // } +} 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..9301737a7 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryIds.java @@ -0,0 +1,33 @@ +/* + * 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; +import net.legacyfabric.fabric.api.util.SinceMC; + +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"); + @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/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..aefcac6fd --- /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,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.api.registry.v2.event; + +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.RegistryEventHelper; + +@FunctionalInterface +public interface RegistryBeforeAddCallback { + void onEntryAdding(int rawId, Identifier id, T object); + + static Event> event(Identifier registryId) { + return RegistryEventHelper.addRegistryBeforeCallback(registryId); + } + + 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 new file mode 100644 index 000000000..58ec8db6c --- /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,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.api.registry.v2.event; + +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.RegistryEventHelper; + +@FunctionalInterface +public interface RegistryEntryAddedCallback { + void onEntryAdded(int rawId, Identifier id, T object); + + static Event> event(Identifier registryId) { + return RegistryEventHelper.addedCallbackEvent(registryId); + } + + static Event> event(Registry registry) { + return registry.fabric$getEntryAddedCallback(); + } +} 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java similarity index 51% rename from legacy-fabric-registry-sync-api-v1/1.10.2/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/api/registry/v2/event/RegistryInitializedEvent.java index 4475180c2..d1b5e7d01 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java @@ -15,26 +15,21 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +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.util.Identifier; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; -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; +/** + * Triggered only when a new registry is registered. + */ +@FunctionalInterface +public interface RegistryInitializedEvent { + void initialized(Registry registry); - @Override - public V getValue(Object key) { - return this.map.get(this.toKeyType(key)); + 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/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..e904c7c0e --- /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.RegistryEventHelper; + +@FunctionalInterface +public interface RegistryRemapCallback { + void callback(Map> changedIdsMap); + + static Event> event(Identifier registryId) { + return RegistryEventHelper.remapCallbackEvent(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-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java similarity index 69% rename from legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java index 5cf98a69d..d3201800c 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java @@ -15,15 +15,10 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.api.registry.v2.registry; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; -import net.minecraft.world.biome.Biome; - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor - String getParent(); +public interface RegistrableRegistry extends Registry, Registrable { } 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistrableRegistry.java similarity index 68% rename from legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistrableRegistry.java index 5cf98a69d..25e5c5767 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistrableRegistry.java @@ -15,15 +15,9 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.api.registry.v2.registry; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; -import net.minecraft.world.biome.Biome; - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor - String getParent(); +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 new file mode 100644 index 000000000..0882fc172 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java @@ -0,0 +1,41 @@ +/* + * 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 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 Registry extends Iterable { + Identifier fabric$getId(); + Event> fabric$getEntryAddedCallback(); + Event> fabric$getBeforeAddedCallback(); + + K fabric$toKeyType(Identifier identifier); + + 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-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/ItemCompat.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java similarity index 75% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/ItemCompat.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java index 358e29aae..a2d123f28 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java @@ -15,13 +15,12 @@ * limitations under the License. */ -package net.legacyfabric.fabric.impl.registry.sync.compat; +package net.legacyfabric.fabric.api.registry.v2.registry.holder; -import java.util.Map; +import net.legacyfabric.fabric.api.util.Identifier; -import net.minecraft.block.Block; -import net.minecraft.item.Item; - -public interface ItemCompat { - Map getBLOCK_ITEMS(); +public interface RegistryEntry { + int getId(); + Identifier getIdentifier(); + T getValue(); } 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java similarity index 51% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/ArrayBasedRegistry.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java index 6b2400249..7665f7636 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java @@ -15,31 +15,24 @@ * limitations under the License. */ -package net.legacyfabric.fabric.impl.registry.util; - -import com.google.common.collect.HashBiMap; +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 abstract class ArrayBasedRegistry extends ArrayAndMapBasedRegistry { - public ArrayBasedRegistry(V[] valueArray) { - super(valueArray, HashBiMap.create()); +public interface SyncedRegistry extends Registry { + int fabric$getRawId(T value); + default int fabric$getRawId(Identifier identifier) { + T value = fabric$getValue(identifier); + return fabric$getRawId(value); } - @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); - } + T fabric$getValue(int rawId); + default Identifier fabric$getId(int rawId) { + T value = fabric$getValue(rawId); + return fabric$getId(value); } - @Override - public KeyType getKeyType() { - return KeyType.FABRIC; - } + Event> fabric$getRegistryRemapCallback(); } 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java similarity index 73% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/PacketByteBufCompat.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java index 9b4421ce3..9194d63fc 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java @@ -15,11 +15,12 @@ * limitations under the License. */ -package net.legacyfabric.fabric.impl.registry.sync.compat; +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.PacketByteBuf; +public interface DesynchronizeableRegistrable { + default boolean canSynchronize() { + return true; + } -public interface PacketByteBufCompat { - PacketByteBuf writeCompound(NbtCompound compound); + void setSynchronize(boolean synchronize); } 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java similarity index 63% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/util/NumericalIdPair.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java index 43209445c..eefefc030 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java @@ -15,21 +15,19 @@ * limitations under the License. */ -package net.legacyfabric.fabric.impl.registry.util; +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; -public class NumericalIdPair { - private final int main, secondary; +public interface IdsHolder extends Iterable { + IdsHolder fabric$new(); - public NumericalIdPair(int main, int secondary) { - this.main = main; - this.secondary = secondary; - } + int fabric$nextId(); - public int getMain() { - return main; + 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; } - public int getSecondary() { - return secondary; - } + T fabric$getValue(int rawId); } 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java similarity index 70% rename from legacy-fabric-registry-sync-api-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BiomeAccessor.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java index 5cf98a69d..2bcac0a91 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java @@ -15,15 +15,10 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; +import net.legacyfabric.fabric.api.util.Identifier; -import net.minecraft.world.biome.Biome; - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor - String getParent(); +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/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..9a0c19df4 --- /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,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; + +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/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..bb8d0eeb1 --- /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,28 @@ +/* + * 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(); + } + + void fabric$updateRegistry(IdsHolder ids); +} 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-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java similarity index 72% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/client/registry/sync/ClientRemapInitializer.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java index ded3d09bb..45af51ed1 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.impl.client.registry.sync; +package net.legacyfabric.fabric.impl.registry; import java.io.IOException; import java.io.UncheckedIOException; @@ -23,17 +23,13 @@ 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) -> { + ClientPlayNetworking.registerGlobalReceiver(RegistryHelperImplementation.PACKET_ID, (client, handler, buf, responseSender) -> { NbtCompound nbt; try { @@ -42,7 +38,7 @@ public void onInitializeClient() { throw new UncheckedIOException(e); } - client.submit(() -> ClientRegistryRemapper.getInstance().readAndRemap(nbt)); + client.submit(() -> RegistryHelperImplementation.readAndRemap(nbt)); }); } } 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..da31e5450 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java @@ -0,0 +1,91 @@ +/* + * 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(); + + private final int minId; + + public IdsHolderImpl(int minId) { + this.minId = minId; + } + + public IdsHolderImpl() { + this(0); + } + + @Override + public IdsHolder fabric$new() { + return new IdsHolderImpl<>(this.minId); + } + + @Override + public int fabric$nextId() { + int id = this.minId; + + 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 this.valueToId.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 >= this.minId && 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/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..0c9e4f9eb --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryCreatorImpl.java @@ -0,0 +1,56 @@ +/* + * 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; + +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-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/RegistryRemapperRegistry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java similarity index 55% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/registries/RegistryRemapperRegistry.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java index e6459eb7c..09cdd6615 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryEntryImpl.java @@ -15,19 +15,34 @@ * limitations under the License. */ -package net.legacyfabric.fabric.impl.registry.registries; +package net.legacyfabric.fabric.impl.registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; 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(); +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 KeyType getKeyType() { - return KeyType.FABRIC; + public T getValue() { + return this.value; } } 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 new file mode 100644 index 000000000..7989c7b3d --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java @@ -0,0 +1,266 @@ +/* + * 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.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; +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.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.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; +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<>(); + 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; + + if (INITIALIZATION_EVENTS.containsKey(registryId)) { + event = INITIALIZATION_EVENTS.get(registryId); + } else { + event = EventFactory.createArrayBacked(RegistryInitializedEvent.class, + (callbacks) -> new RegistryInitializedEvent() { + @Override + public void initialized(Registry registry) { + for (RegistryInitializedEvent callback : callbacks) { + callback.initialized(registry); + } + } + } + ); + INITIALIZATION_EVENTS.put(registryId, event); + } + + return event; + } + + public static Registry getRegistry(Identifier identifier) { + return (Registry) REGISTRIES.get(identifier); + } + + 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); + + boolean remappable = true; + + if (holder instanceof DesynchronizeableRegistrable) { + remappable = ((DesynchronizeableRegistrable) holder).canSynchronize(); + } + + if (holder instanceof SyncedRegistrableRegistry && remappable) { + REMAPPERS.put(identifier, new RegistryRemapper<>((SyncedRegistrableRegistry) 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 SyncedRegistrableRegistry && remappable) { + ((SyncedRegistrableRegistry) 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) { + 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; + int computedId = -1; + + boolean remappable = true; + + if (registry instanceof DesynchronizeableRegistrable) { + remappable = ((DesynchronizeableRegistrable) registry).canSynchronize(); + } + + if (registry instanceof SyncedRegistrable && remappable) { + computedId = ((SyncedRegistrable) registrable).fabric$nextId(); + } + + registrable.fabric$register(computedId, identifier, value); + } + + 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; + int computedId = registrable.fabric$nextId(); + + T value = valueConstructor.apply(computedId); + + registrable.fabric$register(computedId, identifier, value); + + 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(); + } + } + + 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()); + 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() { + 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 new file mode 100644 index 000000000..65353a884 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java @@ -0,0 +1,181 @@ +/* + * 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.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.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; +import net.legacyfabric.fabric.impl.logger.LoggerImpl; + +public class RegistryRemapper { + protected static final Logger LOGGER = Logger.get(LoggerImpl.API, "RegistryRemapper"); + private final SyncedRegistrableRegistry registry; + private BiMap entryDump; + private BiMap missingMap = HashBiMap.create(); + + public RegistryRemapper(SyncedRegistrableRegistry 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()); + }); + + this.entryDump.putAll(this.missingMap); + } + + 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(); + + IntSupplier previousSize = normalizeEntryList(dumpIds); + + invokeListeners(dumpIds); + + updateRegistry(dumpIds); + + this.entryDump.clear(); + this.dump(); + LOGGER.info("Remapped " + previousSize.getAsInt() + " entries"); + } + + 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); + + 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); + } + }); + + 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!"); + } + } + + addNewEntries(ids); + + if (currentSize.getAsInt() != previousSize.getAsInt() && this.missingMap.isEmpty()) { + throw new IllegalStateException("An error occurred during remapping"); + } + + return previousSize; + } + + private void addNewEntries(IdsHolder newList) { + LOGGER.info("Checking for missing entries in registry"); + + this.registry.stream() + .filter(obj -> !newList.fabric$contains(obj)) + .collect(Collectors.toList()) + .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()); + }); + } + + 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); + } +} 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); + } +} 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-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java similarity index 77% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/sync/compat/BlockCompat.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java index da593b90f..f320032a0 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package net.legacyfabric.fabric.impl.registry.sync.compat; +package net.legacyfabric.fabric.impl.registry.accessor; -import net.minecraft.block.BlockState; +import net.legacyfabric.fabric.api.util.Identifier; -public interface BlockCompat { - void setBLOCK_STATES(IdListCompat BLOCK_STATES); +public interface RegistryIdSetter { + void fabric$setId(Identifier identifier); } 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..6aa7e5cb0 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/MapRegistryWrapper.java @@ -0,0 +1,112 @@ +/* + * 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.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; +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; + + 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; + this.valueToId = valueToId; + this.toMapKey = toMapKey; + this.fromMapKey = fromMapKey; + } + + @Override + public Identifier fabric$getId() { + return this.id; + } + + @Override + public Event> fabric$getEntryAddedCallback() { + return this.addObjectEvent; + } + + @Override + public Event> fabric$getBeforeAddedCallback() { + return this.beforeAddObjectEvent; + } + + @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); + } +} 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..77fb6e349 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayMapRegistryWrapper.java @@ -0,0 +1,171 @@ +/* + * 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; + + 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, 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; + 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); + + 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..2a0ea154c --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/wrapper/SyncedArrayRegistryWrapper.java @@ -0,0 +1,181 @@ +/* + * 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.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; +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 SyncedArrayRegistryWrapper implements SyncedRegistrableRegistry { + private IdsHolder idsHolder; + + 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, 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; + 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); + } +} 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-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java similarity index 54% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixin.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java index d4b23e6a3..35170c1a1 100644 --- 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-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; @@ -26,55 +25,54 @@ import net.minecraft.util.collection.IdList; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; @Mixin(IdList.class) -public abstract class IdListMixin implements IdListCompat { +public abstract class IdListMixinV2 implements IdsHolder { @Shadow - @Final - private IdentityHashMap idMap; - - @Shadow - @Final - private List list; + public abstract T fromId(int index); @Shadow - public abstract V fromId(int index); + public abstract void set(T value, int index); @Shadow - public abstract void set(V value, int index); + public abstract int getId(T value); @Shadow - public abstract int getId(V value); + @Final + private IdentityHashMap idMap; @Override - public IdentityHashMap getIdMap(SimpleRegistryCompat simpleRegistry) { - return this.idMap; + public IdsHolder fabric$new() { + return (IdsHolder) new IdList<>(); } @Override - public List getList() { - return this.list; + public int fabric$nextId() { + int id = 1; + + while (this.fabric$getValue(id) != null) id++; + + return id; } @Override - public V fromInt(int index) { - return this.fromId(index); + public void fabric$setValue(T value, int id) { + set(value, id); } @Override - public void setValue(V value, int index) { - this.set(value, index); + public int fabric$size() { + return idMap.size(); } @Override - public int getInt(V value) { - return this.getId(value); + public T fabric$getValue(int rawId) { + return this.fromId(rawId); } @Override - public IdListCompat createIdList() { - return (IdListCompat) new IdList(); + 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/MutableRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixinV2.java new file mode 100644 index 000000000..096c664b1 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MutableRegistryMixinV2.java @@ -0,0 +1,125 @@ +/* + * 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.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 MutableRegistryMixinV2 implements net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry, 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 Event> fabric_addObjectEvent; + + @Unique + 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; + } + + @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(Identifier identifier) { + return RegistryHelperImplementation.hasFlatteningBegun ? (K) new net.minecraft.util.Identifier(identifier.toString()) : (K) identifier.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) { + 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-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java similarity index 70% rename from legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockEntityAccessor.java rename to legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java index 53c6422bf..5977956c1 100644 --- 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-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java @@ -18,16 +18,12 @@ 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; - } +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, DesynchronizeableRegistrable { } 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-v1/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json similarity index 58% rename from legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json rename to legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json index 909da100a..027f6bc9f 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1", - "name": "Legacy Fabric Registry Sync API (V1)", + "id": "legacy-fabric-registry-sync-api-v2-common", + "name": "Legacy Fabric Registry Sync API (V2)", "version": "${version}", "environment": "*", "license": "Apache-2.0", @@ -21,15 +21,19 @@ }, "description": "Registry hooks", "entrypoints": { - "preLaunch": [ - "net.legacyfabric.fabric.impl.registry.sync.RegistrySyncEarlyInitializer" + "client": [ + "net.legacyfabric.fabric.impl.registry.ClientRemapInitializer" ] }, "mixins": [ - "legacy-fabric-registry-sync-api-v1.mixins.json" + "legacy-fabric-registry-sync-api-v2-common.mixins.json" ], - "accessWidener": "registrysync.accesswidener", "custom": { + "loom:injected_interfaces": { + "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" ], "parent": { @@ -37,7 +41,7 @@ "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" + "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..f0cedd1d4 --- /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,16 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "IdListMixinV2", + "MutableRegistryMixinV2", + "SimpleRegistryMixinV2", + "WorldSaveHandlerMixin" + ], + "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")