11package generations .gg .generations .core .generationscore .world .level .block .shrines ;
22
3+ import com .google .common .collect .ImmutableMap ;
34import generations .gg .generations .core .generationscore .config .LegendKeys ;
45import generations .gg .generations .core .generationscore .config .SpeciesKey ;
56import generations .gg .generations .core .generationscore .world .entity .block .PokemonUtil ;
67import generations .gg .generations .core .generationscore .world .level .block .GenerationsShrines ;
8+ import generations .gg .generations .core .generationscore .world .level .block .GenerationsVoxelShapes ;
79import generations .gg .generations .core .generationscore .world .level .block .entities .GenerationsBlockEntities ;
810import generations .gg .generations .core .generationscore .world .level .block .entities .shrines .LunarShrineBlockEntity ;
911import generations .gg .generations .core .generationscore .world .level .block .entities .shrines .ShrineBlockEntity ;
1012import net .minecraft .core .BlockPos ;
13+ import net .minecraft .resources .ResourceLocation ;
14+ import net .minecraft .server .level .ServerLevel ;
15+ import net .minecraft .util .RandomSource ;
1116import net .minecraft .world .InteractionHand ;
1217import net .minecraft .world .InteractionResult ;
1318import net .minecraft .world .entity .player .Player ;
19+ import net .minecraft .world .level .BlockGetter ;
1420import net .minecraft .world .level .Level ;
21+ import net .minecraft .world .level .block .Block ;
1522import net .minecraft .world .level .block .Blocks ;
23+ import net .minecraft .world .level .block .ConduitBlock ;
24+ import net .minecraft .world .level .block .entity .BlockEntity ;
25+ import net .minecraft .world .level .block .entity .BlockEntityTicker ;
26+ import net .minecraft .world .level .block .entity .BlockEntityType ;
27+ import net .minecraft .world .level .block .entity .ConduitBlockEntity ;
1628import net .minecraft .world .level .block .state .BlockBehaviour ;
1729import net .minecraft .world .level .block .state .BlockState ;
30+ import net .minecraft .world .level .block .state .StateDefinition ;
31+ import net .minecraft .world .level .block .state .properties .BlockStateProperties ;
32+ import net .minecraft .world .level .block .state .properties .BooleanProperty ;
33+ import net .minecraft .world .level .block .state .properties .IntegerProperty ;
34+ import net .minecraft .world .level .block .state .properties .Property ;
1835import net .minecraft .world .phys .BlockHitResult ;
36+ import net .minecraft .world .phys .shapes .CollisionContext ;
37+ import net .minecraft .world .phys .shapes .Shapes ;
38+ import net .minecraft .world .phys .shapes .VoxelShape ;
1939import org .jetbrains .annotations .NotNull ;
40+ import org .jetbrains .annotations .Nullable ;
41+
42+ import java .util .function .Function ;
2043
2144public class LunarShrineBlock extends ShrineBlock <LunarShrineBlockEntity > {
45+ private static final GenerationsVoxelShapes .DirectionalShapes LIGHT = GenerationsVoxelShapes .generateDirectionVoxelShape (Shapes .box (0 , 0 , 0.1875 , 1 , 0.4375 , 0.8125 ));
46+ private static final GenerationsVoxelShapes .DirectionalShapes DARK = GenerationsVoxelShapes .generateDirectionVoxelShape (Shapes .box (0 , 0 , 0 , 1 , 0.5625 , 1 ));
47+
48+ public static final BooleanProperty IS_LIGHT = BooleanProperty .create ("is_light" );
2249
2350 public LunarShrineBlock (BlockBehaviour .Properties properties ) {
2451 super (properties , GenerationsBlockEntities .LUNAR_SHRINE , null );
2552 }
2653
54+ @ Override
55+ protected void createBlockStateDefinition (@ NotNull StateDefinition .Builder <Block , BlockState > builder ) {
56+ super .createBlockStateDefinition (builder );
57+ builder .add (IS_LIGHT );
58+ }
59+
60+ @ Override
61+ protected BlockState createDefaultState () {
62+ return super .createDefaultState ().setValue (IS_LIGHT , false );
63+ }
64+
65+ @ Nullable
66+ @ Override
67+ public <T extends BlockEntity > BlockEntityTicker <T > getTicker (Level level , BlockState state , BlockEntityType <T > blockEntityType ) {
68+ return ConduitBlock .createTickerHelper (blockEntityType , GenerationsBlockEntities .LUNAR_SHRINE .get (), level .isClientSide ? (level1 , blockPos , blockState , blockEntity ) -> {} : (level12 , pos , blockState , blockEntity ) -> {
69+ var state1 = level12 .getBlockState (pos ).setValue (IS_LIGHT , level12 .getMaxLocalRawBrightness (pos ) >= 10 );
70+ level12 .setBlockAndUpdate (pos , state1 );
71+ });
72+ }
73+
74+ @ Override
75+ public void tick (BlockState state , ServerLevel level , BlockPos pos , RandomSource random ) {
76+ state = state .setValue (IS_LIGHT , level .getMaxLocalRawBrightness (pos ) >= 10 );
77+ level .setBlock (pos , state , 4 );
78+ }
79+
80+ @ Override
81+ public BlockState setSize (BlockState state , int x , int y , int z ) {
82+ return super .setSize (state , x , y , z );
83+ }
84+
2785 @ Override
2886 public @ NotNull InteractionResult use (@ NotNull BlockState state , Level level , @ NotNull BlockPos pos , @ NotNull Player player , @ NotNull InteractionHand hand , @ NotNull BlockHitResult hit ) {
2987 if (!level .isClientSide ()) {
30- var key = getSpecies (level , pos );
88+ var key = getSpecies (state );
3189
3290 var block = (key == LegendKeys .CRESSELIA ? GenerationsShrines .LIGHT_CRYSTAL : GenerationsShrines .DARK_CRYSTAL ).get ();
3391
34- var list = RegiShrineBlock .searchForBlock (level , pos , 15 , 5 , (level1 , blockPos ) -> level1 .getBlockState (pos ).is (block ));
92+ var list = RegiShrineBlock .searchForBlock (level , pos , 15 , 5 , (level1 , blockPos ) -> level1 .getBlockState (blockPos ).is (block ));
3593
3694 if (!list .isEmpty () && level .getBlockEntity (pos ) instanceof ShrineBlockEntity shrine && !shrine .isActive ()) {
3795 if (list .size () == 5 ) {
3896 shrine .toggleActive ();
39- list .forEach (a -> level .setBlockAndUpdate (a , Blocks . AIR . defaultBlockState () ));
97+ list .forEach (a -> level .destroyBlock (a , false ));
4098 player .getItemInHand (hand ).shrink (1 );
4199 PokemonUtil .spawn (key .createProperties (70 ), level , shrine .getBlockPos ());
42100 shrine .toggleActive ();
@@ -49,7 +107,12 @@ public LunarShrineBlock(BlockBehaviour.Properties properties) {
49107 return super .use (state , level , pos , player , hand , hit );
50108 }
51109
52- public SpeciesKey getSpecies (Level level , BlockPos pos ) {
53- return level .getLightEmission (pos ) > 10 ? LegendKeys .CRESSELIA : LegendKeys .DARKRAI ;
110+ public SpeciesKey getSpecies (BlockState state ) {
111+ return state .getValue (IS_LIGHT ) ? LegendKeys .CRESSELIA : LegendKeys .DARKRAI ;
112+ }
113+
114+ @ Override
115+ public VoxelShape getShape (BlockState state , BlockGetter level , BlockPos pos , CollisionContext context ) {
116+ return (state .getValue (IS_LIGHT ) ? LIGHT : DARK ).getShape (state );
54117 }
55118}
0 commit comments