Search in sources :

Example 31 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ProgWidgetLiquidInventoryCondition 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);
            int count = 0;
            if (te instanceof IFluidHandler) {
                List<FluidStack> visitedStacks = new ArrayList<FluidStack>();
                IFluidHandler inv = (IFluidHandler) te;
                for (int i = 0; i < 6; i++) {
                    if (((ISidedWidget) widget).getSides()[i]) {
                        FluidTankInfo[] info = inv.getTankInfo(ForgeDirection.getOrientation(i));
                        if (info != null) {
                            for (FluidTankInfo inf : info) {
                                if (inf.fluid != null && !visitedStacks.contains(visitedStacks) && ProgWidgetLiquidFilter.isLiquidValid(inf.fluid.getFluid(), widget, 1)) {
                                    visitedStacks.add(inf.fluid);
                                    count += inf.fluid.amount;
                                }
                            }
                        }
                    }
                }
            } else {
                Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.getWorld().getBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
                if (fluid != null && ProgWidgetLiquidFilter.isLiquidValid(fluid, widget, 1) && FluidUtils.isSourceBlock(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
                    count += 1000;
                }
            }
            return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? count == ((ICondition) widget).getRequiredCount() : count >= ((ICondition) widget).getRequiredCount();
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) FluidStack(net.minecraftforge.fluids.FluidStack) ChunkPosition(net.minecraft.world.ChunkPosition) Fluid(net.minecraftforge.fluids.Fluid) ArrayList(java.util.ArrayList) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 32 with ChunkPosition

use of net.minecraft.world.ChunkPosition 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 33 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ProgWidgetCoordinateOperator method calculateCoordinate.

