Exemple #1
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();
 }
Exemple #2
0
    private void OnServerTick(float dt)
    {
        float res = Math.Min(consume * dt, energyStorage.getEnergyStored());

        energyStorage.modifyEnergyStored(-res);
        ((BEBehaviorTFEngine)Behaviors[0]).speed = res / (consume * dt);
    }
    private void tick(float dt)
    {
        foreach (BlockFacing f in BlockFacing.ALLFACES)
        {
            transferEnergy(f, dt);
        }

        if (pvBh != null && pvBh.Network != null)
        {
            generation = Math.Min(maxgenerate, Math.Abs(maxgenerate * pvBh.Network.Speed * pvBh.GearedRatio / maxspeed));
            energyStorage.modifyEnergyStored(generation * dt);
        }
        else
        {
            generation = 0;
        }
        MarkDirty();
    }
Exemple #4
0
    protected void transferEnergy(BlockFacing side, float dt)
    {
        if (sideConfig[side] != IOEnergySideConfig.OUTPUT)
        {
            return;
        }
        BlockPos    outPos     = Pos.Copy().Offset(side);
        BlockEntity tileEntity = Api.World.BlockAccessor.GetBlockEntity(outPos);

        if (tileEntity == null)
        {
            return;
        }
        if (!(tileEntity is IFluxStorage))
        {
            return;
        }
        float eout = Math.Min(energyStorage.getLimitExtract() * dt, energyStorage.getEnergyStored() * dt);

        energyStorage.modifyEnergyStored(-((IFluxStorage)tileEntity).receiveEnergy(side.Opposite, eout, false, dt));
    }
Exemple #5
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;
    }
Exemple #6
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);
        }
    }