Block entry wrappers
- Simi wants his helpers back
This commit is contained in:
parent
20ab49e46e
commit
3eee3d2c87
17 changed files with 142 additions and 110 deletions
|
@ -2,6 +2,8 @@ package com.simibubi.create;
|
|||
|
||||
import static com.simibubi.create.modules.Sections.SCHEMATICS;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.utility.data.BlockStateGen;
|
||||
import com.simibubi.create.modules.Sections;
|
||||
import com.simibubi.create.modules.contraptions.relays.elementary.CogWheelBlock;
|
||||
|
@ -17,72 +19,96 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
public class AllBlocksNew {
|
||||
|
||||
private static final CreateRegistrate REGISTRATE = Create.registrate();
|
||||
|
||||
static { REGISTRATE.startSection(SCHEMATICS); }
|
||||
static {
|
||||
REGISTRATE.startSection(SCHEMATICS);
|
||||
}
|
||||
|
||||
public static final RegistryEntry<SchematicannonBlock> SCHEMATICANNON = REGISTRATE.block("schematicannon", SchematicannonBlock::new)
|
||||
public static final BlockEntry<SchematicannonBlock> SCHEMATICANNON =
|
||||
REGISTRATE.block("schematicannon", SchematicannonBlock::new, b -> b
|
||||
.initialProperties(() -> Blocks.DISPENSER)
|
||||
.blockstate((ctx, prov) -> prov.simpleBlock(ctx.getEntry(), BlockStateGen.partialBaseModel(ctx, prov)))
|
||||
.item()
|
||||
.model(BlockStateGen::customItemModel)
|
||||
.build()
|
||||
.register();
|
||||
.register());
|
||||
|
||||
public static final RegistryEntry<SchematicTableBlock> SCHEMATIC_TABLE = REGISTRATE.block("schematic_table", SchematicTableBlock::new)
|
||||
public static final BlockEntry<SchematicTableBlock> SCHEMATIC_TABLE =
|
||||
REGISTRATE.block("schematic_table", SchematicTableBlock::new, b -> b
|
||||
.initialProperties(() -> Blocks.LECTERN)
|
||||
.blockstate((ctx, prov) -> prov.horizontalBlock(ctx.getEntry(), prov.models().getExistingFile(ctx.getId()), 0))
|
||||
.blockstate((ctx, prov) -> prov.horizontalBlock(ctx.getEntry(), prov.models()
|
||||
.getExistingFile(ctx.getId()), 0))
|
||||
.simpleItem()
|
||||
.register();
|
||||
.register());
|
||||
|
||||
static { REGISTRATE.startSection(Sections.KINETICS); }
|
||||
static {
|
||||
REGISTRATE.startSection(Sections.KINETICS);
|
||||
}
|
||||
|
||||
public static final RegistryEntry<ShaftBlock> SHAFT = REGISTRATE.block("shaft", ShaftBlock::new)
|
||||
public static final BlockEntry<ShaftBlock> SHAFT = REGISTRATE.block("shaft", ShaftBlock::new, b -> b
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.blockstate((c, p) -> BlockStateGen.axisKineticBlock(c, p, BlockStateGen.standardModel(c, p)))
|
||||
.simpleItem()
|
||||
.register();
|
||||
.register());
|
||||
|
||||
public static final RegistryEntry<CogWheelBlock> COGWHEEL = REGISTRATE.block("cogwheel", CogWheelBlock::small)
|
||||
public static final BlockEntry<CogWheelBlock> COGWHEEL = REGISTRATE.block("cogwheel", CogWheelBlock::small, b -> b
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.properties(p -> p.sound(SoundType.WOOD))
|
||||
.blockstate((c, p) -> BlockStateGen.axisKineticBlock(c, p, BlockStateGen.standardModel(c, p)))
|
||||
.item(CogwheelBlockItem::new).build()
|
||||
.register();
|
||||
.item(CogwheelBlockItem::new)
|
||||
.build()
|
||||
.register());
|
||||
|
||||
public static final RegistryEntry<CogWheelBlock> LARGE_COGWHEEL = REGISTRATE.block("large_cogwheel", CogWheelBlock::large)
|
||||
public static final BlockEntry<CogWheelBlock> LARGE_COGWHEEL =
|
||||
REGISTRATE.block("large_cogwheel", CogWheelBlock::large, b -> b
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.properties(p -> p.sound(SoundType.WOOD))
|
||||
.blockstate((c, p) -> BlockStateGen.axisKineticBlock(c, p, BlockStateGen.standardModel(c, p)))
|
||||
.item(CogwheelBlockItem::new).build()
|
||||
.register();
|
||||
.item(CogwheelBlockItem::new)
|
||||
.build()
|
||||
.register());
|
||||
|
||||
public static final RegistryEntry<EncasedShaftBlock> ENCASED_SHAFT = REGISTRATE.block("encased_shaft", EncasedShaftBlock::new)
|
||||
public static final BlockEntry<EncasedShaftBlock> ENCASED_SHAFT =
|
||||
REGISTRATE.block("encased_shaft", EncasedShaftBlock::new, b -> b
|
||||
.initialProperties(SharedProperties::kinetic)
|
||||
.blockstate((c, p) -> BlockStateGen.axisKineticBlock(c, p, BlockStateGen.partialBaseModel(c, p)))
|
||||
.item()
|
||||
.model(BlockStateGen::customItemModel)
|
||||
.build()
|
||||
.register();
|
||||
.register());
|
||||
|
||||
public static void register() {}
|
||||
|
||||
// Ideally these following three methods would be part of the RegistryEntry instances
|
||||
|
||||
public static <T extends Block & IForgeRegistryEntry<Block>> boolean equals(RegistryEntry<T> entry, BlockState state) {
|
||||
return entry.map(state.getBlock()::equals).get();
|
||||
public static void register() {
|
||||
}
|
||||
|
||||
public static ItemStack asStack(RegistryEntry<? extends Block> entry) {
|
||||
return new ItemStack(entry.get());
|
||||
public static class BlockEntry<B extends Block> implements Supplier<B> {
|
||||
|
||||
private RegistryEntry<B> delegate;
|
||||
|
||||
public BlockEntry(RegistryEntry<B> entry) {
|
||||
this.delegate = entry;
|
||||
}
|
||||
|
||||
public boolean typeOf(BlockState state) {
|
||||
return get() == state.getBlock();
|
||||
}
|
||||
|
||||
public ItemStack asStack() {
|
||||
return new ItemStack(get());
|
||||
}
|
||||
|
||||
public BlockState getDefault() {
|
||||
return get().getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public B get() {
|
||||
return delegate.get();
|
||||
}
|
||||
|
||||
public static BlockState getDefault(RegistryEntry<? extends Block> entry) {
|
||||
return entry.get().getDefaultState();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public final class CreateItemGroup extends ItemGroup {
|
|||
|
||||
@Override
|
||||
public ItemStack createIcon() {
|
||||
return AllBlocksNew.asStack(AllBlocksNew.COGWHEEL);
|
||||
return AllBlocksNew.COGWHEEL.asStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,25 +10,28 @@ import com.tterrag.registrate.builders.BlockBuilder;
|
|||
import com.tterrag.registrate.builders.Builder;
|
||||
import com.tterrag.registrate.util.NonNullLazyValue;
|
||||
import com.tterrag.registrate.util.RegistryEntry;
|
||||
import com.tterrag.registrate.util.nullness.NonNullFunction;
|
||||
import com.tterrag.registrate.util.nullness.NonNullSupplier;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Block.Properties;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
|
||||
|
||||
/**
|
||||
* Create a new {@link CreateRegistrate} and register event listeners for registration and data generation. Used in lieu of adding side-effects to constructor, so that alternate initialization
|
||||
* strategies can be done in subclasses.
|
||||
* Create a new {@link CreateRegistrate} and register event listeners for
|
||||
* registration and data generation. Used in lieu of adding side-effects to
|
||||
* constructor, so that alternate initialization strategies can be done in
|
||||
* subclasses.
|
||||
*
|
||||
* @param modid
|
||||
* The mod ID for which objects will be registered
|
||||
* @param modid The mod ID for which objects will be registered
|
||||
* @return The {@link CreateRegistrate} instance
|
||||
*/
|
||||
public static CreateRegistrate create(String modid) {
|
||||
return new CreateRegistrate(modid)
|
||||
.registerEventListeners(FMLJavaModLoadingContext.get().getModEventBus())
|
||||
return new CreateRegistrate(modid).registerEventListeners(FMLJavaModLoadingContext.get()
|
||||
.getModEventBus())
|
||||
.itemGroup(() -> Create.creativeTab);
|
||||
}
|
||||
|
||||
|
@ -53,11 +56,6 @@ public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
|
|||
return section;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public <T extends Block> BlockBuilder<T, CreateRegistrate> block(String name, NonNullSupplier<T> factory) {
|
||||
return block(name, $ -> factory.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <R extends IForgeRegistryEntry<R>, T extends R> RegistryEntry<T> accept(String name,
|
||||
Class<? super R> type, Builder<R, T, ?, ?> builder, NonNullSupplier<? extends T> creator) {
|
||||
|
@ -66,13 +64,21 @@ public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
|
|||
return ret;
|
||||
}
|
||||
|
||||
// TODO: find a better way to wrap the registry entries
|
||||
public <T extends Block> AllBlocksNew.BlockEntry<T> block(String name, NonNullFunction<Properties, T> factory,
|
||||
NonNullFunction<BlockBuilder<T, CreateRegistrate>, RegistryEntry<T>> registerFunc) {
|
||||
return new AllBlocksNew.BlockEntry<T>(registerFunc.apply(super.block(name, factory)));
|
||||
}
|
||||
|
||||
public Sections getSection(RegistryEntry<?> entry) {
|
||||
return sectionLookup.getOrDefault(entry, Sections.UNASSIGNED);
|
||||
}
|
||||
|
||||
public Sections getSection(IForgeRegistryEntry<?> entry) {
|
||||
return sectionLookup.entrySet().stream()
|
||||
.filter(e -> e.getKey().get() == entry)
|
||||
return sectionLookup.entrySet()
|
||||
.stream()
|
||||
.filter(e -> e.getKey()
|
||||
.get() == entry)
|
||||
.map(Entry::getValue)
|
||||
.findFirst()
|
||||
.orElse(Sections.UNASSIGNED);
|
||||
|
|
|
@ -17,7 +17,7 @@ public abstract class AnimatedKinetics implements IDrawable {
|
|||
}
|
||||
|
||||
protected BlockState shaft(Axis axis) {
|
||||
return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(BlockStateProperties.AXIS, axis);
|
||||
return AllBlocksNew.SHAFT.getDefault().with(BlockStateProperties.AXIS, axis);
|
||||
}
|
||||
|
||||
protected AllBlockPartials cogwheel() {
|
||||
|
|
|
@ -17,7 +17,7 @@ public class MechanicalPistonTileEntityRenderer extends KineticTileEntityRendere
|
|||
|
||||
@Override
|
||||
protected BlockState getRenderedBlockState(KineticTileEntity te) {
|
||||
return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(BlockStateProperties.AXIS,
|
||||
return AllBlocksNew.SHAFT.getDefault().with(BlockStateProperties.AXIS,
|
||||
((IRotate) te.getBlockState().getBlock()).getRotationAxis(te.getBlockState()));
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ public class DeployerTileEntityRenderer extends SafeTileEntityRenderer<DeployerT
|
|||
BlockState state = te.getBlockState();
|
||||
if (!AllBlocks.DEPLOYER.typeOf(state))
|
||||
return Blocks.AIR.getDefaultState();
|
||||
return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(AXIS, ((IRotate) state.getBlock()).getRotationAxis(state));
|
||||
return AllBlocksNew.SHAFT.getDefault().with(AXIS, ((IRotate) state.getBlock()).getRotationAxis(state));
|
||||
}
|
||||
|
||||
private static SuperByteBuffer renderAndTransform(World world, AllBlockPartials renderBlock,
|
||||
|
|
|
@ -39,7 +39,7 @@ public class MechanicalPressTileEntityRenderer extends KineticTileEntityRenderer
|
|||
|
||||
@Override
|
||||
protected BlockState getRenderedBlockState(KineticTileEntity te) {
|
||||
return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(BlockStateProperties.AXIS,
|
||||
return AllBlocksNew.SHAFT.getDefault().with(BlockStateProperties.AXIS,
|
||||
te.getBlockState().get(HORIZONTAL_FACING).getAxis());
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ public class SawTileEntityRenderer extends SafeTileEntityRenderer<SawTileEntity>
|
|||
|
||||
protected BlockState getRenderedBlockState(KineticTileEntity te) {
|
||||
BlockState state = te.getBlockState();
|
||||
return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(AXIS, ((IRotate) state.getBlock()).getRotationAxis(state));
|
||||
return AllBlocksNew.SHAFT.getDefault().with(AXIS, ((IRotate) state.getBlock()).getRotationAxis(state));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer<SpeedContro
|
|||
private SuperByteBuffer getRotatedModel(SpeedControllerTileEntity te) {
|
||||
BlockState state = te.getBlockState();
|
||||
return CreateClient.bufferCache.renderBlockIn(KineticTileEntityRenderer.KINETIC_TILE,
|
||||
AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(ShaftBlock.AXIS, state.get(SpeedControllerBlock.HORIZONTAL_AXIS)));
|
||||
AllBlocksNew.SHAFT.getDefault().with(ShaftBlock.AXIS, state.get(SpeedControllerBlock.HORIZONTAL_AXIS)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
|
|||
drops.addAll(AllBlocks.BRASS_CASING.getDefault().getDrops(builder));
|
||||
TileEntity tileEntity = builder.get(LootParameters.BLOCK_ENTITY);
|
||||
if (tileEntity instanceof BeltTileEntity && ((BeltTileEntity) tileEntity).hasPulley())
|
||||
drops.addAll(AllBlocksNew.getDefault(AllBlocksNew.SHAFT).getDrops(builder));
|
||||
drops.addAll(AllBlocksNew.SHAFT.getDefault().getDrops(builder));
|
||||
return drops;
|
||||
}
|
||||
|
||||
|
@ -292,7 +292,7 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
|
|||
belt.attachKinetics();
|
||||
}
|
||||
if (!player.isCreative())
|
||||
player.inventory.placeItemBackInInventory(world, AllBlocksNew.asStack(AllBlocksNew.SHAFT));
|
||||
player.inventory.placeItemBackInInventory(world, AllBlocksNew.SHAFT.asStack());
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -504,7 +504,7 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
|
|||
}
|
||||
|
||||
BlockState shaftState =
|
||||
AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(BlockStateProperties.AXIS, getRotationAxis(currentState));
|
||||
AllBlocksNew.SHAFT.getDefault().with(BlockStateProperties.AXIS, getRotationAxis(currentState));
|
||||
world.setBlockState(currentPos, hasPulley ? shaftState : Blocks.AIR.getDefaultState(), 3);
|
||||
world.playEvent(2001, currentPos, Block.getStateId(currentState));
|
||||
}
|
||||
|
|
|
@ -91,11 +91,11 @@ public class CogWheelBlock extends ShaftBlock {
|
|||
}
|
||||
|
||||
public static boolean isSmallCog(BlockState state) {
|
||||
return AllBlocksNew.equals(AllBlocksNew.COGWHEEL, state);
|
||||
return AllBlocksNew.COGWHEEL.typeOf(state);
|
||||
}
|
||||
|
||||
public static boolean isLargeCog(BlockState state) {
|
||||
return AllBlocksNew.equals(AllBlocksNew.LARGE_COGWHEEL, state);
|
||||
return AllBlocksNew.LARGE_COGWHEEL.typeOf(state);
|
||||
}
|
||||
|
||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
||||
|
|
|
@ -96,7 +96,7 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
continue;
|
||||
if (blockState.get(CogWheelBlock.AXIS) != axis)
|
||||
continue;
|
||||
if (AllBlocksNew.equals(AllBlocksNew.LARGE_COGWHEEL, blockState) == large)
|
||||
if (AllBlocksNew.LARGE_COGWHEEL.typeOf(blockState) == large)
|
||||
continue;
|
||||
AllTriggers.triggerFor(AllTriggers.SHIFTING_GEARS, player);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ShaftBlock extends RotatedPillarKineticBlock {
|
|||
}
|
||||
|
||||
public static boolean isShaft(BlockState state) {
|
||||
return AllBlocksNew.equals(AllBlocksNew.SHAFT, state);
|
||||
return AllBlocksNew.SHAFT.typeOf(state);
|
||||
}
|
||||
|
||||
// IRotate:
|
||||
|
|
|
@ -16,7 +16,7 @@ public class EncasedShaftTileEntityRenderer extends KineticTileEntityRenderer {
|
|||
|
||||
@Override
|
||||
protected BlockState getRenderedBlockState(KineticTileEntity te) {
|
||||
return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(BlockStateProperties.AXIS,
|
||||
return AllBlocksNew.SHAFT.getDefault().with(BlockStateProperties.AXIS,
|
||||
te.getBlockState().get(BlockStateProperties.AXIS));
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class GaugeTileEntityRenderer extends KineticTileEntityRenderer {
|
|||
|
||||
@Override
|
||||
protected BlockState getRenderedBlockState(KineticTileEntity te) {
|
||||
return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(BlockStateProperties.AXIS,
|
||||
return AllBlocksNew.SHAFT.getDefault().with(BlockStateProperties.AXIS,
|
||||
((IRotate) te.getBlockState().getBlock()).getRotationAxis(te.getBlockState()));
|
||||
}
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ public abstract class LaunchedItem {
|
|||
BlockPos offset = BeltBlock.nextSegmentPosition(state, BlockPos.ZERO, isStart);
|
||||
int i = length - 1;
|
||||
Axis axis = state.get(BeltBlock.HORIZONTAL_FACING).rotateY().getAxis();
|
||||
world.setBlockState(target, AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(ShaftBlock.AXIS, axis));
|
||||
world.setBlockState(target, AllBlocksNew.SHAFT.getDefault().with(ShaftBlock.AXIS, axis));
|
||||
BeltConnectorItem
|
||||
.createBelts(world, target, target.add(offset.getX() * i, offset.getY() * i, offset.getZ() * i));
|
||||
}
|
||||
|
|
|
@ -504,7 +504,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC
|
|||
}
|
||||
if (!isLastSegment)
|
||||
blockState = (blockState.get(BeltBlock.PART) == Part.MIDDLE) ? Blocks.AIR.getDefaultState()
|
||||
: AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(ShaftBlock.AXIS, facing.rotateY().getAxis());
|
||||
: AllBlocksNew.SHAFT.getDefault().with(ShaftBlock.AXIS, facing.rotateY().getAxis());
|
||||
return blockState;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue