示例#1
0
        private bool HandleSteppingOnBlocks(EntityPos pos, Vec3d moveDelta, float dtFac, EntityControls controls)
        {
            if (!controls.TriesToMove || (!entity.OnGround && !entity.Swimming))
            {
                return(false);
            }


            Cuboidd entityCollisionBox = entity.CollisionBox.ToDouble();

            entityCollisionBox.Translate(pos.X, pos.Y, pos.Z);
            entityCollisionBox.Y2 = Math.Max(entityCollisionBox.Y1 + stepHeight, entityCollisionBox.Y2);

            Vec3d walkVec    = controls.WalkVector;
            Vec3d testVec    = new Vec3d();
            Vec3d testMotion = new Vec3d();


            Cuboidd stepableBox = findSteppableCollisionbox(entityCollisionBox, moveDelta.Y, walkVec);



            // Must have walked into a slab
            if (stepableBox != null)
            {
                return
                    (tryStep(pos, testMotion.Set(moveDelta.X, moveDelta.Y, moveDelta.Z), dtFac, stepableBox, entityCollisionBox) ||
                     tryStep(pos, testMotion.Set(moveDelta.X, moveDelta.Y, 0), dtFac, findSteppableCollisionbox(entityCollisionBox, moveDelta.Y, testVec.Set(walkVec.X, walkVec.Y, 0)), entityCollisionBox) ||
                     tryStep(pos, testMotion.Set(0, moveDelta.Y, moveDelta.Z), dtFac, findSteppableCollisionbox(entityCollisionBox, moveDelta.Y, testVec.Set(0, walkVec.Y, walkVec.Z)), entityCollisionBox)
                    );
            }

            return(false);
        }
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (Level <= 0 || TextureName == null)
            {
                return;
            }

            int voxelY = (int)GameMath.Clamp(Level, 0, fillQuadsByLevel.Length - 1);

            IRenderAPI           rpi         = api.Render;
            IClientWorldAccessor worldAccess = api.World;
            EntityPos            plrPos      = worldAccess.Player.Entity.Pos;
            Vec3d camPos = worldAccess.Player.Entity.CameraPos;

            rpi.GlDisableCullFace();
            IStandardShaderProgram prog = rpi.StandardShader;

            prog.Use();
            prog.RgbaAmbientIn = rpi.AmbientColor;
            prog.RgbaFogIn     = rpi.FogColor;
            prog.FogMinIn      = rpi.FogMin;
            prog.FogDensityIn  = rpi.FogDensity;
            prog.RgbaTint      = ColorUtil.WhiteArgbVec;
            prog.WaterWave     = 0;

            Vec4f lightrgbs = api.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);

            float[] glowColor = ColorUtil.GetIncandescenceColorAsColor4f((int)Temperature);
            lightrgbs.R += 2 * glowColor[0];
            lightrgbs.G += 2 * glowColor[1];
            lightrgbs.B += 2 * glowColor[2];

            prog.RgbaLightIn = lightrgbs;
            prog.RgbaBlockIn = ColorUtil.WhiteArgbVec;
            prog.ExtraGlow   = (int)GameMath.Clamp((Temperature - 500) / 4, 0, 255);

            int     texid = api.Render.GetOrLoadTexture(TextureName);
            Cuboidf rect  = fillQuadsByLevel[voxelY];

            rpi.BindTexture2d(texid);

            prog.ModelMatrix = ModelMat
                               .Identity()
                               .Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z)
                               .Translate(1 - rect.X1 / 16f, 1.01f / 16f + Math.Max(0, Level / 16f - 0.0625f / 3), 1 - rect.Z1 / 16f)
                               .RotateX(90 * GameMath.DEG2RAD)
                               .Scale(0.5f * rect.Width / 16f, 0.5f * rect.Length / 16f, 0.5f)
                               .Translate(-1, -1, 0)
                               .Values
            ;

            prog.ViewMatrix       = rpi.CameraMatrixOriginf;
            prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;

            rpi.RenderMesh(quadModelRefs[voxelY]);

            prog.Stop();

            rpi.GlEnableCullFace();
        }
