use of net.minecraftforge.fluids.IFluidHandler 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.minecraftforge.fluids.IFluidHandler 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.minecraftforge.fluids.IFluidHandler 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.minecraftforge.fluids.IFluidHandler 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);
}
}
}
}
use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.
the class AmadronOfferManager method tryRestockCustomOffers.
public void tryRestockCustomOffers() {
for (AmadronOffer offer : allOffers) {
if (offer instanceof AmadronOfferCustom) {
AmadronOfferCustom custom = (AmadronOfferCustom) offer;
TileEntity input = custom.getProvidingTileEntity();
TileEntity output = custom.getReturningTileEntity();
int possiblePickups = ContainerAmadron.capShoppingAmount(custom.invert(), 50, input instanceof IInventory ? (IInventory) input : null, output instanceof IInventory ? (IInventory) output : null, input instanceof IFluidHandler ? (IFluidHandler) input : null, output instanceof IFluidHandler ? (IFluidHandler) output : null, null);
if (possiblePickups > 0) {
ChunkPosition pos = new ChunkPosition(input.xCoord, input.yCoord, input.zCoord);
EntityDrone drone = ContainerAmadron.retrieveOrderItems(custom, possiblePickups, input.getWorldObj(), pos, input.getWorldObj(), pos);
if (drone != null) {
drone.setHandlingOffer(custom.copy(), possiblePickups, null, "Restock");
}
}
custom.invert();
custom.payout();
}
}
}
Aggregations