本文整理汇总了Java中net.minecraftforge.fluids.FluidTank.drain方法的典型用法代码示例。如果您正苦于以下问题:Java FluidTank.drain方法的具体用法?Java FluidTank.drain怎么用?Java FluidTank.drain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.fluids.FluidTank
的用法示例。
在下文中一共展示了FluidTank.drain方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drain
import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
@Override
@Nullable
public FluidStack drain(FluidStack resource, boolean doDrain) {
if (ItemStackTools.getStackSize(container) != 1) {
return null;
}
FluidTank tank = loadTank(container);
if(tank == null)return null;
boolean infi = container.getMetadata() == TankType.CREATIVE.getMeta();
if(infi){
return resource.copy();
}
FluidStack ret = tank.drain(resource, doDrain);
saveTank(container, tank);
return ret;
}
示例2: consumeFluids
import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
public void consumeFluids(ArrayList<FluidStack> fluids, FluidMixingRecipe recipe) {
for (FluidTank tank : tanks) {
FluidStack tankFluid = tank.getFluid();
boolean doContinue = true;
for (int j = 0; j < recipe.inputs.size() && doContinue; j++) {
FluidStack recipeFluid = recipe.inputs.get(j);
if (recipeFluid != null && tankFluid != null && recipeFluid.getFluid() == tankFluid.getFluid()) {
doContinue = false;
tank.drain(recipeFluid.amount,true);
}
}
}
}
示例3: tryFillContainer
import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
/**
* This tries to fill the given container (at inventory[slot]) with fluid from the specified tank
* If successful, it places the resulting filled container in inventory[slot]
*
* Note: this deals with the issue where FluidContainerRegistry.fillFluidContainer() returns null for failed fills
*
* @param tank The tank to take the fluid from
* @param liquid The type of liquid in that tank (the calling method will normally have checked this already)
* @param inventory
* @param slot
* @param canisterType The type of canister to return, if it's a canister being filled (pre-matched with the liquid type)
*
*/
public static void tryFillContainer(FluidTank tank, FluidStack liquid, ItemStack[] inventory, int slot, Item canisterType)
{
ItemStack slotItem = inventory[slot];
boolean isCanister = slotItem.getItem() instanceof ItemCanisterGeneric;
final int amountToFill = Math.min(liquid.amount, isCanister ? slotItem.getItemDamage() - 1 : FluidContainerRegistry.BUCKET_VOLUME);
if (amountToFill <= 0 || (isCanister && slotItem.getItem() != canisterType && slotItem.getItemDamage() != ItemCanisterGeneric.EMPTY))
return;
if (isCanister)
{
inventory[slot] = new ItemStack(canisterType, 1, slotItem.getItemDamage() - amountToFill);
tank.drain(amountToFill, true);
}
else if (amountToFill == FluidContainerRegistry.BUCKET_VOLUME)
{
inventory[slot] = FluidContainerRegistry.fillFluidContainer(liquid, inventory[slot]);
if (inventory[slot] == null)
{
//Failed to fill container: restore item that was there before
inventory[slot] = slotItem;
}
else
{
tank.drain(amountToFill, true);
}
}
}
示例4: consumeIngredients
import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
public boolean consumeIngredients(FluidTank input) {
if (!recipe.apply(input.getFluid())) return false;
return input.drain(recipe.getAmount(), true)!=null;
}
示例5: update
import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void update(TileBarrel barrel) {
// Fluids on top.
if (barrel.getTank().getFluid() != null) {
FluidTank tank = barrel.getTank();
if (tank.getFluid().amount != tank.getCapacity())
return;
Fluid fluidInBarrel = tank.getFluid().getFluid();
BlockPos barrelPos = barrel.getPos();
BlockPos pos = new BlockPos(barrelPos.getX(), barrelPos.getY() + 1, barrelPos.getZ());
Block onTop = barrel.getWorld().getBlockState(pos).getBlock();
Fluid fluidOnTop = null;
if (onTop instanceof BlockLiquid) {
fluidOnTop = onTop.getMaterial(barrel.getWorld().getBlockState(pos)) == Material.WATER
? FluidRegistry.WATER : FluidRegistry.LAVA;
}
if (onTop != null && onTop instanceof IFluidBlock) {
fluidOnTop = ((BlockFluidBase) onTop).getFluid();
}
if (FluidOnTopRegistry.isValidRecipe(fluidInBarrel, fluidOnTop)) {
ItemInfo info = FluidOnTopRegistry.getTransformedBlock(fluidInBarrel, fluidOnTop);
tank.drain(tank.getCapacity(), true);
barrel.setMode("block");
PacketHandler.sendToAllAround(new MessageBarrelModeUpdate("block", barrel.getPos()), barrel);
barrel.getMode().addItem(info.getItemStack(), barrel);
return;
}
// Fluid transforming time!
if (FluidTransformRegistry.containsKey(barrel.getTank().getFluid().getFluid().getName())) {
List<FluidTransformer> transformers = FluidTransformRegistry
.getFluidTransformers(barrel.getTank().getFluid().getFluid().getName());
boolean found = false;
for (int radius = 0; radius <= 2; radius++) {
for (FluidTransformer transformer : transformers) {
if (!BarrelLiquidBlacklistRegistry.isBlacklisted(barrel.getTier(), transformer.getOutputFluid())
&& (Util.isSurroundingBlocksAtLeastOneOf(transformer.getTransformingBlocks(),
barrel.getPos().add(0, -1, 0), barrel.getWorld(), radius)
|| Util.isSurroundingBlocksAtLeastOneOf(transformer.getTransformingBlocks(),
barrel.getPos(), barrel.getWorld(), radius))) {
// Time to start the process.
FluidStack fstack = tank.getFluid();
tank.setFluid(null);
barrel.setMode("fluidTransform");
BarrelModeFluidTransform mode = (BarrelModeFluidTransform) barrel.getMode();
mode.setTransformer(transformer);
mode.setInputStack(fstack);
mode.setOutputStack(FluidRegistry.getFluidStack(transformer.getOutputFluid(), 1000));
PacketHandler.sendNBTUpdate(barrel);
found = true;
}
}
if (found) break;
}
}
}
}