Search in sources :

Example 6 with EntityDamageSource

use of net.minecraft.util.EntityDamageSource in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class FuelHandler method manageSteam.

public void manageSteam(EntityTrainCore train) {
    //manage solid fuel
    if (isFuel(train.getStackInSlot(0), train) && fuel + TileEntityFurnace.getItemBurnTime(train.getStackInSlot(0)) < train.getMaxFuel()) {
        fuel += TileEntityFurnace.getItemBurnTime(train.getStackInSlot(0));
        lastFuelConsumed = train.getStackInSlot(0).getItem();
        if (!train.getBoolean(GenericRailTransport.boolValues.CREATIVE)) {
            train.decrStackSize(0, 1);
        }
    }
    //if there's a fluid item in the slot and the train can consume the entire thing
    if (train.getStackInSlot(1) != null && train.fill(null, isUseableFluid(train.getStackInSlot(1), train), false) >= FluidContainerRegistry.getFluidForFilledItem(train.getStackInSlot(1)).amount) {
        train.fill(null, isUseableFluid(train.getStackInSlot(1), train), true);
        if (!train.getBoolean(GenericRailTransport.boolValues.CREATIVE)) {
            train.decrStackSize(1, 1);
            train.addItem(new ItemStack(Items.bucket));
        }
    }
    //be sure there is fuel before trying to consume it
    if (fuel > 0) {
        /*
					* add steam from burning to the steam tank.
					* steam is equal to water used, minus a small percentage to compensate for impurities in the water that don't transition to steam,
					* the amount of water used is generated from heat which is one part fuel 2 parts air, with more fuel burning more heat is created, but this only works to a point.
					* steam beyond the max point of storage is considered to be expelled through a failsafe.
					* NOTE: in TiM we need to remember steam and fluid are housed in the same tank, and calculate based on that. should also throw in calcium buildup for non-distilled water. TC however isn't so advanced
					*/
        int steam = Math.round(//calculate heat from fuel
        (fuel * 0.00075f) * //calculate surface area of water
        (train.getTankAmount() * 0.005f));
        if (train.drain(null, steam, true) != null) {
            //a lava bucket lasts 1000 seconds, so burnables are processed at 20000*0.05 a second
            fuel -= 10 * train.getEfficiency();
            steamTank += steam;
            if (steamTank > train.getTankCapacity()) {
                //in TiM it needs to be  > getTankCapacity-getTankAmount.
                steamTank = train.getTankCapacity();
            }
        } else if (!train.getBoolean(GenericRailTransport.boolValues.CREATIVE)) {
            train.worldObj.createExplosion(train, train.posX, train.posY, train.posZ, 5f, false);
            train.dropItem(train.getItem(), 1);
            train.attackEntityFromPart(null, new EntityDamageSource("overheat", train), 100);
        }
    } else if (fuel < 0) {
        fuel = 0;
    }
    if (steamTank > 0) {
        train.setBoolean(GenericRailTransport.boolValues.RUNNING, true);
        //steam is expelled through the pistons to push them back and forth, but even when the accelerator is off, a degree of steam is still escaping.
        steamTank -= (5 * train.getEfficiency()) * ((train.accelerator) * train.getEfficiency());
    } else {
        train.setBoolean(GenericRailTransport.boolValues.RUNNING, false);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityDamageSource(net.minecraft.util.EntityDamageSource)

Aggregations

EntityDamageSource (net.minecraft.util.EntityDamageSource)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Block (net.minecraft.block.Block)1 BlockAir (net.minecraft.block.BlockAir)1 Entity (net.minecraft.entity.Entity)1 EntityDragon (net.minecraft.entity.boss.EntityDragon)1 EntityFireworkRocket (net.minecraft.entity.item.EntityFireworkRocket)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityEnderman (net.minecraft.entity.monster.EntityEnderman)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 DamageSource (net.minecraft.util.DamageSource)1 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)1