Files
Mantle/src/main/java/slimeknights/mantle/registration/adapter/BlockRegistryAdapter.java
T
KnightMiner eafa8da4b7 Add more methods to the item registry adapter that make use of default props
Also make default props parameter optional and add some missing javadocs
2020-07-27 21:55:21 -05:00

114 lines
4.4 KiB
Java

package slimeknights.mantle.registration.adapter;
import net.minecraft.block.AbstractBlock.Properties;
import net.minecraft.block.Block;
import net.minecraft.block.FenceBlock;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.StairsBlock;
import net.minecraft.block.WallBlock;
import net.minecraft.block.material.Material;
import net.minecraftforge.fluids.ForgeFlowingFluid;
import net.minecraftforge.registries.IForgeRegistry;
import slimeknights.mantle.registration.object.BuildingBlockObject;
import slimeknights.mantle.registration.object.FenceBuildingBlockObject;
import slimeknights.mantle.registration.object.WallBuildingBlockObject;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* Provides utility registration methods when registering blocks.
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class BlockRegistryAdapter extends EnumRegistryAdapter<Block> {
/** @inheritDoc */
public BlockRegistryAdapter(IForgeRegistry<Block> registry) {
super(registry);
}
/** @inheritDoc */
public BlockRegistryAdapter(IForgeRegistry<Block> registry, String modid) {
super(registry, modid);
}
/**
* Registers a block override based on the given block
* @param constructor Override constructor
* @param base Base block
* @param <T> Block type
* @return Registered block
*/
public <T extends Block> T registerOverride(Function<Properties, T> constructor, Block base) {
return register(constructor.apply(Block.Properties.from(base)), base);
}
/* Building */
/**
* Registers the given block as well as a slab and a stair variant for it.
* Uses the vanilla slab and stair blocks. Uses the passed blocks properties for both.
* Slabs and stairs are registered with a "_slab" and "_stairs" prefix
*
* @param block The main block to register and whose properties to use
* @param name The registry name to use for the block and as base for the slab and stairs
* @return BuildingBlockObject for the given block
*/
public BuildingBlockObject registerBuilding(Block block, String name) {
return BuildingBlockObject.fromBlocks(
this.register(block, name),
this.register(new SlabBlock(Block.Properties.from(block)), name + "_slab"),
this.register(new StairsBlock(block::getDefaultState, Block.Properties.from(block)), name + "_stairs")
);
}
/**
* Same as {@link #registerBuilding(Block, String)}, but also includes a wall variant
*
* @param block The main block to register and whose properties to use
* @param name The registry name to use for the block and as base for the slab and stairs
* @return BuildingBlockObject for the given block
*/
public WallBuildingBlockObject registerWallBuilding(Block block, String name) {
return WallBuildingBlockObject.fromBlocks(
registerBuilding(block, name),
this.register(new WallBlock(Block.Properties.from(block)), name + "_wall")
);
}
/**
* Same as {@link #registerBuilding(Block, String)}, but also includes a fence variant
*
* @param block The main block to register and whose properties to use
* @param name The registry name to use for the block and as base for the slab and stairs
* @return BuildingBlockObject for the given block
*/
public FenceBuildingBlockObject registerFenceBuilding(Block block, String name) {
return FenceBuildingBlockObject.fromBlocks(
registerBuilding(block, name),
this.register(new FenceBlock(Block.Properties.from(block)), name + "_fence")
);
}
/* Fluid */
/**
* Registers a fluid block from a fluid
* @param fluid Fluid supplier
* @param material Fluid material
* @param lightLevel Fluid light level
* @param name Fluid name, unfortunately no way to fetch from the fluid as it does not exist yet
* @return Fluid block instance
*/
public FlowingFluidBlock registerFluidBlock(Supplier<? extends ForgeFlowingFluid> fluid, Material material, int lightLevel, String name) {
return register(
new FlowingFluidBlock(fluid, Block.Properties.create(material)
.doesNotBlockMovement()
.hardnessAndResistance(100.0F)
.noDrops()
.setLightLevel((state) -> lightLevel)),
name + "_fluid");
}
}