Exemplo n.º 1
0
 /// <summary>
 /// Initialize the track.
 /// </summary>
 /// <param name="assetManager">the global Asset Manager</param>
 /// <param name="capi">The Core Client API</param>
 /// <param name="musicEngine"></param>
 public virtual void Initialize(IAssetManager assetManager, ICoreClientAPI capi, IMusicEngine musicEngine)
 {
     this.capi        = capi;
     this.musicEngine = musicEngine;
     Location.Path    = Location.Path.ToLowerInvariant();
     if (!Location.Path.StartsWith("sounds"))
     {
         Location.WithPathPrefixOnce("music/");
     }
     Location.WithPathAppendixOnce(".ogg");
 }
        public override void OnJsonTesselation(ref MeshData sourceMesh, ref int[] lightRgbsByCorner, BlockPos pos, Block[] chunkExtBlocks, int extIndex3d)
        {
            Block upBlock = chunkExtBlocks[extIndex3d + TileSideEnum.MoveIndex[TileSideEnum.Up]];

            if (upBlock is BlockFence)
            {
                int var = (GameMath.MurmurHash3Mod(pos.X, pos.Y, pos.Z, 8) + 1);

                MeshData mesh;
                if (!continousFenceMeches.TryGetValue(cntCode + var, out mesh))
                {
                    AssetLocation loc = Shape.Base.Clone();
                    loc.Path = loc.Path.Replace("-top", "");
                    loc.WithPathAppendixOnce(".json");
                    loc.WithPathPrefixOnce("shapes/");
                    Shape shape = capi.Assets.TryGet(loc).ToObject <Shape>();

                    CompositeTexture ct = Textures["wall"];
                    int prevSubid       = ct.Baked.TextureSubId;
                    ct.Baked.TextureSubId = ct.Baked.BakedVariants[GameMath.MurmurHash3Mod(pos.X, pos.Y, pos.Z, ct.Alternates.Length)].TextureSubId;

                    capi.Tesselator.TesselateShape(this, shape, out mesh, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ), Shape.QuantityElements, Shape.SelectiveElements);

                    ct.Baked.TextureSubId = prevSubid;

                    continousFenceMeches[cntCode] = mesh;
                }

                sourceMesh = mesh;
            }


            // Todo: make this work

            /*            int nBlockId = chunkExtIds[extIndex3d + TileSideEnum.MoveIndex[TileSideEnum.Up]];
             *          Block upblock = api.World.Blocks[nBlockId];
             *
             *          if (upblock.snowLevel >= 1 && snowLayerBlock != null)
             *          {
             *              sourceMesh = sourceMesh.Clone();
             *              sourceMesh.AddMeshData(capi.TesselatorManager.GetDefaultBlockMesh(snowLayerBlock));
             *              return;
             *          }*/

            return;  // no windwave for solid fences!

            //base.OnJsonTesselation(ref sourceMesh, ref lightRgbsByCorner, pos, chunkExtIds, chunkLightExt, extIndex3d);
        }
