0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-22 10:06:16 +00:00
craftbukkit/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.patch

143 lines
5.7 KiB
Diff

--- a/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java
+++ b/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java
@@ -43,6 +43,14 @@
import net.minecraft.world.phys.AxisAlignedBB;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.entity.Vehicle;
+import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
+import org.bukkit.util.Vector;
+// CraftBukkit end
+
public abstract class EntityMinecartAbstract extends VehicleEntity {
private static final Vec3D LOWERED_PASSENGER_ATTACHMENT = new Vec3D(0.0D, 0.0D, 0.0D);
@@ -76,6 +84,17 @@
enummap.put(BlockPropertyTrackPosition.NORTH_EAST, Pair.of(baseblockposition2, baseblockposition1));
});
+ // CraftBukkit start
+ public boolean slowWhenEmpty = true;
+ private double derailedX = 0.5;
+ private double derailedY = 0.5;
+ private double derailedZ = 0.5;
+ private double flyingX = 0.95;
+ private double flyingY = 0.95;
+ private double flyingZ = 0.95;
+ public Double maxSpeed;
+ // CraftBukkit end
+
protected EntityMinecartAbstract(EntityTypes<?> entitytypes, World world) {
super(entitytypes, world);
this.blocksBuilding = true;
@@ -101,7 +120,7 @@
@Nullable
public static <T extends EntityMinecartAbstract> T createMinecart(World world, double d0, double d1, double d2, EntityTypes<T> entitytypes, EntitySpawnReason entityspawnreason, ItemStack itemstack, @Nullable EntityHuman entityhuman) {
- T t0 = (EntityMinecartAbstract) entitytypes.create(world, entityspawnreason);
+ T t0 = (T) entitytypes.create(world, entityspawnreason); // CraftBukkit - decompile error
if (t0 != null) {
t0.setInitialPos(d0, d1, d2);
@@ -262,6 +281,14 @@
@Override
public void tick() {
+ // CraftBukkit start
+ double prevX = this.getX();
+ double prevY = this.getY();
+ double prevZ = this.getZ();
+ float prevYaw = this.getYRot();
+ float prevPitch = this.getXRot();
+ // CraftBukkit end
+
if (this.getHurtTime() > 0) {
this.setHurtTime(this.getHurtTime() - 1);
}
@@ -271,8 +298,20 @@
}
this.checkBelowWorld();
- this.handlePortal();
+ // this.handlePortal(); // CraftBukkit - handled in postTick
this.behavior.tick();
+ // CraftBukkit start
+ org.bukkit.World bworld = this.level().getWorld();
+ Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch);
+ Location to = CraftLocation.toBukkit(this.position(), bworld, this.getYRot(), this.getXRot());
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+
+ this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
+
+ if (!from.equals(to)) {
+ this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to));
+ }
+ // CraftBukkit end
this.updateInWaterStateAndDoFluidPushing();
if (this.isInLava()) {
this.lavaHurt();
@@ -385,12 +424,16 @@
this.setDeltaMovement(MathHelper.clamp(vec3d.x, -d0, d0), vec3d.y, MathHelper.clamp(vec3d.z, -d0, d0));
if (this.onGround()) {
- this.setDeltaMovement(this.getDeltaMovement().scale(0.5D));
+ // CraftBukkit start - replace magic numbers with our variables
+ this.setDeltaMovement(new Vec3D(this.getDeltaMovement().x * this.derailedX, this.getDeltaMovement().y * this.derailedY, this.getDeltaMovement().z * this.derailedZ));
+ // CraftBukkit end
}
this.move(EnumMoveType.SELF, this.getDeltaMovement());
if (!this.onGround()) {
- this.setDeltaMovement(this.getDeltaMovement().scale(0.95D));
+ // CraftBukkit start - replace magic numbers with our variables
+ this.setDeltaMovement(new Vec3D(this.getDeltaMovement().x * this.flyingX, this.getDeltaMovement().y * this.flyingY, this.getDeltaMovement().z * this.flyingZ));
+ // CraftBukkit end
}
}
@@ -521,6 +564,14 @@
if (!this.level().isClientSide) {
if (!entity.noPhysics && !this.noPhysics) {
if (!this.hasPassenger(entity)) {
+ // CraftBukkit start
+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
+ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent);
+
+ if (collisionEvent.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
double d0 = entity.getX() - this.getX();
double d1 = entity.getZ() - this.getZ();
double d2 = d0 * d0 + d1 * d1;
@@ -645,4 +696,26 @@
public boolean isFurnace() {
return false;
}
+
+ // CraftBukkit start - Methods for getting and setting flying and derailed velocity modifiers
+ public Vector getFlyingVelocityMod() {
+ return new Vector(flyingX, flyingY, flyingZ);
+ }
+
+ public void setFlyingVelocityMod(Vector flying) {
+ flyingX = flying.getX();
+ flyingY = flying.getY();
+ flyingZ = flying.getZ();
+ }
+
+ public Vector getDerailedVelocityMod() {
+ return new Vector(derailedX, derailedY, derailedZ);
+ }
+
+ public void setDerailedVelocityMod(Vector derailed) {
+ derailedX = derailed.getX();
+ derailedY = derailed.getY();
+ derailedZ = derailed.getZ();
+ }
+ // CraftBukkit end
}