diff --git a/common/src/main/java/dev/architectury/hooks/block/BlockEntityHooks.java b/common/src/main/java/dev/architectury/hooks/block/BlockEntityHooks.java index 7e19bb02..7494ef00 100644 --- a/common/src/main/java/dev/architectury/hooks/block/BlockEntityHooks.java +++ b/common/src/main/java/dev/architectury/hooks/block/BlockEntityHooks.java @@ -19,13 +19,40 @@ package dev.architectury.hooks.block; +import com.google.common.collect.ImmutableSet; +import com.mojang.datafixers.types.Type; import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +import java.util.Set; public class BlockEntityHooks { private BlockEntityHooks() { } + public static TypeBuilder builder(Constructor constructor, Block... blocks) { + return new TypeBuilder<>(constructor, ImmutableSet.copyOf(blocks)); + } + + public static class TypeBuilder { + private final Constructor constructor; + private final Set validBlocks; + + private TypeBuilder(Constructor constructor, Set validBlocks) { + this.constructor = constructor; + this.validBlocks = validBlocks; + } + + public BlockEntityType build(@Nullable Type type) { + return new BlockEntityType<>(this.constructor::create, this.validBlocks, type); + } + } + /** * Sync data to the clients. */ @@ -33,4 +60,9 @@ public class BlockEntityHooks { public static void syncData(BlockEntity entity) { throw new AssertionError(); } + + @FunctionalInterface + public interface Constructor { + T create(BlockPos pos, BlockState state); + } } diff --git a/common/src/main/resources/architectury.accessWidener b/common/src/main/resources/architectury.accessWidener index 80026d51..9376d749 100644 --- a/common/src/main/resources/architectury.accessWidener +++ b/common/src/main/resources/architectury.accessWidener @@ -39,4 +39,5 @@ accessible field net/minecraft/world/level/biome/BiomeSpecialEffects ambientAddi mutable field net/minecraft/world/level/biome/BiomeSpecialEffects ambientAdditionsSettings Ljava/util/Optional; accessible field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional; mutable field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional; -accessible method net/minecraft/world/level/storage/LevelResource (Ljava/lang/String;)V \ No newline at end of file +accessible method net/minecraft/world/level/storage/LevelResource (Ljava/lang/String;)V +accessible class net/minecraft/world/level/block/entity/BlockEntityType$BlockEntitySupplier \ No newline at end of file diff --git a/fabric/src/main/resources/architectury.accessWidener b/fabric/src/main/resources/architectury.accessWidener index 4379081c..5e44d25c 100644 --- a/fabric/src/main/resources/architectury.accessWidener +++ b/fabric/src/main/resources/architectury.accessWidener @@ -97,4 +97,5 @@ accessible field net/minecraft/world/level/biome/BiomeSpecialEffects ambientAddi mutable field net/minecraft/world/level/biome/BiomeSpecialEffects ambientAdditionsSettings Ljava/util/Optional; accessible field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional; mutable field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional; -accessible method net/minecraft/world/level/storage/LevelResource (Ljava/lang/String;)V \ No newline at end of file +accessible method net/minecraft/world/level/storage/LevelResource (Ljava/lang/String;)V +accessible class net/minecraft/world/level/block/entity/BlockEntityType$BlockEntitySupplier \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 4f132921..7c3b9bb6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ cf_type=release archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=2.0 +base_version=2.1 maven_group=dev.architectury fabric_loader_version=0.11.6