39 lines
1.1 KiB
Java
39 lines
1.1 KiB
Java
package com.thebrokenrail.energonrelics.api.block;
|
|
|
|
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;
|
|
|
|
/**
|
|
* Simple Block With Entity
|
|
*/
|
|
public abstract class SimpleBlockWithEntity extends SimpleBlock implements BlockEntityProvider {
|
|
protected BlockEntityType<BlockEntity> type;
|
|
|
|
public SimpleBlockWithEntity(Settings settings) {
|
|
super(settings);
|
|
}
|
|
|
|
@Override
|
|
public void register(Identifier id) {
|
|
super.register(id);
|
|
type = Registry.register(Registry.BLOCK_ENTITY_TYPE, id, BlockEntityType.Builder.create(() -> getFactory().apply(type), this).build(null));
|
|
}
|
|
|
|
/**
|
|
* Factory To Create Block Entity
|
|
* @return Block Entity Factory
|
|
*/
|
|
protected abstract Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory();
|
|
|
|
@Override
|
|
public BlockEntity createBlockEntity(BlockView world) {
|
|
return getFactory().apply(type);
|
|
}
|
|
}
|