use of org.bukkit.event.vehicle.VehicleEntityCollisionEvent in project Arclight by IzzelAliz.
the class AbstractMinecartEntityMixin method arclight$vehicleCollide.
@Inject(method = "applyEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/minecart/AbstractMinecartEntity;isPassenger(Lnet/minecraft/entity/Entity;)Z"))
private void arclight$vehicleCollide(Entity entityIn, CallbackInfo ci) {
if (!this.isPassenger(entityIn)) {
VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), ((EntityBridge) entityIn).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(collisionEvent);
if (collisionEvent.isCancelled()) {
ci.cancel();
}
}
}
use of org.bukkit.event.vehicle.VehicleEntityCollisionEvent in project Arclight by IzzelAliz.
the class AbstractMinecartEntityMixin method tick.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void tick() {
double prevX = this.posX;
double prevY = this.posY;
double prevZ = this.posZ;
float prevYaw = this.rotationYaw;
float prevPitch = this.rotationPitch;
if (this.getRollingAmplitude() > 0) {
this.setRollingAmplitude(this.getRollingAmplitude() - 1);
}
if (this.getDamage() > 0.0f) {
this.setDamage(this.getDamage() - 1.0f);
}
if (this.posY < -64.0) {
this.outOfWorld();
}
if (this.world.isRemote) {
if (this.turnProgress > 0) {
double d0 = this.posX + (this.minecartX - this.posX) / this.turnProgress;
double d2 = this.posY + (this.minecartY - this.posY) / this.turnProgress;
double d3 = this.posZ + (this.minecartZ - this.posZ) / this.turnProgress;
double d4 = MathHelper.wrapDegrees(this.minecartYaw - this.rotationYaw);
this.rotationYaw += (float) (d4 / this.turnProgress);
this.rotationPitch += (float) ((this.minecartPitch - this.rotationPitch) / this.turnProgress);
--this.turnProgress;
this.setPosition(d0, d2, d3);
this.setRotation(this.rotationYaw, this.rotationPitch);
} else {
this.setPosition(this.posX, this.posY, this.posZ);
this.setRotation(this.rotationYaw, this.rotationPitch);
}
} else {
/*
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
*/
if (!this.hasNoGravity()) {
this.setMotion(this.getMotion().add(0.0, -0.04, 0.0));
}
int i = MathHelper.floor(this.posX);
int j = MathHelper.floor(this.posY);
int k = MathHelper.floor(this.posZ);
if (this.world.getBlockState(new BlockPos(i, j - 1, k)).isIn(BlockTags.RAILS)) {
--j;
}
BlockPos blockposition = new BlockPos(i, j, k);
BlockState iblockdata = this.world.getBlockState(blockposition);
if (iblockdata.isIn(BlockTags.RAILS)) {
this.moveAlongTrack(blockposition, iblockdata);
if (iblockdata.getBlock() == Blocks.ACTIVATOR_RAIL) {
this.onActivatorRailPass(i, j, k, iblockdata.get(PoweredRailBlock.POWERED));
}
} else {
this.moveDerailedMinecart();
}
this.doBlockCollisions();
this.rotationPitch = 0.0f;
double d5 = this.prevPosX - this.posX;
double d6 = this.prevPosZ - this.posZ;
if (d5 * d5 + d6 * d6 > 0.001) {
this.rotationYaw = (float) (MathHelper.atan2(d6, d5) * 180.0 / 3.141592653589793);
if (this.isInReverse) {
this.rotationYaw += 180.0f;
}
}
double d7 = MathHelper.wrapDegrees(this.rotationYaw - this.prevRotationYaw);
if (d7 < -170.0 || d7 >= 170.0) {
this.rotationYaw += 180.0f;
this.isInReverse = !this.isInReverse;
}
this.setRotation(this.rotationYaw, this.rotationPitch);
org.bukkit.World bworld = ((WorldBridge) this.world).bridge$getWorld();
Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch);
Location to = new Location(bworld, this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
Bukkit.getPluginManager().callEvent(new VehicleUpdateEvent(vehicle));
if (!from.equals(to)) {
Bukkit.getPluginManager().callEvent(new VehicleMoveEvent(vehicle, from, to));
}
if (this.getMinecartType() == AbstractMinecartEntity.Type.RIDEABLE && Entity.horizontalMag(this.getMotion()) > 0.01) {
List<Entity> list = this.world.getEntitiesInAABBexcluding((AbstractMinecartEntity) (Object) this, this.getBoundingBox().grow(0.20000000298023224, 0.0, 0.20000000298023224), EntityPredicates.pushableBy((AbstractMinecartEntity) (Object) this));
if (!list.isEmpty()) {
for (Entity entity : list) {
if (!(entity instanceof PlayerEntity) && !(entity instanceof IronGolemEntity) && !(entity instanceof AbstractMinecartEntity) && !this.isBeingRidden() && !entity.isPassenger()) {
VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(collisionEvent);
if (!collisionEvent.isCancelled()) {
entity.startRiding((AbstractMinecartEntity) (Object) this);
}
} else {
if (!isRidingSameEntity(entity)) {
VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(collisionEvent);
if (collisionEvent.isCancelled()) {
continue;
}
}
entity.applyEntityCollision((AbstractMinecartEntity) (Object) this);
}
}
}
} else {
for (Entity entity2 : this.world.getEntitiesWithinAABBExcludingEntity((AbstractMinecartEntity) (Object) this, this.getBoundingBox().grow(0.20000000298023224, 0.0, 0.20000000298023224))) {
if (!this.isPassenger(entity2) && entity2.canBePushed() && entity2 instanceof AbstractMinecartEntity) {
VehicleEntityCollisionEvent collisionEvent2 = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity2).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(collisionEvent2);
if (collisionEvent2.isCancelled()) {
continue;
}
entity2.applyEntityCollision((AbstractMinecartEntity) (Object) this);
}
}
}
this.handleWaterMovement();
}
}
use of org.bukkit.event.vehicle.VehicleEntityCollisionEvent in project Arclight by IzzelAliz.
the class BoatEntityMixin method arclight$collideVehicle.
@Inject(method = "applyEntityCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;applyEntityCollision(Lnet/minecraft/entity/Entity;)V"))
private void arclight$collideVehicle(Entity entityIn, CallbackInfo ci) {
if (isRidingSameEntity(entityIn)) {
VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), ((EntityBridge) entityIn).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
ci.cancel();
}
}
}
Aggregations