5
5
import net .minecraft .block .entity .BlockEntity ;
6
6
import net .minecraft .block .entity .BlockEntityTicker ;
7
7
import net .minecraft .block .entity .BlockEntityType ;
8
- import net .minecraft .block .entity .DispenserBlockEntity ;
9
- import net .minecraft .entity .player .PlayerEntity ;
10
8
import net .minecraft .item .ItemPlacementContext ;
9
+ import net .minecraft .particle .ParticleTypes ;
10
+ import net .minecraft .sound .SoundCategory ;
11
+ import net .minecraft .sound .SoundEvents ;
11
12
import net .minecraft .state .StateManager ;
12
- import net .minecraft .text . Text ;
13
- import net .minecraft .util . ActionResult ;
14
- import net .minecraft .util .Hand ;
15
- import net .minecraft .util .hit . BlockHitResult ;
13
+ import net .minecraft .state . property . BooleanProperty ;
14
+ import net .minecraft .state . property . Properties ;
15
+ import net .minecraft .util .BlockMirror ;
16
+ import net .minecraft .util .BlockRotation ;
16
17
import net .minecraft .util .math .*;
17
- import net .minecraft .util .shape .VoxelShape ;
18
- import net .minecraft .world .BlockStateRaycastContext ;
19
- import net .minecraft .world .BlockView ;
20
- import net .minecraft .world .RaycastContext ;
21
- import net .minecraft .world .World ;
18
+ import net .minecraft .world .*;
22
19
import org .jetbrains .annotations .Nullable ;
23
- import org .joml .Vector3d ;
24
- import org .valkyrienskies .core .api .ships .LoadedServerShip ;
25
- import org .valkyrienskies .core .api .world .ServerShipWorld ;
26
20
import org .valkyrienskies .mod .common .VSGameUtilsKt ;
27
- import org .valkyrienskies .mod .common .ValkyrienSkiesMod ;
28
- import org .valkyrienskies .mod .common .util .DimensionIdProvider ;
29
- import org .valkyrienskies .mod .common .world .RaycastUtilsKt ;
30
21
31
22
public class CannonPrimingBlock extends BlockWithEntity {
32
23
public CannonPrimingBlock (Settings settings ) {
33
24
super (settings );
34
25
}
26
+ public static final BooleanProperty DISARMED = Properties .DISARMED ;
35
27
36
- @ Override
37
- public VoxelShape getOutlineShape (BlockState state , BlockView world , BlockPos pos , ShapeContext context ) {
38
- return Block .createCuboidShape (0 ,0 ,0 ,2 ,2 ,2 );
39
- }
40
28
41
29
@ Override
42
30
public BlockRenderType getRenderType (BlockState state ) {
@@ -45,40 +33,37 @@ public BlockRenderType getRenderType(BlockState state) {
45
33
46
34
@ Override
47
35
protected void appendProperties (StateManager .Builder <Block , BlockState > builder ) {
48
- builder .add (RedstoneLampBlock .LIT );
36
+ builder .add (RedstoneLampBlock .LIT ). add ( Properties . FACING ). add ( DISARMED ) ;
49
37
}
50
38
51
39
@ Nullable
52
40
@ Override
53
41
public BlockState getPlacementState (ItemPlacementContext ctx ) {
54
- return getDefaultState ().with (RedstoneLampBlock .LIT ,false );
55
- }
42
+ BlockPos pos = ctx .getBlockPos ();
43
+ World world = ctx .getWorld ();
44
+ Direction facing ;
56
45
57
- /**
58
- *
59
- * @param origin a point to "look" from
60
- * @param target a point to "look" at
61
- * @return the vector that can be used to travel between these points
62
- */
63
- public Vec3d pointLine (Vec3d origin , Vec3d target )
64
- {
65
- double d = target .x - origin .x ;
66
- double e = target .y - origin .y ;
67
- double f = target .z - origin .z ;
68
- double g = Math .sqrt (d * d + f * f );
69
- float pitch = (MathHelper .wrapDegrees ((float )(-(MathHelper .atan2 (e , g ) * 57.2957763671875 ))));
70
- float yaw = MathHelper .wrapDegrees ((float )(MathHelper .atan2 (f , d ) * 57.2957763671875 ) - 90.0F );
71
- return getRotationVector (pitch ,yaw );
72
- }
46
+ if (world .getBlockState (pos .north ()).isOf (Blocks .DISPENSER )) {
47
+ facing = Direction .NORTH ;
48
+ } else if (world .getBlockState (pos .east ()).isOf (Blocks .DISPENSER )) {
49
+ facing = Direction .EAST ;
50
+ } else if (world .getBlockState (pos .south ()).isOf (Blocks .DISPENSER )) {
51
+ facing = Direction .SOUTH ;
52
+ } else if (world .getBlockState (pos .west ()).isOf (Blocks .DISPENSER )) {
53
+ facing = Direction .WEST ;
54
+ } else if (world .getBlockState (pos .up ()).isOf (Blocks .DISPENSER )) {
55
+ facing = Direction .UP ;
56
+ } else if (world .getBlockState (pos .down ()).isOf (Blocks .DISPENSER )) {
57
+ facing = Direction .DOWN ;
58
+ } else {
59
+ facing = ctx .getPlayerLookDirection ();
73
60
74
- protected final Vec3d getRotationVector (float pitch , float yaw ) {
75
- float f = pitch * 0.017453292F ;
76
- float g = -yaw * 0.017453292F ;
77
- float h = MathHelper .cos (g );
78
- float i = MathHelper .sin (g );
79
- float j = MathHelper .cos (f );
80
- float k = MathHelper .sin (f );
81
- return new Vec3d ((double )(i * j ), (double )(-k ), (double )(h * j ));
61
+ }
62
+
63
+ if (world .getBlockState (pos .add (facing .getVector ())).isOf (Blocks .DISPENSER ) && world .getBlockState (pos .add (facing .getVector ())).get (Properties .FACING ) == facing ) {
64
+ world .setBlockState (pos .add (facing .getVector ()), Pirates .DISPENSER_CANNON_BLOCK .getDefaultState ().with (Properties .FACING , facing ), 3 );
65
+ }
66
+ return getDefaultState ().with (RedstoneLampBlock .LIT ,false ).with (Properties .FACING , facing ).with (DISARMED , true );
82
67
}
83
68
84
69
@ Nullable
@@ -91,20 +76,48 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
91
76
@ Nullable
92
77
@ Override
93
78
public <T extends BlockEntity > BlockEntityTicker <T > getTicker (World world , BlockState state , BlockEntityType <T > type ) {
94
- return checkType (type , Pirates .CANNON_PRIMING_BLOCK_ENTITY , CannonPrimingBlockEntity :: tick );
79
+ return checkType (type , Pirates .CANNON_PRIMING_BLOCK_ENTITY , ( world1 , pos , state1 , be ) -> be . tick ( world1 , pos , state1 , be ) );
95
80
}
96
81
82
+ // @Override
83
+ // public boolean emitsRedstonePower(BlockState state) {
84
+ // return state.get(RedstoneLampBlock.LIT);
85
+ // }
86
+ //
87
+ // @Override
88
+ // public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
89
+ // if(state.get(RedstoneLampBlock.LIT))
90
+ // {
91
+ // return 15;
92
+ // }
93
+ // return 0;
94
+ // }
95
+
97
96
@ Override
98
- public boolean emitsRedstonePower (BlockState state ) {
99
- return state .get (RedstoneLampBlock .LIT );
97
+ public BlockState getStateForNeighborUpdate (BlockState state , Direction direction , BlockState neighborState , WorldAccess world , BlockPos pos , BlockPos neighborPos ) {
98
+
99
+ if (world .getBlockState (pos .add (state .get (Properties .FACING ).getVector ())).isOf (Blocks .DISPENSER ) && world .getBlockState (pos .add (state .get (Properties .FACING ).getVector ())).get (Properties .FACING ) == state .get (Properties .FACING )) {
100
+ world .setBlockState (pos .add (state .get (Properties .FACING ).getVector ()), Pirates .DISPENSER_CANNON_BLOCK .getDefaultState ().with (Properties .FACING , state .get (Properties .FACING )), 3 );
101
+ }
102
+
103
+ if (world .isReceivingRedstonePower (pos ) && !world .isClient ()) {((CannonPrimingBlockEntity )world .getBlockEntity (pos )).fire ((World ) world , pos , state , 19 );}
104
+ return super .getStateForNeighborUpdate (state , direction , neighborState , world , pos , neighborPos );
100
105
}
101
106
102
- @ Override
103
- public int getWeakRedstonePower (BlockState state , BlockView world , BlockPos pos , Direction direction ) {
104
- if (state .get (RedstoneLampBlock .LIT ))
105
- {
106
- return 15 ;
107
- }
108
- return 0 ;
107
+ public BlockState rotate (BlockState state , BlockRotation rotation ) {
108
+ return (BlockState )state .with (Properties .FACING , rotation .rotate ((Direction )state .get (Properties .FACING )));
109
+ }
110
+
111
+ public BlockState mirror (BlockState state , BlockMirror mirror ) {
112
+ return state .rotate (mirror .getRotation ((Direction )state .get (Properties .FACING )));
113
+ }
114
+
115
+ public static void disarm (World world , BlockPos pos ) {
116
+ if (world .isClient ()) return ;
117
+ BlockState blockState = world .getBlockState (pos );
118
+ if (!blockState .get (DISARMED )) {
119
+ world .setBlockState (pos , blockState .with (DISARMED , true ));
120
+ world .playSound (null , pos , SoundEvents .BLOCK_REDSTONE_TORCH_BURNOUT , SoundCategory .BLOCKS , 0.5f , 1.5f );
121
+ }
109
122
}
110
123
}
0 commit comments