Exemplo n.º 1
0
        public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);

            if (Api.Side == EnumAppSide.Client)
            {
                ICoreClientAPI capi = (ICoreClientAPI)api;
                if (currentMesh == null)
                {
                    currentMesh = GenMesh();
                }
            }
            else
            {
                Api.ModLoader.GetModSystem <POIRegistry>().AddPOI(this);

                BlockTroughDoubleBlock doubleblock = Block as BlockTroughDoubleBlock;

                if (doubleblock != null)
                {
                    dummypoi = new DoubleTroughPoiDummy(this)
                    {
                        Position = doubleblock.OtherPartPos(Pos).ToVec3d().Add(0.5, 0.5, 0.5)
                    };
                    Api.ModLoader.GetModSystem <POIRegistry>().AddPOI(dummypoi);
                }
            }

            inventory.SlotModified += Inventory_SlotModified;
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }