Esempio n. 1
0
    private void OnServerTick(float dt)
    {
        float res = Math.Min(consume * dt, energyStorage.getEnergyStored());

        energyStorage.modifyEnergyStored(-res);
        ((BEBehaviorTFEngine)Behaviors[0]).speed = res / (consume * dt);
    }
Esempio n. 2
0
    public override void ToTreeAttributes(ITreeAttribute tree)
    {
        base.ToTreeAttributes(tree);

        if (energyStorage != null)
        {
            tree.SetFloat("energy", energyStorage.getEnergyStored());
        }
    }
Esempio n. 3
0
    public override void ToTreeAttributes(ITreeAttribute tree)
    {
        base.ToTreeAttributes(tree);

        if (energyStorage != null)
        {
            tree.SetFloat("energy", energyStorage.getEnergyStored());
        }
        if (Api != null && Api.World.Side == EnumAppSide.Server)
        {
            tree.SetFloat("gen", generation);
        }
    }
Esempio n. 4
0
 public EnergyDuctCore CombineCores(EnergyDuctCore core)
 {
     storage.setEnergy(Math.Min(storage.getEnergyStored() + core.storage.getEnergyStored(), storage.getMaxEnergyStored()));
     foreach (IEnergyPoint item in core.ducts)
     {
         item.SetCore(this);
     }
     ducts.AddRange(core.ducts);
     return(this);
 }
Esempio n. 5
0
 private void OnTick(float dt)
 {
     if (inventory[0]?.Itemstack?.Item is IFluxStorageItem)
     {
         energyStorage.modifyEnergyStored(-((IFluxStorageItem)inventory[0].Itemstack.Item).receiveEnergy(inventory[0].Itemstack, (int)Math.Min(energyStorage.getLimitExtract() * dt, energyStorage.getEnergyStored())));
     }
     else if (inventory[0]?.Itemstack?.Block is IFluxStorageItem)
     {
         energyStorage.modifyEnergyStored(-((IFluxStorageItem)inventory[0].Itemstack.Block).receiveEnergy(inventory[0].Itemstack, (int)Math.Min(energyStorage.getLimitExtract() * dt, energyStorage.getEnergyStored())));
     }
     MarkDirty();
 }
Esempio n. 6
0
    private void OnCommonTick(float dt)
    {
        if (energyStorage.getEnergyStored() >= consume * dt)
        {
            energyStorage.modifyEnergyStored(-consume * dt);
            if (burning == false)
            {
                burning = true;
                MarkDirty(true);
            }
        }
        else
        {
            if (burning == true)
            {
                burning = false;
                MarkDirty(true);
            }
        }

        if (burning)
        {
            double hoursPassed = Api.World.Calendar.TotalHours - lastTickTotalHours;

            if (contents != null)
            {
                float temp = contents.Collectible.GetTemperature(Api.World, contents);
                if (temp < 1100)
                {
                    float tempGain = (float)(hoursPassed * 1100);

                    //float diff = Math.Abs(temp - 1100);
                    //float tempGain = dt + dt * (diff / 28);

                    contents.Collectible.SetTemperature(Api.World, contents, Math.Min(1100, temp + tempGain));
                    MarkDirty(true);
                }
            }
        }


        tmpPos.Set(Pos.X + 0.5, Pos.Y + 0.5, Pos.Z + 0.5);
        double rainLevel = 0;
        bool   rainCheck =
            Api.Side == EnumAppSide.Server &&
            Api.World.Rand.NextDouble() < 0.15 &&
            Api.World.BlockAccessor.GetRainMapHeightAt(Pos.X, Pos.Z) <= Pos.Y &&
            (rainLevel = wsys.GetPrecipitation(tmpPos)) > 0.1
        ;

        if (rainCheck && Api.World.Rand.NextDouble() < rainLevel * 5)
        {
            bool playsound = false;
            if (burning)
            {
                playsound = true;
                //fuelLevel -= (float)rainLevel / 250f;
                //if (Api.World.Rand.NextDouble() < rainLevel / 30f || fuelLevel <= 0)
                //{
                //    burning = false;
                //}
                MarkDirty(true);
            }


            float temp = contents == null ? 0 : contents.Collectible.GetTemperature(Api.World, contents);
            if (temp > 20)
            {
                playsound = temp > 100;
                contents.Collectible.SetTemperature(Api.World, contents, Math.Min(1100, temp - 8), false);
                MarkDirty(true);
            }

            if (playsound)
            {
                Api.World.PlaySoundAt(new AssetLocation("sounds/effect/extinguish"), Pos.X + 0.5, Pos.Y + 0.75, Pos.Z + 0.5, null, false, 16);
            }
        }

        lastTickTotalHours = Api.World.Calendar.TotalHours;
    }
Esempio n. 7
0
    private void OnBurnTick(float dt)
    {
        // Only tick on the server and merely sync to client
        if (Api is ICoreClientAPI)
        {
            //renderer.contentStackRenderer.OnUpdate(InputStackTemp);
            return;
        }

        // Furnace is burning: Heat furnace
        if (IsBurning)
        {
            furnaceTemperature = changeTemperature(furnaceTemperature, MyMiniLib.GetAttributeInt(Block, "maxheat", 1300), dt);
        }

        // Ore follows furnace temperature
        if (canHeatInput())
        {
            heatInput(dt);
        }
        else
        {
            inputStackCookingTime = 0;
        }

        if (canHeatOutput())
        {
            heatOutput(dt);
        }


        // Finished smelting? Turn to smelted item
        if (canSmeltInput() && inputStackCookingTime > maxCookingTime())
        {
            smeltItems();
        }

        float consume = MyMiniLib.GetAttributeInt(Block, "consume", 300) * dt;

        if (energyStorage.getEnergyStored() >= consume)
        {
            energyStorage.modifyEnergyStored(-consume);

            if (!IsBurning)
            {
                IsBurning = true;

                Api.World.BlockAccessor.ExchangeBlock(Api.World.GetBlock(Block.CodeWithVariant("state", "lit")).BlockId, Pos);
                MarkDirty(true);
            }
        }
        else
        {
            if (IsBurning)
            {
                IsBurning = false;

                Api.World.BlockAccessor.ExchangeBlock(Api.World.GetBlock(Block.CodeWithVariant("state", "unlit")).BlockId, Pos);
                MarkDirty(true);
            }
        }


        // Furnace is not burning: Cool down furnace and ore also turn of fire
        if (!IsBurning)
        {
            furnaceTemperature = changeTemperature(furnaceTemperature, enviromentTemperature(), dt);
        }
    }