private static ModelTransform GetTransform(JsonObject json, ModelTransform baseTransform)
        {
            var trans = baseTransform.Clone();

            if (TryGetVec3f(json, "translation", out var t))
            {
                trans.Translation = t;
            }
            if (TryGetVec3f(json, "rotation", out var r))
            {
                trans.Rotation = r;
            }
            if (TryGetVec3f(json, "origin", out var o))
            {
                trans.Origin = o;
            }
            // Try to get scale both as a Vec3f and single float - for compatibility reasons.
            if (TryGetVec3f(json, "scale", out var sv))
            {
                trans.ScaleXYZ = sv;
            }
            if (TryGetFloat(json, "scale", out var sf))
            {
                trans.ScaleXYZ = new Vec3f(sf, sf, sf);
            }
            return(trans);
        }
示例#2
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null)
            {
                return(false);
            }

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Translation.Set(Math.Min(0.6f, secondsUsed * 2), 0, 0); //-Math.Min(1.1f / 3, secondsUsed * 4 / 3f)
                tf.Rotation.Y = Math.Min(20, secondsUsed * 90 * 2f);

                if (secondsUsed > 0.4f)
                {
                    tf.Translation.X += (float)Math.Sin(secondsUsed * 30) / 10;
                }

                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }

            return(secondsUsed < 2f);
        }
示例#3
0
        public void SetContents(ItemStack newContentStack, ModelTransform transform)
        {
            contentStackRenderer?.Dispose();
            contentStackRenderer = null;

            this.transform = transform;
            if (transform == null)
            {
                this.transform = defaultTransform;
            }
            this.transform.EnsureDefaultValues();

            meshref?.Dispose();
            meshref = null;

            if (newContentStack == null || newContentStack.Class == EnumItemClass.Block)
            {
                this.ContentStack = null;
                return;
            }

            if (newContentStack == null || newContentStack.Class == EnumItemClass.Item)
            {
                this.ContentStack = null;
                return;
            }
            this.ContentStack = newContentStack;
        }
示例#4
0
        public override bool OnHeldAttackStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
        {
            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                //30 - secondsUsed * 90 * 15 = -110
                //-30 + secondsUsed * 90 * 15 = 110
                //secondsUsed * 90 * 15 = 110 - 30
                //secondsUsed = (110 - 30) / (90*15)

                float speed     = 5 + 20 * Math.Max(0, secondsUsed - 0.25f);
                float start     = secondsUsed * 120;
                float rotationY = Math.Min(110, Math.Max(0, secondsUsed - 0.25f) * 90 * speed - start);


                tf.Origin.Set(0, 0, 0.5f);
                tf.Translation.Set(0, 0, Math.Max(-0.25f, -1.25f * Math.Max(0, secondsUsed - 0.25f)));
                tf.Rotation.Y = rotationY;
                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }


            return(secondsUsed < 0.6f);
        }
示例#5
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            int renderVariant     = GameMath.Clamp((int)Math.Ceiling(secondsUsed * 4), 0, 3);
            int prevRenderVariant = slot.Itemstack.Attributes.GetInt("renderVariant", 0);

            slot.Itemstack.TempAttributes.SetInt("renderVariant", renderVariant);
            slot.Itemstack.Attributes.SetInt("renderVariant", renderVariant);

            if (prevRenderVariant != renderVariant)
            {
                (byEntity as EntityPlayer)?.Player?.InventoryManager.BroadcastHotbarSlot();
            }

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                float rot = (float)Math.Max(0, secondsUsed) * GameMath.TWOPI * 85;
                tf.Rotation.Set(rot, 0, 0);
                byEntity.Controls.UsingHeldItemTransformAfter = tf;
            }

            return(true);
        }
        virtual internal void OnDeserialized()
        {
            GuiTransform.EnsureDefaultValues();
            FpHandTransform.EnsureDefaultValues();
            TpHandTransform.EnsureDefaultValues();

            if (TpOffHandTransform == null)
            {
                TpOffHandTransform = TpHandTransform.Clone();
            }
            TpOffHandTransform.EnsureDefaultValues();
            GroundTransform.EnsureDefaultValues();

            if (Texture != null)
            {
                if (Textures == null)
                {
                    Textures = new Dictionary <string, CompositeTexture>(1);
                }
                Textures["all"] = Texture;
            }

            if (HeldOldTpIdleAnimation != null && HeldRightTpIdleAnimation == null)
            {
                HeldRightTpIdleAnimation = HeldOldTpIdleAnimation;
            }
        }
