Example #1
0
        private void CustomTick(object sender, ElapsedEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }
            int mult        = 1;
            int unitstosend = 8;

            pullcounter++;
            if (pullcounter >= 30) // dont pull item into its internal inventory too often to reduce lag
            {
                LinkedStorage.MoveAsManyItemsAsPossible(Storage, OwnerUser);
                pullcounter = 0;
            }
            IEnumerable <ItemStack> nonempty = Storage.NonEmptyStacks;

            nonempty.ForEach(stack =>
            {
                int stackbefore = stack.Quantity;
                if (stack.Item.IsCarried)
                {
                    mult = 5;
                }
                else
                {
                    mult = 1;                                      // transport less carried items per second than normal ones, maybe restrict based on mass?
                }
                if (unitstosend / mult < 1)
                {
                    return;
                }
                outputWire.SendItemConsume(stack, unitstosend / mult); // thats where the items will be sent over the syste,
                unitstosend -= (stackbefore - stack.Quantity) * mult;
                if (stack.Quantity <= 0)
                {
                    Storage.AddItem(stack.Item);
                    Storage.RemoveItem(stack.Item.Type);
                }
            });
        }
Example #2
0
        public bool TryMine(Vector3i pos)
        {
            Block block = World.GetBlock(pos);

            if (block is ImpenetrableStoneBlock)
            {
                StopMining("Mining operation halted! Hit bedrock!");
                return(false);
            }
            //if (pos.XZ.WrappedDistance(this.Position3i.XZ) >= 20)
            //{
            //    StopMining("Mining operation halted! Too far away");
            //    return false;
            //}



            if (block == null || block is EmptyBlock || block is WorldObjectBlock || block is WaterBlock)
            {
                return(true); //skip when worlobject, water or air
            }

            Item blockItem = BlockItem.CreatingItem(block.GetType());
            int  amount    = 1;


            if (block is IRepresentsItem)
            {
                //ChatUtils.SendMessageToAll("RepresentsItem");
                blockItem = Item.Create((block as IRepresentsItem).RepresentedItemType);
                if (block.Is <Minable>())
                {
                    amount = 4;                     // ore, coal or stone, could also limit to ore and coal by stringcomparison
                }
            }
            else if (block is RockySoilBlock)
            {
                blockItem = Item.Create(typeof(DirtItem));
            }


            if ((block.Is <Diggable>() || block.Is <Minable>()) && blockItem != null)
            {
                if ((this.Parent.GetComponent <FuelSupplyComponent>().Energy + this.Parent.GetComponent <FuelSupplyComponent>().EnergyInSupply) < fuelconsumption)
                {
                    // ChatUtils.SendMessageToAll("Not enough fuel");
                    UpdateStatus("NO FUEL! ");
                    return(false);
                }
                if (++hitsperformed < hitsneeded)
                {
                    this.Parent.GetComponent <FuelSupplyComponent>().TryConsumeFuel(fuelconsumption);
                    UpdateStatus();
                    if (RandomUtil.CoinToss())
                    {
                        hitsperformed++;                        //50% chance of a free extra hit for randomization, after Update to prevent values >100%
                    }
                    return(false);
                }



                Result result = LinkedStorage.TryAddItems(blockItem.Type, amount);

                if (result.Success)
                {
                    UpdateStatus();
                    this.Parent.GetComponent <FuelSupplyComponent>().TryConsumeFuel(fuelconsumption);
                    World.DeleteBlock(pos);
                    hitsperformed = 0;
                    Resetpos();
                    return(false);
                }
                else
                {
                    //ChatUtils.SendMessageToAll("No Space");
                    hitsperformed = hitsneeded;
                    UpdateStatus("STORAGE FULL! ");
                    return(false);
                }
            }
            //else ChatUtils.SendMessageToAll("No valid Block");


            return(true);
        }