52 lines
1.9 KiB
Java
52 lines
1.9 KiB
Java
package de.slpnetwork.brewcraft.block;
|
|
|
|
import de.slpnetwork.brewcraft.Brewcraft;
|
|
import de.slpnetwork.brewcraft.item.ModItems;
|
|
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.Blocks;
|
|
import net.minecraft.world.level.block.SoundType;
|
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
import net.minecraftforge.eventbus.api.IEventBus;
|
|
import net.minecraftforge.registries.DeferredRegister;
|
|
import net.minecraftforge.registries.ForgeRegistries;
|
|
import net.minecraftforge.registries.RegistryObject;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
public class ModBlocks {
|
|
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Brewcraft.MODID);
|
|
|
|
|
|
// example development block
|
|
public static final RegistryObject<Block> SAPPHIRE_BLOCK = registerBlock("sapphire_block",
|
|
() -> new Block(BlockBehaviour.Properties.copy(Blocks.EMERALD_BLOCK).sound(SoundType.AMETHYST)));
|
|
|
|
/**
|
|
* Handles registering the block itself and registering it as an item
|
|
* @param name the blocks name
|
|
* @param block the blocks properties
|
|
* @return the blocks registryObject
|
|
*/
|
|
private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block){
|
|
RegistryObject<T> toReturn = BLOCKS.register(name, block);
|
|
registerBlockItem(name, toReturn);
|
|
return toReturn;
|
|
}
|
|
|
|
/**
|
|
* registers blocks as item
|
|
* @param name the blocks name
|
|
* @param block the block
|
|
* @return an item containing that block
|
|
*/
|
|
private static <T extends Block>RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block) {
|
|
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties()));
|
|
}
|
|
|
|
public static void register(IEventBus eventBus) {
|
|
BLOCKS.register(eventBus);
|
|
}
|
|
}
|