Search in sources :

Example 6 with IFluidWrapper

use of com.enderio.core.common.fluid.IFluidWrapper in project EnderIO by SleepyTrousers.

the class ItemXpTransfer method tranferFromBlockToPlayer.

public static boolean tranferFromBlockToPlayer(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side) {
    IFluidWrapper wrapper = FluidWrapper.wrap(world, pos, side);
    if (wrapper != null) {
        FluidStack availableFluid = wrapper.getAvailableFluid();
        if (availableFluid != null && availableFluid.getFluid() == Fluids.XP_JUICE.getFluid() && availableFluid.amount > 0) {
            int currentXP = XpUtil.getPlayerXP(player);
            int nextLevelXP = XpUtil.getExperienceForLevel(player.experienceLevel + 1);
            int requiredXP = nextLevelXP - currentXP;
            int fluidVolume = XpUtil.experienceToLiquid(requiredXP);
            FluidStack fs = new FluidStack(Fluids.XP_JUICE.getFluid(), fluidVolume);
            FluidStack res = wrapper.drain(fs);
            if (res != null && res.amount > 0) {
                int xpToGive = XpUtil.liquidToExperience(res.amount);
                player.addExperience(xpToGive);
                return true;
            }
        }
    }
    return false;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IFluidWrapper(com.enderio.core.common.fluid.IFluidWrapper)

Example 7 with IFluidWrapper

use of com.enderio.core.common.fluid.IFluidWrapper in project EnderIO by SleepyTrousers.

the class LiquidConduit method pushLiquid.

private int pushLiquid(@Nullable EnumFacing from, FluidStack pushStack, boolean doPush, int token) {
    if (token == currentPushToken || pushStack == null || pushStack.amount <= 0 || network == null) {
        return 0;
    }
    currentPushToken = token;
    int pushed = 0;
    int total = pushStack.amount;
    EnumFacing dir = startPushDir;
    FluidStack toPush = pushStack.copy();
    int filledLocal = tank.fill(toPush, doPush);
    toPush.amount -= filledLocal;
    pushed += filledLocal;
    do {
        if (dir != from && canOutputToDir(dir) && !autoExtractForDir(dir)) {
            if (getConduitConnections().contains(dir)) {
                ILiquidConduit conduitCon = getFluidConduit(dir);
                if (conduitCon != null) {
                    int toCon = ((LiquidConduit) conduitCon).pushLiquid(dir.getOpposite(), toPush, doPush, token);
                    toPush.amount -= toCon;
                    pushed += toCon;
                }
            } else if (getExternalConnections().contains(dir)) {
                IFluidWrapper con = getExternalHandler(dir);
                if (con != null) {
                    int toExt = doPush ? con.fill(toPush) : con.offer(toPush);
                    toPush.amount -= toExt;
                    pushed += toExt;
                    if (doPush) {
                        network.outputedToExternal(toExt);
                    }
                }
            }
        }
        dir = getNextDir(dir);
    } while (dir != startPushDir && pushed < total);
    return pushed;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IFluidWrapper(com.enderio.core.common.fluid.IFluidWrapper) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)

Example 8 with IFluidWrapper

use of com.enderio.core.common.fluid.IFluidWrapper in project EnderIO by SleepyTrousers.

the class LiquidConduit method doExtract.

private void doExtract() {
    if (!hasExtractableMode()) {
        return;
    }
    // assume failure, reset to 0 if we do extract
    ticksSinceFailedExtract++;
    if (ticksSinceFailedExtract > 9 && ticksSinceFailedExtract % 10 != 0) {
        // after 10 ticks of failing, only check every 10 ticks
        return;
    }
    for (EnumFacing dir : externalConnections) {
        if (autoExtractForDir(dir)) {
            IFluidWrapper extTank = getExternalHandler(dir);
            if (extTank != null) {
                FluidStack couldDrain = extTank.getAvailableFluid();
                if (couldDrain != null && couldDrain.amount > 0 && canFill(dir, couldDrain)) {
                    couldDrain = couldDrain.copy();
                    if (couldDrain.amount > ConduitConfig.fluid_tier1_extractRate.get()) {
                        couldDrain.amount = ConduitConfig.fluid_tier1_extractRate.get();
                    }
                    int used = pushLiquid(dir, couldDrain, true, network == null ? -1 : network.getNextPushToken());
                    if (used > 0) {
                        couldDrain.amount = used;
                        extTank.drain(couldDrain);
                        if (network != null && network.getFluidType() == null) {
                            network.setFluidType(couldDrain);
                        }
                        ticksSinceFailedExtract = 0;
                    }
                }
            }
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IFluidWrapper(com.enderio.core.common.fluid.IFluidWrapper) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)

Example 9 with IFluidWrapper

use of com.enderio.core.common.fluid.IFluidWrapper in project EnderIO by SleepyTrousers.

the class TileTransceiver method canReceive.

// ---------------- Fluid Handling
public boolean canReceive(Set<Channel> channels, Fluid fluid) {
    if (inFluidFill) {
        return false;
    }
    if (!hasRecieveChannel(channels, ChannelType.FLUID)) {
        return false;
    }
    FluidStack offer = new FluidStack(fluid, 1);
    Map<EnumFacing, IFluidWrapper> neighbours = FluidWrapper.wrapNeighbours(world, pos);
    for (Entry<EnumFacing, IFluidWrapper> entry : neighbours.entrySet()) {
        IoMode mode = getIoMode(entry.getKey());
        if (mode.canOutput() && entry.getValue().offer(offer) > 0) {
            return true;
        }
    }
    return false;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IFluidWrapper(com.enderio.core.common.fluid.IFluidWrapper) IoMode(crazypants.enderio.base.machine.modes.IoMode)

Aggregations

IFluidWrapper (com.enderio.core.common.fluid.IFluidWrapper)9 FluidStack (net.minecraftforge.fluids.FluidStack)8 EnumFacing (net.minecraft.util.EnumFacing)5 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)2 IoMode (crazypants.enderio.base.machine.modes.IoMode)1 ArrayList (java.util.ArrayList)1 BlockPos (net.minecraft.util.math.BlockPos)1