From c21168c3a86c6772ab75c4052e504341599d0c51 Mon Sep 17 00:00:00 2001 From: Su5eD Date: Sat, 22 Jun 2024 15:50:00 +0200 Subject: [PATCH] Port fabric-api-lookup-api-v1 --- .../impl/lookup/block/BlockApiLookupImpl.java | 5 ++-- .../mixin/lookup/BlockEntityTypeAccessor.java | 29 ------------------- .../fabric-api-lookup-api-v1.mixins.json | 1 - .../entity/FabricEntityApiLookupTest.java | 5 +++- settings.gradle.kts | 2 +- 5 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/mixin/lookup/BlockEntityTypeAccessor.java diff --git a/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/impl/lookup/block/BlockApiLookupImpl.java b/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/impl/lookup/block/BlockApiLookupImpl.java index 4aef6753a..88bab7de9 100644 --- a/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/impl/lookup/block/BlockApiLookupImpl.java +++ b/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/impl/lookup/block/BlockApiLookupImpl.java @@ -26,7 +26,6 @@ import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; import net.fabricmc.fabric.api.lookup.v1.custom.ApiLookupMap; import net.fabricmc.fabric.api.lookup.v1.custom.ApiProviderMap; -import net.fabricmc.fabric.mixin.lookup.BlockEntityTypeAccessor; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; @@ -108,7 +107,7 @@ public A find(Level world, BlockPos pos, @Nullable BlockState state, @Nullable B @Override public void registerSelf(BlockEntityType... blockEntityTypes) { for (BlockEntityType blockEntityType : blockEntityTypes) { - Block supportBlock = ((BlockEntityTypeAccessor) blockEntityType).getBlocks().iterator().next(); + Block supportBlock = blockEntityType.getValidBlocks().iterator().next(); Objects.requireNonNull(supportBlock, "Could not get a support block for block entity type."); BlockEntity blockEntity = blockEntityType.create(BlockPos.ZERO, supportBlock.defaultBlockState()); Objects.requireNonNull(blockEntity, "Instantiated block entity may not be null."); @@ -162,7 +161,7 @@ public void registerForBlockEntities(BlockEntityApiProvider provider, Bloc } }; - Block[] blocks = ((BlockEntityTypeAccessor) blockEntityType).getBlocks().toArray(new Block[0]); + Block[] blocks = blockEntityType.getValidBlocks().toArray(new Block[0]); registerForBlocks(nullCheckedProvider, blocks); } } diff --git a/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/mixin/lookup/BlockEntityTypeAccessor.java b/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/mixin/lookup/BlockEntityTypeAccessor.java deleted file mode 100644 index 882ae67d7..000000000 --- a/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/mixin/lookup/BlockEntityTypeAccessor.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.fabric.mixin.lookup; - -import java.util.Set; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntityType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(BlockEntityType.class) -public interface BlockEntityTypeAccessor { - @Accessor("validBlocks") - Set getBlocks(); -} diff --git a/fabric-api-lookup-api-v1/src/main/resources/fabric-api-lookup-api-v1.mixins.json b/fabric-api-lookup-api-v1/src/main/resources/fabric-api-lookup-api-v1.mixins.json index 327b248b1..75cf560e1 100644 --- a/fabric-api-lookup-api-v1/src/main/resources/fabric-api-lookup-api-v1.mixins.json +++ b/fabric-api-lookup-api-v1/src/main/resources/fabric-api-lookup-api-v1.mixins.json @@ -3,7 +3,6 @@ "package": "net.fabricmc.fabric.mixin.lookup", "compatibilityLevel": "JAVA_17", "mixins": [ - "BlockEntityTypeAccessor", "ServerWorldMixin" ], "injectors": { diff --git a/fabric-api-lookup-api-v1/src/testmod/java/net/fabricmc/fabric/test/lookup/entity/FabricEntityApiLookupTest.java b/fabric-api-lookup-api-v1/src/testmod/java/net/fabricmc/fabric/test/lookup/entity/FabricEntityApiLookupTest.java index 6123c8547..a803a48f4 100644 --- a/fabric-api-lookup-api-v1/src/testmod/java/net/fabricmc/fabric/test/lookup/entity/FabricEntityApiLookupTest.java +++ b/fabric-api-lookup-api-v1/src/testmod/java/net/fabricmc/fabric/test/lookup/entity/FabricEntityApiLookupTest.java @@ -30,6 +30,8 @@ import net.minecraft.world.entity.MobCategory; import net.minecraft.world.entity.animal.Pig; import net.minecraft.world.entity.monster.Creeper; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; public class FabricEntityApiLookupTest { public static final EntityApiLookup INSPECTABLE = @@ -44,7 +46,8 @@ public class FabricEntityApiLookupTest { public static void onInitialize() { Registry.register(BuiltInRegistries.ENTITY_TYPE, ResourceLocation.fromNamespaceAndPath(FabricApiLookupTest.MOD_ID, "inspectable_pig"), INSPECTABLE_PIG); - FabricDefaultAttributeRegistry.register(INSPECTABLE_PIG, Pig.createAttributes()); + ModLoadingContext.get().getActiveContainer().getEventBus() + .addListener(FMLCommonSetupEvent.class, e -> FabricDefaultAttributeRegistry.register(INSPECTABLE_PIG, Pig.createAttributes())); INSPECTABLE.registerSelf(INSPECTABLE_PIG); INSPECTABLE.registerForTypes( diff --git a/settings.gradle.kts b/settings.gradle.kts index 2f1790d94..25e16634f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -34,7 +34,7 @@ include("fabric-api-bom") include("fabric-api-catalog") include("fabric-api-base") -//include 'fabric-api-lookup-api-v1' +include("fabric-api-lookup-api-v1") //include 'fabric-biome-api-v1' include("fabric-block-api-v1") include("fabric-block-view-api-v2")