Expose pre-collision moving velocity to VehicleBlockCollisionEvent

This commit is contained in:
SoSeDiK 2022-10-11 23:30:32 +03:00
parent 602506fa98
commit 735cda1084

View file

@ -61,7 +61,7 @@
+// CraftBukkit end
public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder {
+
+ // CraftBukkit start
+ private static final int CURRENT_LEVEL = 2;
+ public boolean preserveMotion = true; // Paper - Fix Entity Teleportation and cancel velocity if teleported; keep initial motion on first setPositionRotation
@ -93,7 +93,7 @@
+ public net.minecraft.world.level.levelgen.PositionalRandomFactory forkPositional() {
+ return new net.minecraft.world.level.levelgen.LegacyRandomSource.LegacyPositionalRandomFactory(this.nextLong());
+ }
+
+ // these below are added to fix reobf issues that I don't wanna deal with right now
+ @Override
+ public int next(int bits) {
@ -538,7 +538,15 @@
}
public boolean isFree(double offsetX, double offsetY, double offsetZ) {
@@ -750,6 +1055,28 @@
@@ -672,6 +977,7 @@
}
public void move(MoverType type, Vec3 movement) {
+ final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
if (this.noPhysics) {
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
@@ -750,6 +1056,28 @@
}
}
@ -558,7 +566,7 @@
+ }
+
+ if (!bl.getType().isAir()) {
+ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
+ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl, org.bukkit.craftbukkit.util.CraftVector.toBukkit(originalMovement)); // Paper - Expose pre-collision velocity
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+ }
+ }
@ -567,7 +575,7 @@
if (!this.level().isClientSide() || this.isControlledByLocalInstance()) {
Entity.MovementEmission entity_movementemission = this.getMovementEmission();
@@ -1131,8 +1458,22 @@
@@ -1131,8 +1459,22 @@
protected SoundEvent getSwimHighSpeedSplashSound() {
return SoundEvents.GENERIC_SPLASH;
@ -576,12 +584,12 @@
+ // CraftBukkit start - Add delegate methods
+ public SoundEvent getSwimSound0() {
+ return this.getSwimSound();
}
+ public SoundEvent getSwimSplashSound0() {
+ return this.getSwimSplashSound();
+ }
+
+ public SoundEvent getSwimSplashSound0() {
+ return this.getSwimSplashSound();
}
+ public SoundEvent getSwimHighSpeedSplashSound0() {
+ return this.getSwimHighSpeedSplashSound();
+ }
@ -590,7 +598,7 @@
public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) {
this.movementThisTick.add(new Entity.Movement(oldPos, newPos));
}
@@ -1599,6 +1940,7 @@
@@ -1599,6 +1941,7 @@
this.setXRot(Mth.clamp(pitch, -90.0F, 90.0F) % 360.0F);
this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
@ -598,7 +606,7 @@
}
public void absMoveTo(double x, double y, double z) {
@@ -1609,6 +1951,7 @@
@@ -1609,6 +1952,7 @@
this.yo = y;
this.zo = d4;
this.setPos(d3, y, d4);
@ -606,7 +614,7 @@
}
public void moveTo(Vec3 pos) {
@@ -1628,11 +1971,19 @@
@@ -1628,11 +1972,19 @@
}
public void moveTo(double x, double y, double z, float yaw, float pitch) {
@ -626,7 +634,7 @@
}
public final void setOldPosAndRot() {
@@ -1701,6 +2052,7 @@
@@ -1701,6 +2053,7 @@
public void push(Entity entity) {
if (!this.isPassengerOfSameVehicle(entity)) {
if (!entity.noPhysics && !this.noPhysics) {
@ -634,7 +642,7 @@
double d0 = entity.getX() - this.getX();
double d1 = entity.getZ() - this.getZ();
double d2 = Mth.absMax(d0, d1);
@@ -1737,7 +2089,21 @@
@@ -1737,7 +2090,21 @@
}
public void push(double deltaX, double deltaY, double deltaZ) {
@ -657,7 +665,7 @@
this.hasImpulse = true;
}
@@ -1858,9 +2224,21 @@
@@ -1858,9 +2225,21 @@
}
public boolean isPushable() {
@ -679,7 +687,7 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled instanceof ServerPlayer) {
CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger((ServerPlayer) entityKilled, this, damageSource);
@@ -1889,74 +2267,133 @@
@@ -1889,74 +2268,133 @@
}
public boolean saveAsPassenger(CompoundTag nbt) {
@ -836,7 +844,7 @@
}
ListTag nbttaglist;
@@ -1972,10 +2409,10 @@
@@ -1972,10 +2410,10 @@
nbttaglist.add(StringTag.valueOf(s));
}
@ -849,7 +857,7 @@
if (this.isVehicle()) {
nbttaglist = new ListTag();
iterator = this.getPassengers().iterator();
@@ -1984,17 +2421,44 @@
@@ -1984,17 +2422,44 @@
Entity entity = (Entity) iterator.next();
CompoundTag nbttagcompound1 = new CompoundTag();
@ -897,7 +905,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved");
@@ -2080,6 +2544,71 @@
@@ -2080,6 +2545,71 @@
} else {
throw new IllegalStateException("Entity has invalid position");
}
@ -969,7 +977,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -2099,7 +2628,13 @@
@@ -2099,7 +2629,13 @@
ResourceLocation minecraftkey = EntityType.getKey(entitytypes);
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
@ -983,7 +991,7 @@
protected abstract void readAdditionalSaveData(CompoundTag nbt);
@@ -2153,9 +2688,31 @@
@@ -2153,9 +2689,31 @@
if (stack.isEmpty()) {
return null;
} else {
@ -1016,7 +1024,7 @@
world.addFreshEntity(entityitem);
return entityitem;
}
@@ -2184,7 +2741,16 @@
@@ -2184,7 +2742,16 @@
if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == player) {
if (!this.level().isClientSide()) {
@ -1034,7 +1042,7 @@
leashable.removeLeash();
} else {
leashable.dropLeash();
@@ -2200,6 +2766,13 @@
@@ -2200,6 +2767,13 @@
if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) {
if (!this.level().isClientSide()) {
@ -1048,7 +1056,7 @@
leashable.setLeashedTo(player, true);
}
@@ -2265,15 +2838,15 @@
@@ -2265,15 +2839,15 @@
}
public boolean showVehicleHealth() {
@ -1067,7 +1075,7 @@
return false;
} else {
for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) {
@@ -2285,11 +2858,32 @@
@@ -2285,11 +2859,32 @@
if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false;
} else {
@ -1101,7 +1109,7 @@
this.vehicle = entity;
this.vehicle.addPassenger(this);
entity.getIndirectPassengersStream().filter((entity2) -> {
@@ -2314,19 +2908,30 @@
@@ -2314,19 +2909,30 @@
}
public void removeVehicle() {
@ -1134,7 +1142,7 @@
protected void addPassenger(Entity passenger) {
if (passenger.getVehicle() != this) {
throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
@@ -2349,21 +2954,53 @@
@@ -2349,21 +2955,53 @@
}
}
@ -1194,7 +1202,7 @@
}
protected boolean canAddPassenger(Entity passenger) {
@@ -2464,7 +3101,7 @@
@@ -2464,7 +3102,7 @@
if (teleporttransition != null) {
ServerLevel worldserver1 = teleporttransition.newLevel();
@ -1203,7 +1211,7 @@
this.teleport(teleporttransition);
}
}
@@ -2547,7 +3184,7 @@
@@ -2547,7 +3185,7 @@
}
public boolean isCrouching() {
@ -1212,7 +1220,7 @@
}
public boolean isSprinting() {
@@ -2563,7 +3200,7 @@
@@ -2563,7 +3201,7 @@
}
public boolean isVisuallySwimming() {
@ -1221,7 +1229,7 @@
}
public boolean isVisuallyCrawling() {
@@ -2571,6 +3208,13 @@
@@ -2571,6 +3209,13 @@
}
public void setSwimming(boolean swimming) {
@ -1235,7 +1243,7 @@
this.setSharedFlag(4, swimming);
}
@@ -2609,6 +3253,7 @@
@@ -2609,6 +3254,7 @@
@Nullable
public PlayerTeam getTeam() {
@ -1243,7 +1251,7 @@
return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName());
}
@@ -2624,8 +3269,12 @@
@@ -2624,8 +3270,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false;
}
@ -1257,7 +1265,7 @@
}
public boolean getSharedFlag(int index) {
@@ -2644,7 +3293,7 @@
@@ -2644,7 +3294,7 @@
}
public int getMaxAirSupply() {
@ -1266,7 +1274,7 @@
}
public int getAirSupply() {
@@ -2652,7 +3301,18 @@
@@ -2652,7 +3302,18 @@
}
public void setAirSupply(int air) {
@ -1286,7 +1294,7 @@
}
public int getTicksFrozen() {
@@ -2679,11 +3339,44 @@
@@ -2679,11 +3340,44 @@
public void thunderHit(ServerLevel world, LightningBolt lightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1);
@ -1333,7 +1341,7 @@
}
public void onAboveBubbleCol(boolean drag) {
@@ -2713,7 +3406,7 @@
@@ -2713,7 +3407,7 @@
this.resetFallDistance();
}
@ -1342,7 +1350,7 @@
return true;
}
@@ -2818,7 +3511,7 @@
@@ -2818,7 +3512,7 @@
public String toString() {
String s = this.level() == null ? "~NULL~" : this.level().toString();
@ -1351,7 +1359,7 @@
}
public final boolean isInvulnerableToBase(DamageSource damageSource) {
@@ -2838,6 +3531,13 @@
@@ -2838,6 +3532,13 @@
}
public void restoreFrom(Entity original) {
@ -1365,7 +1373,7 @@
CompoundTag nbttagcompound = original.saveWithoutId(new CompoundTag());
nbttagcompound.remove("Dimension");
@@ -2850,8 +3550,57 @@
@@ -2850,8 +3551,57 @@
public Entity teleport(TeleportTransition teleportTarget) {
Level world = this.level();
@ -1423,7 +1431,7 @@
ServerLevel worldserver1 = teleportTarget.newLevel();
boolean flag = worldserver1.dimension() != worldserver.dimension();
@@ -2918,10 +3667,19 @@
@@ -2918,10 +3668,19 @@
gameprofilerfiller.pop();
return null;
} else {
@ -1444,7 +1452,7 @@
Iterator iterator1 = list1.iterator();
while (iterator1.hasNext()) {
@@ -2947,7 +3705,7 @@
@@ -2947,7 +3706,7 @@
}
private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) {
@ -1453,7 +1461,7 @@
Iterator iterator = this.getIndirectPassengers().iterator();
while (iterator.hasNext()) {
@@ -2995,9 +3753,17 @@
@@ -2995,9 +3754,17 @@
}
protected void removeAfterChangingDimensions() {
@ -1474,7 +1482,7 @@
}
}
@@ -3006,11 +3772,34 @@
@@ -3006,11 +3773,34 @@
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
}
@ -1509,7 +1517,7 @@
if (from.dimension() == Level.END && to.dimension() == Level.OVERWORLD) {
Iterator iterator = this.getPassengers().iterator();
@@ -3134,10 +3923,16 @@
@@ -3134,10 +3924,16 @@
return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE);
}
@ -1529,7 +1537,7 @@
return entity != null;
}
@@ -3187,7 +3982,7 @@
@@ -3187,7 +3983,7 @@
/** @deprecated */
@Deprecated
protected void fixupDimensions() {
@ -1538,7 +1546,7 @@
EntityDimensions entitysize = this.getDimensions(entitypose);
this.dimensions = entitysize;
@@ -3196,7 +3991,7 @@
@@ -3196,7 +3992,7 @@
public void refreshDimensions() {
EntityDimensions entitysize = this.dimensions;
@ -1547,7 +1555,7 @@
EntityDimensions entitysize1 = this.getDimensions(entitypose);
this.dimensions = entitysize1;
@@ -3258,10 +4053,29 @@
@@ -3258,10 +4054,29 @@
}
public final void setBoundingBox(AABB boundingBox) {
@ -1579,7 +1587,7 @@
return this.getDimensions(pose).eyeHeight();
}
@@ -3300,7 +4114,14 @@
@@ -3300,7 +4115,14 @@
public void startSeenByPlayer(ServerPlayer player) {}
@ -1595,7 +1603,7 @@
public float rotate(Rotation rotation) {
float f = Mth.wrapDegrees(this.getYRot());
@@ -3335,7 +4156,7 @@
@@ -3335,7 +4157,7 @@
}
@Nullable
@ -1604,7 +1612,7 @@
return null;
}
@@ -3373,20 +4194,34 @@
@@ -3373,20 +4195,34 @@
}
private Stream<Entity> getIndirectPassengersStream() {
@ -1639,7 +1647,7 @@
return () -> {
return this.getIndirectPassengersStream().iterator();
};
@@ -3399,6 +4234,7 @@
@@ -3399,6 +4235,7 @@
}
public boolean hasExactlyOnePlayerPassenger() {
@ -1647,7 +1655,7 @@
return this.countPlayerPassengers() == 1;
}
@@ -3435,7 +4271,7 @@
@@ -3435,7 +4272,7 @@
}
public boolean isControlledByLocalInstance() {
@ -1656,7 +1664,7 @@
if (entityliving instanceof Player entityhuman) {
return entityhuman.isLocalPlayer();
@@ -3445,7 +4281,7 @@
@@ -3445,7 +4282,7 @@
}
public boolean isControlledByClient() {
@ -1665,7 +1673,7 @@
return entityliving != null && entityliving.isControlledByClient();
}
@@ -3463,7 +4299,7 @@
@@ -3463,7 +4300,7 @@
return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3);
}
@ -1674,7 +1682,7 @@
return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
}
@@ -3489,8 +4325,37 @@
@@ -3489,8 +4326,37 @@
return 1;
}
@ -1713,20 +1721,19 @@
}
public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) {
@@ -3550,7 +4415,12 @@
@@ -3551,6 +4417,11 @@
vec3d = vec3d.add(vec3d1);
++k1;
+ }
}
+ // CraftBukkit start - store last lava contact location
+ if (tag == FluidTags.LAVA) {
+ this.lastLavaContact = blockposition_mutableblockposition.immutable();
}
+ }
+ // CraftBukkit end
}
}
}
@@ -3613,7 +4483,7 @@
@@ -3613,7 +4484,7 @@
return new ClientboundAddEntityPacket(this, entityTrackerEntry);
}
@ -1735,7 +1742,7 @@
return this.type.getDimensions();
}
@@ -3714,7 +4584,39 @@
@@ -3714,7 +4585,39 @@
return this.getZ((2.0D * this.random.nextDouble() - 1.0D) * widthScale);
}
@ -1775,7 +1782,7 @@
if (this.position.x != x || this.position.y != y || this.position.z != z) {
this.position = new Vec3(x, y, z);
int i = Mth.floor(x);
@@ -3732,6 +4634,12 @@
@@ -3732,6 +4635,12 @@
this.levelCallback.onMove();
}
@ -1788,7 +1795,7 @@
}
public void checkDespawn() {}
@@ -3818,8 +4726,16 @@
@@ -3818,8 +4727,16 @@
@Override
public final void setRemoved(Entity.RemovalReason reason) {
@ -1806,7 +1813,7 @@
}
if (this.removalReason.shouldDestroy()) {
@@ -3827,8 +4743,8 @@
@@ -3827,8 +4744,8 @@
}
this.getPassengers().forEach(Entity::stopRiding);
@ -1817,7 +1824,7 @@
}
public void unsetRemoved() {
@@ -3887,7 +4803,7 @@
@@ -3887,7 +4804,7 @@
}
public Vec3 getKnownMovement() {
@ -1826,7 +1833,7 @@
if (entityliving instanceof Player entityhuman) {
if (this.isAlive()) {
@@ -3962,4 +4878,14 @@
@@ -3962,4 +4879,14 @@
void accept(Entity entity, double x, double y, double z);
}