示例#3
0
        public void MsgHandler(NetIncomingMessage msg)
        {
            var code = msg.ReadInt32();

            switch (code)
            {
            case 1:
                var c = msg.ReadString();
                //Console.WriteLine(c);
                map = new Map(70, 50, null);
                map.grid.mapFromString(c);
                Players[LocalName].pos = map.findPPos();
                mapReady = true;
                break;

            case 2:
                var name   = msg.ReadString();
                var x      = msg.ReadInt32();
                var y      = msg.ReadInt32();
                var newPos = new EntityPos(x, y);
                if (Players.ContainsKey(name))
                {
                    Players[name].pos = newPos;
                }
                else
                {
                    Players[name] = new Player(x, y, 100, '@', name);
                }
                break;
            }
        }
示例#4
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (workItemMeshRef == null)
            {
                return;
            }
            if (stage == EnumRenderStage.AfterFinalComposition)
            {
                RenderRecipeOutLine();
                return;
            }

            IRenderAPI           rpi         = api.Render;
            IClientWorldAccessor worldAccess = api.World;
            Vec3d     camPos = worldAccess.Player.Entity.CameraPos;
            EntityPos plrPos = worldAccess.Player.Entity.Pos;

            rpi.GlDisableCullFace();
            IStandardShaderProgram prog = rpi.PreparedStandardShader(pos.X, pos.Y, pos.Z);

            rpi.BindTexture2d(texId);

            prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;
            prog.ViewMatrix       = rpi.CameraMatrixOriginf;
            prog.ModelMatrix      = ModelMat.Identity().Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z).Values;

            rpi.RenderMesh(workItemMeshRef);

            prog.Stop();
        }
        private void IsColliding(EntityPos pos, double impactSpeed)
        {
            pos.Motion.Set(0, 0, 0);

            if (!beforeCollided && World is IServerWorldAccessor && World.ElapsedMilliseconds > msCollide + 500)
            {
                if (impactSpeed >= 0.07)
                {
                    World.PlaySoundAt(new AssetLocation("sounds/arrow-impact"), this, null, false, 32);

                    // Resend position to client
                    WatchedAttributes.MarkAllDirty();

                    if (DamageStackOnImpact)
                    {
                        ProjectileStack.Collectible.DamageItem(World, this, new DummySlot(ProjectileStack));
                    }

                    int leftDurability = ProjectileStack == null ? 1 : ProjectileStack.Attributes.GetInt("durability", 1);
                    if (leftDurability <= 0)
                    {
                        Die();
                    }
                }

                TryAttackEntity(impactSpeed);

                msCollide = World.ElapsedMilliseconds;

                beforeCollided = true;
            }
        }
示例#6
0
        public override void DoApply(float dt, Entity entity, EntityPos pos, EntityControls controls)
        {
            if (controls.IsFlying)
            {
                pos.Motion.Add(controls.FlyVector.X, (controls.Up || controls.Down) ? 0 : controls.FlyVector.Y, controls.FlyVector.Z);

                float moveSpeed = dt * GlobalConstants.BaseMoveSpeed * controls.MovespeedMultiplier / 2;

                pos.Motion.Add(0, (controls.Up ? moveSpeed : 0) + (controls.Down ? -moveSpeed : 0), 0);
            }
            else
            {
                if (controls.IsClimbing)
                {
                    pos.Motion.Add(controls.WalkVector);
                    pos.Motion.X *= (1 - wallDragFactor);
                    pos.Motion.Y *= (1 - wallDragFactor);
                    pos.Motion.Z *= (1 - wallDragFactor);
                }
                else
                {
                    pos.Motion.Add(controls.WalkVector.X * airMovingStrength, controls.WalkVector.Y * airMovingStrength, controls.WalkVector.Z * airMovingStrength);
                }
            }
        }
