Search in sources :

Example 1 with IronGolemEntity

use of net.minecraft.entity.passive.IronGolemEntity 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();
    }
}
Also used : IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractMinecartEntity(net.minecraft.entity.item.minecart.AbstractMinecartEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Vehicle(org.bukkit.entity.Vehicle) VehicleUpdateEvent(org.bukkit.event.vehicle.VehicleUpdateEvent) BlockState(net.minecraft.block.BlockState) VehicleEntityCollisionEvent(org.bukkit.event.vehicle.VehicleEntityCollisionEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) VehicleMoveEvent(org.bukkit.event.vehicle.VehicleMoveEvent) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) BlockPos(net.minecraft.util.math.BlockPos) AbstractMinecartEntity(net.minecraft.entity.item.minecart.AbstractMinecartEntity) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 BlockState (net.minecraft.block.BlockState)1 Entity (net.minecraft.entity.Entity)1 AbstractMinecartEntity (net.minecraft.entity.item.minecart.AbstractMinecartEntity)1 IronGolemEntity (net.minecraft.entity.passive.IronGolemEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 Location (org.bukkit.Location)1 Vehicle (org.bukkit.entity.Vehicle)1 VehicleEntityCollisionEvent (org.bukkit.event.vehicle.VehicleEntityCollisionEvent)1 VehicleMoveEvent (org.bukkit.event.vehicle.VehicleMoveEvent)1 VehicleUpdateEvent (org.bukkit.event.vehicle.VehicleUpdateEvent)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1