public static ChunkPosition calculateCoordinate(IProgWidget widget, int argIndex, EnumOperator operator) {
    ChunkPosition curPos = null;
    switch(operator) {
        case MULIPLY_DIVIDE:
            curPos = new ChunkPosition(1, 1, 1);
            ProgWidgetCoordinate coordinateWidget = (ProgWidgetCoordinate) widget.getConnectedParameters()[argIndex];
            while (coordinateWidget != null) {
                ChunkPosition pos = coordinateWidget.getCoordinate();
                curPos = new ChunkPosition(curPos.chunkPosX * pos.chunkPosX, curPos.chunkPosY * pos.chunkPosY, curPos.chunkPosZ * pos.chunkPosZ);
                coordinateWidget = (ProgWidgetCoordinate) coordinateWidget.getConnectedParameters()[0];
            }
            coordinateWidget = (ProgWidgetCoordinate) widget.getConnectedParameters()[widget.getParameters().length + argIndex];
            while (coordinateWidget != null) {
                ChunkPosition pos = coordinateWidget.getCoordinate();
                if (pos.chunkPosX != 0 && pos.chunkPosY != 0 && pos.chunkPosZ != 0)
                    curPos = new ChunkPosition(curPos.chunkPosX / pos.chunkPosX, curPos.chunkPosY / pos.chunkPosY, curPos.chunkPosZ / pos.chunkPosZ);
                coordinateWidget = (ProgWidgetCoordinate) coordinateWidget.getConnectedParameters()[0];
            }
            break;
        case PLUS_MINUS:
            curPos = new ChunkPosition(0, 0, 0);
            coordinateWidget = (ProgWidgetCoordinate) widget.getConnectedParameters()[argIndex];
            while (coordinateWidget != null) {
                ChunkPosition pos = coordinateWidget.getCoordinate();
                curPos = new ChunkPosition(curPos.chunkPosX + pos.chunkPosX, curPos.chunkPosY + pos.chunkPosY, curPos.chunkPosZ + pos.chunkPosZ);
                coordinateWidget = (ProgWidgetCoordinate) coordinateWidget.getConnectedParameters()[0];
            }
            coordinateWidget = (ProgWidgetCoordinate) widget.getConnectedParameters()[widget.getParameters().length + argIndex];
            while (coordinateWidget != null) {
                ChunkPosition pos = coordinateWidget.getCoordinate();
                curPos = new ChunkPosition(curPos.chunkPosX - pos.chunkPosX, curPos.chunkPosY - pos.chunkPosY, curPos.chunkPosZ - pos.chunkPosZ);
                coordinateWidget = (ProgWidgetCoordinate) coordinateWidget.getConnectedParameters()[0];
            }
            break;
        case MAX_MIN:
            curPos = new ChunkPosition(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
            coordinateWidget = (ProgWidgetCoordinate) widget.getConnectedParameters()[argIndex];
            while (coordinateWidget != null) {
                ChunkPosition pos = coordinateWidget.getCoordinate();
                curPos = new ChunkPosition(Math.max(curPos.chunkPosX, pos.chunkPosX), Math.max(curPos.chunkPosY, pos.chunkPosY), Math.max(curPos.chunkPosZ, pos.chunkPosZ));
                coordinateWidget = (ProgWidgetCoordinate) coordinateWidget.getConnectedParameters()[0];
            }
            if (curPos.equals(new ChunkPosition(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE)))
                curPos = new ChunkPosition(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
            coordinateWidget = (ProgWidgetCoordinate) widget.getConnectedParameters()[widget.getParameters().length + argIndex];
            while (coordinateWidget != null) {
                ChunkPosition pos = coordinateWidget.getCoordinate();
                curPos = new ChunkPosition(Math.min(curPos.chunkPosX, pos.chunkPosX), Math.min(curPos.chunkPosY, pos.chunkPosY), Math.min(curPos.chunkPosZ, pos.chunkPosZ));
                coordinateWidget = (ProgWidgetCoordinate) coordinateWidget.getConnectedParameters()[0];
            }
            break;
    }
    return curPos;
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition)

Example 34 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ProgWidgetCoordinateOperator method getOutputWidget.

@Override
public IProgWidget getOutputWidget(IDroneBase drone, List<IProgWidget> allWidgets) {
    if (!variable.equals("")) {
        ChunkPosition curPos = calculateCoordinate(this, 0, operator);
        aiManager.setCoordinate(variable, curPos);
    }
    return super.getOutputWidget(drone, allWidgets);
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition)

Example 35 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ProgWidgetDropItem method getWidgetAI.

@Override
public EntityAIBase getWidgetAI(IDroneBase drone, IProgWidget widget) {
    return new DroneAIImExBase(drone, (ProgWidgetAreaItemBase) widget) {

        private final Set<ChunkPosition> visitedPositions = new HashSet<ChunkPosition>();

        @Override
        public boolean shouldExecute() {
            boolean shouldExecute = false;
            for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
                ItemStack stack = drone.getInventory().getStackInSlot(i);
                if (stack != null && widget.isItemValidForFilters(stack)) {
                    shouldExecute = super.shouldExecute();
                    break;
                }
            }
            return shouldExecute;
        }

        @Override
        protected boolean moveIntoBlock() {
            return true;
        }

        @Override
        protected boolean isValidPosition(ChunkPosition pos) {
            //another requirement is that the drone can navigate to this exact block, but that's handled by the pathfinder.
            return !visitedPositions.contains(pos);
        }

        @Override
        protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
            visitedPositions.add(pos);
            for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
                ItemStack stack = drone.getInventory().getStackInSlot(i);
                if (stack != null && widget.isItemValidForFilters(stack)) {
                    if (useCount() && getRemainingCount() < stack.stackSize) {
                        stack = stack.splitStack(getRemainingCount());
                        decreaseCount(getRemainingCount());
                    } else {
                        decreaseCount(stack.stackSize);
                        drone.getInventory().setInventorySlotContents(i, null);
                    }
                    EntityItem item = new EntityItem(drone.getWorld(), pos.chunkPosX + 0.5, pos.chunkPosY + 0.5, pos.chunkPosZ + 0.5, stack);
                    if (((IItemDropper) widget).dropStraight()) {
                        item.motionX = 0;
                        item.motionY = 0;
                        item.motionZ = 0;
                    }
                    drone.getWorld().spawnEntityInWorld(item);
                    if (useCount() && getRemainingCount() == 0)
                        break;
                }
            }
            return false;
        }
    };
}
Also used : DroneAIImExBase(pneumaticCraft.common.ai.DroneAIImExBase) Set(java.util.Set) HashSet(java.util.HashSet) ChunkPosition(net.minecraft.world.ChunkPosition) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

ChunkPosition (net.minecraft.world.ChunkPosition)94 ItemStack (net.minecraft.item.ItemStack)16 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 NBTTagList (net.minecraft.nbt.NBTTagList)10 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)9 TileEntity (net.minecraft.tileentity.TileEntity)9 ArrayList (java.util.ArrayList)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 Chunk (net.minecraft.world.chunk.Chunk)4 FluidStack (net.minecraftforge.fluids.FluidStack)4 Stack (java.util.Stack)3 Block (net.minecraft.block.Block)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 IInventory (net.minecraft.inventory.IInventory)3 PathPoint (net.minecraft.pathfinding.PathPoint)3 Vec3 (net.minecraft.util.Vec3)3