3
3
import io .izzel .arclight .common .bridge .core .entity .EntityBridge ;
4
4
import io .izzel .arclight .common .bridge .core .world .WorldBridge ;
5
5
import io .izzel .arclight .common .mixin .core .world .entity .EntityMixin ;
6
+ import io .izzel .arclight .mixin .Eject ;
6
7
import net .minecraft .core .BlockPos ;
7
8
import net .minecraft .tags .BlockTags ;
8
9
import net .minecraft .util .Mth ;
20
21
import net .minecraft .world .level .block .state .BlockState ;
21
22
import net .minecraft .world .level .gameevent .GameEvent ;
22
23
import net .minecraft .world .phys .Vec3 ;
24
+ import net .minecraftforge .common .extensions .IForgeAbstractMinecart ;
23
25
import org .bukkit .Bukkit ;
24
26
import org .bukkit .Location ;
25
27
import org .bukkit .entity .Vehicle ;
36
38
import org .spongepowered .asm .mixin .injection .Inject ;
37
39
import org .spongepowered .asm .mixin .injection .Redirect ;
38
40
import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
41
+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
39
42
40
43
import java .util .List ;
41
44
42
45
@ Mixin (AbstractMinecart .class )
43
- public abstract class AbstractMinecartMixin extends EntityMixin {
46
+ public abstract class AbstractMinecartMixin extends EntityMixin implements IForgeAbstractMinecart {
44
47
45
48
// @formatter:off
46
49
@ Shadow public abstract void setHurtDir (int rollingDirection );
@@ -60,7 +63,6 @@ public abstract class AbstractMinecartMixin extends EntityMixin {
60
63
@ Shadow public abstract void activateMinecart (int x , int y , int z , boolean receivingPower );
61
64
@ Shadow private boolean flipped ;
62
65
@ Shadow public abstract AbstractMinecart .Type getMinecartType ();
63
- @ Shadow (remap = false ) public abstract boolean canUseRail ();
64
66
@ Shadow private boolean onRails ;
65
67
// @formatter:on
66
68
@@ -130,130 +132,59 @@ public boolean hurt(DamageSource source, float amount) {
130
132
131
133
private transient Location arclight$prevLocation ;
132
134
133
- /**
134
- * @author IzzelAliz
135
- * @reason
136
- */
137
- @ Overwrite
138
- public void tick () {
139
- this .arclight$prevLocation = new Location (null , this .getX (), this .getY (), this .getZ (), this .getYRot (), this .getXRot ());
140
- if (this .getHurtTime () > 0 ) {
141
- this .setHurtTime (this .getHurtTime () - 1 );
135
+ @ Inject (method = "tick" , at = @ At ("HEAD" ))
136
+ private void arclight$storePrevLocation (CallbackInfo ci ) {
137
+ arclight$prevLocation = new Location (null , getX (), getY (), getZ (), getYRot (), getXRot ());
138
+ }
139
+
140
+ @ Redirect (method = "tick" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;handleNetherPortal()V" ))
141
+ private void arclight$skipHandleNetherPortal (AbstractMinecart instance ) {
142
+ // CraftBukkit - handled in postTick
143
+ }
144
+
145
+ @ Inject (method = "tick" , at = @ At (value = "INVOKE" , shift = At .Shift .AFTER , target = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;setRot(FF)V" ))
146
+ private void arclight$fireVehicleEvents (CallbackInfo ci ) {
147
+ org .bukkit .World bworld = ((WorldBridge ) this .level ()).bridge$getWorld ();
148
+ Location from = this .arclight$prevLocation ;
149
+ this .arclight$prevLocation = null ;
150
+ from .setWorld (bworld );
151
+ Location to = new Location (bworld , this .getX (), this .getY (), this .getZ (), this .getYRot (), this .getXRot ());
152
+ Vehicle vehicle = (Vehicle ) this .getBukkitEntity ();
153
+ Bukkit .getPluginManager ().callEvent (new VehicleUpdateEvent (vehicle ));
154
+ if (!from .equals (to )) {
155
+ Bukkit .getPluginManager ().callEvent (new VehicleMoveEvent (vehicle , from , to ));
142
156
}
143
- if (this .getDamage () > 0.0f ) {
144
- this .setDamage (this .getDamage () - 1.0f );
157
+ }
158
+
159
+ @ Redirect (method = "tick" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/world/entity/Entity;startRiding(Lnet/minecraft/world/entity/Entity;)Z" ))
160
+ private boolean arclight$fireCollisionEventsRiding (Entity that , Entity self ) {
161
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent ((Vehicle ) this .getBukkitEntity (), ((EntityBridge ) that ).bridge$getBukkitEntity ());
162
+ Bukkit .getPluginManager ().callEvent (collisionEvent );
163
+
164
+ if (collisionEvent .isCancelled ()) {
165
+ return false ;
145
166
}
146
- this .checkBelowWorld ();
147
- if (this .level ().isClientSide ) {
148
- if (this .lSteps > 0 ) {
149
- double d0 = this .getX () + (this .lx - this .getX ()) / this .lSteps ;
150
- double d2 = this .getY () + (this .ly - this .getY ()) / this .lSteps ;
151
- double d3 = this .getZ () + (this .lz - this .getZ ()) / this .lSteps ;
152
- double d4 = Mth .wrapDegrees (this .lyr - this .getYRot ());
153
- this .setYRot (this .getYRot () + (float ) (d4 / this .lSteps ));
154
- this .setXRot (this .getXRot () + (float ) ((this .lxr - this .getXRot ()) / this .lSteps ));
155
- --this .lSteps ;
156
- this .setPos (d0 , d2 , d3 );
157
- this .setRot (this .getYRot (), this .getXRot ());
158
- } else {
159
- this .setPos (this .getX (), this .getY (), this .getZ ());
160
- this .setRot (this .getYRot (), this .getXRot ());
161
- }
162
- } else {
163
- /*
164
- this.prevPosX = this.getPosX();
165
- this.prevPosY = this.getPosY();
166
- this.prevPosZ = this.getPosZ();
167
- */
168
- if (!this .isNoGravity ()) {
169
- this .setDeltaMovement (this .getDeltaMovement ().add (0.0 , -0.04 , 0.0 ));
170
- }
171
- int i = Mth .floor (this .getX ());
172
- int j = Mth .floor (this .getY ());
173
- int k = Mth .floor (this .getZ ());
174
- if (this .level ().getBlockState (new BlockPos (i , j - 1 , k )).is (BlockTags .RAILS )) {
175
- --j ;
176
- }
177
- BlockPos blockposition = new BlockPos (i , j , k );
178
- BlockState blockstate = this .level ().getBlockState (blockposition );
179
- this .onRails = BaseRailBlock .isRail (blockstate );
180
- if (this .canUseRail () && this .onRails ) {
181
- this .moveAlongTrack (blockposition , blockstate );
182
- if (blockstate .getBlock () instanceof PoweredRailBlock && ((PoweredRailBlock ) blockstate .getBlock ()).isActivatorRail ()) {
183
- this .activateMinecart (i , j , k , blockstate .getValue (PoweredRailBlock .POWERED ));
184
- }
185
- } else {
186
- this .comeOffTrack ();
187
- }
188
- this .checkInsideBlocks ();
189
- this .setXRot (0.f );
190
- double d5 = this .xo - this .getX ();
191
- double d6 = this .zo - this .getZ ();
192
- if (d5 * d5 + d6 * d6 > 0.001 ) {
193
- this .setYRot ((float ) (Mth .atan2 (d6 , d5 ) * 180.0 / 3.141592653589793 ));
194
- if (this .flipped ) {
195
- this .setYRot (this .getYRot () + 180.0f );
196
- }
197
- }
198
- double d7 = Mth .wrapDegrees (this .getYRot () - this .yRotO );
199
- if (d7 < -170.0 || d7 >= 170.0 ) {
200
- this .setYRot (this .getYRot () + 180.0f );
201
- this .flipped = !this .flipped ;
202
- }
203
- this .setRot (this .getYRot (), this .getXRot ());
204
- org .bukkit .World bworld = ((WorldBridge ) this .level ()).bridge$getWorld ();
205
- Location from = this .arclight$prevLocation ;
206
- this .arclight$prevLocation = null ;
207
- from .setWorld (bworld );
208
- Location to = new Location (bworld , this .getX (), this .getY (), this .getZ (), this .getYRot (), this .getXRot ());
209
- Vehicle vehicle = (Vehicle ) this .getBukkitEntity ();
210
- Bukkit .getPluginManager ().callEvent (new VehicleUpdateEvent (vehicle ));
211
- if (!from .equals (to )) {
212
- Bukkit .getPluginManager ().callEvent (new VehicleMoveEvent (vehicle , from , to ));
213
- }
214
- if (this .getMinecartType () == AbstractMinecart .Type .RIDEABLE && this .getDeltaMovement ().horizontalDistanceSqr () > 0.01 ) {
215
- List <Entity > list = this .level ().getEntities ((AbstractMinecart ) (Object ) this , this .getBoundingBox ().inflate (0.20000000298023224 , 0.0 , 0.20000000298023224 ), EntitySelector .pushableBy ((AbstractMinecart ) (Object ) this ));
216
- if (!list .isEmpty ()) {
217
- for (Entity entity : list ) {
218
- if (!(entity instanceof Player ) && !(entity instanceof IronGolem ) && !(entity instanceof AbstractMinecart ) && !this .isVehicle () && !entity .isPassenger ()) {
219
- VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent (vehicle , ((EntityBridge ) entity ).bridge$getBukkitEntity ());
220
- Bukkit .getPluginManager ().callEvent (collisionEvent );
221
- if (!collisionEvent .isCancelled ()) {
222
- entity .startRiding ((AbstractMinecart ) (Object ) this );
223
- }
224
- } else {
225
- if (!isPassengerOfSameVehicle (entity )) {
226
- VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent (vehicle , ((EntityBridge ) entity ).bridge$getBukkitEntity ());
227
- Bukkit .getPluginManager ().callEvent (collisionEvent );
228
- if (collisionEvent .isCancelled ()) {
229
- continue ;
230
- }
231
- }
232
- entity .push ((AbstractMinecart ) (Object ) this );
233
- }
234
- }
235
- }
236
- } else {
237
- for (Entity entity2 : this .level ().getEntities ((AbstractMinecart ) (Object ) this , this .getBoundingBox ().inflate (0.20000000298023224 , 0.0 , 0.20000000298023224 ))) {
238
- if (!this .hasPassenger (entity2 ) && entity2 .isPushable () && entity2 instanceof AbstractMinecart ) {
239
- VehicleEntityCollisionEvent collisionEvent2 = new VehicleEntityCollisionEvent (vehicle , ((EntityBridge ) entity2 ).bridge$getBukkitEntity ());
240
- Bukkit .getPluginManager ().callEvent (collisionEvent2 );
241
- if (collisionEvent2 .isCancelled ()) {
242
- continue ;
243
- }
244
- entity2 .push ((AbstractMinecart ) (Object ) this );
245
- }
246
- }
247
- }
248
- this .updateInWaterStateAndDoFluidPushing ();
249
- if (this .isInLava ()) {
250
- this .lavaHurt ();
251
- this .fallDistance *= 0.5F ;
252
- }
253
- this .firstTick = false ;
167
+ return that .startRiding ((Entity ) (Object ) this );
168
+ }
169
+
170
+ @ Redirect (method = "tick" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/world/entity/Entity;push(Lnet/minecraft/world/entity/Entity;)V" ))
171
+ private void arclight$fireCollisionEventsPush (Entity that , Entity self ) {
172
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent ((Vehicle ) this .getBukkitEntity (), ((EntityBridge ) that ).bridge$getBukkitEntity ());
173
+ Bukkit .getPluginManager ().callEvent (collisionEvent );
174
+
175
+ if (collisionEvent .isCancelled ()) {
176
+ return ;
254
177
}
178
+ that .push ((Entity ) (Object ) this );
255
179
}
256
180
181
+ /*
182
+ * Don't use Overwrite to preserve LVT for injectors.
183
+ * See #1677 and Spelunkery AbstractMinecartMixin#rattleMinecart
184
+ */
185
+ //@Overwrite
186
+ //public void tick()
187
+
257
188
/**
258
189
* @author IzzelAliz
259
190
* @reason
0 commit comments