Search in sources :

Example 1 with ItemSkyhook

use of blusunrize.immersiveengineering.common.items.ItemSkyhook in project ImmersiveEngineering by BluSunrize.

the class SkylineHelper method spawnHook.

public static EntitySkylineHook spawnHook(EntityPlayer player, TileEntity start, Connection connection) {
    BlockPos cc0 = connection.end == Utils.toCC(start) ? connection.start : connection.end;
    BlockPos cc1 = connection.end == Utils.toCC(start) ? connection.end : connection.start;
    IImmersiveConnectable iicStart = ApiUtils.toIIC(cc1, player.worldObj);
    IImmersiveConnectable iicEnd = ApiUtils.toIIC(cc0, player.worldObj);
    Vec3d vStart = new Vec3d(cc1);
    Vec3d vEnd = new Vec3d(cc0);
    if (iicStart != null)
        vStart = Utils.addVectors(vStart, iicStart.getConnectionOffset(connection));
    if (iicEnd != null)
        vEnd = Utils.addVectors(vEnd, iicEnd.getConnectionOffset(connection));
    Vec3d[] steps = getConnectionCatenary(connection, vStart, vEnd);
    double dx = (steps[0].xCoord - vStart.xCoord);
    double dy = (steps[0].yCoord - vStart.yCoord);
    double dz = (steps[0].zCoord - vStart.zCoord);
    //connection.length;
    double d = 1;
    //						Math.sqrt(dx*dx+dz*dz+dy*dy);
    //		Vec3 moveVec = Vec3.createVectorHelper(dx,dy,dz);
    //		Vec3 moveVec = Vec3.createVectorHelper(dx/d,dy/d,dz/d);
    EntitySkylineHook hook = new EntitySkylineHook(player.worldObj, vStart.xCoord, vStart.yCoord, vStart.zCoord, connection, cc0, steps);
    float speed = 1;
    if (player.getActiveItemStack() != null && player.getActiveItemStack().getItem() instanceof ItemSkyhook)
        speed = ((ItemSkyhook) player.getActiveItemStack().getItem()).getSkylineSpeed(player.getActiveItemStack());
    Vec3d moveVec = getSubMovementVector(vStart, steps[0], speed);
    //*speed;
    hook.motionX = moveVec.xCoord;
    //*speed;
    hook.motionY = moveVec.yCoord;
    //*speed;
    hook.motionZ = moveVec.zCoord;
    if (!player.worldObj.isRemote)
        player.worldObj.spawnEntityInWorld(hook);
    ItemSkyhook.existingHooks.put(player.getName(), hook);
    player.startRiding(hook);
    return hook;
}
Also used : EntitySkylineHook(blusunrize.immersiveengineering.common.entities.EntitySkylineHook) ItemSkyhook(blusunrize.immersiveengineering.common.items.ItemSkyhook) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with ItemSkyhook

use of blusunrize.immersiveengineering.common.items.ItemSkyhook in project ImmersiveEngineering by BluSunrize.

the class EntitySkylineHook method onUpdate.