示例#7
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            Vec3d pos = byEntity.Pos.AheadCopy(0.4f).XYZ.Add(byEntity.LocalEyePos);

            pos.Y -= 0.4f;

            IPlayer player = (byEntity as EntityPlayer).Player;


            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.Origin.Set(1.1f, 0.5f, 0.5f);
                tf.EnsureDefaultValues();

                tf.Translation.X -= Math.Min(1.7f, secondsUsed * 4 * 1.8f) / FpHandTransform.ScaleXYZ.X;
                tf.Translation.Y += Math.Min(0.4f, secondsUsed * 1.8f) / FpHandTransform.ScaleXYZ.X;
                tf.Scale          = 1 + Math.Min(0.5f, secondsUsed * 4 * 1.8f) / FpHandTransform.ScaleXYZ.X;
                tf.Rotation.X    += Math.Min(40f, secondsUsed * 350 * 0.75f) / FpHandTransform.ScaleXYZ.X;

                if (secondsUsed > 0.5f)
                {
                    tf.Translation.Y += GameMath.Sin(30 * secondsUsed) / 10 / FpHandTransform.ScaleXYZ.Y;
                }

                byEntity.Controls.UsingHeldItemTransformBefore = tf;


                return(secondsUsed <= 1.5f);
            }
            return(true);
        }
示例#8
0
        public static void Write(this Stream IO, ModelTransform MT,
                                 string Temp, bool A3DC, bool IsX = false, byte Flags = 0b11111)
        {
            if (A3DC && !MT.Writed && (Flags & 0b10000) == 0b10000)
            {
                IO.Write(Temp + MTBO + "=", MT.BinOffset); MT.Writed = true;
            }

            if (A3DC)
            {
                return;
            }

            if ((Flags & 0b01000) == 0b01000)
            {
                IO.Write(MT.Rot, Temp + "rot" + d, A3DC);
            }
            if ((Flags & 0b00100) == 0b00100)
            {
                IO.Write(MT.Scale, Temp + "scale" + d, A3DC);
            }
            if ((Flags & 0b00010) == 0b00010)
            {
                IO.Write(MT.Trans, Temp + "trans" + d, A3DC);
            }
            if ((Flags & 0b00001) == 0b00001)
            {
                IO.Write(MT.Visibility, Temp + "visibility" + d, A3DC);
            }
        }
示例#9
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            EntityBehaviorHarvestable bh;

            if (entitySel != null && (bh = entitySel.Entity.GetBehavior <EntityBehaviorHarvestable>()) != null)
            {
                if (bh.IsHarvested)
                {
                    return(false);
                }

                if (byEntity.World.Side == EnumAppSide.Client)
                {
                    ModelTransform tf = new ModelTransform();
                    tf.EnsureDefaultValues();

                    tf.Translation.Set(0, 0, Math.Min(0.6f, secondsUsed * 2));
                    tf.Rotation.Y = Math.Min(20, secondsUsed * 90 * 2f);

                    if (secondsUsed > 0.4f)
                    {
                        tf.Translation.X += (float)Math.Cos(secondsUsed * 15) / 10;
                        tf.Translation.Z += (float)Math.Sin(secondsUsed * 5) / 30;
                    }

                    byEntity.Controls.UsingHeldItemTransformBefore = tf;
                }



                return(secondsUsed < bh.HarvestDuration + 0.15f);
            }

            return(false);
        }
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Origin.Set(0, -0.1f, 0);
                tf.Rotation.Z = Math.Min(30, secondsUsed * 40);
                byEntity.Controls.UsingHeldItemTransformAfter = tf;

                if (secondsUsed > 0.6)
                {
                    Vec3d pos =
                        byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0)
                        .Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)
                    ;

                    Vec3f speedVec = new Vec3d(0, 0, 0).Ahead(5, byEntity.Pos.Pitch, byEntity.Pos.Yaw).ToVec3f();
                    particles.MinVelocity = speedVec;
                    Random rand = new Random();
                    particles.Color  = ColorUtil.ToRgba(255, 176, 176, 176);
                    particles.MinPos = pos.AddCopy(-0.05, -0.05, -0.05);
                    particles.AddPos.Set(0.1, 0.1, 0.1);
                    particles.MinSize    = 0.1F;
                    particles.MaxSize    = 0.5f;
                    particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.QUADRATIC, 1);
                    byEntity.World.SpawnParticles(particles);
                }
            }
            return(true);
        }
