Search in sources :

Example 1 with IFuelable

use of micdoodle8.mods.galacticraft.api.entity.IFuelable in project Galacticraft by micdoodle8.

the class TileEntityFuelLoader method update.

@Override
public void update() {
    super.update();
    if (!this.worldObj.isRemote) {
        this.loadedFuelLastTick = false;
        final FluidStack liquidContained = FluidUtil.getFluidContained(this.containingItems[1]);
        if (FluidUtil.isFuel(liquidContained)) {
            FluidUtil.loadFromContainer(this.fuelTank, GCFluids.fluidFuel, this.containingItems, 1, liquidContained.amount);
        }
        if (this.ticks % 100 == 0) {
            this.attachedFuelable = null;
            BlockVec3 thisVec = new BlockVec3(this);
            for (final EnumFacing dir : EnumFacing.VALUES) {
                final TileEntity pad = thisVec.getTileEntityOnSide(this.worldObj, dir);
                if (pad instanceof TileEntityMulti) {
                    final TileEntity mainTile = ((TileEntityMulti) pad).getMainBlockTile();
                    if (mainTile instanceof IFuelable) {
                        this.attachedFuelable = (IFuelable) mainTile;
                        break;
                    }
                } else if (pad instanceof IFuelable) {
                    this.attachedFuelable = (IFuelable) pad;
                    break;
                }
            }
        }
        if (this.fuelTank != null && this.fuelTank.getFluid() != null && this.fuelTank.getFluid().amount > 0) {
            final FluidStack liquid = new FluidStack(GCFluids.fluidFuel, 2);
            if (this.attachedFuelable != null && this.hasEnoughEnergyToRun && !this.disabled) {
                int filled = this.attachedFuelable.addFuel(liquid, true);
                this.loadedFuelLastTick = filled > 0;
                this.fuelTank.drain(filled, true);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IFuelable(micdoodle8.mods.galacticraft.api.entity.IFuelable) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 2 with IFuelable

use of micdoodle8.mods.galacticraft.api.entity.IFuelable in project Galacticraft by micdoodle8.

the class TileEntityBuggyFueler method update.

@Override
public void update() {
    if (!this.initialised) {
        if (!this.worldObj.isRemote)
            this.onCreate(this.worldObj, this.getPos());
        this.initialiseMultiTiles(this.getPos(), this.worldObj);
        this.initialised = true;
    }
    if (!this.worldObj.isRemote) {
        final List<Entity> list = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.fromBounds(this.getPos().getX() - 1.5D, this.getPos().getY() - 2.0, this.getPos().getZ() - 1.5D, this.getPos().getX() + 1.5D, this.getPos().getY() + 4.0, this.getPos().getZ() + 1.5D), new Predicate<Entity>() {

            @Override
            public boolean apply(Entity input) {
                return input instanceof IFuelable;
            }
        });
        boolean changed = false;
        for (final Object o : list) {
            if (o != null && o instanceof IDockable && !this.worldObj.isRemote) {
                final IDockable fuelable = (IDockable) o;
                if (fuelable.isDockValid(this)) {
                    this.dockedEntity = fuelable;
                    this.dockedEntity.setPad(this);
                    changed = true;
                }
            }
        }
        if (!changed) {
            if (this.dockedEntity != null) {
                this.dockedEntity.setPad(null);
            }
            this.dockedEntity = null;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ICargoEntity(micdoodle8.mods.galacticraft.api.entity.ICargoEntity) TileEntity(net.minecraft.tileentity.TileEntity) IFuelable(micdoodle8.mods.galacticraft.api.entity.IFuelable) IDockable(micdoodle8.mods.galacticraft.api.entity.IDockable)

Aggregations

IFuelable (micdoodle8.mods.galacticraft.api.entity.IFuelable)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ICargoEntity (micdoodle8.mods.galacticraft.api.entity.ICargoEntity)1 IDockable (micdoodle8.mods.galacticraft.api.entity.IDockable)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 Entity (net.minecraft.entity.Entity)1 EnumFacing (net.minecraft.util.EnumFacing)1