77import net .minecraft .nbt .CompoundTag ;
88import net .minecraft .network .protocol .Packet ;
99import net .minecraft .network .protocol .game .ClientGamePacketListener ;
10+ import net .minecraft .server .level .ServerLevel ;
1011import net .minecraft .util .Mth ;
1112import net .minecraft .world .InteractionResult ;
1213import net .minecraft .world .entity .Entity ;
1516import net .minecraft .world .entity .player .Player ;
1617import net .minecraft .world .entity .vehicle .DismountHelper ;
1718import net .minecraft .world .level .Level ;
18- import net .minecraft .world .level .block .state .BlockState ;
1919import net .minecraft .world .phys .AABB ;
2020import net .minecraft .world .phys .Vec3 ;
2121import org .jetbrains .annotations .NotNull ;
@@ -35,28 +35,48 @@ private SittableEntity(Level level, BlockPos pos, double offset, float yaw) {
3535 this .setRot (yaw , 0F );
3636 }
3737
38+ private int removalDelay = 5 ; // Wait 5 ticks before removal
39+
3840 @ Override
39- public void tick ()
40- {
41+ public void tick () {
4142 super .tick ();
42- if (!this .level ().isClientSide )
43- {
44- if (this .getPassengers ().isEmpty () || this .level ().isEmptyBlock (this .blockPosition ()))
45- {
43+ if (!this .level ().isClientSide ) {
44+ if (this .getPassengers ().isEmpty ()) {
45+ if (removalDelay > 0 ) {
46+ removalDelay --; // Countdown before deletion
47+ } else {
48+ this .remove (RemovalReason .DISCARDED );
49+ }
50+ } else {
51+ removalDelay = 5 ; // Reset countdown if occupied
52+ }
53+
54+ if (this .level ().isEmptyBlock (this .blockPosition ())) {
4655 this .remove (RemovalReason .DISCARDED );
4756 this .level ().updateNeighbourForOutputSignal (blockPosition (), this .level ().getBlockState (blockPosition ()).getBlock ());
4857 }
4958 }
5059 }
5160
61+ // @Override
62+ // public void tick() {
63+ // super.tick();
64+ // if(!this.level().isClientSide) {
65+ // if(this.getPassengers().isEmpty() || this.level().isEmptyBlock(this.blockPosition())) {
66+ // this.remove(RemovalReason.DISCARDED);
67+ // this.level().updateNeighbourForOutputSignal(blockPosition(), this.level().getBlockState(blockPosition()).getBlock());
68+ // }
69+ // }
70+ // }
71+
5272 @ Override
5373 protected void defineSynchedData () {}
5474
5575 @ Override
56- protected void readAdditionalSaveData (CompoundTag compound ) {}
76+ protected void readAdditionalSaveData (@ NotNull CompoundTag compound ) {}
5777
5878 @ Override
59- protected void addAdditionalSaveData (CompoundTag compound ) {}
79+ protected void addAdditionalSaveData (@ NotNull CompoundTag compound ) {}
6080
6181 @ Override
6282 public double getPassengersRidingOffset ()
@@ -65,22 +85,19 @@ public double getPassengersRidingOffset()
6585 }
6686
6787 @ Override
68- protected boolean canRide (Entity entity )
88+ protected boolean canRide (@ NotNull Entity entity )
6989 {
7090 return true ;
7191 }
7292
7393 // Call to mount the player to a newly created SittableEntity
74- public static InteractionResult mount (Level level , BlockPos pos , double yOffset , Player player , float direction )
75- {
76- if (!level .isClientSide ())
77- {
94+ public static InteractionResult mount (Level level , BlockPos pos , double yOffset , Player player , float direction ) {
95+ if (level instanceof ServerLevel serverLevel ) {
7896 List <SittableEntity > seats = level .getEntitiesOfClass (SittableEntity .class , new AABB (pos .getX (), pos .getY (), pos .getZ (), pos .getX () + 1.0 , pos .getY () + 1.0 , pos .getZ () + 1.0 ));
79- if (seats .isEmpty ())
80- {
97+ if (seats .isEmpty ()) {
8198 SittableEntity seat = new SittableEntity (level , pos , yOffset , direction );
8299 level .addFreshEntity (seat );
83- player .startRiding (seat , true );
100+ player .startRiding (seat );
84101 }
85102 }
86103 return InteractionResult .SUCCESS ;
@@ -94,43 +111,38 @@ public static InteractionResult mount(Level level, BlockPos pos, double yOffset,
94111
95112 // Tick the key and check if the block is removed or if there are no more passengers
96113 @ Override
97- public Vec3 getDismountLocationForPassenger (LivingEntity entity )
98- {
114+ public @ NotNull Vec3 getDismountLocationForPassenger (@ NotNull LivingEntity entity ) {
99115 Direction original = this .getDirection ();
100116 Direction [] offsets = {original , original .getClockWise (), original .getCounterClockWise (), original .getOpposite ()};
101- for (Direction dir : offsets )
102- {
117+ for (Direction dir : offsets ) {
103118 Vec3 safeVec = DismountHelper .findSafeDismountLocation (entity .getType (), this .level (), this .blockPosition ().relative (dir ), false );
104119 if (safeVec != null )
105120 {
106121 return safeVec .add (0 , 0.25 , 0 );
107122 }
108123 }
124+
109125 return super .getDismountLocationForPassenger (entity );
110126 }
111127
112128 @ Override
113- protected void addPassenger (Entity entity )
114- {
129+ protected void addPassenger (@ NotNull Entity entity ) {
115130 super .addPassenger (entity );
116131 entity .setYRot (this .getYRot ());
117132 }
118133
119134 @ Override
120- public void positionRider (Entity entity , Entity .MoveFunction function )
121- {
135+ public void positionRider (@ NotNull Entity entity , Entity .@ NotNull MoveFunction function ) {
122136 super .positionRider (entity , function );
123137 this .clampYaw (entity );
124138 }
125139
126140 @ Override
127- public void onPassengerTurned (Entity entity )
128- {
141+ public void onPassengerTurned (@ NotNull Entity entity ) {
129142 this .clampYaw (entity );
130143 }
131144
132- private void clampYaw (Entity passenger )
133- {
145+ private void clampYaw (Entity passenger ) {
134146 passenger .setYBodyRot (this .getYRot ());
135147 float wrappedYaw = Mth .wrapDegrees (passenger .getYRot () - this .getYRot ());
136148 float clampedYaw = Mth .clamp (wrappedYaw , -120.0F , 120.0F );
0 commit comments