本文整理汇总了Java中net.minecraftforge.fluids.FluidUtil类的典型用法代码示例。如果您正苦于以下问题:Java FluidUtil类的具体用法?Java FluidUtil怎么用?Java FluidUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FluidUtil类属于net.minecraftforge.fluids包,在下文中一共展示了FluidUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onFillBucket
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
@SubscribeEvent
public void onFillBucket(FillBucketEvent event) {
RayTraceResult rtr = event.getTarget();
if (rtr != null) {
Block b = event.getWorld().getBlockState(rtr.getBlockPos()).getBlock();
if (b instanceof IFluidBlock) {
Fluid fluid = ((IFluidBlock) b).getFluid();
ItemStack filled = FluidUtil.getFilledBucket(new FluidStack(fluid, 1000));
if (!filled.isEmpty()) {
event.setFilledBucket(FluidUtil.getFilledBucket(new FluidStack(fluid, 1000)));
event.getWorld().setBlockToAir(rtr.getBlockPos());
event.setResult(Result.ALLOW);
if (TileEntityRefinery.isInputFluidValid(fluid, 4) && event.getEntityPlayer() instanceof EntityPlayerMP) {
AdvancementTriggers.OIL_BUCKET.trigger((EntityPlayerMP) event.getEntityPlayer());
}
}
}
}
}
示例2: doFluidInteraction
import net.minecraftforge.fluids.FluidUtil; //导入依赖的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;
}
示例3: autoExportLiquid
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
public void autoExportLiquid() {
if (hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) {
IFluidHandler handler = getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
FluidStack toDrain = handler.drain(1000, false);
if (toDrain != null && toDrain.amount > 0) {
for (EnumFacing d : EnumFacing.VALUES) {
TileEntity te = getTileCache()[d.ordinal()].getTileEntity();
if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, d.getOpposite())) {
IFluidHandler destHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, d.getOpposite());
FluidStack sent = FluidUtil.tryFluidTransfer(destHandler, handler, toDrain, true);
toDrain.amount -= sent == null ? 0 : sent.amount;
if (toDrain.amount <= 0) break;
}
}
}
}
}
示例4: registerGeoBurnables
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
@SubscribeEvent
public static void registerGeoBurnables(RegistryEvent.Register<IGeoburnable> event){
IForgeRegistry<IGeoburnable> reg = event.getRegistry();
reg.register(new BlockGeoburnable(Blocks.MAGMA, 40, 1));
reg.register(new BlockGeoburnable(Blocks.FIRE, 80, 2){
@Override
public ItemStack getJEIIcon() {
return new ItemStack(Items.FLINT_AND_STEEL);
}
});
reg.register(new BlockGeoburnable(Blocks.LAVA, 160, 3){
@Override
public ItemStack getJEIIcon() {
return FluidUtil.getFilledBucket(new FluidStack(FluidRegistry.LAVA, Fluid.BUCKET_VOLUME));
}
});
}
示例5: interactWithFluidItem
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
private boolean interactWithFluidItem(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing)
{
if (getContent().canInteractWithFluidItem.get(getSubtype(state)).orElse(true))
{
TileEntity tile = worldIn.getTileEntity(pos);
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing))
{
if (worldIn.isRemote)
{
return true;
}
if (FluidUtil.interactWithFluidHandler(playerIn, hand, worldIn, pos, facing))
{
playerIn.inventoryContainer.detectAndSendChanges();
return true;
}
}
}
return false;
}
示例6: onBlockActivated
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if(!worldIn.isRemote) {
TileEntity te = worldIn.getTileEntity(pos);
if(te != null && te instanceof TileFluidTank) {
ItemStack activeHand = playerIn.getHeldItem(hand);
if(!activeHand.isEmpty() && FluidUtil.getFluidHandler(activeHand) != null) {
FluidTank ft = ((TileFluidTank) te).getTank();
boolean canFillPrev = ft.canFill();
boolean canDrainPrev = ft.canDrain();
ft.setCanFill(true);
ft.setCanDrain(true);
try {
FluidUtil.interactWithFluidHandler(playerIn, hand, ft);
} finally {
ft.setCanFill(canFillPrev);
ft.setCanDrain(canDrainPrev);
}
return true;
}
playerIn.openGui(ModularMachinery.MODID, CommonProxy.GuiType.TANK_INVENTORY.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
}
}
return true;
}
示例7: matches
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
boolean foundSyringe = false;
boolean foundBucket = false;
ItemStack bucket = FluidUtil.getFilledBucket(new FluidStack(ModBlocks.FLUID_MANA.getFluid(), 1));
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack.getItem() == ModItems.SYRINGE && stack.getItemDamage() == 0) {
foundSyringe = true;
}
if (ItemStack.areItemStacksEqual(bucket, stack))
foundBucket = true;
}
return foundSyringe && foundBucket;
}
示例8: matches
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
boolean foundSyringe = false;
boolean foundMana = false;
boolean foundNacre = false;
boolean foundLava = false;
boolean foundDevilDust = false;
ItemStack mana = FluidUtil.getFilledBucket(new FluidStack(ModBlocks.FLUID_MANA.getFluid(), 1));
ItemStack nacre = FluidUtil.getFilledBucket(new FluidStack(ModBlocks.FLUID_NACRE.getFluid(), 1));
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack.getItem() == ModItems.SYRINGE && stack.getItemDamage() == 0) foundSyringe = true;
if (ItemStack.areItemStacksEqual(mana, stack)) foundMana = true;
if (ItemStack.areItemStacksEqual(nacre, stack)) foundNacre = true;
if (stack.getItem() == Items.LAVA_BUCKET) foundLava = true;
if (stack.getItem() == ModItems.DEVIL_DUST) foundDevilDust = true;
}
return foundSyringe && foundMana && foundDevilDust && foundLava && foundNacre;
}
示例9: onItemUse
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (world.isRemote)
return null;
IFluidHandler h = FluidUtil.getFluidHandler(world, pos, side);
if (h != null) {
for (Entry<FluidStack, ItemStack> e : fluidToItem.entrySet()) {
FluidStack drain = h.drain(new FluidStack(e.getKey(), e.getKey().amount), false);
if (e.getKey().isFluidStackIdentical(drain)) {
h.drain(drain, true);
ItemStack s = e.getValue().copy();
stack.shrink(1);
player.setHeldItem(hand, stack);
if (!player.inventory.addItemStackToInventory(s)) {
InventoryHelper.spawnItemStack(world, player.posX, player.posY, player.posZ, s);
}
player.inventoryContainer.detectAndSendChanges();
return EnumActionResult.SUCCESS;
}
}
}
return null;
}
示例10: onBlockActivated
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
public boolean onBlockActivated(ItemStack stack, EntityPlayer player) {
if (stack == null)
return false;
//Bucketing out the fluid.
if (stack != null && stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) {
boolean result = FluidUtil.interactWithFluidHandler(stack, tank, player);
if (result) {
PacketHandler.sendNBTUpdate(this);
}
return true;
}
//Adding a meltable.
ItemStack addStack = stack.copy(); addStack.stackSize = 1;
ItemStack insertStack = itemHandler.insertItem(0, addStack, true);
if (!ItemStack.areItemStacksEqual(addStack, insertStack)) {
itemHandler.insertItem(0, addStack, false);
stack.stackSize--;
PacketHandler.sendNBTUpdate(this);
return true;
}
return true;
}
示例11: 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 heldStack = player.getHeldItem(hand);
ItemStack cauldron = getDrops(world, pos, state, 0).get(0);
if (player.isSneaking() && (player.getHeldItemMainhand().isEmpty() && player.getHeldItemOffhand().isEmpty())) {
this.onBlockDestroyedByPlayer(world, pos, state);
InventoryHandlerHelper.giveItem(player, hand, cauldron);
world.setBlockToAir(pos);
}
TileFluidTank tank = new TileFluidTank(0);
if (cauldron.getTagCompound() != null) {
tank.readFromNBT(cauldron.getTagCompound());
}
if (removeDye(world, pos, player, hand, heldStack, tank)) {
return true;
}
//Fluid handling
FluidUtil.interactWithFluidHandler(player, hand, world, pos, facing);
return FluidUtil.getFluidHandler(heldStack) != null;
}
示例12: fillWithRain
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
@Override
public void fillWithRain(World world, BlockPos pos) {
if (world.rand.nextInt(10) == 1) {
IFluidHandler handler = FluidUtil.getFluidHandler(world, pos, null);
ItemStack cauldron = getDrops(world, pos, world.getBlockState(pos), 0).get(0);
TileFluidTank tank = new TileFluidTank(0);
tank.readFromNBT(NBTHelper.getTag(cauldron));
float temperature = world.getBiome(pos).getFloatTemperature(pos);
if (world.getBiomeProvider().getTemperatureAtHeight(temperature, pos.getY()) >= 0.15F) {
if ((tank.getFluidAmount() == 0 || tank.getFluid() != null && tank.getFluid().getFluid() == FluidRegistry.WATER) && tank.getFluidAmount() < Fluid.BUCKET_VOLUME) {
if (handler != null) {
handler.fill(new FluidStack(FluidRegistry.WATER, 250), true);
}
}
}
}
}
示例13: dumpContainer
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
/**
* Drains a filled container and places the fluid.
*
* RETURN new item stack that has been drained after placing in world if it works null otherwise
*/
public static ItemStack dumpContainer(World world, BlockPos pos, ItemStack stackIn) {
// BlockSourceImpl blocksourceimpl = new BlockSourceImpl(world, pos);
ItemStack dispensedStack = stackIn.copy();
dispensedStack.setCount(1);
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(dispensedStack);
if (fluidHandler == null) {
return null;
}
FluidStack fluidStack = fluidHandler.drain(Fluid.BUCKET_VOLUME, false);
if (fluidStack != null && fluidStack.amount >= Fluid.BUCKET_VOLUME) {
// FluidActionResult placeResult = FluidUtil.tryPlaceFluid(null, world, pos, dispensedStack, fluidStack);
if (FluidUtil.tryPlaceFluid(null, world, pos, dispensedStack, fluidStack).isSuccess()) {
//http://www.minecraftforge.net/forum/topic/56265-1112-fluidhandler-capability-on-buckets/
fluidHandler.drain(Fluid.BUCKET_VOLUME, true);
ItemStack returnMe = fluidHandler.getContainer();
// stackIn.deserializeNBT(returnMe.serializeNBT());
return returnMe;
}
}
return null;
}
示例14: addPoisonRecipe
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
public static void addPoisonRecipe() {
try {
//dont do this, FluidsRegistry.fluid_poison , some other mod might have added poison first, then we get rejected --> null
Fluid poison = FluidRegistry.getFluid(FluidsRegistry.fluid_poison.getName());
if (poison == null) {
return;
}
RecipeRegistry.addShapelessRecipe(FluidUtil.getFilledBucket(new FluidStack(poison, Fluid.BUCKET_VOLUME)),
FluidUtil.getFilledBucket(new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME)),
Items.SPIDER_EYE, Items.POISONOUS_POTATO, Items.SUGAR);
}
catch (Exception e) {
//if another mod adds poison fluid (such as biomes o plenty), then our fluid gets rejected
ModCyclic.logger.error("Error: Cyclic failed to add recipe for Poison Bucket");
e.printStackTrace();
}
}
示例15: onBlockActivated
import net.minecraftforge.fluids.FluidUtil; //导入依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
// TODO: display text if any
boolean success = false;
TileEntityItemCable te = (TileEntityItemCable) world.getTileEntity(pos);
if (te != null && world.isRemote == false) {
String msg = null;
if (te.getLabelText() != "") {
msg = te.getLabelText();
if (te.getIncomingStrings() != "") {
msg += " (" + UtilChat.lang("cyclic.item.flowing") + te.getIncomingStrings() + ")";
}
}
else {
msg = UtilChat.lang("cyclic.item.empty");
}
UtilChat.sendStatusMessage(player, msg);
success = true;
}
// otherwise return true if it is a fluid handler to prevent in world placement
return success || FluidUtil.getFluidHandler(player.getHeldItem(hand)) != null || super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}