Search in sources :

Example 86 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class ProgWidgetPressureCondition method getEvaluator.

@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
    return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {

        @Override
        protected boolean evaluate(ChunkPosition pos) {
            TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
            if (te instanceof IPneumaticMachine) {
                IAirHandler airHandler = ((IPneumaticMachine) te).getAirHandler();
                float pressure = Float.MIN_VALUE;
                for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                    if (getSides()[d.ordinal()]) {
                        pressure = Math.max(airHandler.getPressure(d), pressure);
                    }
                }
                return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? pressure == ((ICondition) widget).getRequiredCount() : pressure >= ((ICondition) widget).getRequiredCount();
            }
            return false;
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAirHandler(pneumaticCraft.api.tileentity.IAirHandler) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ChunkPosition(net.minecraft.world.ChunkPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 87 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class DroneInteractRFImport method doInteract.

@Override
public boolean doInteract(ChunkPosition pos, IDrone drone, IBlockInteractHandler interactHandler, boolean simulate) {
    IEnergyStorage droneEnergy = CoFHCore.getEnergyStorage(drone);
    if (droneEnergy.getEnergyStored() == droneEnergy.getMaxEnergyStored()) {
        interactHandler.abort();
        return false;
    } else {
        TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        if (te instanceof IEnergyProvider) {
            IEnergyProvider provider = (IEnergyProvider) te;
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                if (interactHandler.getSides()[d.ordinal()]) {
                    int transferedEnergy = droneEnergy.receiveEnergy(provider.extractEnergy(d, interactHandler.useCount() ? interactHandler.getRemainingCount() : Integer.MAX_VALUE, true), true);
                    if (transferedEnergy > 0) {
                        if (!simulate) {
                            interactHandler.decreaseCount(transferedEnergy);
                            droneEnergy.receiveEnergy(transferedEnergy, false);
                            provider.extractEnergy(d, transferedEnergy, false);
                        }
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEnergyProvider(cofh.api.energy.IEnergyProvider) IEnergyStorage(cofh.api.energy.IEnergyStorage) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 88 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class WailaHeatHandler method getNBTData.

@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z) {
    if (te instanceof IHeatExchanger) {
        Set<IHeatExchangerLogic> heatExchangers = new HashSet<IHeatExchangerLogic>();
        IHeatExchangerLogic logic = null;
        boolean isMultisided = true;
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            logic = ((IHeatExchanger) te).getHeatExchangerLogic(d);
            if (logic != null) {
                if (heatExchangers.contains(logic)) {
                    isMultisided = false;
                    break;
                } else {
                    heatExchangers.add(logic);
                }
            }
        }
        if (isMultisided) {
            NBTTagList tagList = new NBTTagList();
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                logic = ((IHeatExchanger) te).getHeatExchangerLogic(d);
                if (logic != null) {
                    NBTTagCompound heatTag = new NBTTagCompound();
                    heatTag.setByte("side", (byte) d.ordinal());
                    heatTag.setInteger("temp", (int) logic.getTemperature());
                    tagList.appendTag(heatTag);
                }
            }
            tag.setTag("heat", tagList);
        } else if (logic != null) {
            tag.setInteger("temp", (int) logic.getTemperature());
        }
    }
    return tag;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IHeatExchanger(pneumaticCraft.api.tileentity.IHeatExchanger) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic) HashSet(java.util.HashSet)

Example 89 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class TileEntityAssemblyDrill method updateEntity.

@Override
public void updateEntity() {
    oldDrillRotation = drillRotation;
    super.updateEntity();
    if (isDrillOn) {
        drillSpeed = Math.min(drillSpeed + TileEntityConstants.ASSEMBLY_DRILL_ACCELERATION * speed, TileEntityConstants.ASSEMBLY_DRILL_MAX_SPEED);
    } else {
        drillSpeed = Math.max(drillSpeed - TileEntityConstants.ASSEMBLY_DRILL_ACCELERATION, 0);
    }
    drillRotation += drillSpeed;
    while (drillRotation >= 360) {
        drillRotation -= 360;
    }
    if (!worldObj.isRemote && drillStep > 0) {
        ForgeDirection[] platformDirection = getPlatformDirection();
        if (platformDirection == null)
            drillStep = 1;
        switch(drillStep) {
            case 1:
                slowMode = false;
                gotoHomePosition();
                break;
            case 2:
                hoverOverNeighbour(platformDirection[0], platformDirection[1]);
                break;
            case 3:
                isDrillOn = true;
                break;
            case 4:
                slowMode = true;
                gotoNeighbour(platformDirection[0], platformDirection[1]);
                break;
            case 5:
                hoverOverNeighbour(platformDirection[0], platformDirection[1]);
                isDrillOn = false;
                TileEntity te = getTileEntityForCurrentDirection();
                if (te instanceof TileEntityAssemblyPlatform) {
                    TileEntityAssemblyPlatform platform = (TileEntityAssemblyPlatform) te;
                    platform.hasDrilledStack = true;
                    ItemStack output = getDrilledOutputForItem(platform.getHeldStack());
                    if (output != null) {
                        platform.setHeldStack(output);
                    }
                }
                break;
            case 6:
                slowMode = false;
                gotoHomePosition();
                break;
        }
        if (isDoneInternal()) {
            drillStep++;
            if (drillStep > 6)
                drillStep = 0;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack)

Example 90 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class TileEntityBase method autoExportLiquid.

public void autoExportLiquid() {
    FluidStack extractedStack = ((IFluidHandler) this).drain(ForgeDirection.UNKNOWN, Integer.MAX_VALUE, false);
    if (extractedStack != null) {
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            TileEntity te = getTileCache()[d.ordinal()].getTileEntity();
            if (te instanceof IFluidHandler) {
                if (((IFluidHandler) te).canFill(d.getOpposite(), extractedStack.getFluid())) {
                    int filledAmount = ((IFluidHandler) te).fill(d.getOpposite(), extractedStack, true);
                    ((IFluidHandler) this).drain(ForgeDirection.UNKNOWN, filledAmount, true);
                    extractedStack.amount -= filledAmount;
                    if (extractedStack.amount <= 0)
                        break;
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint)

Aggregations

ForgeDirection (net.minecraftforge.common.util.ForgeDirection)242 TileEntity (net.minecraft.tileentity.TileEntity)80 ItemStack (net.minecraft.item.ItemStack)47 ArrayList (java.util.ArrayList)29 Block (net.minecraft.block.Block)28 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)24 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)21 IInventory (net.minecraft.inventory.IInventory)19 FluidStack (net.minecraftforge.fluids.FluidStack)18 SideOnly (cpw.mods.fml.relauncher.SideOnly)17 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)17 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)16 HashMap (java.util.HashMap)12 Pair (logisticspipes.utils.tuples.Pair)11 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)10 World (net.minecraft.world.World)10 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)9 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)9 List (java.util.List)8