Search in sources :

Example 1 with EntityDraggable

use of ValkyrienWarfareBase.Interaction.EntityDraggable in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityCollisionInjector method alterEntityMovement.

// Returns false if game should use default collision
public static boolean alterEntityMovement(Entity entity, double dx, double dy, double dz) {
    if (entity instanceof PhysicsWrapperEntity) {
        return true;
    }
    Vector velVec = new Vector(dx, dy, dz);
    double origDx = dx;
    double origDy = dy;
    double origDz = dz;
    boolean isLiving = entity instanceof EntityLivingBase;
    boolean isMoving = false;
    if (isLiving) {
        EntityLivingBase living = (EntityLivingBase) entity;
        isMoving = Math.abs(living.moveForward) > .01 || Math.abs(living.moveStrafing) > .01;
    }
    Vec3d velocity = new Vec3d(dx, dy, dz);
    ArrayList<EntityPolygonCollider> fastCollisions = new ArrayList<EntityPolygonCollider>();
    EntityPolygon playerBeforeMove = new EntityPolygon(entity.getEntityBoundingBox(), entity);
    ArrayList<Polygon> colPolys = getCollidingPolygonsAndDoBlockCols(entity, velocity);
    PhysicsWrapperEntity worldBelow = null;
    EntityDraggable draggable = EntityDraggable.getDraggableFromEntity(entity);
    for (Polygon poly : colPolys) {
        if (poly instanceof ShipPolygon) {
            ShipPolygon shipPoly = (ShipPolygon) poly;
            EntityPolygonCollider fast = new EntityPolygonCollider(playerBeforeMove, shipPoly, shipPoly.normals, velVec);
            if (!fast.seperated) {
                fastCollisions.add(fast);
                worldBelow = shipPoly.shipFrom.wrapper;
            }
        }
    }
    //TODO: Make this more comprehensive
    draggable.worldBelowFeet = worldBelow;
    if (fastCollisions.isEmpty()) {
        return false;
    }
    int contX = 0;
    int contY = 0;
    int contZ = 0;
    Vector total = new Vector();
    for (EntityPolygonCollider col : fastCollisions) {
        Vector response = col.collisions[col.minDistanceIndex].getResponse();
        // TODO: Add more potential yResponses
        double stepSquared = entity.stepHeight * entity.stepHeight;
        boolean isStep = isLiving && entity.onGround;
        if (response.Y > 0 && BigBastardMath.canStandOnNormal(col.potentialSeperatingAxes[col.minDistanceIndex])) {
            response = new Vector(0, -col.collisions[col.minDistanceIndex].penetrationDistance / col.potentialSeperatingAxes[col.minDistanceIndex].Y, 0);
        }
        if (isStep) {
            EntityLivingBase living = (EntityLivingBase) entity;
            if (Math.abs(living.moveForward) > .01 || Math.abs(living.moveStrafing) > .01) {
                for (int i = 3; i < 6; i++) {
                    Vector tempResponse = col.collisions[i].getResponse();
                    if (tempResponse.Y > 0 && BigBastardMath.canStandOnNormal(col.collisions[i].axis) && tempResponse.lengthSq() < stepSquared) {
                        response = tempResponse;
                    }
                }
            }
        }
        // total.add(response);
        if (Math.abs(response.X) > .01) {
            total.X += response.X;
            contX++;
        }
        if (Math.abs(response.Y) > .01) {
            total.Y += response.Y;
            contY++;
        }
        if (Math.abs(response.Z) > .01) {
            total.Z += response.Z;
            contZ++;
        }
    }
    if (contX != 0) {
        total.X /= contX;
    }
    if (contY != 0) {
        total.Y /= contY;
    }
    if (contZ != 0) {
        total.Z /= contZ;
    }
    dx += total.X;
    dy += total.Y;
    dz += total.Z;
    boolean alreadyOnGround = entity.onGround && (dy == origDy) && origDy < 0;
    Vector original = new Vector(origDx, origDy, origDz);
    Vector newMov = new Vector(dx - origDx, dy - origDy, dz - origDz);
    entity.isCollidedHorizontally = original.dot(newMov) < 0;
    entity.isCollidedVertically = isDifSignificant(dy, origDy);
    entity.onGround = entity.isCollidedVertically && origDy < 0 || alreadyOnGround;
    entity.isCollided = entity.isCollidedHorizontally || entity.isCollidedVertically;
    if (entity instanceof EntityLivingBase) {
        EntityLivingBase base = (EntityLivingBase) entity;
        base.motionY = dy;
        if (base.isOnLadder()) {
            float f9 = 0.15F;
            base.motionX = MathHelper.clamp_double(base.motionX, -0.15000000596046448D, 0.15000000596046448D);
            base.motionZ = MathHelper.clamp_double(base.motionZ, -0.15000000596046448D, 0.15000000596046448D);
            base.fallDistance = 0.0F;
            if (base.motionY < -0.15D) {
                base.motionY = -0.15D;
            }
            boolean flag = base.isSneaking() && base instanceof EntityPlayer;
            if (flag && base.motionY < 0.0D) {
                base.motionY = 0.0D;
            }
        }
        entity.moveEntity(dx, base.motionY, dz);
    } else {
        entity.moveEntity(dx, dy, dz);
    }
    entity.isCollidedHorizontally = (motionInterfering(dx, origDx)) || (motionInterfering(dz, origDz));
    entity.isCollidedVertically = isDifSignificant(dy, origDy);
    entity.onGround = entity.isCollidedVertically && origDy < 0 || alreadyOnGround || entity.onGround;
    entity.isCollided = entity.isCollidedHorizontally || entity.isCollidedVertically;
    if (dx != origDx) {
        entity.motionX = dx;
    }
    if (dy != origDy) {
        if (!(entity.motionY > 0 && dy > 0)) {
            entity.motionY = 0;
        }
    }
    if (dz != origDz) {
        entity.motionZ = dz;
    }
    return true;
}
Also used : EntityDraggable(ValkyrienWarfareBase.Interaction.EntityDraggable) ArrayList(java.util.ArrayList) Vec3d(net.minecraft.util.math.Vec3d) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vector(ValkyrienWarfareBase.API.Vector)

