Exemplo n.º 1
0
        ItemStack stackFromCode(JsonItemStack jstack, ItemStack fromMetal)
        {
            string metaltype = fromMetal.Collectible.LastCodePart();
            string tooltype  = block.LastCodePart();

            jstack.Code.Path = jstack.Code.Path.Replace("{tooltype}", tooltype).Replace("{metal}", metaltype);
            jstack.Resolve(api.World, "tool mold drop for " + block.Code);
            return(jstack.ResolvedItemstack);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resolves the ingredients that are used to their actual types in the world.
        /// </summary>
        /// <param name="world">The world accessor for data.</param>
        /// <param name="sourceForErrorLogging"></param>
        public void Resolve(IServerWorldAccessor world, string sourceForErrorLogging)
        {
            for (int i = 0; i < Ingredients.Length; i++)
            {
                Ingredients[i].Resolve(world, sourceForErrorLogging);
            }

            Output.Resolve(world, sourceForErrorLogging);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deserializes the alloy
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="resolver"></param>
        public void FromBytes(BinaryReader reader, IWorldAccessor resolver)
        {
            Ingredients = new MetalAlloyIngredient[reader.ReadInt32()];

            for (int i = 0; i < Ingredients.Length; i++)
            {
                Ingredients[i] = new MetalAlloyIngredient();
                Ingredients[i].FromBytes(reader, resolver.ClassRegistry);
                Ingredients[i].Resolve(resolver, "[FromBytes]");
            }

            Output = new JsonItemStack();
            Output.FromBytes(reader, resolver.ClassRegistry);
            Output.Resolve(resolver, "[FromBytes]");
        }
Exemplo n.º 4
0
        public override void OnLoaded(ICoreAPI api)
        {
            base.OnLoaded(api);

            rnd = new LCGRandom(api.World.Seed);

            JsonItemStack[]  jstacks   = Attributes["craftingResults"].AsObject <JsonItemStack[]>();
            List <ItemStack> stacklist = new List <ItemStack>();

            for (int i = 0; i < jstacks.Length; i++)
            {
                JsonItemStack jstack = jstacks[i];
                jstack.Resolve(api.World, "Scrap weapon kit craft result");
                if (jstack.ResolvedItemstack != null)
                {
                    stacklist.Add(jstack.ResolvedItemstack);
                }
            }

            craftResultStacks = stacklist.ToArray();
        }
        public override void Initialize(EntityProperties properties, JsonObject attributes)
        {
            base.Initialize(properties, attributes);

            blockCheck = entity.World.GetCachingBlockAccessor(false, false);

            if (attributes.IsTrue("relaxed"))
            {
                relaxed = true;
            }
            if (attributes.IsTrue("nochest"))
            {
                nochest = true;
            }
            if (attributes.IsTrue("nobarrel"))
            {
                nobarrel = true;
            }
            if (attributes.IsTrue("invLocked"))
            {
                invLocked = true;
            }

            if (attributes["restrictItem"] != null)
            {
                JsonItemStack prestack = attributes["restrictItem"].AsObject <JsonItemStack>();
                if (prestack != null)
                {
                    prestack.Resolve(entity.World, "Locust Program");
                    if (prestack.ResolvedItemstack != null)
                    {
                        maintree.SetItemstack("workStack", prestack.ResolvedItemstack);
                        maintree.SetBool("restrictItem", true);
                        restricted = true;
                    }
                }
            }

            ITreeAttribute area   = maintree.GetTreeAttribute("workArea");
            ITreeAttribute box    = maintree.GetTreeAttribute("workChest");
            ITreeAttribute barrel = maintree.GetTreeAttribute("workBarrel");


            workStack = maintree.GetItemstack("workStack");
            workStack?.ResolveBlockOrItem(entity.World);
            if (entity.Api.Side == EnumAppSide.Client && maintree.GetBool("restrictItem"))
            {
                restricted = true;
            }

            if (area != null)
            {
                workArea = cuboiddFromTree(area);
            }
            if (box != null)
            {
                workChest = new BlockPos(box.GetInt("x"), box.GetInt("y"), box.GetInt("z"));
            }
            if (barrel != null)
            {
                workBarrel = new BlockPos(barrel.GetInt("x"), barrel.GetInt("y"), barrel.GetInt("z"));
            }

            ITreeAttribute tree = maintree["workInv"] as ITreeAttribute;

            if (tree != null)
            {
                workInv.FromTreeAttributes(tree);
            }
        }
Exemplo n.º 6
0
        public override void OnLoaded(ICoreAPI api)
        {
            base.OnLoaded(api);

            drop?.Resolve(api.World, "HorizontalOrientable drop for " + block.Code);
        }
Exemplo n.º 7
0
        private void onServerTick3s(float dt)
        {
            BlockPos coalPilePos      = Pos.DownCopy(2);
            BlockPos othercoalPilePos = coalPilePos.AddCopy(blockScs.Orientation.Opposite);

            bool beforeReceiveHeat       = receivesHeat;
            bool beforeStructureComplete = structureComplete;

            if (!receivesHeat)
            {
                totalHoursLastUpdate = Api.World.Calendar.TotalHours;
            }

            BlockEntityCoalPile becp = Api.World.BlockAccessor.GetBlockEntity(coalPilePos) as BlockEntityCoalPile;
            float leftHeatHoursLeft  = (becp != null && becp.IsBurning) ? becp.GetHoursLeft(totalHoursLastUpdate) : 0f;

            becp = Api.World.BlockAccessor.GetBlockEntity(othercoalPilePos) as BlockEntityCoalPile;
            float rightHeatHoursLeft = (becp != null && becp.IsBurning) ? becp.GetHoursLeft(totalHoursLastUpdate) : 0f;

            receivesHeat = leftHeatHoursLeft > 0 && rightHeatHoursLeft > 0;


            if (processComplete || !IsFull || !hasLid())
            {
                return;
            }

            MultiblockStructure msInUse  = null;
            BlockPos            posInUse = null;

            structureComplete = false;
            if (ms.InCompleteBlockCount(Api.World, Pos) == 0)
            {
                msInUse           = ms;
                posInUse          = Pos;
                structureComplete = true;
            }
            else if (msOpp.InCompleteBlockCount(Api.World, Pos.AddCopy(blockScs.Orientation.Opposite)) == 0)
            {
                msInUse           = msOpp;
                posInUse          = Pos.AddCopy(blockScs.Orientation.Opposite);
                structureComplete = true;
            }

            if (beforeReceiveHeat != receivesHeat || beforeStructureComplete != structureComplete)
            {
                MarkDirty();
            }

            if (receivesHeat)
            {
                if (!structureComplete)
                {
                    return;
                }

                double hoursPassed       = Api.World.Calendar.TotalHours - totalHoursLastUpdate;
                double heatHoursReceived = Math.Max(0, Math.Min(hoursPassed, Math.Min(leftHeatHoursLeft, rightHeatHoursLeft)));

                progress            += heatHoursReceived / 160f;
                totalHoursLastUpdate = Api.World.Calendar.TotalHours;
                MarkDirty();
            }

            if (progress >= 1.0)
            {
                int stacksize = inv[1].Itemstack.StackSize;

                JsonItemStack jstack = inv[1].Itemstack.ItemAttributes?["carburizableProps"]["carburizedOutput"].AsObject <JsonItemStack>(null, Block.Code.Domain);
                if (jstack.Resolve(Api.World, "carburizable output"))
                {
                    inv[0].Itemstack.StackSize -= 8;
                    inv[1].Itemstack            = jstack.ResolvedItemstack.Clone();
                    inv[1].Itemstack.StackSize  = stacksize;
                }
                MarkDirty();

                msInUse.WalkMatchingBlocks(Api.World, posInUse, (block, pos) =>
                {
                    float resis = block.Attributes?["heatResistance"].AsFloat(1) ?? 1;

                    if (Api.World.Rand.NextDouble() > resis)
                    {
                        Block nowblock = Api.World.GetBlock(block.CodeWithVariant("state", "damaged"));
                        Api.World.BlockAccessor.SetBlock(nowblock.Id, pos);
                    }
                });

                processComplete = true;
            }
        }