11package com .rae .creatingspace .content .rocket .engine ;
22
33import com .rae .creatingspace .init .ingameobject .BlockInit ;
4+ import com .rae .formicapi .multiblock .MBStructureBlock ;
45import com .simibubi .create .api .equipment .goggles .IProxyHoveringInformation ;
56import com .simibubi .create .content .equipment .wrench .IWrenchable ;
67import com .simibubi .create .foundation .block .render .MultiPosDestructionHandler ;
2930import net .minecraftforge .api .distmarker .Dist ;
3031import net .minecraftforge .api .distmarker .OnlyIn ;
3132import net .minecraftforge .client .extensions .common .IClientBlockExtensions ;
33+ import org .jetbrains .annotations .NotNull ;
3234import org .jetbrains .annotations .Nullable ;
35+ import org .lwjgl .system .NonnullDefault ;
3336
3437import java .util .ArrayList ;
3538import java .util .HashSet ;
3639import java .util .Set ;
3740import java .util .function .Consumer ;
38-
39- public class SuperRocketStructuralBlock extends DirectionalBlock implements IWrenchable , IProxyHoveringInformation {
40-
41+ import java . util . function . Supplier ;
42+ @ NonnullDefault
43+ public class SuperRocketStructuralBlock extends MBStructureBlock implements IProxyHoveringInformation {
4144 public SuperRocketStructuralBlock (Properties p_52591_ ) {
4245 super (p_52591_ );
4346 }
44-
45- @ Override
46- protected void createBlockStateDefinition (Builder <Block , BlockState > pBuilder ) {
47- super .createBlockStateDefinition (pBuilder .add (FACING ));
48- }
49-
50- @ Override
51- public float getShadeBrightness (BlockState pState , BlockGetter pLevel , BlockPos pPos ) {
52- return 1.0F ;
53- }
54-
55- @ Override
56- public boolean propagatesSkylightDown (BlockState pState , BlockGetter pReader , BlockPos pPos ) {
57- return true ;
58- }
59-
60- @ Override
61- public InteractionResult onWrenched (BlockState state , UseOnContext context ) {
62- return InteractionResult .PASS ;
63- }
64-
6547 @ Override
6648 public ItemStack getCloneItemStack (BlockGetter pLevel , BlockPos pPos , BlockState pState ) {
67- return BlockInit .SMALL_ROCKET_ENGINE .asStack ();
68- }
69-
70- @ Override
71- public InteractionResult onSneakWrenched (BlockState state , UseOnContext context ) {
72- BlockPos clickedPos = context .getClickedPos ();
73- Level level = context .getLevel ();
74-
75- if (stillValid (level , clickedPos , state )) {
76- BlockPos masterPos = getMaster (level , clickedPos , state );
77- context = new UseOnContext (level , context .getPlayer (), context .getHand (), context .getItemInHand (),
78- new BlockHitResult (context .getClickLocation (), context .getClickedFace (), masterPos ,
79- context .isInside ()));
80- state = level .getBlockState (masterPos );
81- }
82-
83- return IWrenchable .super .onSneakWrenched (state , context );
84- }
85-
86-
87- /*@Override
88- public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
89- if (stillValid(pLevel, pPos, pState)) {
90- pLevel.destroyBlock(getMaster(pLevel, pPos, pState), true);
91- }
92- }*/
93-
94- public void playerWillDestroy (Level pLevel , BlockPos pPos , BlockState pState , Player pPlayer ) {
95- if (stillValid (pLevel , pPos , pState )) {
96- BlockPos masterPos = getMaster (pLevel , pPos , pState );
97- pLevel .destroyBlockProgress (masterPos .hashCode (), masterPos , -1 );
98- if (!pLevel .isClientSide () && pPlayer .isCreative ())
99- pLevel .destroyBlock (masterPos , false );
100- }
101- super .playerWillDestroy (pLevel , pPos , pState , pPlayer );
49+ return stillValid (pLevel ,pPos ,pState )?pLevel .getBlockState (getMaster (pLevel ,pPos ,pState )).getBlock ().getCloneItemStack (pLevel , pPos , pState ):ItemStack .EMPTY ;
10250 }
10351
10452 @ Override
10553 public BlockState updateShape (BlockState pState , Direction pFacing , BlockState pFacingState , LevelAccessor pLevel ,
106- BlockPos pCurrentPos , BlockPos pFacingPos ) {
54+ BlockPos pCurrentPos , BlockPos pFacingPos ) {
10755 if (stillValid (pLevel , pCurrentPos , pState )) {
10856 BlockPos masterPos = getMaster (pLevel , pCurrentPos , pState );
57+ Block masterBlock = pLevel .getBlockState (masterPos ).getBlock ();
10958 if (!pLevel .getBlockTicks ()
110- .hasScheduledTick (masterPos , BlockInit . SMALL_ROCKET_ENGINE . get () ))
111- pLevel .scheduleTick (masterPos , BlockInit . SMALL_ROCKET_ENGINE . get () , 1 );
59+ .hasScheduledTick (masterPos , masterBlock ))
60+ pLevel .scheduleTick (masterPos , masterBlock , 1 );
11261 return pState ;
11362 }
11463 if (!(pLevel instanceof Level level ) || level .isClientSide ())
@@ -118,98 +67,4 @@ public BlockState updateShape(BlockState pState, Direction pFacing, BlockState p
11867 level .scheduleTick (pCurrentPos , this , 1 );
11968 return pState ;
12069 }
121-
122- public static BlockPos getMaster (BlockGetter level , BlockPos pos , BlockState state ) {
123- //makeSomething to prevent stackOverFlow -> while
124- ArrayList <BlockPos > posDiscovered = new ArrayList <>();
125- //posDiscovered.add(pos);
126- BlockState targetedState ;
127- BlockPos targetedPos = pos ;
128- //make it like the oxygen ... and make something to prevent a lo
129- while (!posDiscovered .contains (pos ) && posDiscovered .size () < 10 ) {
130- targetedState = level .getBlockState (targetedPos );
131-
132- if (targetedState .is (BlockInit .ENGINE_STRUCTURAL .get ())) {
133- posDiscovered .add (targetedPos );
134- } else if (targetedState .is (BlockInit .ROCKET_ENGINE .get ())) {
135- return targetedPos ;
136- }
137- if (targetedState .hasProperty (FACING )) {
138- Direction direction = level .getBlockState (targetedPos ).getValue (FACING );
139-
140- targetedPos = pos .relative (direction );
141- } else {
142- return targetedPos ;
143- }
144-
145- }
146-
147- return targetedPos ;
148- }
149-
150- public boolean stillValid (BlockGetter level , BlockPos pos , BlockState state ) {
151- if (!state .is (this ))
152- return false ;
153-
154- Direction direction = state .getValue (FACING );
155- BlockPos targetedPos = pos .relative (direction );
156- BlockState targetedState = level .getBlockState (targetedPos );
157- return targetedState .getBlock () instanceof SuperRocketStructuralBlock ||
158- targetedState .getBlock () instanceof RocketEngineBlock ;
159- }
160-
161- @ Override
162- public void tick (BlockState pState , ServerLevel pLevel , BlockPos pPos , RandomSource pRandom ) {
163- if (!stillValid (pLevel , pPos , pState )) {
164- pLevel .setBlockAndUpdate (pPos , Blocks .AIR .defaultBlockState ());
165- }
166- }
167-
168- @ OnlyIn (Dist .CLIENT )
169- public void initializeClient (Consumer <IClientBlockExtensions > consumer ) {
170- consumer .accept (new RenderProperties ());
171- }
172-
173- @ Override
174- public boolean addLandingEffects (BlockState state1 , ServerLevel level , BlockPos pos , BlockState state2 ,
175- LivingEntity entity , int numberOfParticles ) {
176- return true ;
177- }
178-
179- public static class RenderProperties implements IClientBlockExtensions , MultiPosDestructionHandler {
180-
181- @ Override
182- public boolean addDestroyEffects (BlockState state , Level Level , BlockPos pos , ParticleEngine manager ) {
183- return true ;
184- }
185-
186- @ Override
187- public boolean addHitEffects (BlockState state , Level level , HitResult target , ParticleEngine manager ) {
188- if (target instanceof BlockHitResult bhr ) {
189- BlockPos targetPos = bhr .getBlockPos ();
190- @ NonnullType SuperRocketStructuralBlock structuralBlock = BlockInit .ENGINE_STRUCTURAL .get ();
191- if (structuralBlock .stillValid (level , targetPos , state ))
192- manager .crack (SuperRocketStructuralBlock .getMaster (level , targetPos , state ), bhr .getDirection ());
193- return true ;
194- }
195- return IClientBlockExtensions .super .addHitEffects (state , level , target , manager );
196- }
197-
198- @ Override
199- @ Nullable
200- public Set <BlockPos > getExtraPositions (ClientLevel level , BlockPos pos , BlockState blockState , int progress ) {
201- @ NonnullType SuperRocketStructuralBlock structuralBlock = BlockInit .ENGINE_STRUCTURAL .get ();
202- if (!structuralBlock .stillValid (level , pos , blockState ))
203- return null ;
204- HashSet <BlockPos > set = new HashSet <>();
205- set .add (SuperRocketStructuralBlock .getMaster (level , pos , blockState ));
206- return set ;
207- }
208- }
209-
210- @ Override
211- public BlockPos getInformationSource (Level level , BlockPos pos , BlockState state ) {
212- return stillValid (level , pos , state ) ? getMaster (level , pos , state ) : pos ;
213- }
214-
21570}
0 commit comments