public ForgeContentsRenderer(BlockPos pos, ICoreClientAPI capi)
        {
            this.pos  = pos;
            this.capi = capi;

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

            Block block = capi.World.GetBlock(new AssetLocation("forge"));

            coaltexpos  = capi.BlockTextureAtlas.GetPosition(block, "coal");
            embertexpos = capi.BlockTextureAtlas.GetPosition(block, "ember");

            MeshData emberMesh = QuadMeshUtil.GetCustomQuadHorizontal(3 / 16f, 0, 3 / 16f, 10 / 16f, 10 / 16f, 255, 255, 255, 255);

            for (int i = 0; i < emberMesh.Uv.Length; i += 2)
            {
                emberMesh.Uv[i + 0] = embertexpos.x1 + emberMesh.Uv[i + 0] * 32f / AtlasSize;
                emberMesh.Uv[i + 1] = embertexpos.y1 + emberMesh.Uv[i + 1] * 32f / AtlasSize;
            }
            emberMesh.Flags = new int[] { 128, 128, 128, 128 };

            MeshData coalMesh = QuadMeshUtil.GetCustomQuadHorizontal(3 / 16f, 0, 3 / 16f, 10 / 16f, 10 / 16f, 255, 255, 255, 255);

            for (int i = 0; i < coalMesh.Uv.Length; i += 2)
            {
                coalMesh.Uv[i + 0] = coaltexpos.x1 + coalMesh.Uv[i + 0] * 32f / AtlasSize;;
                coalMesh.Uv[i + 1] = coaltexpos.y1 + coalMesh.Uv[i + 1] * 32f / AtlasSize;;
            }


            emberQuadRef = capi.Render.UploadMesh(emberMesh);
            coalQuadRef  = capi.Render.UploadMesh(coalMesh);
        }
Example #2
0
        internal void GenMeshes()
        {
            meshesByType = new Dictionary <AssetLocation, MeshData[]>();

            tmpBlock         = api.World.BlockAccessor.GetBlock(pos);
            tmpTextureSource = ((ICoreClientAPI)api).Tesselator.GetTexSource(tmpBlock);
            Shape         shape  = api.Assets.TryGet("shapes/block/metal/platepile.json").ToObject <Shape>();
            MetalProperty metals = api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();

            for (int i = 0; i < metals.Variants.Length; i++)
            {
                ITesselatorAPI mesher = ((ICoreClientAPI)api).Tesselator;
                MeshData[]     meshes = new MeshData[17];

                tmpMetal = metals.Variants[i].Code;

                for (int j = 0; j <= 16; j++)
                {
                    mesher.TesselateShape("platePile", shape, out meshes[j], this, null, 0, 0, j);
                }

                meshesByType[tmpMetal] = meshes;
            }

            tmpTextureSource = null;
            tmpMetal         = null;
            tmpBlock         = null;
        }
Example #3
0
        public override void Start(ICoreAPI api)
        {
            GameVersion.EnsureEqualVersionOrKillExecutable(api, System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion, GameVersion.OverallVersion, "VSSurvivalMod");

            this.api = api;
            api.Network.RegisterChannel("survivalCoreConfig").RegisterMessageType <SurvivalConfig>();

            RegisterDefaultBlocks();
            RegisterDefaultBlockBehaviors();
            RegisterDefaultBlockEntityBehaviors();

            RegisterDefaultCollectibleBehaviors();

            RegisterDefaultCropBehaviors();
            RegisterDefaultItems();
            RegisterDefaultEntities();
            RegisterDefaultEntityBehaviors();
            RegisterDefaultBlockEntities();

            api.RegisterMountable("bed", BlockBed.GetMountable);
            AiTaskRegistry.Register("throwatentity", typeof(AiTaskThrowAtEntity));

            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];
            }
        }