示例#7
0
        private void RenderRecipeOutLine()
        {
            if (recipeOutlineMeshRef == null || api.HideGuis)
            {
                return;
            }
            IRenderAPI           rpi         = api.Render;
            IClientWorldAccessor worldAccess = api.World;
            EntityPos            plrPos      = worldAccess.Player.Entity.Pos;
            Vec3d camPos = worldAccess.Player.Entity.CameraPos;

            ModelMat.Set(rpi.CameraMatrixOriginf).Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z);
            outLineColorMul.A = 1 - GameMath.Clamp((float)Math.Sqrt(plrPos.SquareDistanceTo(pos.X, pos.Y, pos.Z)) / 5 - 1f, 0, 1);

            rpi.LineWidth = 2;
            rpi.GLEnableDepthTest();
            rpi.GlToggleBlend(true);

            IShaderProgram prog = rpi.GetEngineShader(EnumShaderProgram.Wireframe);

            prog.Use();
            prog.UniformMatrix("projectionMatrix", rpi.CurrentProjectionMatrix);
            prog.UniformMatrix("modelViewMatrix", ModelMat.Values);
            prog.Uniform("colorIn", outLineColorMul);
            rpi.RenderMesh(recipeOutlineMeshRef);
            prog.Stop();
        }
        public override void OnCollided()
        {
            EntityPos pos = SidedPos;

            IsColliding(SidedPos, Math.Max(motionBeforeCollide.Length(), pos.Motion.Length()));
            motionBeforeCollide.Set(pos.Motion.X, pos.Motion.Y, pos.Motion.Z);
        }
示例#9
0
        public override void DoApply(float dt, Entity entity, EntityPos pos, EntityControls controls)
        {
            if (controls.IsFlying)
            {
                pos.Motion.Add(controls.FlyVector.X, (controls.Up || controls.Down) ? 0 : controls.FlyVector.Y, controls.FlyVector.Z);

                float moveSpeed = dt * GlobalConstants.BaseMoveSpeed * controls.MovespeedMultiplier / 2;

                pos.Motion.Add(0, (controls.Up ? moveSpeed : 0) + (controls.Down ? -moveSpeed : 0), 0);
            }
            else
            {
                if (controls.IsClimbing)
                {
                    pos.Motion.Add(controls.WalkVector);
                    pos.Motion.X *= System.Math.Pow(1 - wallDragFactor, dt * 60);
                    pos.Motion.Y *= System.Math.Pow(1 - wallDragFactor, dt * 60);
                    pos.Motion.Z *= System.Math.Pow(1 - wallDragFactor, dt * 60);
                }
                else
                {
                    float strength = airMovingStrength * (float)System.Math.Min(1, entity.Stats?.GetBlended("walkspeed") ?? 1.0) * dt * 60f;

                    if (!controls.Jump && entity is EntityPlayer)
                    {
                        strength      = airMovingStrengthFalling;
                        pos.Motion.X *= (float)System.Math.Pow(0.98f, dt * 33);
                        pos.Motion.Z *= (float)System.Math.Pow(0.98f, dt * 33);
                    }

                    pos.Motion.Add(controls.WalkVector.X * strength, controls.WalkVector.Y * strength, controls.WalkVector.Z * strength);
                }
            }
        }
示例#10
0
        void TreeLineup(IServerPlayer player, CmdArgs arguments)
        {
            if (arguments.Length < 2)
            {
                player.SendMessage(groupId, "/wgen treelineup {treeWorldPropertyCode} [0.1 - 3]", EnumChatType.CommandError);
                return;
            }

            EntityPos      pos           = player.Entity.Pos;
            BlockPos       center        = pos.HorizontalAheadCopy(25).AsBlockPos;
            IBlockAccessor blockAccessor = api.WorldManager.GetBlockAccessorBulkUpdate(true, true, true);

            int size = 12;

            for (int dx = -2 * size; dx < 2 * size; dx++)
            {
                for (int dz = -size; dz < size; dz++)
                {
                    for (int dy = 0; dy < 2 * size; dy++)
                    {
                        blockAccessor.SetBlock(0, center.AddCopy(dx, dy, dz));
                    }
                }
            }


            treeGenerators.ReloadTreeGenerators();
            treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, center.AddCopy(0, -1, 0));
            treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, center.AddCopy(-9, -1, 0));
            treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, center.AddCopy(9, -1, 0));

            blockAccessor.Commit();
        }
