Exemplo n.º 1
0
        public override void Initialize(ICoreAPI api)
        {
            ownBlock = Block as BlockCrate;
            capi     = api as ICoreClientAPI;

            bool isNewlyplaced = inventory == null;

            if (isNewlyplaced)
            {
                InitInventory(Block);
            }

            base.Initialize(api);

            if (api.Side == EnumAppSide.Client && !isNewlyplaced)
            {
                loadOrCreateMesh();
            }
        }
Exemplo n.º 2
0
        private void loadOrCreateMesh()
        {
            BlockCrate block = Block as BlockCrate;

            if (Block == null)
            {
                block = Api.World.BlockAccessor.GetBlock(Pos) as BlockCrate;
                Block = block;
            }
            if (block == null)
            {
                return;
            }

            string cacheKey = "crateMeshes" + block.FirstCodePart();
            Dictionary <string, MeshData> meshes = ObjectCacheUtil.GetOrCreate(Api, cacheKey, () => new Dictionary <string, MeshData>());

            MeshData mesh;

            CompositeShape cshape = ownBlock.Props[type].Shape;

            if (cshape?.Base == null)
            {
                return;
            }

            var firstStack = inventory.FirstNonEmptySlot?.Itemstack;

            string meshKey = type + block.Subtype + "-" + label + "-" + LidState + "-" + (LidState == "closed" ? null : firstStack?.StackSize + "-" + firstStack?.GetHashCode());

            if (!meshes.TryGetValue(meshKey, out mesh))
            {
                mesh            = block.GenMesh(Api as ICoreClientAPI, firstStack, type, label, LidState, cshape, new Vec3f(cshape.rotateX, cshape.rotateY, cshape.rotateZ));
                meshes[meshKey] = mesh;
            }

            ownMesh = mesh.Clone().Rotate(origin, 0, MeshAngle, 0).Scale(origin, rndScale, rndScale, rndScale);
        }