@Override
public void onUpdate() {
    EntityPlayer player = null;
    //		if(this.getControllingPassenger() instanceof EntityPlayer)
    //			player = ((EntityPlayer)this.getControllingPassenger());
    List<Entity> list = this.getPassengers();
    if (!list.isEmpty() && list.get(0) instanceof EntityPlayer)
        player = (EntityPlayer) list.get(0);
    if (this.ticksExisted == 1 && !worldObj.isRemote) {
        IELogger.debug("init tick at " + System.currentTimeMillis());
        if (player instanceof EntityPlayerMP)
            ImmersiveEngineering.packetHandler.sendTo(new MessageSkyhookSync(this), (EntityPlayerMP) player);
    }
    super.onUpdate();
    //			return;
    if (subPoints != null && targetPoint < subPoints.length - 1) {
        double dist = subPoints[targetPoint].distanceTo(new Vec3d(posX, posY, posZ));
        IELogger.debug("dist: " + dist);
        if (dist <= 0) {
            this.posX = subPoints[targetPoint].xCoord;
            this.posY = subPoints[targetPoint].yCoord;
            this.posZ = subPoints[targetPoint].zCoord;
            targetPoint++;
            if (player instanceof EntityPlayerMP)
                ImmersiveEngineering.packetHandler.sendTo(new MessageSkyhookSync(this), (EntityPlayerMP) player);
            IELogger.debug("next vertex: " + targetPoint);
            return;
        }
        float speed = 2f;
        if (player != null && player.getActiveItemStack() != null && player.getActiveItemStack().getItem() instanceof ItemSkyhook)
            speed = ((ItemSkyhook) player.getActiveItemStack().getItem()).getSkylineSpeed(player.getActiveItemStack());
        Vec3d moveVec = SkylineHelper.getSubMovementVector(new Vec3d(posX, posY, posZ), subPoints[targetPoint], speed);
        //*speed;
        motionX = moveVec.xCoord;
        //*speed;
        motionY = moveVec.yCoord;
        //*speed;
        motionZ = moveVec.zCoord;
    }
    if (target != null && targetPoint == subPoints.length - 1) {
        TileEntity end = this.worldObj.getTileEntity(target);
        IImmersiveConnectable iicEnd = ApiUtils.toIIC(end, worldObj);
        if (iicEnd == null) {
            this.setDead();
            return;
        }
        Vec3d vEnd = new Vec3d(target.getX(), target.getY(), target.getZ());
        vEnd = Utils.addVectors(vEnd, iicEnd.getConnectionOffset(connection));
        double gDist = vEnd.distanceTo(new Vec3d(posX, posY, posZ));
        IELogger.debug("distance to goal: " + gDist);
        if (gDist <= .3) {
            reachedTarget(end);
            return;
        } else if (gDist > 5) {
            setDead();
            return;
        }
    }
    this.posX += this.motionX;
    this.posY += this.motionY;
    this.posZ += this.motionZ;
    float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
    this.rotationYaw = (float) (Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) + 90.0F;
    for (this.rotationPitch = (float) (Math.atan2((double) f1, this.motionY) * 180.0D / Math.PI) - 90.0F; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) ;
    while (this.rotationPitch - this.prevRotationPitch >= 180.0F) this.prevRotationPitch += 360.0F;
    while (this.rotationYaw - this.prevRotationYaw < -180.0F) this.prevRotationYaw -= 360.0F;
    while (this.rotationYaw - this.prevRotationYaw >= 180.0F) this.prevRotationYaw += 360.0F;
    this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
    this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
    if (this.isInWater()) {
        for (int j = 0; j < 4; ++j) {
            float f3 = 0.25F;
            this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * (double) f3, this.posY - this.motionY * (double) f3, this.posZ - this.motionZ * (double) f3, this.motionX, this.motionY, this.motionZ);
        }
    }
    if (player != null) {
        double dx = this.posX - this.prevPosX;
        double dy = this.posY - this.prevPosY;
        double dz = this.posZ - this.prevPosZ;
        int distTrvl = Math.round(MathHelper.sqrt_double(dx * dx + dy * dy + dz * dz) * 100.0F);
        if (distTrvl > 0)
            player.addStat(IEAchievements.statDistanceSkyhook, distTrvl);
        if (!worldObj.isRemote && SkylineHelper.isInBlock(player, worldObj)) {
        //				setDead();
        //				player.setPosition(posX-3*dx, posY-3*dy+getMountedYOffset(),posZ-3*dz);
        }
    //TODO
    //			if(player instanceof EntityPlayerMP)
    //				if(((EntityPlayerMP)player).getStatFile().func_150870_b(IEAchievements.statDistanceSkyhook)>100000)
    //					player.triggerAchievement(IEAchievements.skyhookPro);
    }
    this.setPosition(this.posX, this.posY, this.posZ);
}
Also used : MessageSkyhookSync(blusunrize.immersiveengineering.common.util.network.MessageSkyhookSync) TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ItemSkyhook(blusunrize.immersiveengineering.common.items.ItemSkyhook) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with ItemSkyhook

use of blusunrize.immersiveengineering.common.items.ItemSkyhook in project ImmersiveEngineering by BluSunrize.

the class EntitySkylineHook method reachedTarget.

public void reachedTarget(TileEntity end) {
    this.setDead();
    IELogger.debug("last tick at " + System.currentTimeMillis());
    List<Entity> list = this.getPassengers();
    if (list.isEmpty() || !(list.get(0) instanceof EntityPlayer))
        return;
    //		if(!(this.getControllingPassenger() instanceof EntityPlayer))
    //			return;
    //		EntityPlayer player = (EntityPlayer)this.getControllingPassenger();
    EntityPlayer player = (EntityPlayer) list.get(0);
    ItemStack hook = player.getActiveItemStack();
    if (hook == null || !(hook.getItem() instanceof ItemSkyhook))
        return;
    Connection line = SkylineHelper.getTargetConnection(worldObj, target, player, connection);
    if (line != null) {
        player.setActiveHand(player.getActiveHand());
        //					setItemInUse(hook, hook.getItem().getMaxItemUseDuration(hook));
        SkylineHelper.spawnHook(player, end, line);
    //					ChunkCoordinates cc0 = line.end==target?line.start:line.end;
    //					ChunkCoordinates cc1 = line.end==target?line.end:line.start;
    //					double dx = cc0.posX-cc1.posX;
    //					double dy = cc0.posY-cc1.posY;
    //					double dz = cc0.posZ-cc1.posZ;
    //
    //					EntityZiplineHook zip = new EntityZiplineHook(worldObj, target.posX+.5,target.posY+.5,target.posZ+.5, line, cc0);
    //					zip.motionX = dx*.05f;
    //					zip.motionY = dy*.05f;
    //					zip.motionZ = dz*.05f;
    //					if(!worldObj.isRemote)
    //						worldObj.spawnEntityInWorld(zip);
    //					ItemSkyHook.existingHooks.put(this.riddenByEntity.getCommandSenderName(), zip);
    //					this.riddenByEntity.mountEntity(zip);
    } else {
        player.motionX = motionX;
        player.motionY = motionY;
        player.motionZ = motionZ;
        IELogger.debug("player motion: " + player.motionX + "," + player.motionY + "," + player.motionZ);
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ItemSkyhook(blusunrize.immersiveengineering.common.items.ItemSkyhook) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemSkyhook (blusunrize.immersiveengineering.common.items.ItemSkyhook)3 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)2 Entity (net.minecraft.entity.Entity)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Vec3d (net.minecraft.util.math.Vec3d)2 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)1 EntitySkylineHook (blusunrize.immersiveengineering.common.entities.EntitySkylineHook)1 MessageSkyhookSync (blusunrize.immersiveengineering.common.util.network.MessageSkyhookSync)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1