示例#11
0
        private void IsColliding(EntityPos pos, double impactSpeed)
        {
            pos.Motion.Set(0, 0, 0);

            if (!beforeCollided && World is IServerWorldAccessor && World.ElapsedMilliseconds > msCollide + 500)
            {
                if (impactSpeed >= 0.07)
                {
                    World.PlaySoundAt(new AssetLocation("sounds/arrow-impact"), this, null, false, 32);

                    // Slighty randomize orientation to make it a bit more realistic
                    //pos.Yaw += (float)(World.Rand.NextDouble() * 0.05 - 0.025);
                    //pos.Roll += (float)(World.Rand.NextDouble() * 0.05 - 0.025);

                    // Resend position to client
                    WatchedAttributes.MarkAllDirty();

                    int leftDurability = ProjectileStack == null ? 1 : ProjectileStack.Attributes.GetInt("durability", 1);
                    if (leftDurability <= 0)
                    {
                        Die();
                    }
                }

                TryAttackEntity(impactSpeed);

                msCollide = World.ElapsedMilliseconds;

                beforeCollided = true;
            }
        }
        public override void OnGameTick(float deltaTime)
        {
            if (entity.State == EnumEntityState.Inactive)
            {
                return;
            }

            Vec3d pos = entity.LocalPos.XYZ;

            pushVector.Set(0, 0, 0);
            Vec3d p = new Vec3d();

            entity.World.GetEntitiesAround(pos, 10, 5, (e) => {
                EntityPos epos    = e.LocalPos;
                double distanceSq = epos.SquareDistanceTo(pos);

                if (e != entity && distanceSq < touchDistance * touchDistance && e.HasBehavior("repulseagents") && e.IsInteractable)
                {
                    p.Set(pos.X - epos.X, pos.Y - epos.Y, pos.Z - epos.Z);
                    p.Normalize().Mul(1 - GameMath.Sqrt(distanceSq) / touchDistance);
                    pushVector.Add(p.X, p.Y, p.Z);
                }

                return(false);
            });


            pushVector.X = GameMath.Clamp(pushVector.X, -3, 3);
            pushVector.Y = GameMath.Clamp(pushVector.Y, -3, 3);
            pushVector.Z = GameMath.Clamp(pushVector.Z, -3, 3);
            entity.LocalPos.Motion.Add(pushVector.X / 15, pushVector.Y / 30, pushVector.Z / 15);

            entity.World.FrameProfiler.Mark("entity-repulse");
        }
示例#13
0
        public override void OnGameTick(float dt)
        {
            base.OnGameTick(dt);
            if (ShouldDespawn)
            {
                return;
            }

            EntityPos pos = SidedPos;

            stuck = Collided || collTester.IsColliding(World.BlockAccessor, collisionTestBox, pos.XYZ);

            double impactSpeed = Math.Max(motionBeforeCollide.Length(), pos.Motion.Length());

            if (stuck)
            {
                IsColliding(pos, impactSpeed);
                return;
            }

            if (TryAttackEntity(impactSpeed))
            {
                return;
            }

            beforeCollided = false;
            motionBeforeCollide.Set(pos.Motion.X, pos.Motion.Y, pos.Motion.Z);
            SetRotation();
        }
示例#14
0
        public override void DoApply(float dt, Entity entity, EntityPos pos, EntityControls controls)
        {
            Block belowBlock = entity.World.BlockAccessor.GetBlock((int)pos.X, (int)(pos.Y - 0.05f), (int)pos.Z);

            if (!entity.Swimming && entity.Alive)
            {
                double multiplier = (entity as EntityAgent).GetWalkSpeedMultiplier(groundDragFactor);

                motionDelta.Set(
                    motionDelta.X + (controls.WalkVector.X * multiplier - motionDelta.X) * belowBlock.DragMultiplier,
                    0,
                    motionDelta.Z + (controls.WalkVector.Z * multiplier - motionDelta.Z) * belowBlock.DragMultiplier
                    );

                pos.Motion.Add(motionDelta.X, 0, motionDelta.Z);
            }

            if (controls.Jump && entity.World.ElapsedMilliseconds - lastJump > 500 && entity.Alive && !entity.Swimming)
            {
                lastJump = entity.World.ElapsedMilliseconds;

                pos.Motion.Y = GlobalConstants.BaseJumpForce * dt;
                EntityPlayer entityPlayer = entity as EntityPlayer;
                IPlayer      player       = entityPlayer != null?entityPlayer.World.PlayerByUid(entityPlayer.PlayerUID) : null;

                entity.PlayEntitySound("jump", player, false);
            }

            if (!entity.Swimming)
            {
                pos.Motion.X *= (1 - groundDragFactor);
                pos.Motion.Z *= (1 - groundDragFactor);
            }
        }
