本文整理汇总了Java中net.minecraftforge.fluids.FluidUtil.tryEmptyContainer方法的典型用法代码示例。如果您正苦于以下问题:Java FluidUtil.tryEmptyContainer方法的具体用法?Java FluidUtil.tryEmptyContainer怎么用?Java FluidUtil.tryEmptyContainer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.fluids.FluidUtil
的用法示例。
在下文中一共展示了FluidUtil.tryEmptyContainer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockActivated
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack original = player.getHeldItem(hand);
if (!original.isEmpty()) {
ItemStack stack = original.copy();
stack.setCount(1);
TileEntity tank = getTileEntity(world, pos);
if (tank instanceof TileEntityBTank) {
IFluidHandler handler = ((TileEntityBTank) tank).getFluidHandler();
FluidActionResult result = FluidUtil.tryEmptyContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true);
if (!result.success) {
result = FluidUtil.tryFillContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true);
}
if (result.success) {
original.setCount(original.getCount() - 1);
stack = InvUtil.putStackInInventory(result.result, player.inventory, true, false, false, null);
if (!stack.isEmpty()) {
WorldUtil.dropItemsRandom(world, stack, player.getPosition());
}
return true;
}
}
}
return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
}
示例2: tryFluidInsertion
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
/**
* Attempt to insert fluid into the given fluid handler from the given fluid container item.
*
* @param handler the handler to extract from
* @param srcStack the fluid container item to insert to
* @param returnedItems the modified fluid container after insertion
* @return true if any fluid was moved, false otherwise
*/
public static boolean tryFluidInsertion(IFluidHandler handler, ItemStack srcStack, NonNullList<ItemStack> returnedItems) {
FluidActionResult result = FluidUtil.tryEmptyContainer(srcStack, handler, 1000, null, true);
if (result.isSuccess()) {
returnedItems.add(result.getResult());
srcStack.shrink(1);
return true;
} else {
return false;
}
}
示例3: tryEmptyOrFillContainer
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
public static FluidActionResult tryEmptyOrFillContainer(ItemStack stack, IFluidHandler handler, int maxTransfer, EntityPlayer player) {
FluidActionResult result = FluidUtil.tryEmptyContainer(stack, handler, maxTransfer, player, true);
if (result.success) {
return result;
} else {
FluidActionResult resultFill = FluidUtil.tryFillContainer(stack, handler, maxTransfer, player, true);
return resultFill;
}
}
示例4: setInventorySlotContents
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
if (index < 0 || index >= this.getSizeInventory())
return;
if (!stack.isEmpty() && stack.getCount() > this.getInventoryStackLimit())
stack.setCount(this.getInventoryStackLimit());
if (!stack.isEmpty() && stack.getCount() == 0)
stack = ItemStack.EMPTY;
ItemStack emptyContainer = ItemStack.EMPTY;
if (!stack.isEmpty()) {
FluidStack fluid = FluidUtil.getFluidContained(stack);
if (fluid != null) {
FluidActionResult result = FluidUtil.tryEmptyContainer(stack, new FluidTank(Integer.MAX_VALUE), 1000,
null, true);
if (result.success)
emptyContainer = result.getResult();
}
if (stack.getItem() == Items.WATER_BUCKET) {
emptyContainer = new ItemStack(Items.BUCKET);
}
if (stack.getItem() == Items.LAVA_BUCKET) {
emptyContainer = new ItemStack(Items.BUCKET);
}
if (stack.getItem() == Items.MILK_BUCKET) {
emptyContainer = new ItemStack(Items.BUCKET);
}
}
if (!emptyContainer.isEmpty())
this.inventory.set(index, emptyContainer);
else
this.inventory.set(index, stack);
this.markDirty();
}
示例5: tryFillTankFromItems
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
public void tryFillTankFromItems() {
ItemStack maybeBucket = this.getStackInSlot(SLOT_INFLUID);
FluidStack f = FluidUtil.getFluidContained(maybeBucket);
IFluidHandlerItem bucketHandler = FluidUtil.getFluidHandler(maybeBucket);
if (f != null && bucketHandler != null && f.getFluid().equals(FluidRegistry.WATER)) {
//https://github.com/BluSunrize/ImmersiveEngineering/blob/fc022675bb550318cbadc879b3f28dde511e29c3/src/main/java/blusunrize/immersiveengineering/common/blocks/wooden/TileEntityWoodenBarrel.java
FluidActionResult r = FluidUtil.tryEmptyContainer(maybeBucket, tank, Fluid.BUCKET_VOLUME, null, true);
//in the case of a full bucket, it becomes empty.
//also supports any other fluid holding item, simply draining that fixed amount each round
if (r.success) {
this.setInventorySlotContents(SLOT_INFLUID, r.result);
}
}
}
示例6: update
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public void update() {
boolean curTickPower = world.isBlockIndirectlyGettingPowered(pos)!=0;
//TODO: Actually lock tanks
{ //Bottle fluids out
ItemStack bottles = itemStorage.getStackInSlot(SLOT_EMPTY_BUCKET_IN);
ItemStack outputItem = itemStorage.getStackInSlot(SLOT_FULL_BUCKET_OUT);
FluidStack outputFluid = outputTank.getFluid();
//Are there bottles to fill, is there room to put them, is there fluid to fill them with, and is there *enough* of that fluid?
if (!bottles.isEmpty() && outputItem.getCount()<outputItem.getMaxStackSize() && outputFluid!=null && outputFluid.amount>250) {
ItemStack outBottle = new ItemStack(ThermionicsItems.SPIRIT_BOTTLE);
outBottle.setTagCompound(outputFluid.tag.copy());
if (itemStorage.insertItem(SLOT_FULL_BUCKET_OUT, outBottle, true).isEmpty()) {
outputTank.drainInternal(250, true);
itemStorage.insertItem(SLOT_FULL_BUCKET_OUT, outBottle, false);
itemStorage.extractItem(SLOT_EMPTY_BUCKET_IN, 1, false);
}
}
}
if (!tanksLocked) {
if (curTickPower & !lastTickPower) {
//Lock the tanks on a rising current edge.
setTanksLocked(true);
processTime = 0;
} else {
//Fluid loading/unloading mode
ItemStack inBucket = itemStorage.getStackInSlot(SLOT_FULL_BUCKET_IN);
FluidActionResult result = FluidUtil.tryEmptyContainer(inBucket, inputTank, inputTank.getCapacity(), null, true);
if (result.isSuccess()) {
itemStorage.setStackInSlot(SLOT_FULL_BUCKET_IN, ItemStack.EMPTY);
itemStorage.setStackInSlot(SLOT_EMPTY_BUCKET_OUT, result.getResult());
}
}
} else {
if (processTime<MAX_PROCESS_TIME) processTime++;
FluidStack in = inputTank.getFluid();
if (in==null) {
//Batch is done...?
setTanksLocked(false);
} else {
//Find a recipe, let's go :D
//For the moment, use Water->Rum
PotStillRecipe recipe = MachineRecipes.getPotStill(inputTank);
if (recipe!=null) {
FluidStack output = recipe.getOutput();
int filled = outputTank.fillInternal(output, false);
int extracted = heat.extractHeat(HEAT_REQUIRED, true);
if (output.amount==filled && extracted==HEAT_REQUIRED) {
recipe.consumeIngredients(inputTank);
outputTank.fillInternal(output, true);
heat.extractHeat(HEAT_REQUIRED, false);
}
}
}
}
lastTickPower = curTickPower;
}