88import com .simibubi .create .content .redstone .analogLever .AnalogLeverBlock ;
99import com .simibubi .create .content .schematics .requirement .ISpecialBlockItemRequirement ;
1010import com .simibubi .create .content .schematics .requirement .ItemRequirement ;
11+ import com .tterrag .registrate .util .nullness .NonNullSupplier ;
1112import net .minecraft .core .BlockPos ;
1213import net .minecraft .core .Direction ;
1314import net .minecraft .world .InteractionHand ;
3839public class LinkedAnalogLeverBlock extends AnalogLeverBlock implements ISpecialBlockItemRequirement , IWrenchable , LinkedTransmitterBlock {
3940
4041 public static final BooleanProperty POWERED = BlockStateProperties .POWERED ;
41- private final AnalogLeverBlock base ;
42+ private final NonNullSupplier < AnalogLeverBlock > baseSupplier ;
4243
43- public LinkedAnalogLeverBlock (Properties pProperties , AnalogLeverBlock base ) {
44+ public LinkedAnalogLeverBlock (Properties pProperties , NonNullSupplier < AnalogLeverBlock > baseSupplier ) {
4445 super (pProperties );
4546 registerDefaultState (defaultBlockState ().setValue (POWERED , false ));
46- this .base = base ;
47+ this .baseSupplier = baseSupplier ;
4748 }
4849
4950 @ Override
@@ -59,7 +60,7 @@ public Block getBlock() {
5960
6061 @ Override
6162 public Block getBase () {
62- return base ;
63+ return baseSupplier . get () ;
6364 }
6465
6566 @ Override
@@ -78,7 +79,7 @@ public Block getBase() {
7879 @ SuppressWarnings ("deprecation" )
7980 @ Override
8081 public @ NotNull List <ItemStack > getDrops (@ NotNull BlockState state , LootParams .@ NotNull Builder builder ) {
81- return base .getDrops (state , builder );
82+ return getBase () .getDrops (state , builder );
8283 }
8384
8485 private boolean isHittingBase (BlockState state , BlockGetter level , BlockPos pos , HitResult hit ) {
@@ -101,7 +102,7 @@ private boolean isHittingBase(BlockState state, BlockGetter level, BlockPos pos,
101102 public void onRemove (@ NotNull BlockState state , @ NotNull Level world , @ NotNull BlockPos pos , @ NotNull BlockState newState , boolean isMoving ) {
102103 if (!state .is (newState .getBlock ()) && !isMoving && getBlockEntityOptional (world , pos ).map (be -> ((LinkedAnalogLeverBlockEntity ) be ).containsBase ).orElse (false ))
103104 Block .popResource (world , pos , new ItemStack (CCItems .LINKED_TRANSMITTER ));
104- base .onRemove (state , world , pos , newState , isMoving );
105+ getBase () .onRemove (state , world , pos , newState , isMoving );
105106 }
106107
107108 @ Override
@@ -132,22 +133,22 @@ public void replaceBase(BlockState baseState, Level world, BlockPos pos) {
132133
133134 public void replaceWithBase (BlockState state , Level world , BlockPos pos ) {
134135 AllSoundEvents .CONTROLLER_TAKE .playOnServer (world , pos );
135- world .setBlockAndUpdate (pos , base .defaultBlockState ()
136+ world .setBlockAndUpdate (pos , getBase () .defaultBlockState ()
136137 .setValue (FACING , state .getValue (FACING ))
137138 .setValue (FACE , state .getValue (FACE )));
138139 }
139140
140141 @ Override
141142 public ItemStack getCloneItemStack (BlockState state , HitResult target , BlockGetter world , BlockPos pos , Player player ) {
142143 if (isHittingBase (state , world , pos , target ))
143- return base .getCloneItemStack (state , target , world , pos , player );
144+ return getBase () .getCloneItemStack (state , target , world , pos , player );
144145 return new ItemStack (CCItems .LINKED_TRANSMITTER .get ());
145146 }
146147
147148 @ Override
148149 public ItemRequirement getRequiredItems (BlockState state , BlockEntity be ) {
149150 ArrayList <ItemStack > requiredItems = new ArrayList <>();
150- requiredItems .add (new ItemStack (base ));
151+ requiredItems .add (new ItemStack (getBase () ));
151152 requiredItems .add (new ItemStack (CCItems .LINKED_TRANSMITTER .get ()));
152153 return new ItemRequirement (ItemRequirement .ItemUseType .CONSUME , requiredItems );
153154 }
0 commit comments