示例#15
0
        // Return true if we have further to go, false otherwise.
        public Result LandAt(Vec3d p)
        {
            float distance = (float)VecDistance(entity.ServerPos.XYZ, p);

            // Come in a little high, and then go down to land the last bit.
            if (distance > 1)
            {
                p = new Vec3d(p.X, p.Y + 0.2, p.Z);
            }
            else if (distance < arrivalDistance)
            {
                // We've arrived!
                entity.Controls.FlyVector.Set(0, 0, 0);
                if (previousPos != null && entity.ServerPos.BasicallySameAs(previousPos))
                {
                    previousPos = null;
                    return(Result.Complete);
                }
                else
                {
                    previousPos = entity.ServerPos.Copy();
                    return(Result.Incomplete);
                }
            }

            return(FlyTowards(p, true));
        }
示例#16
0
        private void WalkEntity(Entity e)
        {
            double    hisTouchDistance = (e.CollisionBox.X2 - e.CollisionBox.X1) / 2;
            EntityPos epos             = e.LocalPos;

            hisPos.Set(
                epos.X + (e.CollisionBox.X2 - e.OriginCollisionBox.X2),
                epos.Y + (e.CollisionBox.Y2 - e.OriginCollisionBox.Y2),
                epos.Z + (e.CollisionBox.Z2 - e.OriginCollisionBox.Z2)
                );

            double centerToCenterDistance = GameMath.Sqrt(hisPos.SquareDistanceTo(ownPos));

            if (e != entity && centerToCenterDistance < ownTouchDistance + hisTouchDistance && e.HasBehavior("repulseagents") && e.IsInteractable)
            {
                tmppos.Set(ownPos.X - hisPos.X, ownPos.Y - hisPos.Y, ownPos.Z - hisPos.Z);
                tmppos.Normalize().Mul(1 - centerToCenterDistance / (ownTouchDistance + hisTouchDistance));

                float hisSize  = e.CollisionBox.Length * e.CollisionBox.Height;
                float mySize   = entity.CollisionBox.Length * entity.CollisionBox.Height;
                float pushDiff = GameMath.Clamp(hisSize / mySize, 0, 1);

                pushVector.Add(tmppos.X * pushDiff, tmppos.Y * pushDiff, tmppos.Z * pushDiff);
            }
        }