示例#11
0
        protected override MeshData genMesh(ItemStack stack, int index)
        {
            BlockCrock crockblock = stack.Collectible as BlockCrock;
            BlockMeal  mealblock  = stack.Collectible as BlockMeal;
            MeshData   mesh;

            if (crockblock != null)
            {
                Vec3f rot = new Vec3f(0, block.Shape.rotateY, 0);
                mesh = BlockEntityCrock.GetMesh(capi.Tesselator, Api, crockblock, crockblock.GetContents(Api.World, stack), crockblock.GetRecipeCode(Api.World, stack), rot).Clone();
            }
            else if (mealblock != null)
            {
                ICoreClientAPI capi      = Api as ICoreClientAPI;
                MealMeshCache  meshCache = capi.ModLoader.GetModSystem <MealMeshCache>();
                mesh = meshCache.GenMealInContainerMesh(mealblock, mealblock.GetCookingRecipe(capi.World, stack), mealblock.GetNonEmptyContents(capi.World, stack));
            }
            else
            {
                ICoreClientAPI capi = Api as ICoreClientAPI;
                if (stack.Class == EnumItemClass.Block)
                {
                    mesh = capi.TesselatorManager.GetDefaultBlockMesh(stack.Block).Clone();
                }
                else
                {
                    nowTesselatingItem  = stack.Item;
                    nowTesselatingShape = capi.TesselatorManager.GetCachedShape(stack.Item.Shape.Base);
                    capi.Tesselator.TesselateItem(stack.Item, out mesh, this);

                    mesh.RenderPasses.Fill((short)EnumChunkRenderPass.BlendNoCull);
                }
            }

            if (stack.Collectible.Attributes?["onDisplayTransform"].Exists == true)
            {
                ModelTransform transform = stack.Collectible.Attributes?["onDisplayTransform"].AsObject <ModelTransform>();
                transform.EnsureDefaultValues();
                mesh.ModelTransform(transform);
            }


            if (stack.Class == EnumItemClass.Item && (stack.Item.Shape == null || stack.Item.Shape.VoxelizeTexture))
            {
                mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), GameMath.PIHALF, 0, 0);
                mesh.Scale(new Vec3f(0.5f, 0.5f, 0.5f), 0.33f, 0.5f, 0.33f);
                mesh.Translate(0, -7.5f / 16f, 0f);
            }


            float x = ((index % 4) >= 2) ? 12 / 16f : 4 / 16f;
            float y = index >= 4 ? 10 / 16f : 2 / 16f;
            float z = (index % 2 == 0) ? 4 / 16f : 10 / 16f;

            Vec4f offset = mat.TransformVector(new Vec4f(x - 0.5f, y, z - 0.5f, 0));

            mesh.Translate(offset.XYZ);

            return(mesh);
        }
示例#12
0
        public override bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
        {
            if (byEntity.World.Side == EnumAppSide.Client)
            {
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;
                ModelTransform       tf    = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Rotation.X = Math.Min(60, secondsPassed * 360);
                if (secondsPassed > 0.3)
                {
                    tf.Translation.Z -= Math.Min(1.5f, 36f * (secondsPassed - 0.3f));
                    tf.Rotation.X    -= Math.Max(-40, secondsPassed * 500);
                }


                byEntity.Controls.UsingHeldItemTransformAfter = tf;

                if (secondsPassed > 0.43f && byEntity.Attributes.GetInt("didattack") == 0)
                {
                    world.TryAttackEntity(entitySel);
                    byEntity.Attributes.SetInt("didattack", 1);
                    world.AddCameraShake(0.25f);
                }
            }

            return(secondsPassed < 0.9f);
        }
