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();
}
};
}
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;
}
};
}
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;
}
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);
}
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;
}
};
}
Aggregations