Wrapper for BlockEntityType.Builder (#115)

Signed-off-by: shedaniel <daniel@shedaniel.me>

Co-authored-by: Max <maxh2709@gmail.com>
This commit is contained in:
shedaniel
2021-07-02 00:38:16 +08:00
committed by GitHub
parent f6649ae398
commit 15ffb25551
4 changed files with 37 additions and 3 deletions

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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