diff --git a/src/main/java/com/simibubi/create/AllBlocksNew.java b/src/main/java/com/simibubi/create/AllBlocksNew.java index 144b0a1cf..9f3fff496 100644 --- a/src/main/java/com/simibubi/create/AllBlocksNew.java +++ b/src/main/java/com/simibubi/create/AllBlocksNew.java @@ -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); } - - public static final RegistryEntry SCHEMATICANNON = REGISTRATE.block("schematicannon", SchematicannonBlock::new) - .initialProperties(() -> Blocks.DISPENSER) - .blockstate((ctx, prov) -> prov.simpleBlock(ctx.getEntry(), BlockStateGen.partialBaseModel(ctx, prov))) - .item() - .model(BlockStateGen::customItemModel) - .build() - .register(); - public static final RegistryEntry SCHEMATIC_TABLE = REGISTRATE.block("schematic_table", SchematicTableBlock::new) - .initialProperties(() -> Blocks.LECTERN) - .blockstate((ctx, prov) -> prov.horizontalBlock(ctx.getEntry(), prov.models().getExistingFile(ctx.getId()), 0)) - .simpleItem() - .register(); - - static { REGISTRATE.startSection(Sections.KINETICS); } - - public static final RegistryEntry SHAFT = REGISTRATE.block("shaft", ShaftBlock::new) + static { + REGISTRATE.startSection(SCHEMATICS); + } + + public static final BlockEntry 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()); + + public static final BlockEntry 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)) + .simpleItem() + .register()); + + static { + REGISTRATE.startSection(Sections.KINETICS); + } + + public static final BlockEntry SHAFT = REGISTRATE.block("shaft", ShaftBlock::new, b -> b .initialProperties(SharedProperties::kinetic) .blockstate((c, p) -> BlockStateGen.axisKineticBlock(c, p, BlockStateGen.standardModel(c, p))) .simpleItem() - .register(); - - public static final RegistryEntry COGWHEEL = REGISTRATE.block("cogwheel", CogWheelBlock::small) - .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(); - - public static final RegistryEntry LARGE_COGWHEEL = REGISTRATE.block("large_cogwheel", CogWheelBlock::large) - .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(); - - public static final RegistryEntry ENCASED_SHAFT = REGISTRATE.block("encased_shaft", EncasedShaftBlock::new) - .initialProperties(SharedProperties::kinetic) - .blockstate((c, p) -> BlockStateGen.axisKineticBlock(c, p, BlockStateGen.partialBaseModel(c, p))) - .item() - .model(BlockStateGen::customItemModel) - .build() - .register(); - - public static void register() {} + .register()); - // Ideally these following three methods would be part of the RegistryEntry instances - - public static > boolean equals(RegistryEntry entry, BlockState state) { - return entry.map(state.getBlock()::equals).get(); + public static final BlockEntry 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()); + + public static final BlockEntry 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()); + + public static final BlockEntry 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()); + + public static void register() { } - - public static ItemStack asStack(RegistryEntry entry) { - return new ItemStack(entry.get()); + + public static class BlockEntry implements Supplier { + + private RegistryEntry delegate; + + public BlockEntry(RegistryEntry 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 entry) { - return entry.get().getDefaultState(); - } - + } diff --git a/src/main/java/com/simibubi/create/CreateItemGroup.java b/src/main/java/com/simibubi/create/CreateItemGroup.java index fbcf9fd1d..360a09daf 100644 --- a/src/main/java/com/simibubi/create/CreateItemGroup.java +++ b/src/main/java/com/simibubi/create/CreateItemGroup.java @@ -23,7 +23,7 @@ public final class CreateItemGroup extends ItemGroup { @Override public ItemStack createIcon() { - return AllBlocksNew.asStack(AllBlocksNew.COGWHEEL); + return AllBlocksNew.COGWHEEL.asStack(); } @Override diff --git a/src/main/java/com/simibubi/create/CreateRegistrate.java b/src/main/java/com/simibubi/create/CreateRegistrate.java index 70a18c4fc..1f062d2c5 100644 --- a/src/main/java/com/simibubi/create/CreateRegistrate.java +++ b/src/main/java/com/simibubi/create/CreateRegistrate.java @@ -10,54 +10,52 @@ 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 { - /** - * 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 - * @return The {@link CreateRegistrate} instance - */ - public static CreateRegistrate create(String modid) { - return new CreateRegistrate(modid) - .registerEventListeners(FMLJavaModLoadingContext.get().getModEventBus()) - .itemGroup(() -> Create.creativeTab); - } - - public static NonNullLazyValue lazy(String modid) { - return new NonNullLazyValue<>(() -> create(modid)); - } + /** + * 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 + * @return The {@link CreateRegistrate} instance + */ + public static CreateRegistrate create(String modid) { + return new CreateRegistrate(modid).registerEventListeners(FMLJavaModLoadingContext.get() + .getModEventBus()) + .itemGroup(() -> Create.creativeTab); + } - protected CreateRegistrate(String modid) { - super(modid); - } - - private Map, Sections> sectionLookup = new IdentityHashMap<>(); - - private Sections section; + public static NonNullLazyValue lazy(String modid) { + return new NonNullLazyValue<>(() -> create(modid)); + } + + protected CreateRegistrate(String modid) { + super(modid); + } + + private Map, Sections> sectionLookup = new IdentityHashMap<>(); + + private Sections section; public CreateRegistrate startSection(Sections section) { this.section = section; return self(); } - + public Sections currentSection() { return section; } - - @Deprecated - public BlockBuilder block(String name, NonNullSupplier factory) { - return block(name, $ -> factory.get()); - } - + @Override protected , T extends R> RegistryEntry accept(String name, Class type, Builder builder, NonNullSupplier creator) { @@ -65,14 +63,22 @@ public class CreateRegistrate extends AbstractRegistrate { sectionLookup.put(ret, currentSection()); return ret; } - + + // TODO: find a better way to wrap the registry entries + public AllBlocksNew.BlockEntry block(String name, NonNullFunction factory, + NonNullFunction, RegistryEntry> registerFunc) { + return new AllBlocksNew.BlockEntry(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); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java index 71b6c0753..5e484c685 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java @@ -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() { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonTileEntityRenderer.java index 9bf6452e3..0c80000d3 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonTileEntityRenderer.java @@ -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())); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntityRenderer.java index 4fa2b2d0f..9df178d1c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntityRenderer.java @@ -139,7 +139,7 @@ public class DeployerTileEntityRenderer extends SafeTileEntityRenderer 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)); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/advanced/SpeedControllerRenderer.java index a37c6f80f..37f122b25 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -30,7 +30,7 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer items) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/CogwheelBlockItem.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/CogwheelBlockItem.java index dbb7288e1..7b045d2bd 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/CogwheelBlockItem.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/CogwheelBlockItem.java @@ -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); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/ShaftBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/ShaftBlock.java index 3ff507ab0..fd8642d97 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/ShaftBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/ShaftBlock.java @@ -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: diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/EncasedShaftTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/EncasedShaftTileEntityRenderer.java index e0400836e..453e9719b 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/EncasedShaftTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/EncasedShaftTileEntityRenderer.java @@ -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)); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeTileEntityRenderer.java index 9b0949ede..88a8be2ed 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeTileEntityRenderer.java @@ -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())); } diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/LaunchedItem.java b/src/main/java/com/simibubi/create/modules/schematics/block/LaunchedItem.java index e325b7279..8ef4cd460 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/LaunchedItem.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/LaunchedItem.java @@ -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)); } diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonTileEntity.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonTileEntity.java index d98f99b34..65d3bca0e 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonTileEntity.java @@ -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; }