2021-08-22 21:33:22 +02:00
|
|
|
package de.ellpeck.actuallyadditions.registration;
|
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.world.item.BlockItem;
|
|
|
|
import net.minecraft.world.item.Item;
|
|
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
2024-03-04 20:21:48 +01:00
|
|
|
import net.neoforged.neoforge.registries.DeferredBlock;
|
|
|
|
import net.neoforged.neoforge.registries.DeferredItem;
|
2021-08-22 21:33:22 +02:00
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.function.Function;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public class AABlockReg<B extends Block, I extends Item, T extends BlockEntity> implements Supplier<Block> {
|
2021-08-22 21:33:22 +02:00
|
|
|
private final String name;
|
2024-03-04 20:21:48 +01:00
|
|
|
private DeferredBlock<B> block;
|
|
|
|
private DeferredItem<I> item;
|
|
|
|
private Supplier<BlockEntityType<T>> tileEntityType;
|
2021-08-22 21:33:22 +02:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public AABlockReg(String name, Supplier<B> blockSupplier, Function<B, I> itemSupplier, BlockEntityType.BlockEntitySupplier<T> tileSupplier) {
|
2021-08-22 21:33:22 +02:00
|
|
|
this.name = name;
|
|
|
|
this.block = ActuallyBlocks.BLOCKS.register(name, blockSupplier);
|
|
|
|
this.item = ActuallyItems.ITEMS.register(name, () -> itemSupplier.apply(block.get()));
|
2024-03-02 21:23:08 +01:00
|
|
|
this.tileEntityType = ActuallyBlocks.TILES.register(name, () -> BlockEntityType.Builder.of(tileSupplier, block.get()).build(null));
|
2021-08-22 21:33:22 +02:00
|
|
|
}
|
|
|
|
public AABlockReg(String name, Supplier<B> blockSupplier, Function<B, I> itemSupplier) {
|
|
|
|
this.name = name;
|
|
|
|
this.block = ActuallyBlocks.BLOCKS.register(name, blockSupplier);
|
|
|
|
this.item = ActuallyItems.ITEMS.register(name, () -> itemSupplier.apply(block.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
public AABlock(BlockBuilder builder) {
|
|
|
|
this.name = builder.name;
|
|
|
|
this.block = ActuallyBlocks.BLOCKS.register(name, builder.blockSupplier);
|
|
|
|
this.item = ActuallyItems.ITEMS.register(name, () -> builder.itemSupplier.apply(block.get()));
|
|
|
|
if (builder.hasTile)
|
|
|
|
this.tileEntityType = ActuallyTiles.TILES.register(name, () -> TileEntityType.Builder.create(builder.tileSupplier, block.get()).build(null));
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public String getName() {return name;}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Block get() {
|
|
|
|
return block.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public B getBlock() {
|
|
|
|
return block.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public I getItem() {
|
|
|
|
return item.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
2024-03-02 21:23:08 +01:00
|
|
|
public BlockEntityType<T> getTileEntityType() { return Objects.requireNonNull(tileEntityType.get());}
|
2021-08-22 21:33:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
public static class BlockBuilder {
|
|
|
|
private final String name;
|
|
|
|
private Supplier<Block> blockSupplier;
|
|
|
|
private Function<Block, Item> itemSupplier = (b) -> new BlockItem(b, ActuallyItems.defaultProps());
|
|
|
|
private boolean hasTile = false;
|
2024-03-02 21:23:08 +01:00
|
|
|
private Supplier<BlockEntityType<?>> tileSupplier;
|
2021-08-22 21:33:22 +02:00
|
|
|
|
|
|
|
private BlockBuilder(String nameIn, Supplier<Block> blockSupplierIn) {
|
|
|
|
this.name = nameIn;
|
|
|
|
this.blockSupplier = blockSupplierIn;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BlockBuilder block(String nameIn, Supplier<Block> blockSupplierIn) {
|
|
|
|
return new BlockBuilder(nameIn, blockSupplierIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockBuilder item(Function<Block, Item> itemSupplierIn) {
|
|
|
|
itemSupplier = itemSupplierIn;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public BlockBuilder tile(Supplier<BlockEntityType<?>> tileSupplierIn) {
|
2021-08-22 21:33:22 +02:00
|
|
|
tileSupplier = tileSupplierIn;
|
|
|
|
hasTile = true;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
public AABlock build() {
|
|
|
|
return new AABlock(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|