Skip to content

Commit

Permalink
Port fabric-api-lookup-api-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jun 22, 2024
1 parent 7b33eef commit c21168c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -162,7 +161,7 @@ public void registerForBlockEntities(BlockEntityApiProvider<A, C> provider, Bloc
}
};

Block[] blocks = ((BlockEntityTypeAccessor) blockEntityType).getBlocks().toArray(new Block[0]);
Block[] blocks = blockEntityType.getValidBlocks().toArray(new Block[0]);
registerForBlocks(nullCheckedProvider, blocks);
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"package": "net.fabricmc.fabric.mixin.lookup",
"compatibilityLevel": "JAVA_17",
"mixins": [
"BlockEntityTypeAccessor",
"ServerWorldMixin"
],
"injectors": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, Void> INSPECTABLE =
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c21168c

Please sign in to comment.