示例#13
0
 public ItemType()
 {
     Class           = "Item";
     GuiTransform    = ModelTransform.ItemDefaultGui();
     FpHandTransform = ModelTransform.ItemDefaultFp();
     TpHandTransform = ModelTransform.ItemDefaultTp();
     GroundTransform = ModelTransform.ItemDefaultGround();
 }
示例#14
0
 public void OnAtk(EquipmentAttribute model, HexCell TargetCell)
 {
     //int[] _damage = model.GetDamage(DataModel.dataModel.baseAttribute);
     //DamageMessage damage = new DamageMessage(this, _damage, ResistanceEnum.none, null, null);
     //TargetCell.unit.Damage(damage);
     weapot.AtkTarget(model, TargetCell);
     ModelTransform.LookAt(TargetCell.transform);
     animation.SetTrigger(AnimatorManager.Attack);
 }
示例#15
0
        public static ModelTransform Transform()
        {
            ModelTransform tf = new ModelTransform();

            tf.EnsureDefaultValues();
            tf.Origin.Set(0f, 0f, 0f);
            tf.Translation.Set(0f, 0f, 0f);

            return(tf);
        }
示例#16
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandling handling)
        {
            if (blockSel == null)
            {
                return(false);
            }

            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                return(false);
            }


            Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);

            EnumHandling igniteHandled = EnumHandling.PassThrough;
            bool         handledResult = block.OnTryIgniteBlock(byEntity, blockSel.Position, secondsUsed, ref igniteHandled);

            if (igniteHandled == EnumHandling.PassThrough && !byEntity.Controls.Sneak)
            {
                return(false);
            }

            handling = EnumHandling.PreventDefault;

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Translation.Set(0, -Math.Min(1.1f / 3, secondsUsed * 4 / 3f), -Math.Min(1.1f, secondsUsed * 4));
                tf.Rotation.X = -Math.Min(85, secondsUsed * 90 * 4f);
                byEntity.Controls.UsingHeldItemTransformBefore = tf;


                if (igniteHandled == EnumHandling.PassThrough && secondsUsed > 0.25f && (int)(30 * secondsUsed) % 2 == 1)
                {
                    Vec3d pos = BlockEntityFire.RandomBlockPos(byEntity.World.BlockAccessor, blockSel.Position, block, blockSel.Face);

                    Block blockFire = byEntity.World.GetBlock(new AssetLocation("fire"));

                    AdvancedParticleProperties props = blockFire.ParticleProperties[blockFire.ParticleProperties.Length - 1];
                    props.basePos      = pos;
                    props.Quantity.avg = 1;

                    byEntity.World.SpawnParticles(props, byPlayer);

                    props.Quantity.avg = 0;
                }
            }

            return(igniteHandled != EnumHandling.PassThrough ? handledResult : secondsUsed <= 3.1);
        }
