mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Wrapper for BlockEntityType.Builder (#115)
Signed-off-by: shedaniel <daniel@shedaniel.me> Co-authored-by: Max <maxh2709@gmail.com>
This commit is contained in:
@@ -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 <T extends BlockEntity> TypeBuilder<T> builder(Constructor<? extends T> constructor, Block... blocks) {
|
||||
return new TypeBuilder<>(constructor, ImmutableSet.copyOf(blocks));
|
||||
}
|
||||
|
||||
public static class TypeBuilder<T extends BlockEntity> {
|
||||
private final Constructor<? extends T> constructor;
|
||||
private final Set<Block> validBlocks;
|
||||
|
||||
private TypeBuilder(Constructor<? extends T> constructor, Set<Block> validBlocks) {
|
||||
this.constructor = constructor;
|
||||
this.validBlocks = validBlocks;
|
||||
}
|
||||
|
||||
public BlockEntityType<T> 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 extends BlockEntity> {
|
||||
T create(BlockPos pos, BlockState state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <init> (Ljava/lang/String;)V
|
||||
accessible method net/minecraft/world/level/storage/LevelResource <init> (Ljava/lang/String;)V
|
||||
accessible class net/minecraft/world/level/block/entity/BlockEntityType$BlockEntitySupplier
|
||||
@@ -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 <init> (Ljava/lang/String;)V
|
||||
accessible method net/minecraft/world/level/storage/LevelResource <init> (Ljava/lang/String;)V
|
||||
accessible class net/minecraft/world/level/block/entity/BlockEntityType$BlockEntitySupplier
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user