Exemplo n.º 3
0
        public MeshData GetPieMesh(ItemStack pieStack, ModelTransform transform = null)
        {
            // Slot 0: Base dough
            // Slot 1: Filling
            // Slot 2: Crust dough

            nowTesselatingBlock = pieStack.Block as BlockPie;
            if (nowTesselatingBlock == null)
            {
                return(null);                              //This will occur if the pieStack changed to rot
            }
            contentStacks = nowTesselatingBlock.GetContents(capi.World, pieStack);

            int pieSize = pieStack.Attributes.GetInt("pieSize");


            // At this spot we have to determine the textures for "dough" and "filling"
            // Texture determination rules:
            // 1. dough is simple: first itemstack must be dough, take from attributes
            // 2. pie allows 4 items as fillings, but with specific mixing rules
            //    - berries/fruit can be mixed
            //    - vegetables can be mixed
            //    - meat can be mixed
            // no other mixing allowed

            // Thus we deduce: It's enough to test if
            // a) all 4 fillings are equal: Then use texture from inPieProperties from first one
            // b) Otherwise use hardcoded
            //    for item.NutritionProps.FoodCategory == Vegetable   => block/food/pie/fill-mixedvegetable.png
            //    for item.NutritionProps.FoodCategory == Protein   => block/food/pie/fill-mixedmeat.png
            //    for item.NutritionProps.FoodCategory == Fruit   => block/food/pie/fill-mixedfruit.png

            var stackprops = contentStacks.Select(stack => stack?.ItemAttributes?["inPieProperties"]?.AsObject <InPieProperties>(null, stack.Collectible.Code.Domain)).ToArray();

            int bakeLevel = pieStack.Attributes.GetInt("bakeLevel", 0);

            if (stackprops.Length == 0)
            {
                return(null);
            }


            ItemStack cstack = contentStacks[1];
            bool      equal  = true;

            for (int i = 2; equal && i < contentStacks.Length - 1; i++)
            {
                if (contentStacks[i] == null || cstack == null)
                {
                    continue;
                }

                equal &= cstack.Equals(capi.World, contentStacks[i], GlobalConstants.IgnoredStackAttributes);
                cstack = contentStacks[i];
            }


            if (ContentsRotten(contentStacks))
            {
                crustTextureLoc    = new AssetLocation("block/rot/rot");
                fillingTextureLoc  = new AssetLocation("block/rot/rot");
                topCrustTextureLoc = new AssetLocation("block/rot/rot");
            }
            else
            {
                if (stackprops[0] != null)
                {
                    crustTextureLoc      = stackprops[0].Texture.Clone();
                    crustTextureLoc.Path = crustTextureLoc.Path.Replace("{bakelevel}", "" + (bakeLevel + 1));
                    fillingTextureLoc    = new AssetLocation("block/transparent");
                }

                topCrustTextureLoc = new AssetLocation("block/transparent");
                if (stackprops[5] != null)
                {
                    topCrustTextureLoc      = stackprops[5].Texture.Clone();
                    topCrustTextureLoc.Path = topCrustTextureLoc.Path.Replace("{bakelevel}", "" + (bakeLevel + 1));
                }

                if (contentStacks[1] != null)
                {
                    EnumFoodCategory fillingFoodCat =
                        contentStacks[1].Collectible.NutritionProps?.FoodCategory
                        ?? contentStacks[1].ItemAttributes?["nutritionPropsWhenInMeal"]?.AsObject <FoodNutritionProperties>()?.FoodCategory
                        ?? EnumFoodCategory.Vegetable
                    ;

                    fillingTextureLoc = equal ? stackprops[1]?.Texture : pieMixedFillingTextures[(int)fillingFoodCat];
                }
            }


            int  fillLevel  = (contentStacks[1] != null ? 1 : 0) + (contentStacks[2] != null ? 1 : 0) + (contentStacks[3] != null ? 1 : 0) + (contentStacks[4] != null ? 1 : 0);
            bool isComplete = fillLevel == 4;

            AssetLocation shapeloc = isComplete ? pieShapeBySize[pieSize - 1] : pieShapeLocByFillLevel[fillLevel];

            shapeloc.WithPathAppendixOnce(".json").WithPathPrefixOnce("shapes/");
            Shape    shape = capi.Assets.TryGet(shapeloc).ToObject <Shape>();
            MeshData mesh;

            int topCrustType = pieStack.Attributes.GetInt("topCrustType");

            string[] topCrusts         = new string[] { "origin/base/top crust full/*", "origin/base/top crust square/*", "origin/base/top crust diagonal/*" };
            string[] selectiveElements = new string[] { "origin/base/crust regular/*", "origin/base/filling/*", "origin/base/base-quarter/*", "origin/base/fillingquarter/*", topCrusts[topCrustType] };

            capi.Tesselator.TesselateShape("pie", shape, out mesh, this, null, 0, 0, 0, null, selectiveElements);
            if (transform != null)
            {
                mesh.ModelTransform(transform);
            }

            return(mesh);
        }