示例#17
0
        public static ModelTransform ReadMT(this Dictionary <string, object> Dict, string Temp)
        {
            ModelTransform MT = new ModelTransform();

            Dict.FindValue(out MT.BinOffset, Temp + MTBO);

            MT.Rot        = Dict.ReadVec3(Temp + "rot" + d);
            MT.Scale      = Dict.ReadVec3(Temp + "scale" + d);
            MT.Trans      = Dict.ReadVec3(Temp + "trans" + d);
            MT.Visibility = Dict.ReadKey(Temp + "visibility" + d);
            return(MT);
        }
        protected virtual MeshData genMesh(ItemStack stack)
        {
            MeshData mesh;
            var      dynBlock = stack.Collectible as IContainedMeshSource;

            if (dynBlock != null)
            {
                mesh = dynBlock.GenMesh(stack, capi.BlockTextureAtlas, Pos);
                mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), 0, Block.Shape.rotateY * GameMath.DEG2RAD, 0);
            }
            else
            {
                ICoreClientAPI capi = Api as ICoreClientAPI;
                if (stack.Class == EnumItemClass.Block)
                {
                    mesh = capi.TesselatorManager.GetDefaultBlockMesh(stack.Block).Clone();
                }
                else
                {
                    nowTesselatingObj   = stack.Collectible;
                    nowTesselatingShape = null;
                    if (stack.Item.Shape != null)
                    {
                        nowTesselatingShape = capi.TesselatorManager.GetCachedShape(stack.Item.Shape.Base);
                    }
                    capi.Tesselator.TesselateItem(stack.Item, out mesh, this);

                    mesh.RenderPassesAndExtraBits.Fill((short)EnumChunkRenderPass.BlendNoCull);
                }
            }

            if (stack.Collectible.Attributes?[AttributeTransformCode].Exists == true)
            {
                ModelTransform transform = stack.Collectible.Attributes?[AttributeTransformCode].AsObject <ModelTransform>();
                transform.EnsureDefaultValues();
                mesh.ModelTransform(transform);

                transform.Rotation.X = 0;
                transform.Rotation.Y = Block.Shape.rotateY;
                transform.Rotation.Z = 0;
                mesh.ModelTransform(transform);
            }

            if (stack.Class == EnumItemClass.Item && (stack.Item.Shape == null || stack.Item.Shape.VoxelizeTexture))
            {
                mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), GameMath.PIHALF, 0, 0);
                mesh.Scale(new Vec3f(0.5f, 0.5f, 0.5f), 0.33f, 0.5f, 0.33f);
                mesh.Translate(0, -7.5f / 16f, 0f);
            }

            return(mesh);
        }
示例#19
0
 public BlockType()
 {
     Class = "Block";
     Shape = new CompositeShape()
     {
         Base = new AssetLocation("game", "block/basic/cube")
     };
     GuiTransform    = ModelTransform.BlockDefaultGui();
     FpHandTransform = ModelTransform.BlockDefaultFp();
     TpHandTransform = ModelTransform.BlockDefaultTp();
     GroundTransform = ModelTransform.BlockDefaultGround();
     MaxStackSize    = 64;
 }
示例#20
0
        public static bool Hit(EntityAgent byEntity, float secondsUsed)
        {
            if (byEntity.World.Side.IsClient())
            {
                ModelTransform tf = Transform();

                tf.Rotation.X -= (float)Math.Sin(secondsUsed * 6) * 90;

                byEntity.Controls.UsingHeldItemTransformAfter = tf;
                return(tf.Rotation.X > -80);
            }
            return(true);
        }
示例#21
0
 public BlockType()
 {
     Class = "Block";
     Shape = new CompositeShape()
     {
         Base = new AssetLocation(GlobalConstants.DefaultDomain, "block/basic/cube")
     };
     GuiTransform       = ModelTransform.BlockDefaultGui();
     FpHandTransform    = ModelTransform.BlockDefaultFp();
     TpHandTransform    = ModelTransform.BlockDefaultTp();
     TpOffHandTransform = null;
     GroundTransform    = ModelTransform.BlockDefaultGround();
     MaxStackSize       = 64;
 }
示例#22
0
        public static bool Collect(EntityAgent byEntity, float secondsUsed)
        {
            if (byEntity.World.Side.IsClient())
            {
                ModelTransform tf    = Transform();
                float          scale = ((float)Math.Sin(secondsUsed * 2) * 0.5f);
                tf.ScaleXYZ.Add(-scale, -scale, -scale);
                tf.Translation.Z -= (scale * 2);
                byEntity.Controls.UsingHeldItemTransformBefore = tf;

                return(scale > 0.0);
            }
            return(true);
        }