Example #4
0
        Dictionary <AssetLocation, MeshData[]> GenMeshes()
        {
            Dictionary <AssetLocation, MeshData[]> meshesByType = new Dictionary <AssetLocation, MeshData[]>();

            tmpBlock         = Api.World.BlockAccessor.GetBlock(Pos);
            tmpTextureSource = ((ICoreClientAPI)Api).Tesselator.GetTexSource(tmpBlock);
            Shape         shape     = Api.Assets.TryGet("shapes/block/wood/plankpile.json").ToObject <Shape>();
            MetalProperty woodtpyes = Api.Assets.TryGet("worldproperties/block/wood.json").ToObject <MetalProperty>();

            woodtpyes.Variants = woodtpyes.Variants.Append(new MetalPropertyVariant()
            {
                Code = new AssetLocation("aged")
            });

            for (int i = 0; i < woodtpyes.Variants.Length; i++)
            {
                ITesselatorAPI mesher = ((ICoreClientAPI)Api).Tesselator;
                MeshData[]     meshes = new MeshData[49];

                tmpWood = woodtpyes.Variants[i].Code;

                for (int j = 0; j <= 48; j++)
                {
                    mesher.TesselateShape("PlankPile", shape, out meshes[j], this, null, 0, 0, 0, j);
                }

                meshesByType[tmpWood] = meshes;
            }

            tmpTextureSource = null;
            tmpWood          = null;
            tmpBlock         = null;

            return(meshesByType);
        }
Example #5
0
        public override void Start(ICoreAPI api)
        {
            this.api = api;
            api.Network.RegisterChannel("survivalCoreConfig").RegisterMessageType <SurvivalConfig>();

            RegisterDefaultBlocks();
            RegisterDefaultBlockBehaviors();
            RegisterDefaultBlockEntityBehaviors();
            RegisterDefaultCropBehaviors();
            RegisterDefaultItems();
            RegisterDefaultEntities();
            RegisterDefaultEntityBehaviors();
            RegisterDefaultBlockEntities();

            api.RegisterMountable("bed", BlockBed.GetMountable);


            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];
            }
        }
Example #6
0
        internal void EnsureMeshExists()
        {
            if (meshesByType == null)
            {
                meshesByType = new Dictionary <AssetLocation, MeshData[]>();
            }
            if (MetalType == null || meshesByType.ContainsKey(new AssetLocation(MetalType)))
            {
                return;
            }
            if (Api.Side != EnumAppSide.Client)
            {
                return;
            }

            tmpBlock         = Api.World.BlockAccessor.GetBlock(Pos);
            tmpTextureSource = ((ICoreClientAPI)Api).Tesselator.GetTexSource(tmpBlock);
            string        path   = Block.Attributes["pileshapes"]?["*"]?.AsString("shapes/block/metal/ingotpile.json");
            MetalProperty metals = Api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();
            List <MetalPropertyVariant> variants = metals.Variants.ToList();
            var a = Api.Assets.TryGet("config/immersionproperties/customingots.json")?.ToObject <List <MetalPropertyVariant> >();

            if (a != null)
            {
                variants.AddRange(a);
            }

            metals.Variants = variants.ToArray();

            for (int i = 0; i < metals.Variants.Length; i++)
            {
                if (!metals.Variants[i].Code.Path.Equals(MetalType))
                {
                    continue;
                }

                ITesselatorAPI mesher = ((ICoreClientAPI)Api).Tesselator;
                MeshData[]     meshes = new MeshData[65];

                tmpMetal = metals.Variants[i].Code;
                if (tmpMetal != null)
                {
                    path = Block.Attributes["pileshapes"]?[tmpMetal.Path]?.AsString(path);
                }
                Shape shape = Api.Assets.TryGet(path + ".json").ToObject <Shape>();

                for (int j = 0; j <= 64; j++)
                {
                    mesher.TesselateShape("ingotPile", shape, out meshes[j], this, null, 0, 0, j);
                }

                meshesByType[tmpMetal] = meshes;
            }

            tmpTextureSource = null;
            tmpMetal         = null;
            tmpBlock         = null;
        }
