예제 #1
0
 public static Mat3f Add(Mat3f left, Mat3f right)
 {
     return(new Mat3f()
     {
         c0 = Vec3f.Add(left.c0, right.c0),
         c1 = Vec3f.Add(left.c1, right.c1),
         c2 = Vec3f.Add(left.c2, right.c2)
     });
 }
예제 #2
0
 public static void Add(ref Mat3f left, ref Mat3f right, out Mat3f result)
 {
     Vec3f.Add(ref left.c0, ref right.c0, out result.c0);
     Vec3f.Add(ref left.c1, ref right.c1, out result.c1);
     Vec3f.Add(ref left.c2, ref right.c2, out result.c2);
 }
예제 #3
0
        internal MeshData GenMesh()
        {
            if (Block == null || contentCode == "")
            {
                return(null);
            }
            ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode);

            if (config == null)
            {
                return(null);
            }

            ICoreClientAPI capi = Api as ICoreClientAPI;

            ItemStack firstStack = inventory[0].Itemstack;

            if (firstStack == null)
            {
                return(null);
            }

            int    fillLevel = Math.Max(0, firstStack.StackSize / config.QuantityPerFillLevel - 1);
            string shapeLoc  = config.ShapesPerFillLevel[Math.Min(config.ShapesPerFillLevel.Length - 1, fillLevel)];

            Vec3f    rotation = new Vec3f(Block.Shape.rotateX, Block.Shape.rotateY, Block.Shape.rotateZ);
            MeshData meshbase;
            MeshData meshadd;

            blockTexPosSource = capi.Tesselator.GetTexSource(Block);
            capi.Tesselator.TesselateShape("betrough", Api.Assets.TryGet("shapes/" + shapeLoc + ".json").ToObject <Shape>(), out meshbase, this, rotation);

            BlockTroughDoubleBlock doubleblock = Block as BlockTroughDoubleBlock;

            if (doubleblock != null)
            {
                // Load only contents and flip 180 degrees
                capi.Tesselator.TesselateShape("betroughcontents", Api.Assets.TryGet("shapes/" + shapeLoc + ".json").ToObject <Shape>(), out meshadd, this, rotation.Add(0, 180, 0), 0, 0, 0, null, new string[] { "Origin point/contents/*" });
                BlockFacing facing = doubleblock.OtherPartPos();
                meshadd.Translate(facing.Normalf);
                meshbase.AddMeshData(meshadd);
            }

            return(meshbase);
        }
예제 #4
0
        public void HandleBoyancy(Vec3d pos, Vec3f velocity, bool boyant, float gravityStrength, float deltatime, float height)
        {
            int xPrev = (int)pos.X;
            int yPrev = (int)pos.Y;
            int zPrev = (int)pos.Z;

            tmpPos.Set(xPrev, yPrev, zPrev);
            Block block     = BlockAccess.GetBlock(tmpPos);
            Block prevBlock = block;

            if (block == null)
            {
                return;
            }

            if (boyant)
            {
                if (block.IsLiquid())
                {
                    tmpPos.Set(xPrev, (int)(pos.Y + 1), zPrev);
                    block = BlockAccess.GetBlock(tmpPos);
                    if (block == null)
                    {
                        return;
                    }

                    float waterY = (int)pos.Y + prevBlock.LiquidLevel / 8f + (block.IsLiquid() ? 9 / 8f : 0);
                    float bottomSubmergedness = waterY - (float)pos.Y;

                    float swimlineSubmergedness = GameMath.Clamp(bottomSubmergedness + height, 0, 1);

                    float boyancyStrength = GameMath.Clamp(9 * swimlineSubmergedness, -1.25f, 1.25f); // was 3* before. Dunno why it has to be 9* now

                    velocity.Y += gravityStrength * deltatime * boyancyStrength;

                    float waterDrag = (float)GameMath.Clamp(30 * Math.Abs(velocity.Y) - 0.02f, 1, 1.25f);

                    velocity.Y /= waterDrag;
                    velocity.X *= 0.99f;
                    velocity.Z *= 0.99f;

                    if (prevBlock.PushVector != null && swimlineSubmergedness >= 0)
                    {
                        float factor = deltatime / (33f / 1000f);
                        velocity.Add(
                            (float)prevBlock.PushVector.X * 15 * factor,
                            (float)prevBlock.PushVector.Y * 15 * factor,
                            (float)prevBlock.PushVector.Z * 15 * factor
                            );
                    }
                }
            }
            else
            {
                if (block.PushVector != null)
                {
                    velocity.Add(
                        (float)block.PushVector.X * 30 * deltatime,
                        (float)block.PushVector.Y * 30 * deltatime,
                        (float)block.PushVector.Z * 30 * deltatime
                        );
                }
            }
        }
예제 #5
0
        internal MeshData GenMesh()
        {
            if (Block == null)
            {
                return(null);
            }
            ItemStack firstStack = inventory[0].Itemstack;

            if (firstStack == null)
            {
                return(null);
            }

            string         shapeLoc = "";
            ICoreClientAPI capi     = Api as ICoreClientAPI;

            if (contentCode == "" || contentConfigs == null)
            {
                if (firstStack.Collectible.Code.Path == "rot")
                {
                    shapeLoc = "block/wood/trough/" + (Block.Variant["part"] == "small" ? "small" : "large") + "/rotfill" + GameMath.Clamp(firstStack.StackSize / 4, 1, 4);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode);
                if (config == null)
                {
                    return(null);
                }

                int fillLevel = Math.Max(0, firstStack.StackSize / config.QuantityPerFillLevel - 1);
                shapeLoc = config.ShapesPerFillLevel[Math.Min(config.ShapesPerFillLevel.Length - 1, fillLevel)];
            }



            Vec3f    rotation = new Vec3f(Block.Shape.rotateX, Block.Shape.rotateY, Block.Shape.rotateZ);
            MeshData meshbase;
            MeshData meshadd;

            blockTexPosSource = capi.Tesselator.GetTexSource(Block);
            Shape shape = Api.Assets.TryGet("shapes/" + shapeLoc + ".json").ToObject <Shape>();

            capi.Tesselator.TesselateShape("betroughcontentsleft", shape, out meshbase, this, rotation);

            BlockTroughDoubleBlock doubleblock = Block as BlockTroughDoubleBlock;

            if (doubleblock != null)
            {
                capi.Tesselator.TesselateShape("betroughcontentsright", shape, out meshadd, this, rotation.Add(0, 180, 0));
                BlockFacing facing = doubleblock.OtherPartFacing();
                meshadd.Translate(facing.Normalf);
                meshbase.AddMeshData(meshadd);
            }

            return(meshbase);
        }