Example 2 with EntityDraggable

use of ValkyrienWarfareBase.Interaction.EntityDraggable in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EventsClient method onClientTickEvent.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onClientTickEvent(ClientTickEvent event) {
    if (mc.theWorld != null) {
        if (!mc.isGamePaused()) {
            WorldPhysObjectManager manager = ValkyrienWarfareMod.physicsManager.getManagerForWorld(mc.theWorld);
            if (event.phase == Phase.END) {
                for (PhysicsWrapperEntity wrapper : manager.physicsEntities) {
                    wrapper.wrapping.onPostTickClient();
                }
                EntityDraggable.tickAddedVelocityForWorld(mc.theWorld);
            }
        }
        if (event.phase == Phase.END) {
            Object o = Minecraft.getMinecraft().thePlayer;
            EntityDraggable draggable = (EntityDraggable) o;
            if (draggable.worldBelowFeet != null) {
                PlayerShipRefrenceMessage playerPosMessage = new PlayerShipRefrenceMessage(Minecraft.getMinecraft().thePlayer, draggable.worldBelowFeet);
                ValkyrienWarfareMod.physWrapperNetwork.sendToServer(playerPosMessage);
            }
        }
    }
}
Also used : WorldPhysObjectManager(ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager) EntityDraggable(ValkyrienWarfareBase.Interaction.EntityDraggable) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) PlayerShipRefrenceMessage(ValkyrienWarfareBase.Network.PlayerShipRefrenceMessage) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityDraggable (ValkyrienWarfareBase.Interaction.EntityDraggable)2 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)2 Vector (ValkyrienWarfareBase.API.Vector)1 PlayerShipRefrenceMessage (ValkyrienWarfareBase.Network.PlayerShipRefrenceMessage)1 WorldPhysObjectManager (ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager)1 ArrayList (java.util.ArrayList)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Vec3d (net.minecraft.util.math.Vec3d)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1