Example #1
0
 public override void OnBlockRemoved()
 {
     if (workitemRenderer != null)
     {
         workitemRenderer.Unregister();
         workitemRenderer = null;
     }
 }
Example #2
0
        public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);

            metalsByCode = new Dictionary <string, MetalPropertyVariant>();

            MetalProperty metals = api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();

            for (int i = 0; i < metals.Variants.Length; i++)
            {
                // Metals currently don't have a domain
                metalsByCode[metals.Variants[i].Code.Path] = metals.Variants[i];
            }

            if (workItemStack != null)
            {
                workItemStack.ResolveBlockOrItem(api.World);
                baseMaterial = new ItemStack(api.World.GetItem(new AssetLocation("ingot-" + workItemStack.Collectible.LastCodePart())));
            }

            if (api is ICoreClientAPI)
            {
                ICoreClientAPI capi = (ICoreClientAPI)api;
                capi.Event.RegisterRenderer(workitemRenderer = new AnvilWorkItemRenderer(pos, capi), EnumRenderStage.Opaque);
                capi.Event.RegisterRenderer(workitemRenderer, EnumRenderStage.AfterFinalComposition);

                RegenMeshAndSelectionBoxes();
            }

            Block  block     = api.World.BlockAccessor.GetBlock(pos);
            string metalType = block.LastCodePart();

            if (metalsByCode.ContainsKey(metalType))
            {
                OwnMetalTier = metalsByCode[metalType].Tier;
            }
        }
Example #3
0
        public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);

            workItemStack?.ResolveBlockOrItem(api.World);

            if (api is ICoreClientAPI)
            {
                ICoreClientAPI capi = (ICoreClientAPI)api;
                capi.Event.RegisterRenderer(workitemRenderer = new AnvilWorkItemRenderer(this, Pos, capi), EnumRenderStage.Opaque);
                capi.Event.RegisterRenderer(workitemRenderer, EnumRenderStage.AfterFinalComposition);

                RegenMeshAndSelectionBoxes();
                capi.Tesselator.TesselateBlock(Block, out currentMesh);
            }

            string metalType = Block.Variant["metal"];
            MetalPropertyVariant var;

            if (api.ModLoader.GetModSystem <SurvivalCoreSystem>().metalsByCode.TryGetValue(metalType, out var))
            {
                OwnMetalTier = var.Tier;
            }
        }
Example #4
0
 public override void OnBlockRemoved()
 {
     workitemRenderer?.Dispose();
     workitemRenderer = null;
 }