diff --git a/build.gradle b/build.gradle index b2360176e..426cc5ebe 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 bd168873e..a35f69914 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,5 +19,8 @@ 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-item-api-v1.version = 1.0.0 +legacy-fabric-block-api-v1.version = 1.0.0 legacy-fabric-rendering-api-v1.version = 1.0.0 legacy-fabric-resource-loader-v1.version = 2.2.1 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-block-api-v1/1.12.2/build.gradle b/legacy-fabric-block-api-v1/1.12.2/build.gradle new file mode 100644 index 000000000..306a9d690 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/build.gradle @@ -0,0 +1,3 @@ +loom { + accessWidenerPath = file("src/main/resources/legacy-fabric-block-api-v1.accesswidener") +} diff --git a/legacy-fabric-block-api-v1/1.12.2/gradle.properties b/legacy-fabric-block-api-v1/1.12.2/gradle.properties new file mode 100644 index 000000000..7d5606688 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.8 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/BlockStateRemapper.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/BlockStateRemapper.java new file mode 100644 index 000000000..d1f6010ce --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/BlockStateRemapper.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.block.versioned; + +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.util.collection.IdList; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.api.util.VersionUtils; +import net.legacyfabric.fabric.mixin.block.versioned.BlockAccessor; + +public class BlockStateRemapper implements RegistryRemapCallback { + private static final boolean hasSpecialCase = VersionUtils.matches(">1.8.9"); + private static final Identifier specialCaseId = new Identifier("tripwire"); + + @Override + public void callback(Map> changedIdsMap) { + IdsHolder newList = Block.BLOCK_STATES.fabric$new(); + + for (Block block : Block.REGISTRY) { + int blockRawId = RegistryHelper.getRawId(Block.REGISTRY, block); + + if (changedIdsMap.containsKey(blockRawId)) { + blockRawId = changedIdsMap.get(blockRawId).getId(); + } + + Identifier blockId = RegistryHelper.getId(Block.REGISTRY, block); + + if (blockId.equals(specialCaseId) && hasSpecialCase) { + for (int i = 0; i < 15; ++i) { + int blockStateId = blockRawId << 4 | i; + BlockState state = block.stateFromData(i); + + newList.fabric$setValue(state, blockStateId); + } + } else { + for (BlockState state : block.getStateManager().getBlockStates()) { + int blockStateId = blockRawId << 4 | block.getData(state); + + newList.fabric$setValue(state, blockStateId); + } + } + } + + BlockAccessor.setBLOCK_STATES((IdList) newList); + } +} diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java new file mode 100644 index 000000000..eb2820a14 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.block.versioned; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.SlabBlock; +import net.minecraft.block.StairsBlock; +import net.minecraft.block.material.Material; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.api.util.VersionUtils; +import net.legacyfabric.fabric.mixin.block.versioned.ItemAccessor; + +public class EarlyInitializer implements PreLaunchEntrypoint { + private static final boolean checkGrass = VersionUtils.matches(">1.8.9"); + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.BLOCKS).register(EarlyInitializer::blockRegistryInit); + RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); + } + + private static void blockRegistryInit(Registry holder) { + SyncedRegistry registry = (SyncedRegistry) holder; + + registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> { + for (BlockState blockState : block.getStateManager().getBlockStates()) { + int i = rawId << 4 | block.getData(blockState); + Block.BLOCK_STATES.set(blockState, i); + } + }); + + registry.fabric$getRegistryRemapCallback().register(new BlockStateRemapper()); + + registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> { + if (block.material == Material.AIR) { + block.useNeighbourLight = false; + } else { + boolean var12 = false; + boolean var13 = block instanceof StairsBlock; + boolean var14 = block instanceof SlabBlock; + boolean var15 = block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("farmland")) + || (checkGrass && block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("grass_path"))); + boolean var16 = block.transluscent; + boolean var17 = block.opacity == 0; + + if (var13 || var14 || var15 || var16 || var17) { + var12 = true; + } + + block.useNeighbourLight = var12; + } + }); + } + + private static void itemRegistryInit(Registry holder) { + SyncedRegistry registry = (SyncedRegistry) holder; + + registry.fabric$getEntryAddedCallback().register((rawId, id, item) -> { + if (item instanceof BlockItem) { + ItemAccessor.getBLOCK_ITEMS().put(((BlockItem) item).getBlock(), item); + } + }); + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java similarity index 60% rename from legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java rename to legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java index a51824472..836e1105d 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.java @@ -15,27 +15,18 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.block.versioned; -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.gen.Accessor; import net.minecraft.block.Block; -import net.minecraft.item.Item; - -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; - -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; +import net.minecraft.block.BlockState; +import net.minecraft.util.collection.IdList; - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; +@Mixin(Block.class) +public interface BlockAccessor { + @Accessor + static void setBLOCK_STATES(IdList blockStates) { } } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java similarity index 59% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java rename to legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java index b7f06b894..6bd40b175 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/BlockMixin.java +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java @@ -15,34 +15,30 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync.registry; +package net.legacyfabric.fabric.mixin.block.versioned; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.block.Block; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.BiDefaultedRegistry; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockRegistryRemapper; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; @Mixin(Block.class) public class BlockMixin { - @Inject(method = "setup", at = @At("RETURN")) - private static void initRegistryRemapper(CallbackInfo ci) { - RegistryHelperImpl.registerRegistryRemapper(BlockRegistryRemapper::new); - - if (!RegistryHelperImpl.bootstrap) { - try { - Class.forName(StatusEffect.class.getName()); + @Shadow + @Final + public static BiDefaultedRegistry REGISTRY; - Class.forName(Enchantment.class.getName()); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } + @Inject(method = "setup", at = @At("RETURN")) + private static void registerRegistry(CallbackInfo ci) { + RegistryHelper.addRegistry(RegistryIds.BLOCKS, REGISTRY); } } diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemAccessor.java similarity index 67% rename from legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java rename to legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemAccessor.java index a51824472..290aa26b3 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemAccessor.java @@ -15,27 +15,20 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.block.versioned; import java.util.Map; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.gen.Accessor; import net.minecraft.block.Block; import net.minecraft.item.Item; -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; - @Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; - - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; +public interface ItemAccessor { + @Accessor + static Map getBLOCK_ITEMS() { + return null; } } diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..b018250ea --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json @@ -0,0 +1,46 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-api-v1", + "name": "Legacy Fabric Block API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.block.versioned.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-block-api-v1.mixins.json" + ], + "accessWidener": "legacy-fabric-block-api-v1.accesswidener", + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.accesswidener b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.accesswidener new file mode 100644 index 000000000..b3e9ad4a4 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.accesswidener @@ -0,0 +1,6 @@ +accessWidener v2 named + +accessible field net/minecraft/block/Block useNeighbourLight Z +accessible field net/minecraft/block/Block transluscent Z +accessible field net/minecraft/block/Block material Lnet/minecraft/block/material/Material; +accessible field net/minecraft/block/Block opacity I diff --git a/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.mixins.json b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.mixins.json new file mode 100644 index 000000000..6368baf84 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.block.versioned", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "BlockAccessor", + "BlockMixin", + "ItemAccessor" + ], + "client": [ + ] +} diff --git a/legacy-fabric-block-api-v1/1.7.10/build.gradle b/legacy-fabric-block-api-v1/1.7.10/build.gradle new file mode 100644 index 000000000..306a9d690 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/build.gradle @@ -0,0 +1,3 @@ +loom { + accessWidenerPath = file("src/main/resources/legacy-fabric-block-api-v1.accesswidener") +} diff --git a/legacy-fabric-block-api-v1/1.7.10/gradle.properties b/legacy-fabric-block-api-v1/1.7.10/gradle.properties new file mode 100644 index 000000000..c01c52c6b --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.7.10 diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java new file mode 100644 index 000000000..f97bb4994 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.block.versioned; + +import net.minecraft.block.Block; +import net.minecraft.block.SlabBlock; +import net.minecraft.block.material.Material; +import net.minecraft.item.Item; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; +import net.legacyfabric.fabric.api.util.Identifier; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.BLOCKS).register(EarlyInitializer::blockRegistryInit); + } + + private static void blockRegistryInit(Registry holder) { + SyncedRegistry registry = (SyncedRegistry) holder; + + registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> { + if (block.getMaterial() == Material.AIR) { + block.useNeighbourLight = false; + } else { + boolean var12 = false; + boolean var13 = block.getBlockType() == 10; + boolean var14 = block instanceof SlabBlock; + boolean var15 = block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("farmland")); + boolean var16 = block.transluscent; + boolean var17 = block.getOpacity() == 0; + + if (var13 || var14 || var15 || var16 || var17) { + var12 = true; + } + + block.useNeighbourLight = var12; + } + }); + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockItemAccessor.java similarity index 60% rename from legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java rename to legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockItemAccessor.java index a51824472..aaad9cbfb 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockItemAccessor.java @@ -15,27 +15,16 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.block.versioned; -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.gen.Accessor; import net.minecraft.block.Block; -import net.minecraft.item.Item; - -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; - -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; +import net.minecraft.item.BlockItem; - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; - } +@Mixin(BlockItem.class) +public interface BlockItemAccessor { + @Accessor + Block getBlock(); } diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java new file mode 100644 index 000000000..7b959d0aa --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.block.versioned; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.util.registry.SimpleRegistry; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.util.Identifier; + +@Mixin(Block.class) +public class BlockMixin { + @Shadow + @Final + public static SimpleRegistry REGISTRY; + + @Inject(method = "setup", at = @At("RETURN")) + private static void registerRegistry(CallbackInfo ci) { + RegistryHelper.addRegistry(RegistryIds.BLOCKS, REGISTRY); + } + + @Inject(method = "getBlockFromItem", at = @At("HEAD"), cancellable = true) + private static void fixBlockFromItem(Item item, CallbackInfoReturnable cir) { + if (item instanceof BlockItem) { + cir.setReturnValue(((BlockItemAccessor) item).getBlock()); + return; + } + + Identifier identifier = RegistryHelper.getId(Item.REGISTRY, item); + + if (identifier != null) { + Block blockFromId = RegistryHelper.getValue(REGISTRY, identifier); + + if (blockFromId != null) { + cir.setReturnValue(blockFromId); + return; + } + } + + cir.setReturnValue(null); + } +} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemMixin.java similarity index 54% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java rename to legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemMixin.java index 3f6281b9e..da5fd6879 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/client/MinecraftClientMixin.java +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemMixin.java @@ -15,25 +15,34 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync.client; +package net.legacyfabric.fabric.mixin.block.versioned; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.client.MinecraftClient; +import net.minecraft.block.Block; +import net.minecraft.item.Item; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.client.registry.sync.ClientRegistryRemapper; +@Mixin(Item.class) +public class ItemMixin { + @Inject(method = "fromBlock", at = @At("HEAD"), cancellable = true) + private static void fixItemFromBlock(Block block, CallbackInfoReturnable cir) { + Identifier identifier = RegistryHelper.getId(Block.REGISTRY, block); -@Environment(EnvType.CLIENT) -@Mixin(MinecraftClient.class) -public class MinecraftClientMixin { - @Inject(method = "", at = @At("RETURN")) - private static void remapperInit(CallbackInfo ci) { - ClientRegistryRemapper.getInstance(); + if (identifier != null) { + Item item = RegistryHelper.getValue(Item.REGISTRY, identifier); + + if (item != null) { + cir.setReturnValue(item); + return; + } + } + + cir.setReturnValue(null); } } diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..b018250ea --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/fabric.mod.json @@ -0,0 +1,46 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-api-v1", + "name": "Legacy Fabric Block API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.block.versioned.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-block-api-v1.mixins.json" + ], + "accessWidener": "legacy-fabric-block-api-v1.accesswidener", + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener new file mode 100644 index 000000000..55067474a --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.accesswidener @@ -0,0 +1,6 @@ +accessWidener v2 named + +transitive-accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V + +accessible field net/minecraft/block/Block useNeighbourLight Z +accessible field net/minecraft/block/Block transluscent Z diff --git a/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.mixins.json b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.mixins.json new file mode 100644 index 000000000..0fbf43835 --- /dev/null +++ b/legacy-fabric-block-api-v1/1.7.10/src/main/resources/legacy-fabric-block-api-v1.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.block.versioned", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "BlockItemAccessor", + "BlockMixin", + "ItemMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-block-api-v1/common.gradle b/legacy-fabric-block-api-v1/common.gradle new file mode 100644 index 000000000..7102014bf --- /dev/null +++ b/legacy-fabric-block-api-v1/common.gradle @@ -0,0 +1,7 @@ +moduleDependencies(project, [ + "legacy-fabric-api-base", + "legacy-fabric-networking-api-v1", + "legacy-fabric-resource-loader-v1", + "legacy-fabric-registry-sync-api-v2", + "legacy-fabric-item-api-v1" +]) diff --git a/legacy-fabric-block-api-v1/common/build.gradle b/legacy-fabric-block-api-v1/common/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-block-api-v1/common/gradle.properties b/legacy-fabric-block-api-v1/common/gradle.properties new file mode 100644 index 000000000..a499ab733 --- /dev/null +++ b/legacy-fabric-block-api-v1/common/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-block-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/EarlyInitializer.java b/legacy-fabric-block-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/EarlyInitializer.java new file mode 100644 index 000000000..9039efbc3 --- /dev/null +++ b/legacy-fabric-block-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/block/EarlyInitializer.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.block; + +import net.minecraft.block.Block; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.BLOCKS).register(EarlyInitializer::blockRegistryInit); + } + + private static void blockRegistryInit(Registry holder) { + Registry registry = (Registry) holder; + + registry.fabric$getBeforeAddedCallback().register((rawId, id, block) -> block.setTranslationKey(id.toTranslationKey())); + } +} diff --git a/legacy-fabric-block-api-v1/common/src/main/resources/fabric.mod.json b/legacy-fabric-block-api-v1/common/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..39d3627f1 --- /dev/null +++ b/legacy-fabric-block-api-v1/common/src/main/resources/fabric.mod.json @@ -0,0 +1,45 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-block-api-v1-common", + "name": "Legacy Fabric Block API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Block utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.block.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-block-api-v1-common.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-block-api-v1/common/src/main/resources/legacy-fabric-block-api-v1-common.mixins.json b/legacy-fabric-block-api-v1/common/src/main/resources/legacy-fabric-block-api-v1-common.mixins.json new file mode 100644 index 000000000..4c2ea7c54 --- /dev/null +++ b/legacy-fabric-block-api-v1/common/src/main/resources/legacy-fabric-block-api-v1-common.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.block", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + ], + "client": [ + ] +} diff --git a/legacy-fabric-item-api-v1/1.12.2/build.gradle b/legacy-fabric-item-api-v1/1.12.2/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-item-api-v1/1.12.2/gradle.properties b/legacy-fabric-item-api-v1/1.12.2/gradle.properties new file mode 100644 index 000000000..7d5606688 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.8 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java new file mode 100644 index 000000000..17d33b408 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.item.versioned; + +import net.minecraft.item.Item; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); + } + + private static void itemRegistryInit(Registry holder) { + SyncedRegistry registry = (SyncedRegistry) holder; + + registry.fabric$getRegistryRemapCallback().register(new ItemModelsRemapper()); + } +} diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/ItemModelsRemapper.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/ItemModelsRemapper.java new file mode 100644 index 000000000..e82792a61 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/ItemModelsRemapper.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.item.versioned; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.item.ItemModels; +import net.minecraft.client.util.ModelIdentifier; +import net.minecraft.item.Item; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryEntry; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.mixin.item.versioned.ItemModelsAccessor; + +public class ItemModelsRemapper implements RegistryRemapCallback { + private static final Map> modelIds = new HashMap<>(); + + public static void registerModelId(Identifier id, int metadata, ModelIdentifier modelId) { + modelIds.computeIfAbsent(id, k -> new HashMap<>()) + .put(metadata, modelId); + } + + private int pack(int itemId, int metadata) { + return itemId << 16 | metadata; + } + + private ItemModels getModelRegistry() { + return MinecraftClient.getInstance().getItemRenderer().getModels(); + } + + @Override + public void callback(Map> changedIdsMap) { + ((ItemModelsAccessor) getModelRegistry()).getModelIds().clear(); + + for (Map.Entry> entry : modelIds.entrySet()) { + Identifier itemId = entry.getKey(); + + Item item = RegistryHelper.getValue(Item.REGISTRY, itemId); + int itemIndex = RegistryHelper.getRawId(Item.REGISTRY, item); + + if (changedIdsMap.containsKey(itemIndex)) { + itemIndex = changedIdsMap.get(itemIndex).getId(); + } + + for (Map.Entry modelIdEntry : entry.getValue().entrySet()) { + ((ItemModelsAccessor) getModelRegistry()).getModelIds() + .put(pack(itemIndex, modelIdEntry.getKey()), modelIdEntry.getValue()); + } + } + + getModelRegistry().reloadModels(); + } +} diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsAccessor.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsAccessor.java new file mode 100644 index 000000000..6e5e75d82 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsAccessor.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.item.versioned; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.client.render.item.ItemModels; +import net.minecraft.client.util.ModelIdentifier; + +@Mixin(ItemModels.class) +public interface ItemModelsAccessor { + @Accessor + Map getModelIds(); +} diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java similarity index 54% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java rename to legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java index 9069ffca9..e09f4b938 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/MinecraftServerMixin.java +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.java @@ -15,21 +15,27 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.item.versioned; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.minecraft.server.MinecraftServer; +import net.minecraft.client.render.item.ItemModels; +import net.minecraft.client.util.ModelIdentifier; +import net.minecraft.item.Item; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.util.Identifier; +import net.legacyfabric.fabric.impl.item.versioned.ItemModelsRemapper; -@Mixin(MinecraftServer.class) -public class MinecraftServerMixin { - @Inject(method = "", at = @At("RETURN")) - private static void remapperInit(CallbackInfo ci) { - ServerRegistryRemapper.getInstance(); +@Mixin(ItemModels.class) +public class ItemModelsMixin { + @Inject(method = "putModel", at = @At("RETURN")) + private void lf$registerModelId(Item item, int metadata, ModelIdentifier id, CallbackInfo ci) { + Identifier identifier = RegistryHelper.getId(Item.REGISTRY, item); + + if (identifier != null) ItemModelsRemapper.registerModelId(identifier, metadata, id); } } diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..7132ed22b --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json @@ -0,0 +1,45 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-item-api-v1", + "name": "Legacy Fabric Item API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Item utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.item.versioned.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-item-api-v1.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json new file mode 100644 index 000000000..8882e989a --- /dev/null +++ b/legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.item", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + ], + "client": [ + "versioned.ItemModelsAccessor", + "versioned.ItemModelsMixin" + ] +} diff --git a/legacy-fabric-item-api-v1/1.7.10/build.gradle b/legacy-fabric-item-api-v1/1.7.10/build.gradle new file mode 100644 index 000000000..66b589ecb --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/build.gradle @@ -0,0 +1,3 @@ +loom { + accessWidenerPath = file("src/main/resources/legacy-fabric-item-api.accesswidener") +} diff --git a/legacy-fabric-item-api-v1/1.7.10/gradle.properties b/legacy-fabric-item-api-v1/1.7.10/gradle.properties new file mode 100644 index 000000000..c6dcd9541 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.3 +maxVersionIncluded=1.7.10 diff --git a/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java b/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java new file mode 100644 index 000000000..79448f1eb --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.item.versioned; + +import net.minecraft.item.Item; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); + } + + private static void itemRegistryInit(Registry holder) { + Registry registry = (Registry) holder; + } +} diff --git a/legacy-fabric-item-api-v1/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..17176f15b --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/fabric.mod.json @@ -0,0 +1,44 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-item-api-v1", + "name": "Legacy Fabric Item API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Item utils", + "entrypoints": { + "preLaunch": [] + }, + "mixins": [ + "legacy-fabric-item-api-v1.mixins.json" + ], + "accessWidener": "legacy-fabric-item-api.accesswidener", + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api-v1.mixins.json b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api-v1.mixins.json new file mode 100644 index 000000000..86feace33 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api-v1.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.item", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + ], + "client": [ + ] +} diff --git a/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api.accesswidener b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api.accesswidener new file mode 100644 index 000000000..10be8bab6 --- /dev/null +++ b/legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api.accesswidener @@ -0,0 +1,3 @@ +accessWidener v2 named + +transitive-accessible method net/minecraft/item/Item getFromId (Ljava/lang/String;)Lnet/minecraft/item/Item; diff --git a/legacy-fabric-item-api-v1/common.gradle b/legacy-fabric-item-api-v1/common.gradle new file mode 100644 index 000000000..e139671fc --- /dev/null +++ b/legacy-fabric-item-api-v1/common.gradle @@ -0,0 +1,6 @@ +moduleDependencies(project, [ + "legacy-fabric-api-base", + "legacy-fabric-networking-api-v1", + "legacy-fabric-resource-loader-v1", + "legacy-fabric-registry-sync-api-v2" +]) diff --git a/legacy-fabric-item-api-v1/common/build.gradle b/legacy-fabric-item-api-v1/common/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-item-api-v1/common/gradle.properties b/legacy-fabric-item-api-v1/common/gradle.properties new file mode 100644 index 000000000..a499ab733 --- /dev/null +++ b/legacy-fabric-item-api-v1/common/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java new file mode 100644 index 000000000..f33d072c5 --- /dev/null +++ b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/item/EarlyInitializer.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.item; + +import net.minecraft.item.Item; + +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; + +public class EarlyInitializer implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); + } + + private static void itemRegistryInit(Registry holder) { + Registry registry = (Registry) holder; + + registry.fabric$getBeforeAddedCallback().register((rawId, id, item) -> item.setTranslationKey(id.toTranslationKey())); + } +} 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-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java similarity index 60% rename from legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/ItemMixin.java rename to legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java index 70edb7a39..915f9423c 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/registry/ItemMixin.java +++ b/legacy-fabric-item-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/item/ItemMixin.java @@ -15,34 +15,30 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync.registry; +package net.legacyfabric.fabric.mixin.item; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.minecraft.block.entity.BlockEntity; import net.minecraft.item.Item; -import net.minecraft.world.biome.Biome; +import net.minecraft.util.registry.SimpleRegistry; -import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl; -import net.legacyfabric.fabric.impl.registry.sync.remappers.ItemRegistryRemapper; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryIds; +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; @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()); + @Shadow + @Final + public static SimpleRegistry REGISTRY; - Class.forName(BlockEntity.class.getName()); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } + @Inject(method = "setup", at = @At("RETURN")) + private static void registerRegistry(CallbackInfo ci) { + RegistryHelper.addRegistry(RegistryIds.ITEMS, (Registry) REGISTRY); } } diff --git a/legacy-fabric-item-api-v1/common/src/main/resources/fabric.mod.json b/legacy-fabric-item-api-v1/common/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..4f5fde51c --- /dev/null +++ b/legacy-fabric-item-api-v1/common/src/main/resources/fabric.mod.json @@ -0,0 +1,45 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-item-api-v1-common", + "name": "Legacy Fabric Item API (V1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Item utils", + "entrypoints": { + "preLaunch": [ + "net.legacyfabric.fabric.impl.item.EarlyInitializer" + ] + }, + "mixins": [ + "legacy-fabric-item-api-v1-common.mixins.json" + ], + "custom": { + "loom:injected_interfaces": { + }, + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-item-api-v1/common/src/main/resources/legacy-fabric-item-api-v1-common.mixins.json b/legacy-fabric-item-api-v1/common/src/main/resources/legacy-fabric-item-api-v1-common.mixins.json new file mode 100644 index 000000000..fb9e6d8f5 --- /dev/null +++ b/legacy-fabric-item-api-v1/common/src/main/resources/legacy-fabric-item-api-v1-common.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.item", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "ItemMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java new file mode 100644 index 000000000..c6e206be2 --- /dev/null +++ b/legacy-fabric-networking-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.networking.versioned; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.PacketByteBuf; + +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; + +@Mixin(PacketByteBuf.class) +public abstract class PacketByteBufMixin implements PacketByteBufExtension { + @Shadow + public abstract PacketByteBuf writeNbtCompound(@Nullable NbtCompound nbt); + + @Override + public PacketByteBuf writeCompound(NbtCompound tag) { + return writeNbtCompound(tag); + } +} diff --git a/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/PacketByteBufMixin.java index c360a2c04..1ed1a52a3 100644 --- a/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/PacketByteBufMixin.java +++ b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/PacketByteBufMixin.java @@ -30,7 +30,7 @@ import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; @Mixin(PacketByteBuf.class) -public class PacketByteBufMixin implements PacketByteBufExtension { +public abstract class PacketByteBufMixin implements PacketByteBufExtension { @Override @Environment(EnvType.CLIENT) public Packet createCustomPayloadC2SPacket(String channelName) { diff --git a/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java new file mode 100644 index 000000000..d4611ec2b --- /dev/null +++ b/legacy-fabric-networking-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.networking.versioned; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.PacketByteBuf; + +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; + +@Mixin(PacketByteBuf.class) +public abstract class PacketByteBufMixin implements PacketByteBufExtension { + @Shadow + public abstract void writeNbtCompound(NbtCompound par1); + + @Override + public PacketByteBuf writeCompound(NbtCompound tag) { + this.writeNbtCompound(tag); + return (PacketByteBuf) (Object) this; + } +} diff --git a/legacy-fabric-networking-api-v1/1.7.10/src/main/resources/legacy-fabric-networking-api-v1.mixins.json b/legacy-fabric-networking-api-v1/1.7.10/src/main/resources/legacy-fabric-networking-api-v1.mixins.json index a09e89bfc..8cd108280 100644 --- a/legacy-fabric-networking-api-v1/1.7.10/src/main/resources/legacy-fabric-networking-api-v1.mixins.json +++ b/legacy-fabric-networking-api-v1/1.7.10/src/main/resources/legacy-fabric-networking-api-v1.mixins.json @@ -7,7 +7,8 @@ "CustomPayloadC2SPacketMixin", "MinecraftServerMixin", "PacketByteBufMixin", - "PlayerManagerMixin" + "PlayerManagerMixin", + "versioned.PacketByteBufMixin" ], "client": [ "client.CustomPayloadS2CPacketMixin", diff --git a/legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java b/legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java new file mode 100644 index 000000000..d4611ec2b --- /dev/null +++ b/legacy-fabric-networking-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/networking/versioned/PacketByteBufMixin.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.networking.versioned; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.PacketByteBuf; + +import net.legacyfabric.fabric.impl.networking.PacketByteBufExtension; + +@Mixin(PacketByteBuf.class) +public abstract class PacketByteBufMixin implements PacketByteBufExtension { + @Shadow + public abstract void writeNbtCompound(NbtCompound par1); + + @Override + public PacketByteBuf writeCompound(NbtCompound tag) { + this.writeNbtCompound(tag); + return (PacketByteBuf) (Object) this; + } +} diff --git a/legacy-fabric-networking-api-v1/1.8.9/src/main/resources/legacy-fabric-networking-api-v1.mixins.json b/legacy-fabric-networking-api-v1/1.8.9/src/main/resources/legacy-fabric-networking-api-v1.mixins.json index a75644c36..8b1ca4521 100644 --- a/legacy-fabric-networking-api-v1/1.8.9/src/main/resources/legacy-fabric-networking-api-v1.mixins.json +++ b/legacy-fabric-networking-api-v1/1.8.9/src/main/resources/legacy-fabric-networking-api-v1.mixins.json @@ -6,7 +6,8 @@ "ClientConnectionMixin", "CustomPayloadC2SPacketMixin", "MinecraftServerMixin", - "PlayerManagerMixin" + "PlayerManagerMixin", + "versioned.PacketByteBufMixin" ], "client": [ "client.CustomPayloadS2CPacketMixin", diff --git a/legacy-fabric-networking-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/networking/PacketByteBufExtension.java b/legacy-fabric-networking-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/networking/PacketByteBufExtension.java index fff07bcc5..ae97f6e9e 100644 --- a/legacy-fabric-networking-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/networking/PacketByteBufExtension.java +++ b/legacy-fabric-networking-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/networking/PacketByteBufExtension.java @@ -17,13 +17,21 @@ package net.legacyfabric.fabric.impl.networking; +import net.minecraft.nbt.NbtCompound; import net.minecraft.network.Packet; +import net.minecraft.util.PacketByteBuf; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; public interface PacketByteBufExtension { @Environment(EnvType.CLIENT) - Packet createCustomPayloadC2SPacket(String channelName); - Packet createCustomPayloadS2CPacket(String channelName); + default Packet createCustomPayloadC2SPacket(String channelName) { + return null; + } + default Packet createCustomPayloadS2CPacket(String channelName) { + return null; + } + + PacketByteBuf writeCompound(NbtCompound tag); } diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/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/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/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 9e64957e8..5493ef74a 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.10.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,9 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "class_2929Mixin", - "PlayerManagerMixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", 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/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/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java deleted file mode 100644 index 84ebd46f7..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.ClientConnection; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.integrated.IntegratedServer; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.loader.api.FabricLoader; - -import net.legacyfabric.fabric.api.networking.v1.ServerPlayNetworking; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; - -@Mixin(PlayerManager.class) -public class PlayerManagerMixin { - @Shadow - @Final - private MinecraftServer server; - - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 2), method = "method_12827") - public void playerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { - if (fabric_shouldSend()) { - player.networkHandler.sendPacket(ServerPlayNetworking.createS2CPacket(RegistryRemapperAccess.PACKET_ID, ServerRegistryRemapper.getInstance().createBuf())); - } - } - - @Unique - private boolean fabric_shouldSend() { - boolean published = false; - - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - published = fabric_isPublished(); - } - - return this.server.isDedicated() || published; - } - - @Environment(EnvType.CLIENT) - @Unique - private boolean fabric_isPublished() { - return ((IntegratedServer) this.server).isPublished(); - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index c95574ffd..aeb78a447 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,9 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "class_2929Mixin", - "PlayerManagerMixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", 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 index 5058a1900..8b1378917 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/build.gradle +++ b/legacy-fabric-registry-sync-api-v1/1.7.10/build.gradle @@ -1,3 +1 @@ -loom { - accessWidenerPath = file("src/main/resources/registrysync.accesswidener") -} + diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json index 909da100a..ac4e75d72 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json +++ b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/fabric.mod.json @@ -28,7 +28,6 @@ "mixins": [ "legacy-fabric-registry-sync-api-v1.mixins.json" ], - "accessWidener": "registrysync.accesswidener", "custom": { "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index c1478703e..2b3435c36 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -7,7 +7,6 @@ }, "mixins": [ "SimpleRegistryMixin", - "PlayerManagerMixin", "PacketByteBufMixin", "BlockEntityAccessor", "BlockEntityMixin", diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener b/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/resources/registrysync.accesswidener 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/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/mixin/registry/sync/BlockMixin.java b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java deleted file mode 100644 index ce4eecb72..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.impl.registry.sync.compat.BlockCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -@Mixin(Block.class) -public class BlockMixin implements BlockCompat { - @Mutable - @Shadow - @Final - public static IdList BLOCK_STATES; - - @Override - public void setBLOCK_STATES(IdListCompat block_states) { - BLOCK_STATES = (IdList) block_states; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index cb9f7aaad..1a5914904 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -7,9 +7,6 @@ }, "mixins": [ "SimpleRegistryMixin", - "PlayerManagerMixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/resources/fabric.mod.json deleted file mode 100644 index d6b0884ad..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1-testmod", - "description": "Tests for registry", - "version": "1.0.0", - "entrypoints": { - "main": [ - "net.legacyfabric.fabric.test.registry.RegistryTest" - ] - }, - "depends": { - "minecraft": "${minecraft_version}" - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/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/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v1/1.8/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/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/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index cb9f7aaad..1a5914904 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -7,9 +7,6 @@ }, "mixins": [ "SimpleRegistryMixin", - "PlayerManagerMixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener index be5a8fb24..45ae69ced 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener +++ b/legacy-fabric-registry-sync-api-v1/1.8/src/main/resources/registrysync.accesswidener @@ -1,3 +1,3 @@ -accessWidener v1 named +accessWidener v2 named -accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V +transitive-accessible method net/minecraft/block/Block (Lnet/minecraft/block/material/Material;)V diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/resources/fabric.mod.json deleted file mode 100644 index d6b0884ad..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "schemaVersion": 1, - "id": "legacy-fabric-registry-sync-api-v1-testmod", - "description": "Tests for registry", - "version": "1.0.0", - "entrypoints": { - "main": [ - "net.legacyfabric.fabric.test.registry.RegistryTest" - ] - }, - "depends": { - "minecraft": "${minecraft_version}" - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java deleted file mode 100644 index ce4eecb72..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/BlockMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.util.collection.IdList; - -import net.legacyfabric.fabric.impl.registry.sync.compat.BlockCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; - -@Mixin(Block.class) -public class BlockMixin implements BlockCompat { - @Mutable - @Shadow - @Final - public static IdList BLOCK_STATES; - - @Override - public void setBLOCK_STATES(IdListCompat block_states) { - BLOCK_STATES = (IdList) block_states; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java deleted file mode 100644 index a51824472..000000000 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.registry.sync; - -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; - -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; - -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; - - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; - } -} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json index 9e64957e8..5493ef74a 100644 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/1.9.4/src/main/resources/legacy-fabric-registry-sync-api-v1.mixins.json @@ -8,9 +8,6 @@ "mixins": [ "SimpleRegistryMixin", "class_2929Mixin", - "PlayerManagerMixin", - "BlockMixin", - "ItemMixin", "PacketByteBufMixin", "MutableRegistryMixin", "BlockEntityAccessor", 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..561f4dfa6 100644 --- a/legacy-fabric-registry-sync-api-v1/common.gradle +++ b/legacy-fabric-registry-sync-api-v1/common.gradle @@ -1,5 +1,7 @@ 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", + "legacy-fabric-item-api-v2" ]) diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryAddCallback.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryAddCallback.java index 47e70a0f9..55023e78d 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryAddCallback.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryAddCallback.java @@ -19,13 +19,13 @@ import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; +import net.legacyfabric.fabric.impl.registry.BackwardCompatibilityHelper; @FunctionalInterface public interface RegistryEntryAddCallback { void onEntryAdded(int rawId, Identifier key, T object); static Event> event(Identifier registryId) { - return RegistryRemapper.getEventsHolder(registryId).getAddEvent(); + return BackwardCompatibilityHelper.getEventHolder(registryId).getAddEvent(); } } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryRemapCallback.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryRemapCallback.java index 41aa0dcce..c947e5f4d 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryRemapCallback.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryEntryRemapCallback.java @@ -19,13 +19,13 @@ import net.legacyfabric.fabric.api.event.Event; import net.legacyfabric.fabric.api.util.Identifier; -import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; +import net.legacyfabric.fabric.impl.registry.BackwardCompatibilityHelper; @FunctionalInterface public interface RegistryEntryRemapCallback { void onEntryAdded(int oldId, int newId, Identifier key, T object); static Event> event(Identifier registryId) { - return RegistryRemapper.getEventsHolder(registryId).getRemapEvent(); + return BackwardCompatibilityHelper.getEventHolder(registryId).getRemapEvent(); } } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java index 3f18a60cc..d9179d2b5 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryHelper.java @@ -71,11 +71,16 @@ public static Event onRegistryInitialized(Identifier identi * @return The block registered */ public static Block registerBlock(Block block, Identifier id) { - return RegistryHelperImpl.registerBlock(block, id); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.BLOCKS, + id, block + ); + + return block; } public static Block getBlock(Identifier id) { - return RegistryHelperImpl.getValue(id, RegistryIds.BLOCKS); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(net.legacyfabric.fabric.api.registry.v2.RegistryIds.BLOCKS, id); } /** @@ -88,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 + ); } /** @@ -215,8 +254,8 @@ public static BiomePair registerBiomeWithMutatedVariant( return RegistryHelperImpl.registerBiomeWithMutatedVariant(parentBiome, parentId, mutatedBiome, mutatedId); } - public static Biome getBiome(Identifier identifier) { - return RegistryHelperImpl.getValue(identifier, RegistryIds.BIOMES); + public static Biome getBiome(Identifier id) { + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(RegistryIds.BIOMES, id); } /** @@ -227,11 +266,16 @@ public static Biome getBiome(Identifier identifier) { * @return The entity type class registered */ public static Class registerEntityType(Class entityTypeClass, Identifier id) { - return RegistryHelperImpl.registerEntityType(entityTypeClass, id); + net.legacyfabric.fabric.api.registry.v2.RegistryHelper.register( + net.legacyfabric.fabric.api.registry.v2.RegistryIds.ENTITY_TYPES, + id, entityTypeClass + ); + + return entityTypeClass; } public static Class getEntityType(Identifier id) { - return RegistryHelperImpl.getValue(id, RegistryIds.ENTITY_TYPES); + return net.legacyfabric.fabric.api.registry.v2.RegistryHelper.getValue(RegistryIds.ENTITY_TYPES, id); } @FunctionalInterface diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryIds.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryIds.java index 1f9ccb673..9fd34e60e 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryIds.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/api/registry/v1/RegistryIds.java @@ -21,11 +21,11 @@ public class RegistryIds { public static final Identifier REGISTRY_REMAPPER = new Identifier("legacy-fabric-registry-sync-api-v1-common", "registry_remappers"); - public static final Identifier ITEMS = new Identifier("items"); - public static final Identifier BLOCKS = new Identifier("blocks"); - public static final Identifier BLOCK_ENTITY_TYPES = new Identifier("block_entity_types"); - public static final Identifier STATUS_EFFECTS = new Identifier("status_effects"); - public static final Identifier ENCHANTMENTS = new Identifier("enchantments"); - public static final Identifier BIOMES = new Identifier("biomes"); - public static final Identifier ENTITY_TYPES = new Identifier("entity_types"); + public static final Identifier ITEMS = net.legacyfabric.fabric.api.registry.v2.RegistryIds.ITEMS; + public static final Identifier BLOCKS = net.legacyfabric.fabric.api.registry.v2.RegistryIds.BLOCKS; + public static final Identifier BLOCK_ENTITY_TYPES = net.legacyfabric.fabric.api.registry.v2.RegistryIds.BLOCK_ENTITY_TYPES; + public static final Identifier STATUS_EFFECTS = net.legacyfabric.fabric.api.registry.v2.RegistryIds.STATUS_EFFECTS; + public static final Identifier ENCHANTMENTS = net.legacyfabric.fabric.api.registry.v2.RegistryIds.ENCHANTMENTS; + public static final Identifier BIOMES = net.legacyfabric.fabric.api.registry.v2.RegistryIds.BIOMES; + public static final Identifier ENTITY_TYPES = net.legacyfabric.fabric.api.registry.v2.RegistryIds.ENTITY_TYPES; } diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/BackwardCompatibilityHelper.java new file mode 100644 index 000000000..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 index 4ad5ae3c0..ddc5417e3 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImpl.java @@ -25,14 +25,10 @@ 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; @@ -45,7 +41,6 @@ import net.legacyfabric.fabric.impl.client.registry.sync.ClientRegistryRemapper; import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; import net.legacyfabric.fabric.impl.registry.sync.compat.IdListCompat; -import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat; import net.legacyfabric.fabric.impl.registry.sync.compat.RegistriesGetter; import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat; import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper; @@ -86,33 +81,6 @@ public static T register(RegistryHelper.EntryCreator entryCreator, Identi return instance; } - public static Block registerBlock(Block block, Identifier id) { - block.setTranslationKey(formatTranslationKey(id)); - int rawId = register(block, id, RegistryIds.BLOCKS); - - if (hasFlatteningBegun) { - for (BlockState blockState : block.getStateManager().getBlockStates()) { - int i = rawId << 4 | block.getData(blockState); - Block.BLOCK_STATES.set(blockState, i); - } - } - - return block; - } - - public static Item registerItem(Item item, Identifier id) { - item.setTranslationKey(formatTranslationKey(id)); - register(item, id, RegistryIds.ITEMS); - - if (hasFlatteningBegun) { - if (item instanceof BlockItem) { - ((ItemCompat) item).getBLOCK_ITEMS().put(((BlockItem) item).getBlock(), item); - } - } - - return item; - } - public static Class registerBlockEntityType(Class blockEntityClass, Identifier id) { register(blockEntityClass, id, RegistryIds.BLOCK_ENTITY_TYPES); diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/fabric.mod.json index 261a4f9a4..99e4b85f7 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/fabric.mod.json +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/fabric.mod.json @@ -21,8 +21,8 @@ }, "description": "Registry hooks", "entrypoints": { - "client": [ - "net.legacyfabric.fabric.impl.client.registry.sync.ClientRemapInitializer" + "preLaunch": [ + "net.legacyfabric.fabric.impl.registry.BackwardCompatibilityHelper" ] }, "mixins": [ diff --git a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json index baf230136..017961d1e 100644 --- a/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json +++ b/legacy-fabric-registry-sync-api-v1/common/src/main/resources/legacy-fabric-registry-sync-api-v1-common.mixins.json @@ -6,11 +6,7 @@ "defaultRequire": 1 }, "mixins": [ - "MinecraftServerMixin", - "WorldSaveHandlerMixin", "IdListMixin", - "registry.ItemMixin", - "registry.BlockMixin", "registry.BlockEntityMixin", "registry.StatusEffectMixin", "registry.EnchantmentMixin", @@ -18,6 +14,5 @@ "registry.EntityTypeMixin" ], "client": [ - "client.MinecraftClientMixin" ] } diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/build.gradle b/legacy-fabric-registry-sync-api-v2/1.12.2/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties new file mode 100644 index 000000000..22c79abec --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/gradle.properties @@ -0,0 +1,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/AAAAAA.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/AAAAAA.java new file mode 100644 index 000000000..8e3277db6 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/AAAAAA.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.registry.sync; + +public class AAAAAA { +} diff --git a/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.9.4/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.9.4/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.9.4/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-v2/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..1f20467ce --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/fabric.mod.json @@ -0,0 +1,42 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-registry-sync-api-v2", + "name": "Legacy Fabric Registry Sync API (V2)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Registry hooks", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + "legacy-fabric-registry-sync-api-v2.mixins.json" + ], + "custom": { + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json new file mode 100644 index 000000000..f2e024e25 --- /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,15 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.OtherIdListMixin", + "versioned.PlayerManagerMixin", + "versioned.SimpleRegistryMixin" + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/build.gradle b/legacy-fabric-registry-sync-api-v2/1.7.10/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties new file mode 100644 index 000000000..af031afbf --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7.10 +maxVersionIncluded=1.7.10 diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java similarity index 87% rename from legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java rename to legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java index f26b66ee0..67599b93c 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/PlayerManagerMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/PlayerManagerMixin.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.registry.sync; +package net.legacyfabric.fabric.mixin.registry.sync.versioned; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -36,8 +36,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.legacyfabric.fabric.api.networking.v1.ServerPlayNetworking; -import net.legacyfabric.fabric.impl.registry.sync.RegistryRemapperAccess; -import net.legacyfabric.fabric.impl.registry.sync.ServerRegistryRemapper; +import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; @Mixin(PlayerManager.class) public class PlayerManagerMixin { @@ -48,7 +47,7 @@ public class PlayerManagerMixin { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 2), method = "onPlayerConnect") public void playerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { if (fabric_shouldSend()) { - ServerPlayNetworking.send(player, RegistryRemapperAccess.PACKET_ID, ServerRegistryRemapper.getInstance().createBuf()); + ServerPlayNetworking.send(player, RegistryHelperImplementation.PACKET_ID, RegistryHelperImplementation.createBuf()); } } diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixinV2.java new file mode 100644 index 000000000..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-v2/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..1f20467ce --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/fabric.mod.json @@ -0,0 +1,42 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-registry-sync-api-v2", + "name": "Legacy Fabric Registry Sync API (V2)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Registry hooks", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + "legacy-fabric-registry-sync-api-v2.mixins.json" + ], + "custom": { + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json new file mode 100644 index 000000000..9298f31f9 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.7.10/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.PlayerManagerMixin", + "versioned.SimpleRegistryMixinV2" + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/build.gradle b/legacy-fabric-registry-sync-api-v2/1.8.9/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties b/legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties new file mode 100644 index 000000000..9056fbd37 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.8 +maxVersionIncluded=1.8.9 diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/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.9/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.9/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-v2/1.8.9/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..1f20467ce --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/fabric.mod.json @@ -0,0 +1,42 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-registry-sync-api-v2", + "name": "Legacy Fabric Registry Sync API (V2)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Registry hooks", + "entrypoints": { + "preLaunch": [ + ] + }, + "mixins": [ + "legacy-fabric-registry-sync-api-v2.mixins.json" + ], + "custom": { + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json new file mode 100644 index 000000000..9298f31f9 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/1.8.9/src/main/resources/legacy-fabric-registry-sync-api-v2.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "package": "net.legacyfabric.fabric.mixin.registry.sync", + "compatibilityLevel": "JAVA_8", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "versioned.PlayerManagerMixin", + "versioned.SimpleRegistryMixinV2" + ], + "client": [ + ] +} diff --git a/legacy-fabric-registry-sync-api-v2/common.gradle b/legacy-fabric-registry-sync-api-v2/common.gradle new file mode 100644 index 000000000..594e150a8 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common.gradle @@ -0,0 +1,5 @@ +moduleDependencies(project, [ + "legacy-fabric-api-base", + "legacy-fabric-networking-api-v1", + "legacy-fabric-resource-loader-v1" +]) diff --git a/legacy-fabric-registry-sync-api-v2/common/build.gradle b/legacy-fabric-registry-sync-api-v2/common/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-registry-sync-api-v2/common/gradle.properties b/legacy-fabric-registry-sync-api-v2/common/gradle.properties new file mode 100644 index 000000000..a499ab733 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java new file mode 100644 index 000000000..f2ee7b69b --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.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); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryIds.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryIds.java new file mode 100644 index 000000000..83f11fba7 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryIds.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2; + +import net.legacyfabric.fabric.api.util.Identifier; + +public class RegistryIds { + public static final Identifier ITEMS = new Identifier("items"); + public static final Identifier BLOCKS = new Identifier("blocks"); + public static final Identifier BLOCK_ENTITY_TYPES = new Identifier("block_entity_types"); + public static final Identifier STATUS_EFFECTS = new Identifier("status_effects"); + public static final Identifier ENCHANTMENTS = new Identifier("enchantments"); + public static final Identifier BIOMES = new Identifier("biomes"); + public static final Identifier ENTITY_TYPES = new Identifier("entity_types"); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryBeforeAddCallback.java 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java new file mode 100644 index 000000000..d1b5e7d01 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.RegistryHelperImplementation; + +/** + * Triggered only when a new registry is registered. + */ +@FunctionalInterface +public interface RegistryInitializedEvent { + void initialized(Registry registry); + + static Event event(Identifier registryId) { + return RegistryHelperImplementation.getInitializationEvent(registryId); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java new file mode 100644 index 000000000..d3201800c --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/RegistrableRegistry.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry; + +import net.legacyfabric.fabric.api.registry.v2.registry.holder.Registry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; + +public interface RegistrableRegistry extends Registry, Registrable { +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistrableRegistry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistrableRegistry.java new file mode 100644 index 000000000..25e5c5767 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistrableRegistry.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry; + +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; + +public interface SyncedRegistrableRegistry extends net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry, SyncedRegistrable { +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/Registry.java 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-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java new file mode 100644 index 000000000..a2d123f28 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/RegistryEntry.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.holder; + +import net.legacyfabric.fabric.api.util.Identifier; + +public interface RegistryEntry { + int getId(); + Identifier getIdentifier(); + T getValue(); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java new file mode 100644 index 000000000..7665f7636 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/holder/SyncedRegistry.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.holder; + +import net.legacyfabric.fabric.api.event.Event; +import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; +import net.legacyfabric.fabric.api.util.Identifier; + +public interface SyncedRegistry extends Registry { + int fabric$getRawId(T value); + default int fabric$getRawId(Identifier identifier) { + T value = fabric$getValue(identifier); + return fabric$getRawId(value); + } + + T fabric$getValue(int rawId); + default Identifier fabric$getId(int rawId) { + T value = fabric$getValue(rawId); + return fabric$getId(value); + } + + Event> fabric$getRegistryRemapCallback(); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java new file mode 100644 index 000000000..9194d63fc --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/DesynchronizeableRegistrable.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; + +public interface DesynchronizeableRegistrable { + default boolean canSynchronize() { + return true; + } + + void setSynchronize(boolean synchronize); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java new file mode 100644 index 000000000..eefefc030 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/IdsHolder.java @@ -0,0 +1,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.registry.registrable; + +public interface IdsHolder extends Iterable { + IdsHolder fabric$new(); + + int fabric$nextId(); + + void fabric$setValue(T value, int id); + int fabric$size(); + int fabric$getId(T value); + default boolean fabric$contains(T value) { + return fabric$getId(value) != -1; + } + + T fabric$getValue(int rawId); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java new file mode 100644 index 000000000..2bcac0a91 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/Registrable.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.api.registry.v2.registry.registrable; + +import net.legacyfabric.fabric.api.util.Identifier; + +public interface Registrable { + void fabric$register(int rawId, Identifier identifier, T value); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/registrable/SyncedRegistrable.java new file mode 100644 index 000000000..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-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java new file mode 100644 index 000000000..45af51ed1 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/ClientRemapInitializer.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.registry; + +import java.io.IOException; +import java.io.UncheckedIOException; + +import net.minecraft.nbt.NbtCompound; + +import net.fabricmc.api.ClientModInitializer; + +import net.legacyfabric.fabric.api.client.networking.v1.ClientPlayNetworking; + +public class ClientRemapInitializer implements ClientModInitializer { + @Override + public void onInitializeClient() { + ClientPlayNetworking.registerGlobalReceiver(RegistryHelperImplementation.PACKET_ID, (client, handler, buf, responseSender) -> { + NbtCompound nbt; + + try { + nbt = buf.readNbtCompound(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + + client.submit(() -> RegistryHelperImplementation.readAndRemap(nbt)); + }); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/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/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..53052a06d --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryHelperImplementation.java @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.registrable.DesynchronizeableRegistrable; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.Registrable; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; +import net.legacyfabric.fabric.api.util.Identifier; +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 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..382757f25 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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()); + }); + } + + 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.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(); + + 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); + } + + private static class RegistryEntryImpl implements RegistryEntry { + private final int id; + private final Identifier identifier; + private final T value; + + RegistryEntryImpl(int id, Identifier identifier, T value) { + this.id = id; + this.identifier = identifier; + this.value = value; + } + + @Override + public int getId() { + return this.id; + } + + @Override + public Identifier getIdentifier() { + return this.identifier; + } + + @Override + public T getValue() { + return this.value; + } + } +} 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-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java new file mode 100644 index 000000000..f320032a0 --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/accessor/RegistryIdSetter.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.registry.accessor; + +import net.legacyfabric.fabric.api.util.Identifier; + +public interface RegistryIdSetter { + void fabric$setId(Identifier identifier); +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/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/mixin/registry/sync/IdListMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java new file mode 100644 index 000000000..8a7d3f42a --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.mixin.registry.sync; + +import java.util.IdentityHashMap; +import java.util.List; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.util.collection.IdList; + +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; + +@Mixin(IdList.class) +public abstract class IdListMixinV2 implements IdsHolder { + @Shadow + public abstract T fromId(int index); + + @Shadow + public abstract void set(T value, int index); + + @Shadow + public abstract int getId(T value); + + @Shadow + @Final + private IdentityHashMap idMap; + + @Override + public IdsHolder fabric$new() { + return (IdsHolder) new IdList<>(); + } + + @Override + public int fabric$nextId() { + int id = 1; + + while (this.fabric$getValue(id) != null) id++; + + return id; + } + + @Override + public void fabric$setValue(T value, int id) { + set(value, id); + } + + @Override + public int fabric$size() { + return idMap.size(); + } + + @Override + public T fabric$getValue(int rawId) { + return this.fromId(rawId); + } + + @Override + public int fabric$getId(T value) { + return getId(value); + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/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.10.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/ItemMixin.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java similarity index 62% 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/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java index a51824472..5977956c1 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/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/SimpleRegistryMixinV2.java @@ -17,25 +17,13 @@ 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; +import net.minecraft.util.registry.SimpleRegistry; -@Mixin(Item.class) -public class ItemMixin implements ItemCompat { - @Shadow - @Final - private static Map BLOCK_ITEMS; +import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistrableRegistry; +import net.legacyfabric.fabric.api.registry.v2.registry.registrable.DesynchronizeableRegistrable; - @Override - public Map getBLOCK_ITEMS() { - return BLOCK_ITEMS; - } +@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-v2/common/src/main/resources/fabric.mod.json b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..027f6bc9f --- /dev/null +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-registry-sync-api-v2-common", + "name": "Legacy Fabric Registry Sync API (V2)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "description": "Registry hooks", + "entrypoints": { + "client": [ + "net.legacyfabric.fabric.impl.registry.ClientRemapInitializer" + ] + }, + "mixins": [ + "legacy-fabric-registry-sync-api-v2-common.mixins.json" + ], + "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": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric/icon.png" + } + } + } +} diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json b/legacy-fabric-registry-sync-api-v2/common/src/main/resources/legacy-fabric-registry-sync-api-v2-common.mixins.json new file mode 100644 index 000000000..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/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 85% rename from legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 3d72858aa..0b2e631a3 100644 --- a/legacy-fabric-registry-sync-api-v1/1.12.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.10.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,8 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; + import java.util.concurrent.ThreadLocalRandom; @@ -32,9 +33,13 @@ import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; @@ -48,8 +53,8 @@ public void onInitialize() { Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); - RegistryHelper.registerBlock(block, identifier); - RegistryHelper.registerItem(new BlockItem(block), identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); diff --git a/legacyfabric-api/1.10.2/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.10.2/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.10.2/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 78% rename from legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 3d72858aa..e337ff849 100644 --- a/legacy-fabric-registry-sync-api-v1/1.10.2/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.11.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,8 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; + import java.util.concurrent.ThreadLocalRandom; @@ -28,13 +29,17 @@ import net.fabricmc.api.ModInitializer; -import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; @@ -48,12 +53,15 @@ public void onInitialize() { Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); - RegistryHelper.registerBlock(block, identifier); - RegistryHelper.registerItem(new BlockItem(block), identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); } Item testItem = new Item().setItemGroup(ItemGroup.FOOD); - RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); + RegistryHelper.register( + Item.REGISTRY, + new Identifier("legacy-fabric-api", "test_item"), testItem + ); ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); } } diff --git a/legacyfabric-api/1.11.2/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.11.2/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.11.2/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java new file mode 100644 index 000000000..e337ff849 --- /dev/null +++ b/legacyfabric-api/1.12.2/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.testing; + + +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialColor; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.itemgroup.ItemGroup; + +import net.fabricmc.api.ModInitializer; + +import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; +import net.legacyfabric.fabric.api.resource.ItemModelRegistry; +import net.legacyfabric.fabric.api.util.Identifier; + +public class TestMod implements ModInitializer { + @Override + public void onInitialize() { + registerItem(); + } + + private void registerItem() { + Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); + Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); + Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; + + for (Block block : blocks) { + int color = 1644825; + + if (block == concBlock2) { + color = 3361970; + } + + Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color); + + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerBlock(block, identifier); + net.legacyfabric.fabric.api.registry.v1.RegistryHelper.registerItem(new BlockItem(block), identifier); + } + + Item testItem = new Item().setItemGroup(ItemGroup.FOOD); + RegistryHelper.register( + Item.REGISTRY, + new Identifier("legacy-fabric-api", "test_item"), testItem + ); + ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item")); + } +} diff --git a/legacyfabric-api/1.12.2/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.12.2/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.12.2/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 81% rename from legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index d44e15cdf..0c8506f82 100644 --- a/legacy-fabric-registry-sync-api-v1/1.7.10/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.7.10/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,13 +15,15 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; + import java.util.concurrent.ThreadLocalRandom; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; import net.minecraft.item.itemgroup.ItemGroup; import net.fabricmc.api.ModInitializer; @@ -29,9 +31,13 @@ import net.legacyfabric.fabric.api.registry.v1.RegistryHelper; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; @@ -41,5 +47,8 @@ public void onInitialize() { RegistryHelper.registerBlock(block, identifier); RegistryHelper.registerItem(new BlockItem(block), identifier); } + + Item testItem = new Item().setItemGroup(ItemGroup.FOOD).getFromId("legacy-fabric-api:test_item"); + RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item")); } } diff --git a/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.7.10/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 93% rename from legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 903995adf..d338c86fe 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8.9/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.8.9/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,8 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; + import java.util.concurrent.ThreadLocalRandom; @@ -32,9 +33,13 @@ import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; diff --git a/legacyfabric-api/1.8.9/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.8.9/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.8.9/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 93% rename from legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 987555b4e..1b356eef7 100644 --- a/legacy-fabric-registry-sync-api-v1/1.8/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.8/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,8 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; + import java.util.concurrent.ThreadLocalRandom; @@ -31,9 +32,13 @@ import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.GLASS).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; diff --git a/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.8/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java similarity index 93% rename from legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java rename to legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java index 3d72858aa..970a1a683 100644 --- a/legacy-fabric-registry-sync-api-v1/1.9.4/src/testmod/java/net/legacyfabric/fabric/test/registry/RegistryTest.java +++ b/legacyfabric-api/1.9.4/src/testmod/java/net/legacyfabric/fabric/testing/TestMod.java @@ -15,7 +15,8 @@ * limitations under the License. */ -package net.legacyfabric.fabric.test.registry; +package net.legacyfabric.fabric.testing; + import java.util.concurrent.ThreadLocalRandom; @@ -32,9 +33,13 @@ import net.legacyfabric.fabric.api.resource.ItemModelRegistry; import net.legacyfabric.fabric.api.util.Identifier; -public class RegistryTest implements ModInitializer { +public class TestMod implements ModInitializer { @Override public void onInitialize() { + registerItem(); + } + + private void registerItem() { Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD); Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD); Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock}; diff --git a/legacyfabric-api/1.9.4/src/testmod/resources/fabric.mod.json b/legacyfabric-api/1.9.4/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..c7cf043bc --- /dev/null +++ b/legacyfabric-api/1.9.4/src/testmod/resources/fabric.mod.json @@ -0,0 +1,48 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-api-testmod", + "name": "Legacy Fabric API", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-api/icon.png", + "contact": { + "homepage": "https://legacyfabric.net/", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + { + "name": "Legacy Fabric", + "contact": { + "homepage": "https://legacyfabric.net/", + "discord": "https://legacyfabric.net/discord", + "sources": "https://github.com/Legacy-Fabric/fabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues" + } + }, + { + "name": "FabricMC", + "contact": { + "homepage": "https://fabricmc.net", + "discord": "https://discord.gg/v6v4pMv", + "sources": "https://github.com/FabricMC/fabric", + "issues": "https://github.com/FabricMC/fabric/issues" + } + } + ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "depends": { + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + "main": [ + "net.legacyfabric.fabric.testing.TestMod" + ] + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +} diff --git a/legacyfabric-api/common.gradle b/legacyfabric-api/common.gradle index 57e88309f..9598864ea 100644 --- a/legacyfabric-api/common.gradle +++ b/legacyfabric-api/common.gradle @@ -10,6 +10,9 @@ moduleDependencies(project, [ "legacy-fabric-networking-api-v1", "legacy-fabric-permissions-api-v1", "legacy-fabric-registry-sync-api-v1", + "legacy-fabric-registry-sync-api-v2", + "legacy-fabric-item-api-v1", + "legacy-fabric-block-api-v1", "legacy-fabric-rendering-api-v1", "legacy-fabric-crash-report-info-v1", "legacy-fabric-command-api-v2" diff --git a/settings.gradle b/settings.gradle index 9181e3e3d..8384c772b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -37,6 +37,9 @@ 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-item-api-v1") +loadProject("legacy-fabric-block-api-v1") loadProject("legacy-fabric-rendering-api-v1") loadProject("legacy-fabric-crash-report-info-v1") loadProject("legacy-fabric-command-api-v2")