本文整理汇总了Java中net.minecraftforge.fluids.FluidActionResult类的典型用法代码示例。如果您正苦于以下问题:Java FluidActionResult类的具体用法?Java FluidActionResult怎么用?Java FluidActionResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FluidActionResult类属于net.minecraftforge.fluids包,在下文中一共展示了FluidActionResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFluidInteraction
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的package包/类
private static boolean doFluidInteraction(TileEntity te, EnumFacing face, EntityPlayer player, EnumHand hand, boolean isInserting) {
ItemStack stack = player.getHeldItem(hand);
IFluidHandlerItem stackHandler = FluidUtil.getFluidHandler(stack);
if (stackHandler != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face)) {
int capacity = stackHandler.getTankProperties()[0].getCapacity();
IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face);
PlayerInvWrapper invWrapper = new PlayerInvWrapper(player.inventory);
FluidActionResult result = isInserting ?
FluidUtil.tryEmptyContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player) :
FluidUtil.tryFillContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player);
if (result.isSuccess()) {
player.setHeldItem(hand, result.getResult());
return true;
}
}
return false;
}
示例2: onBlockActivated
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的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);
}
示例3: onBlockActivated
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的package包/类
@Override
public boolean onBlockActivated(EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) return true;
if (hand == EnumHand.MAIN_HAND) {
final ItemStack heldItem = player.getHeldItemMainhand();
if (!heldItem.isEmpty()) {
final FluidActionResult result = tryEmptyItem(player, heldItem.copy());
if (result.success) {
if (!player.isCreative())
player.setHeldItem(EnumHand.MAIN_HAND, result.result);
return true;
}
} else
return tryDrainXp(player);
}
return false;
}
示例4: tryFluidExtraction
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的package包/类
/**
* Attempt to extract fluid from the given fluid handler into the given fluid-containing item.
*
* @param srcHandler fluid handler into which to place the fluid
* @param destStack the fluid container item to extract from
* @param returnedItems the modified fluid container after extraction
* @return true if any fluid was moved, false otherwise
*/
public static boolean tryFluidExtraction(IFluidHandler srcHandler, ItemStack destStack, NonNullList<ItemStack> returnedItems) {
FluidActionResult result = FluidUtil.tryFillContainer(destStack, srcHandler, 1000, null, true);
if (result.isSuccess()) {
returnedItems.add(result.getResult());
destStack.shrink(1);
return true;
} else {
return false;
}
}
示例5: tryFluidInsertion
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的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;
}
}
示例6: tryEmptyOrFillContainer
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的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;
}
}
示例7: handleRightClickFluidStorage
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的package包/类
public static boolean handleRightClickFluidStorage(EntityPlayer player, EnumHand hand, IFluidHandler tank, int maxTransfer) {
ItemStack fluidItem = player.getHeldItem(hand);
if (fluidItem==null || fluidItem.isEmpty()) return false;
if (!fluidItem.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
return false;
}
FluidActionResult result = tryEmptyOrFillContainer(fluidItem, tank, maxTransfer, player);
if (result.isSuccess()) {
player.setHeldItem(hand, result.result);
return true;
} else {
return false;
}
}
示例8: setInventorySlotContents
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的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();
}
示例9: interactWithFluidHandler
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static boolean interactWithFluidHandler(IFluidHandler tankOnSide, EntityPlayer playerIn, EnumHand hand) {
if (tankOnSide != null) {
FluidActionResult r = FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), tankOnSide, playerIn);
if (r.success)
playerIn.setHeldItem(hand, r.result);
return r.success;
} else
return false;
}
示例10: onBlockActivated
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的package包/类
@Override
public boolean onBlockActivated(World w, BlockPos pos, IBlockState state, EntityPlayer p, EnumHand h, EnumFacing f, float x, float y, float z) {
ItemStack is = p.getHeldItem(h);
if (!w.isRemote) {
TileEntity te = w.getTileEntity(pos);
if (te instanceof TileEntityFluxGen) {
FluidActionResult far = FluidUtil.tryEmptyContainerAndStow(is, (TileEntityFluxGen) te, new InvWrapper(p.inventory), TileEntityFluxGen.fluidCap, p);
if (far.success)
p.setHeldItem(h, far.result);
else
p.openGui(MCFlux.MF, R.MF_GUI_FLUXGEN, w, pos.getX(), pos.getY(), pos.getZ());
}
}
return true;
}
示例11: fillContainer
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的package包/类
/**
* Picks up fluid fills a container with it.
*/
public static FluidActionResult fillContainer(World world, BlockPos pos, ItemStack stackIn, EnumFacing facing) {
// ItemStack result = stackIn.copy();
return FluidUtil.tryPickUpFluid(stackIn, null, world, pos, facing);
// if (--stackIn.stackSize == 0) {
// stackIn.deserializeNBT(result.serializeNBT());
// }
// if (res == FluidActionResult.FAILURE) { return stackIn; }
// return res.getResult();
}
示例12: tryFillTankFromItems
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的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);
}
}
}
示例13: tryEmptyItem
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的package包/类
protected FluidActionResult tryEmptyItem(EntityPlayer player, @Nonnull ItemStack container) {
// not using FluidUtils.tryEmptyContainer, since it limits stack size to 1
final IFluidHandlerItem containerFluidHandler = FluidUtil.getFluidHandler(container);
if (containerFluidHandler != null) {
FluidStack transfer = FluidUtil.tryFluidTransfer(tankCapabilityWrapper, containerFluidHandler, Fluid.BUCKET_VOLUME, true);
if (transfer != null) {
SoundEvent soundevent = transfer.getFluid().getEmptySound(transfer);
player.playSound(soundevent, 1f, 1f);
return new FluidActionResult(containerFluidHandler.getContainer());
}
}
return FluidActionResult.FAILURE;
}
示例14: update
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的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;
}
示例15: rightClickFluidAttempt
import net.minecraftforge.fluids.FluidActionResult; //导入依赖的package包/类
private boolean rightClickFluidAttempt(BlockPos targetPos) {
ItemStack maybeTool = fakePlayer.get().getHeldItemMainhand();
if (maybeTool != null && !maybeTool.isEmpty() && UtilFluid.stackHasFluidHandler(maybeTool)) {
if (UtilFluid.hasFluidHandler(world.getTileEntity(targetPos), this.getCurrentFacing().getOpposite())) {//tile has fluid
ItemStack originalRef = maybeTool.copy();
int hack = (maybeTool.getCount() == 1) ? 1 : 0;//HAX: if bucket stack size is 1, it somehow doesnt work so yeah. good enough EH?
maybeTool.grow(hack);
boolean success = UtilFluid.interactWithFluidHandler(fakePlayer.get(), this.world, targetPos, this.getCurrentFacing().getOpposite());
if (success) {
if (UtilFluid.isEmptyOfFluid(originalRef)) { //original was empty.. maybe its full now IDK
maybeTool.shrink(1 + hack);
}
else {//original had fluid in it. so make sure we drain it now hey
ItemStack drained = UtilFluid.drainOneBucket(maybeTool.splitStack(1));
// drained.setCount(1);
// UtilItemStack.dropItemStackInWorld(this.world, getCurrentFacingPos(), drained);
maybeTool.shrink(1 + hack);
}
this.tryDumpFakePlayerInvo();
}
}
else {//no tank, just open world
//dispense stack so either pickup or place liquid
if (UtilFluid.isEmptyOfFluid(maybeTool)) {
FluidActionResult res = UtilFluid.fillContainer(world, targetPos, maybeTool, this.getCurrentFacing());
if (res != FluidActionResult.FAILURE) {
maybeTool.shrink(1);
UtilItemStack.dropItemStackInWorld(this.world, getCurrentFacingPos(), res.getResult());
return true;
}
}
else {
ItemStack drainedStackOrNull = UtilFluid.dumpContainer(world, targetPos, maybeTool);
if (drainedStackOrNull != null) {
maybeTool.shrink(1);
UtilItemStack.dropItemStackInWorld(this.world, getCurrentFacingPos(), drainedStackOrNull);
}
}
return true;
}
}
return false;
}