示例#23
0
        /// <summary>
        /// Called every frame while the player is using this collectible. Return false to stop the interaction.
        /// </summary>
        /// <param name="secondsUsed"></param>
        /// <param name="slot"></param>
        /// <param name="byEntity"></param>
        /// <param name="blockSel"></param>
        /// <param name="entitySel"></param>
        /// <returns>False if the interaction should be stopped. True if the interaction should continue</returns>
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (GetContentNutritionProperties(byEntity.World, slot, byEntity) == null)
            {
                return(false);
            }

            Vec3d pos = byEntity.Pos.AheadCopy(0.4f).XYZ.Add(byEntity.LocalEyePos);

            pos.Y -= 0.4f;

            IPlayer player = (byEntity as EntityPlayer).Player;

            if (secondsUsed > 0.5f && (int)(30 * secondsUsed) % 7 == 1)
            {
                ItemStack[] contents = GetNonEmptyContents(byEntity.World, slot.Itemstack);
                if (contents.Length > 0)
                {
                    ItemStack rndStack = contents[byEntity.World.Rand.Next(contents.Length)];
                    byEntity.World.SpawnCubeParticles(pos, rndStack, 0.3f, 4, 1, player);
                }
            }


            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.Origin.Set(1.1f, 0.5f, 0.5f);
                tf.EnsureDefaultValues();

                tf.Translation.X -= Math.Min(1.7f, secondsUsed * 4 * 1.8f) / FpHandTransform.ScaleXYZ.X;
                tf.Translation.Y += Math.Min(0.4f, secondsUsed * 1.8f) / FpHandTransform.ScaleXYZ.X;
                tf.Scale          = 1 + Math.Min(0.5f, secondsUsed * 4 * 1.8f) / FpHandTransform.ScaleXYZ.X;
                tf.Rotation.X    += Math.Min(40f, secondsUsed * 350 * 0.75f) / FpHandTransform.ScaleXYZ.X;

                if (secondsUsed > 0.5f)
                {
                    tf.Translation.Y += GameMath.Sin(30 * secondsUsed) / 10 / FpHandTransform.ScaleXYZ.Y;
                }

                byEntity.Controls.UsingHeldItemTransformBefore = tf;


                return(secondsUsed <= 1.5f);
            }

            // Let the client decide when he is done eating
            return(true);
        }
示例#24
0
        /// <summary>
        /// Applies a transformation to the points.
        /// </summary>
        /// <param name="t">ModelTransform object.</param>
        public virtual void Transform(ModelTransform t)
        {
            for (int i = 0; i < _points.Count; i++)
            {
                _points[i] = t.Transform(_points[i]);
            }

            for (int j = 0; j < Triangles.Count; j++)
            {
                for (int k = 0; k < 3; k++)
                {
                    Triangles[j].Points[k] = t.Transform(Triangles[j].Points[k]);
                }
            }
        }
示例#25
0
        public LoadedModel(Assimp.Scene source, string dirName)
        {
            MinimumPosition = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            MaximumPosition = new Vector3(float.MinValue, float.MinValue, float.MinValue);
            UserTransform   = new ModelTransform();

            for (int i = 0; i < source.MeshCount; ++i)
            {
                Meshes.Add(new LoadedMesh(source.Meshes[i]));
            }
            for (int i = 0; i < source.MaterialCount; ++i)
            {
                Materials.Add(new LoadedMaterial(source.Materials[i], dirName));
            }
            ProcessTree(source.RootNode, null, out rootNode);
        }
示例#26
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                float offset = GameMath.Serp(0, 2, GameMath.Clamp(secondsUsed * 4f, 0, 2f) / 2f);

                tf.Translation.Set(0, offset / 5, offset / 3);
                tf.Rotation.Set(offset * 10, 0, 0);
                byEntity.Controls.UsingHeldItemTransformAfter = tf;
            }

            return(true);
        }
示例#27
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            bool result         = true;
            bool preventDefault = false;

            foreach (CollectibleBehavior behavior in CollectibleBehaviors)
            {
                EnumHandling handled = EnumHandling.PassThrough;

                bool behaviorResult = behavior.OnHeldInteractStep(secondsUsed, slot, byEntity, blockSel, entitySel, ref handled);
                if (handled != EnumHandling.PassThrough)
                {
                    result        &= behaviorResult;
                    preventDefault = true;
                }

                if (handled == EnumHandling.PreventSubsequent)
                {
                    return(result);
                }
            }
            if (preventDefault)
            {
                return(result);
            }

            if (byEntity.Attributes.GetInt("aimingCancel") == 1)
            {
                return(false);
            }

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                float offset = GameMath.Clamp(secondsUsed * 3, 0, 1.5f);

                tf.Translation.Set(offset / 4f, offset / 2f, 0);
                tf.Rotation.Set(0, 0, GameMath.Min(90, secondsUsed * 360 / 1.5f));

                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }


            return(true);
        }