示例#17
0
 internal int BlockInsidePlayer(EntityPos pos)
 {
     return(World.BlockAccessor.GetBlockId(
                (int)pos.X,
                (int)(pos.Y + 0.1f),
                (int)pos.Z));
 }
        public override bool ContinueExecute(float dt)
        {
            EntityPos own = entity.ServerPos;
            EntityPos his = targetEntity.ServerPos;

            float desiredYaw = (float)Math.Atan2(his.X - own.X, his.Z - own.Z);
            float yawDist    = GameMath.AngleRadDistance(entity.ServerPos.Yaw, desiredYaw);

            entity.ServerPos.Yaw += GameMath.Clamp(yawDist, -curTurnRadPerSec * dt * GlobalConstants.OverallSpeedMultiplier, curTurnRadPerSec * dt * GlobalConstants.OverallSpeedMultiplier);
            entity.ServerPos.Yaw  = entity.ServerPos.Yaw % GameMath.TWOPI;


            if (lastCheckOrAttackMs + damagePlayerAtMs > entity.World.ElapsedMilliseconds)
            {
                return(true);
            }

            if (!damageInflicted)
            {
                if (!hasDirectContact(targetEntity))
                {
                    return(false);
                }

                bool alive = targetEntity.Alive;

                entity.GetBehavior <EntityBehaviorProgram>()?.ConsumeEnergy(25);

                if (entity.LeftHandItemSlot.Itemstack?.Collectible.Tool != null)
                {
                    damage     = entity.LeftHandItemSlot.Itemstack.Collectible.GetAttackPower(entity.LeftHandItemSlot.Itemstack);
                    damageTier = entity.LeftHandItemSlot.Itemstack.Collectible.ToolTier;
                }

                ((EntityAgent)targetEntity).ReceiveDamage(
                    new DamageSource()
                {
                    Source       = EnumDamageSource.Entity,
                    SourceEntity = prog.owner?.Entity != null ? prog.owner?.Entity : entity,
                    Type         = damageType,
                    DamageTier   = damageTier
                },
                    damage
                    );

                if (alive && !targetEntity.Alive)
                {
                    this.entity.GetBehavior <EntityBehaviorEmotionStates>()?.TryTriggerState("saturated");
                }

                damageInflicted = true;
            }

            if (lastCheckOrAttackMs + attackDurationMs > entity.World.ElapsedMilliseconds)
            {
                return(true);
            }
            return(false);
        }
        public override bool ContinueExecute(float dt)
        {
            EntityPos own = entity.ServerPos;
            EntityPos his = targetEntity.ServerPos;

            float desiredYaw = (float)Math.Atan2(his.X - own.X, his.Z - own.Z);
            float yawDist    = GameMath.AngleRadDistance(entity.ServerPos.Yaw, desiredYaw);

            entity.ServerPos.Yaw += GameMath.Clamp(yawDist, -curTurnRadPerSec * dt * GlobalConstants.OverallSpeedMultiplier, curTurnRadPerSec * dt * GlobalConstants.OverallSpeedMultiplier);
            entity.ServerPos.Yaw  = entity.ServerPos.Yaw % GameMath.TWOPI;

            bool correctYaw = Math.Abs(yawDist) < 20 * GameMath.DEG2RAD;

            if (correctYaw && !didStartAnim)
            {
                didStartAnim = true;
                base.StartExecute();
            }

            if (lastCheckOrAttackMs + damagePlayerAtMs > entity.World.ElapsedMilliseconds)
            {
                return(true);
            }

            if (!damageInflicted && correctYaw)
            {
                if (!hasDirectContact(targetEntity, minDist, minVerDist))
                {
                    return(false);
                }

                bool alive = targetEntity.Alive;

                targetEntity.ReceiveDamage(
                    new DamageSource()
                {
                    Source            = EnumDamageSource.Entity,
                    SourceEntity      = entity,
                    Type              = damageType,
                    DamageTier        = damageTier,
                    KnockbackStrength = knockbackStrength
                },
                    damage * GlobalConstants.CreatureDamageModifier
                    );

                if (alive && !targetEntity.Alive)
                {
                    bhEmo?.TryTriggerState("saturated", targetEntity.EntityId);
                }

                damageInflicted = true;
            }

            if (lastCheckOrAttackMs + attackDurationMs > entity.World.ElapsedMilliseconds)
            {
                return(true);
            }
            return(false);
        }
示例#20
0
 public override bool Applicable(Entity entity, EntityPos pos, EntityControls controls)
 {
     return
         ((!controls.IsFlying && entity.Properties.Habitat != EnumHabitat.Air) &&
          (entity.Properties.Habitat != EnumHabitat.Sea || !entity.Swimming) &&
          !controls.IsClimbing
         );
 }
示例#21
0
 public string Fmt(EntityPos p)
 {
     if (p == null)
     {
         return("(null)");
     }
     return($"(XYZ={p.X:F2}/{p.Y:F2}/{p.Z:F2} YPR={p.Yaw:F2}/{p.Pitch:F2}/{p.Roll:F2})");
 }
示例#22
0
        internal int BlockUnderPlayer()
        {
            EntityPos pos = SidedPos;

            return(World.BlockAccessor.GetBlockId(
                       (int)pos.X,
                       (int)(pos.Y - 0.1f),
                       (int)pos.Z));
        }
示例#23
0
        public void TickEntityPhysics(EntityPos pos, EntityControls controls, float dt)
        {
            IBlockAccessor blockAccessor = entity.World.BlockAccessor;

            foreach (EntityLocomotion locomotor in Locomotors)
            {
                if (locomotor.Applicable(entity, pos, controls))
                {
                    locomotor.Apply(dt, entity, pos, controls);
                }
            }

            EntityAgent agent = entity as EntityAgent;

            if (agent?.MountedOn != null)
            {
                pos.SetFrom(agent.MountedOn.MountPosition);
                pos.Motion.X = 0;
                pos.Motion.Y = 0;
                pos.Motion.Z = 0;
                return;
            }


            pos.Motion.X = GameMath.Clamp(pos.Motion.X, -10, 10);
            pos.Motion.Y = GameMath.Clamp(pos.Motion.Y, -10, 10);
            pos.Motion.Z = GameMath.Clamp(pos.Motion.Z, -10, 10);

            if (!controls.NoClip)
            {
                DisplaceWithBlockCollision(pos, controls, dt);
            }
            else
            {
                pos.X += pos.Motion.X;
                pos.Y += pos.Motion.Y;
                pos.Z += pos.Motion.Z;

                entity.Swimming     = false;
                entity.FeetInLiquid = false;
                entity.OnGround     = false;
            }



            // Shake the player violently when falling at high speeds

            /*if (movedy < -50)
             * {
             *  pos.X += (rand.NextDouble() - 0.5) / 5 * (-movedy / 50f);
             *  pos.Z += (rand.NextDouble() - 0.5) / 5 * (-movedy / 50f);
             * }
             */

            //return result;
        }
