5
5
6
6
import net .minecraft .core .BlockPos ;
7
7
import net .minecraft .nbt .CompoundTag ;
8
+ import net .minecraft .network .protocol .Packet ;
9
+ import net .minecraft .network .protocol .game .ClientGamePacketListener ;
8
10
import net .minecraft .network .protocol .game .ClientboundAddEntityPacket ;
9
11
import net .minecraft .network .syncher .EntityDataAccessor ;
10
12
import net .minecraft .network .syncher .EntityDataSerializers ;
11
13
import net .minecraft .network .syncher .SynchedEntityData ;
14
+ import net .minecraft .server .level .ServerEntity ;
12
15
import net .minecraft .world .entity .Entity ;
13
16
import net .minecraft .world .entity .EntityDimensions ;
14
17
import net .minecraft .world .entity .EntityType ;
15
- import net .minecraft .world .entity .MoverType ;
16
18
import net .minecraft .world .entity .Pose ;
17
19
import net .minecraft .world .level .Level ;
18
20
import net .minecraft .world .level .block .Block ;
19
21
import net .minecraft .world .level .block .Blocks ;
20
22
import net .minecraft .world .level .block .state .BlockState ;
21
23
import net .minecraft .world .level .block .state .properties .BlockStateProperties ;
24
+ import net .minecraft .world .phys .AABB ;
22
25
import net .minecraft .world .phys .Vec3 ;
23
26
24
27
import lombok .Getter ;
25
28
import org .jetbrains .annotations .NotNull ;
26
29
30
+ import java .util .List ;
31
+
27
32
@ Getter
28
33
public class AnimateAscendingBlockEntity extends Entity {
29
34
@@ -77,21 +82,26 @@ protected void defineSynchedData(SynchedEntityData.@NotNull Builder builder) {
77
82
builder .define (DATA_START_POS , BlockPos .ZERO ).define (DATA_END_POS , BlockPos .ZERO );
78
83
}
79
84
85
+ @ Override
86
+ public void onSyncedDataUpdated (List <SynchedEntityData .DataValue <?>> dataValues ) {
87
+ super .onSyncedDataUpdated (dataValues );
88
+ }
89
+
80
90
@ Override
81
91
public void tick () {
82
92
if (this .blockState .isAir ()) {
83
93
this .discard ();
84
94
return ;
85
95
}
86
- if (!this .isNoGravity ()) {
87
- this .setDeltaMovement (this .getDeltaMovement ().add (0.0 , 0.4 , 0.0 ));
88
- }
89
- this .move (MoverType .SELF , this .getDeltaMovement ());
96
+ Vec3 mov = this .getDeltaMovement ().add (0.0 , 0.4 , 0.0 );
97
+ this .setDeltaMovement (mov );
98
+ this .setPos (this .getX () + mov .x , this .getY () + mov .y , this .getZ () + mov .z );
90
99
if (this .level ().isClientSide ) return ;
91
100
BlockPos current = this .blockPosition ();
92
101
BlockPos eyePos = BlockPos .containing (this .getEyePosition ());
93
102
BlockPos up = current .above ();
94
- if (!this .level ().getBlockState (up ).isAir ()
103
+ BlockState bs = this .level ().getBlockState (up );
104
+ if (!bs .isAir ()
95
105
|| current .getY () >= getEndPos ().getY ()
96
106
|| eyePos .getY () >= getEndPos ().getY ()) {
97
107
this .discard ();
@@ -123,6 +133,11 @@ public static void animate(
123
133
level .addFreshEntity (entity );
124
134
}
125
135
136
+ @ Override
137
+ @ NotNull public Packet <ClientGamePacketListener > getAddEntityPacket (@ NotNull ServerEntity entity ) {
138
+ return new ClientboundAddEntityPacket (this , entity , Block .getId (this .getBlockState ()));
139
+ }
140
+
126
141
@ Override
127
142
public void recreateFromPacket (@ NotNull ClientboundAddEntityPacket packet ) {
128
143
super .recreateFromPacket (packet );
@@ -135,6 +150,11 @@ public void recreateFromPacket(@NotNull ClientboundAddEntityPacket packet) {
135
150
this .setStartPos (this .blockPosition ());
136
151
}
137
152
153
+ @ Override
154
+ protected @ NotNull AABB makeBoundingBox () {
155
+ return new AABB (this .blockPosition ());
156
+ }
157
+
138
158
@ Override
139
159
public @ NotNull EntityDimensions getDimensions (@ NotNull Pose pose ) {
140
160
return EntityDimensions .fixed (1 , 1 );
0 commit comments