8
8
import com .simibubi .create .content .redstone .analogLever .AnalogLeverBlock ;
9
9
import com .simibubi .create .content .schematics .requirement .ISpecialBlockItemRequirement ;
10
10
import com .simibubi .create .content .schematics .requirement .ItemRequirement ;
11
+ import com .tterrag .registrate .util .nullness .NonNullSupplier ;
11
12
import net .minecraft .core .BlockPos ;
12
13
import net .minecraft .core .Direction ;
13
14
import net .minecraft .world .InteractionHand ;
38
39
public class LinkedAnalogLeverBlock extends AnalogLeverBlock implements ISpecialBlockItemRequirement , IWrenchable , LinkedTransmitterBlock {
39
40
40
41
public static final BooleanProperty POWERED = BlockStateProperties .POWERED ;
41
- private final AnalogLeverBlock base ;
42
+ private final NonNullSupplier < AnalogLeverBlock > baseSupplier ;
42
43
43
- public LinkedAnalogLeverBlock (Properties pProperties , AnalogLeverBlock base ) {
44
+ public LinkedAnalogLeverBlock (Properties pProperties , NonNullSupplier < AnalogLeverBlock > baseSupplier ) {
44
45
super (pProperties );
45
46
registerDefaultState (defaultBlockState ().setValue (POWERED , false ));
46
- this .base = base ;
47
+ this .baseSupplier = baseSupplier ;
47
48
}
48
49
49
50
@ Override
@@ -59,7 +60,7 @@ public Block getBlock() {
59
60
60
61
@ Override
61
62
public Block getBase () {
62
- return base ;
63
+ return baseSupplier . get () ;
63
64
}
64
65
65
66
@ Override
@@ -78,7 +79,7 @@ public Block getBase() {
78
79
@ SuppressWarnings ("deprecation" )
79
80
@ Override
80
81
public @ NotNull List <ItemStack > getDrops (@ NotNull BlockState state , LootParams .@ NotNull Builder builder ) {
81
- return base .getDrops (state , builder );
82
+ return getBase () .getDrops (state , builder );
82
83
}
83
84
84
85
private boolean isHittingBase (BlockState state , BlockGetter level , BlockPos pos , HitResult hit ) {
@@ -101,7 +102,7 @@ private boolean isHittingBase(BlockState state, BlockGetter level, BlockPos pos,
101
102
public void onRemove (@ NotNull BlockState state , @ NotNull Level world , @ NotNull BlockPos pos , @ NotNull BlockState newState , boolean isMoving ) {
102
103
if (!state .is (newState .getBlock ()) && !isMoving && getBlockEntityOptional (world , pos ).map (be -> ((LinkedAnalogLeverBlockEntity ) be ).containsBase ).orElse (false ))
103
104
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 );
105
106
}
106
107
107
108
@ Override
@@ -132,22 +133,22 @@ public void replaceBase(BlockState baseState, Level world, BlockPos pos) {
132
133
133
134
public void replaceWithBase (BlockState state , Level world , BlockPos pos ) {
134
135
AllSoundEvents .CONTROLLER_TAKE .playOnServer (world , pos );
135
- world .setBlockAndUpdate (pos , base .defaultBlockState ()
136
+ world .setBlockAndUpdate (pos , getBase () .defaultBlockState ()
136
137
.setValue (FACING , state .getValue (FACING ))
137
138
.setValue (FACE , state .getValue (FACE )));
138
139
}
139
140
140
141
@ Override
141
142
public ItemStack getCloneItemStack (BlockState state , HitResult target , BlockGetter world , BlockPos pos , Player player ) {
142
143
if (isHittingBase (state , world , pos , target ))
143
- return base .getCloneItemStack (state , target , world , pos , player );
144
+ return getBase () .getCloneItemStack (state , target , world , pos , player );
144
145
return new ItemStack (CCItems .LINKED_TRANSMITTER .get ());
145
146
}
146
147
147
148
@ Override
148
149
public ItemRequirement getRequiredItems (BlockState state , BlockEntity be ) {
149
150
ArrayList <ItemStack > requiredItems = new ArrayList <>();
150
- requiredItems .add (new ItemStack (base ));
151
+ requiredItems .add (new ItemStack (getBase () ));
151
152
requiredItems .add (new ItemStack (CCItems .LINKED_TRANSMITTER .get ()));
152
153
return new ItemRequirement (ItemRequirement .ItemUseType .CONSUME , requiredItems );
153
154
}
0 commit comments