示例#24
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (workItemMeshRef == null)
            {
                return;
            }
            if (stage == EnumRenderStage.AfterFinalComposition)
            {
                RenderRecipeOutLine();
                return;
            }

            IRenderAPI           rpi         = api.Render;
            IClientWorldAccessor worldAccess = api.World;
            Vec3d     camPos = worldAccess.Player.Entity.CameraPos;
            EntityPos plrPos = worldAccess.Player.Entity.Pos;
            int       temp   = (int)ingot.Collectible.GetTemperature(api.World, ingot);

            Vec4f lightrgbs = worldAccess.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);

            float[] glowColor = ColorUtil.GetIncandescenceColorAsColor4f(temp);
            lightrgbs[0] += 2 * glowColor[0];
            lightrgbs[1] += 2 * glowColor[1];
            lightrgbs[2] += 2 * glowColor[2];



            rpi.GlDisableCullFace();

            IStandardShaderProgram prog = rpi.StandardShader;

            prog.Use();
            rpi.BindTexture2d(texId);
            prog.RgbaAmbientIn    = rpi.AmbientColor;
            prog.RgbaFogIn        = rpi.FogColor;
            prog.FogMinIn         = rpi.FogMin;
            prog.DontWarpVertices = 0;
            prog.AddRenderFlags   = 0;
            prog.FogDensityIn     = rpi.FogDensity;
            prog.RgbaTint         = ColorUtil.WhiteArgbVec;
            prog.RgbaLightIn      = lightrgbs;
            prog.RgbaBlockIn      = ColorUtil.WhiteArgbVec;
            prog.ExtraGlow        = GameMath.Clamp((temp - 700) / 2, 0, 255);
            prog.ModelMatrix      = ModelMat
                                    .Identity()
                                    .Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z)
                                    .Values
            ;


            prog.ViewMatrix       = rpi.CameraMatrixOriginf;
            prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;
            rpi.RenderMesh(workItemMeshRef);
            prog.Stop();
        }
        public static EntityPos LookAtTarget(this EntityPos agentPos, Vec3d targetPos)
        {
            var cartesianCoordinates = targetPos.SubCopy(agentPos.XYZ).Normalize();
            var yaw       = GameMath.TWOPI - (float)Math.Atan2(cartesianCoordinates.Z, cartesianCoordinates.X);
            var pitch     = (float)Math.Asin(cartesianCoordinates.Y);
            var entityPos = agentPos.Copy();

            entityPos.Yaw   = yaw % GameMath.TWOPI;
            entityPos.Pitch = GameMath.PI - pitch;
            return(entityPos);
        }
        public bool PlayerInRange()
        {
            if (minPlayerDistanceSquared == null)
            {
                return(false);
            }

            EntityPos    pos    = entity.ServerPos;
            EntityPlayer player = entity.World.NearestPlayer(pos.X, pos.Y, pos.Z)?.Entity;

            return(player != null && player.ServerPos.SquareDistanceTo(pos.X, pos.Y, pos.Z) < minPlayerDistanceSquared);
        }
        public bool LightLevelOk()
        {
            if (belowLightLevel == null)
            {
                return(false);
            }

            EntityPos pos   = entity.ServerPos;
            int       level = entity.World.BlockAccessor.GetLightLevel((int)pos.X, (int)pos.Y, (int)pos.Z, EnumLightLevelType.MaxLight);

            return(level >= belowLightLevel);
        }
