Exemple #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;
        }
Exemple #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);
        }