Example #7
0
        internal void EnsureMeshExists()
        {
            if (meshesByType == null)
            {
                meshesByType = new Dictionary <AssetLocation, MeshData[]>();
            }
            if (MetalType == null || meshesByType.ContainsKey(new AssetLocation(MetalType)))
            {
                return;
            }
            if (api.Side != EnumAppSide.Client)
            {
                return;
            }

            tmpBlock         = api.World.BlockAccessor.GetBlock(pos);
            tmpTextureSource = ((ICoreClientAPI)api).Tesselator.GetTexSource(tmpBlock);
            Shape         shape  = api.Assets.TryGet("shapes/block/metal/ingotpile.json").ToObject <Shape>();
            MetalProperty metals = api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();

            for (int i = 0; i < metals.Variants.Length; i++)
            {
                if (!metals.Variants[i].Code.Path.Equals(MetalType))
                {
                    continue;
                }

                ITesselatorAPI mesher = ((ICoreClientAPI)api).Tesselator;
                MeshData[]     meshes = new MeshData[65];

                tmpMetal = metals.Variants[i].Code;

                for (int j = 0; j <= 64; j++)
                {
                    mesher.TesselateShape("ingotPile", shape, out meshes[j], this, null, 0, 0, j);
                }

                meshesByType[tmpMetal] = meshes;
            }

            tmpTextureSource = null;
            tmpMetal         = null;
            tmpBlock         = null;
        }