示例#28
0
        //-- Fetches the entity type, assigns the entity to an object, sets its position on server and client, then returns the entity object --//
        private Entity InitEntity(string meteorCode, int atPlayer)
        {
            EntityProperties entityType = serverAPI.World.GetEntityType(new AssetLocation("meteoricexpansion", meteorCode));
            Entity           entity     = serverAPI.World.ClassRegistry.CreateEntity(entityType);

            EntityPos entityPos = new EntityPos(serverAPI.World.AllOnlinePlayers[atPlayer].Entity.ServerPos.X + GetSpawnOffset(), serverAPI.WorldManager.MapSizeY - 10, serverAPI.World.AllOnlinePlayers[atPlayer].Entity.ServerPos.Z + GetSpawnOffset());

            entity.ServerPos.SetPos(entityPos);
            entity.Pos.SetFrom(entity.ServerPos);

            return(entity);
        }
示例#29
0
        private void HandleSneaking(EntityPos pos, EntityControls controls, float dt)
        {
            if (!controls.Sneak || !entity.OnGround || pos.Motion.Y > 0)
            {
                return;
            }

            // Sneak to prevent falling off blocks
            Vec3d testPosition = new Vec3d();

            testPosition.Set(pos.X, pos.Y - GlobalConstants.GravityPerSecond * dt, pos.Z);

            // Only apply this if he was on the ground in the first place
            if (!collisionTester.IsColliding(entity.World.BlockAccessor, sneakTestCollisionbox, testPosition))
            {
                return;
            }

            Block belowBlock = entity.World.BlockAccessor.GetBlock((int)pos.X, (int)pos.Y - 1, (int)pos.Z);


            // Test for X
            testPosition.Set(outposition.X, outposition.Y - GlobalConstants.GravityPerSecond * dt, pos.Z);
            if (!collisionTester.IsColliding(entity.World.BlockAccessor, sneakTestCollisionbox, testPosition))
            {
                // Weird hack so you can climb down ladders more easily
                if (belowBlock.Climbable)
                {
                    outposition.X += (pos.X - outposition.X) / 10;
                }
                else
                {
                    outposition.X = pos.X;
                }
            }


            // Test for Z
            testPosition.Set(pos.X, outposition.Y - GlobalConstants.GravityPerSecond * dt, outposition.Z);
            if (!collisionTester.IsColliding(entity.World.BlockAccessor, sneakTestCollisionbox, testPosition))
            {
                // Weird hack so you can climb down ladders more easily
                if (belowBlock.Climbable)
                {
                    outposition.Z += (pos.Z - outposition.Z) / 10;
                }
                else
                {
                    outposition.Z = pos.Z;
                }
            }
        }
示例#30
0
        /// <summary>
        /// Calculates the movement vectors for the player.
        /// </summary>
        /// <param name="pos">The position of the player.</param>
        /// <param name="dt">The change in time.</param>
        public void CalcMovementVectors(EntityPos pos, float dt)
        {
            double moveSpeed = dt * GlobalConstants.BaseMoveSpeed * MovespeedMultiplier * GlobalConstants.OverallSpeedMultiplier;

            double dz = (Forward ? -moveSpeed : 0) + (Backward ? moveSpeed : 0);
            double dx = (Right ? moveSpeed : 0) + (Left ? -moveSpeed : 0);

            if (this.Sitting)
            {
                dz = 0; dx = 0;
            }

            double cosPitch = Math.Cos(pos.Pitch);
            double sinPitch = Math.Sin(pos.Pitch);

            double cosYaw = Math.Cos(Math.PI / 2 - pos.Yaw);
            double sinYaw = Math.Sin(Math.PI / 2 - pos.Yaw);

            WalkVector.Set(
                dx * cosYaw - dz * sinYaw,
                0,
                dx * sinYaw + dz * cosYaw
                );

            if (FlyPlaneLock == EnumFreeMovAxisLock.Y)
            {
                cosPitch = -1;
            }

            FlyVector.Set(
                dx * cosYaw + dz * cosPitch * sinYaw,
                -dz * sinPitch,
                dx * sinYaw - dz * cosPitch * cosYaw
                );

            double normalization = (Forward || Backward) && (Right || Left) ? 1 / Math.Sqrt(2) : 1;

            WalkVector.Mul(normalization);

            if (FlyPlaneLock == EnumFreeMovAxisLock.X)
            {
                FlyVector.X = 0;
            }
            if (FlyPlaneLock == EnumFreeMovAxisLock.Y)
            {
                FlyVector.Y = 0;
            }
            if (FlyPlaneLock == EnumFreeMovAxisLock.Z)
            {
                FlyVector.Z = 0;
            }
        }