示例#28
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null)
            {
                return(false);
            }

            IPlayer byPlayer = (byEntity as EntityPlayer).Player;

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                float rotateToTill = GameMath.Clamp(secondsUsed * 18, 0, 2f);
                float scrape       = GameMath.SmoothStep(1 / 0.4f * GameMath.Clamp(secondsUsed - 0.35f, 0, 1));
                float scrapeShake  = secondsUsed > 0.35f && secondsUsed < 0.75f ? (float)(GameMath.Sin(secondsUsed * 50) / 60f) : 0;

                float rotateWithReset = Math.Max(0, rotateToTill - GameMath.Clamp(24 * (secondsUsed - 0.75f), 0, 2));
                float scrapeWithReset = Math.Max(0, scrape - Math.Max(0, 20 * (secondsUsed - 0.75f)));

                tf.Origin.Set(0f, 0, 0.5f);
                tf.Rotation.Set(0, rotateWithReset * 45, 0);
                tf.Translation.Set(scrapeShake, 0, scrapeWithReset / 2);

                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }

            if (secondsUsed > 0.35f && secondsUsed < 0.87f)
            {
                Vec3d dir = new Vec3d().AheadCopy(1, 0, byEntity.SidedPos.Yaw - GameMath.PI);
                Vec3d pos = blockSel.Position.ToVec3d().Add(0.5 + dir.X, 1.03, 0.5 + dir.Z);

                pos.X -= dir.X * secondsUsed * 1 / 0.75f * 1.2f;
                pos.Z -= dir.Z * secondsUsed * 1 / 0.75f * 1.2f;

                byEntity.World.SpawnCubeParticles(blockSel.Position, pos, 0.25f, 3, 0.5f, byPlayer);
            }

            if (secondsUsed > 0.6f && byEntity.Attributes.GetInt("didtill") == 0 && byEntity.World.Side == EnumAppSide.Server)
            {
                byEntity.Attributes.SetInt("didtill", 1);
                DoTill(secondsUsed, slot, byEntity, blockSel, entitySel);
            }

            return(secondsUsed < 1);
        }
示例#29
0
 public static void WriteOffset(this Stream IO, ref ModelTransform MT, bool ReturnToOffset)
 {
     if (ReturnToOffset)
     {
         IO.Position = (int)MT.BinOffset;
         IO.WriteOffset(MT.Scale);
         IO.WriteOffset(MT.Rot);
         IO.WriteOffset(MT.Trans);
         IO.Write(MT.Visibility.BinOffset);
     }
     else
     {
         MT.BinOffset = IO.Position;
         IO.Position += 0x30;
         IO.Length   += 0x30;
     }
 }
示例#30
0
        public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null)
            {
                return(false);
            }

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                float offset = GameMath.Clamp(secondsUsed * 3, 0, 2f);

                tf.Translation.Set(-offset, offset / 4f, 0);

                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }

            SimpleParticleProperties bees = BlockEntityBeehive.Bees;
            BlockPos pos  = blockSel.Position;
            Random   rand = byEntity.World.Rand;

            Vec3d startPos = new Vec3d(pos.X + rand.NextDouble(), pos.Y + rand.NextDouble() * 0.25f, pos.Z + rand.NextDouble());
            Vec3d endPos   = new Vec3d(byEntity.LocalPos.X, byEntity.LocalPos.Y + byEntity.EyeHeight - 0.2f, byEntity.LocalPos.Z);

            Vec3f minVelo = new Vec3f((float)(endPos.X - startPos.X), (float)(endPos.Y - startPos.Y), (float)(endPos.Z - startPos.Z));

            minVelo.Normalize();
            minVelo *= 2;

            bees.minPos               = startPos;
            bees.minVelocity          = minVelo;
            bees.WithTerrainCollision = true;

            IPlayer byPlayer = null;

            if (byEntity is IEntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID);
            }

            byEntity.World.SpawnParticles(bees, byPlayer);

            return(secondsUsed < 4);
        }