Example #8
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 #9
0
        public override void OnLoaded(ICoreAPI api)
        {
            if (api.Side != EnumAppSide.Client)
            {
                return;
            }
            ICoreClientAPI capi = api as ICoreClientAPI;

            string createdByText = "metalmolding";

            if (Attributes?["createdByText"].Exists == true)
            {
                createdByText = Attributes["createdByText"].AsString();
            }

            if (Attributes?["drop"].Exists == true)
            {
                JsonItemStack ojstack = Attributes["drop"].AsObject <JsonItemStack>();
                if (ojstack != null)
                {
                    MetalProperty metals = api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();
                    for (int i = 0; i < metals.Variants.Length; i++)
                    {
                        string        metaltype = metals.Variants[i].Code.Path;
                        string        tooltype  = LastCodePart();
                        JsonItemStack jstack    = ojstack.Clone();
                        jstack.Code.Path = jstack.Code.Path.Replace("{tooltype}", tooltype).Replace("{metal}", metaltype);

                        CollectibleObject collObj;

                        if (jstack.Type == EnumItemClass.Block)
                        {
                            collObj = api.World.GetBlock(jstack.Code);
                        }
                        else
                        {
                            collObj = api.World.GetItem(jstack.Code);
                        }

                        if (collObj == null)
                        {
                            continue;
                        }

                        JToken token;

                        if (collObj.Attributes?["handbook"].Exists != true)
                        {
                            if (collObj.Attributes == null)
                            {
                                collObj.Attributes = new JsonObject(JToken.Parse("{ handbook: {} }"));
                            }
                            else
                            {
                                token             = collObj.Attributes.Token;
                                token["handbook"] = JToken.Parse("{ }");
                            }
                        }

                        token = collObj.Attributes["handbook"].Token;
                        token["createdBy"] = JToken.FromObject(createdByText);
                    }
                }
            }


            interactions = ObjectCacheUtil.GetOrCreate(api, "toolmoldBlockInteractions", () =>
            {
                List <ItemStack> smeltedContainerStacks = new List <ItemStack>();

                foreach (CollectibleObject obj in api.World.Collectibles)
                {
                    if (obj is BlockSmeltedContainer)
                    {
                        smeltedContainerStacks.Add(new ItemStack(obj));
                    }
                }

                return(new WorldInteraction[] {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-toolmold-pour",
                        HotKeyCode = "sneak",
                        MouseButton = EnumMouseButton.Right,
                        Itemstacks = smeltedContainerStacks.ToArray(),
                        GetMatchingStacks = (wi, bs, es) =>
                        {
                            BlockEntityToolMold betm = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityToolMold;
                            return (betm != null && !betm.IsFull) ? wi.Itemstacks : null;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-toolmold-takeworkitem",
                        HotKeyCode = null,
                        MouseButton = EnumMouseButton.Right,
                        ShouldApply = (wi, bs, es) =>
                        {
                            BlockEntityToolMold betm = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityToolMold;
                            return betm != null && betm.IsFull && betm.IsHardened;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-toolmold-pickup",
                        HotKeyCode = null,
                        RequireFreeHand = true,
                        MouseButton = EnumMouseButton.Right,
                        ShouldApply = (wi, bs, es) =>
                        {
                            BlockEntityToolMold betm = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityToolMold;
                            return betm != null && betm.metalContent == null;
                        }
                    }
                });
            });
        }
Example #10
0
        public override void OnLoaded(ICoreAPI api)
        {
            base.OnLoaded(api);

            if (api.Side != EnumAppSide.Client)
            {
                return;
            }
            ICoreClientAPI capi = api as ICoreClientAPI;

            Dictionary <string, MetalPropertyVariant> 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];
            }

            string metalType    = LastCodePart();
            int    ownMetalTier = 0;

            if (metalsByCode.ContainsKey(metalType))
            {
                ownMetalTier = metalsByCode[metalType].Tier;
            }

            interactions = ObjectCacheUtil.GetOrCreate(api, "anvilBlockInteractions" + ownMetalTier, () =>
            {
                List <ItemStack> workableStacklist = new List <ItemStack>();
                List <ItemStack> hammerStacklist   = new List <ItemStack>();


                foreach (Item item in api.World.Items)
                {
                    if (item.Code == null)
                    {
                        continue;
                    }

                    bool viableTier = metalsByCode.ContainsKey(metalType) && metalsByCode[metalType].Tier <= ownMetalTier + 1;
                    if (item is ItemIngot && viableTier)
                    {
                        workableStacklist.Add(new ItemStack(item));
                    }

                    if (item is ItemHammer)
                    {
                        hammerStacklist.Add(new ItemStack(item));
                    }
                }

                return(new WorldInteraction[] {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-anvil-takeworkable",
                        HotKeyCode = null,
                        MouseButton = EnumMouseButton.Right,
                        ShouldApply = (wi, bs, es) => {
                            BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil;
                            return bea?.WorkItemStack != null;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-anvil-placeworkable",
                        HotKeyCode = "sneak",
                        MouseButton = EnumMouseButton.Right,
                        Itemstacks = workableStacklist.ToArray(),
                        GetMatchingStacks = (wi, bs, es) => {
                            BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil;
                            return bea?.WorkItemStack == null ? wi.Itemstacks : null;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-anvil-smith",
                        MouseButton = EnumMouseButton.Left,
                        Itemstacks = hammerStacklist.ToArray(),
                        GetMatchingStacks = (wi, bs, es) => {
                            BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil;
                            return bea?.WorkItemStack == null ? null : wi.Itemstacks;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-anvil-rotateworkitem",
                        MouseButton = EnumMouseButton.Right,
                        Itemstacks = hammerStacklist.ToArray(),
                        GetMatchingStacks = (wi, bs, es) => {
                            BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil;
                            return bea?.WorkItemStack == null ? null : wi.Itemstacks;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-selecttoolmode",
                        HotKeyCode = "toolmodeselect",
                        MouseButton = EnumMouseButton.None,
                        Itemstacks = hammerStacklist.ToArray(),
                        GetMatchingStacks = (wi, bs, es) => {
                            BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil;
                            return bea?.WorkItemStack == null ? null : wi.Itemstacks;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-anvil-addvoxels",
                        HotKeyCode = "sneak",
                        MouseButton = EnumMouseButton.Right,
                        Itemstacks = workableStacklist.ToArray(),
                        GetMatchingStacks = (wi, bs, es) => {
                            BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil;
                            return bea?.WorkItemStack == null ? null : new ItemStack[] { (bea.WorkItemStack.Collectible as IAnvilWorkable).GetBaseMaterial(bea.WorkItemStack) };
                        }
                    }
                });
            });
        }