package com.thebrokenrail.energonrelics.block.util; import com.thebrokenrail.energonrelics.EnergonRelics; import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; import net.minecraft.world.BlockView; import java.util.function.Function; public abstract class SimpleBlockWithEntity extends SimpleBlock implements BlockEntityProvider { protected BlockEntityType type; public SimpleBlockWithEntity(Settings settings) { super(settings); } @Override public void register(String name) { super.register(name); type = Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(EnergonRelics.NAMESPACE, name), BlockEntityType.Builder.create(() -> getFactory().apply(type), this).build(null)); } protected abstract Function, BlockEntity> getFactory(); @Override public BlockEntity createBlockEntity(BlockView world) { return getFactory().apply(type); } }