use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class SemiBlockRequester method amountRequested.
@Override
public int amountRequested(FluidStack stack) {
int totalRequestingAmount = getTotalRequestedAmount(stack);
if (totalRequestingAmount > 0) {
TileEntity te = getTileEntity();
if (te instanceof IFluidHandler) {
int count = 0;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
FluidTankInfo[] infos = ((IFluidHandler) te).getTankInfo(d);
if (infos != null) {
for (FluidTankInfo info : infos) {
if (info.fluid != null && info.fluid.getFluid() == stack.getFluid()) {
count += info.fluid.amount;
}
}
if (count > 0)
break;
}
}
count += getIncomingFluid(stack.getFluid());
int requested = Math.max(0, Math.min(stack.amount, totalRequestingAmount - count));
return requested;
}
}
return 0;
}
use of net.minecraft.tileentity.TileEntity 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.tileentity.TileEntity 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.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class AmadronOfferCustom method returnStock.
public void returnStock() {
TileEntity provider = getProvidingTileEntity();
TileEntity returning = getReturningTileEntity();
invert();
while (inStock > 0) {
int stock = Math.min(inStock, 50);
stock = ContainerAmadron.capShoppingAmount(this, stock, returning instanceof IInventory ? (IInventory) returning : null, provider instanceof IInventory ? (IInventory) provider : null, returning instanceof IFluidHandler ? (IFluidHandler) returning : null, provider instanceof IFluidHandler ? (IFluidHandler) provider : null, null);
if (stock > 0) {
inStock -= stock;
if (getInput() instanceof ItemStack) {
ItemStack deliveringItems = (ItemStack) getInput();
int amount = deliveringItems.stackSize * stock;
List<ItemStack> stacks = new ArrayList<ItemStack>();
while (amount > 0) {
ItemStack stack = deliveringItems.copy();
stack.stackSize = Math.min(amount, stack.getMaxStackSize());
stacks.add(stack);
amount -= stack.stackSize;
}
PneumaticRegistry.getInstance().deliverItemsAmazonStyle(provider.getWorldObj(), provider.xCoord, provider.yCoord, provider.zCoord, stacks.toArray(new ItemStack[stacks.size()]));
} else {
FluidStack deliveringFluid = ((FluidStack) getInput()).copy();
deliveringFluid.amount *= stock;
PneumaticRegistry.getInstance().deliverFluidAmazonStyle(provider.getWorldObj(), provider.xCoord, provider.yCoord, provider.zCoord, deliveringFluid);
}
} else {
break;
}
}
}
use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class AmadronOfferCustom method payout.
public void payout() {
TileEntity returning = getReturningTileEntity();
TileEntity provider = getProvidingTileEntity();
if (pendingPayments > 0) {
int paying = Math.min(pendingPayments, 50);
paying = ContainerAmadron.capShoppingAmount(this, paying, provider instanceof IInventory ? (IInventory) provider : null, returning instanceof IInventory ? (IInventory) returning : null, provider instanceof IFluidHandler ? (IFluidHandler) provider : null, returning instanceof IFluidHandler ? (IFluidHandler) returning : null, null);
if (paying > 0) {
pendingPayments -= paying;
if (getInput() instanceof ItemStack) {
ItemStack deliveringItems = (ItemStack) getInput();
int amount = deliveringItems.stackSize * paying;
List<ItemStack> stacks = new ArrayList<ItemStack>();
while (amount > 0) {
ItemStack stack = deliveringItems.copy();
stack.stackSize = Math.min(amount, stack.getMaxStackSize());
stacks.add(stack);
amount -= stack.stackSize;
}
PneumaticRegistry.getInstance().deliverItemsAmazonStyle(returning.getWorldObj(), returning.xCoord, returning.yCoord, returning.zCoord, stacks.toArray(new ItemStack[stacks.size()]));
} else {
FluidStack deliveringFluid = ((FluidStack) getInput()).copy();
deliveringFluid.amount *= paying;
PneumaticRegistry.getInstance().deliverFluidAmazonStyle(returning.getWorldObj(), returning.xCoord, returning.yCoord, returning.zCoord, deliveringFluid);
}
}
}
}
Aggregations