本文整理汇总了Java中net.minecraftforge.fluids.FluidUtil.getFluidContained方法的典型用法代码示例。如果您正苦于以下问题:Java FluidUtil.getFluidContained方法的具体用法?Java FluidUtil.getFluidContained怎么用?Java FluidUtil.getFluidContained使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.fluids.FluidUtil
的用法示例。
在下文中一共展示了FluidUtil.getFluidContained方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockActivated
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
/**
* with thanks and gratitude @KnightMiner https://github.com/KnightMiner/Ceramics/blob/1.11/src/main/java/knightminer/ceramics/blocks/BlockBarrel.java
*
*
*/
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
// check the TE
TileEntityHydrator te = (TileEntityHydrator) world.getTileEntity(pos);
FluidStack bucket = FluidUtil.getFluidContained(player.getHeldItem(hand));
boolean success = false;
if (bucket == null || bucket.getFluid() == FluidRegistry.WATER) {//THEN let fluid insert happen
success = FluidUtil.interactWithFluidHandler(player, hand, world, pos, side);
}
if (te != null) {
if (!world.isRemote) {
int currentFluid = te.getField(Fields.FLUID.ordinal());
UtilChat.sendStatusMessage(player, UtilChat.lang("cyclic.fluid.amount") + currentFluid);
}
}
// 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);
}
示例2: update
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public void update()
{
ItemStack stack = inventory.get(0);
if(!stack.isEmpty() && stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.DOWN))
{
IFluidHandlerItem fh = FluidUtil.getFluidHandler(stack);
FluidStack fluid = FluidUtil.getFluidContained(stack);
if(fh != null && fluid != null)
{
int amountFilled = fluidTanks[0].fillInternal(fluid, false);
FluidStack amountDrained = fh.drain(amountFilled, true);
if(amountDrained != null && amountDrained.amount > 0)
{
fluidTanks[0].fillInternal(amountDrained, true);
inventory.set(0, fh.getContainer());
}
}
}
super.update();
}
示例3: getNameFromStack
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
/**
* TODO: raise a PR to get this into IGW. This adds support for Forge filled buckets (use "item/bucket/{fluid_name}")
*
* @param stack
* @return
*/
static String getNameFromStack(ItemStack stack) {
if (stack.getItem().getRegistryName().toString().equals("forge:bucketfilled")) {
FluidStack fluidStack = FluidUtil.getFluidContained(stack);
if (fluidStack != null) {
return "item/bucket/" + fluidStack.getFluid().getName();
} else {
return "item/bucket";
}
}
return stack.getUnlocalizedName().replace("tile.", "block/").replace("item.", "item/");
}
示例4: scanForFluids
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
private static void scanForFluids(ShapedOreRecipe recipe) {
for (int i = 0; i < recipe.getIngredients().size(); i++) {
Ingredient ingredient = recipe.getIngredients().get(i);
for (ItemStack stack : ingredient.getMatchingStacks()) {
FluidStack fluid = FluidUtil.getFluidContained(stack);
if (fluid != null) {
ForgeRegistries.RECIPES.register(new RecipeFluid(recipe, i));
}
}
}
}
示例5: RecipeFluid
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
public RecipeFluid(ShapedOreRecipe recipe, int fluidIndex) {
super("fluid_recipe_" + recipeIndex++);
this.recipe = recipe;
Ingredient ingredient = recipe.getIngredients().get(fluidIndex);
originalStack = ingredient.getMatchingStacks()[0];
fluidStack = FluidUtil.getFluidContained(originalStack);
if (fluidStack == null)
throw new IllegalArgumentException("Recipe doesn't have fluid item at index " + fluidIndex + ". Item: " + originalStack);
this.fluidIndex = fluidIndex;
}
示例6: handleFuelEvent
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@SubscribeEvent
public void handleFuelEvent(FurnaceFuelBurnTimeEvent event) {
FluidStack fluidStack = FluidUtil.getFluidContained(event.getItemStack());
if (fluidStack != null) {
int value = PneumaticCraftAPIHandler.getInstance().liquidFuels.getOrDefault(fluidStack.getFluid().getName(), -1);
event.setBurnTime(value > 0 ? (int)(value * ConfigHandler.general.fuelBucketEfficiencyMultiplier) : -1);
}
}
示例7: getCaskLiquid
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
public CaskLiquid getCaskLiquid(ItemStack stack) {
FluidStack fluid = FluidUtil.getFluidContained(stack);
if(fluid != null) {
CaskLiquid liquid = CaskManager.getFromFluid(fluid.getFluid());
return liquid;
}
return null;
}
示例8: getItemStackDisplayName
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public String getItemStackDisplayName(ItemStack stack) {
FluidStack fluid = FluidUtil.getFluidContained(stack);
if(fluid != null)
return I18n.translateToLocalFormatted("item.mug.name",fluid.getLocalizedName());
else
return I18n.translateToLocal("item.mug.empty.name");
}
示例9: isEmptyFluidContainer
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
public static boolean isEmptyFluidContainer(ItemStack stack)
{
//If the stack has a fluid cap, but no contained fluid, it's probably empty
if(stack != null && CapUtils.hasFluidHandler(stack) && FluidUtil.getFluidContained(stack) == null)
return true;
else
return false;
}
示例10: handleItemState
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
{
FluidStack fluidStack = FluidUtil.getFluidContained(stack);
// not a fluid item apparently
if (fluidStack == null)
{
// empty bucket
return originalModel;
}
BakedDynBucket model = (BakedDynBucket)originalModel;
Fluid fluid = fluidStack.getFluid();
String name = fluid.getName();
if (!model.cache.containsKey(name))
{
IModel parent = model.parent.process(ImmutableMap.of("fluid", name));
Function<ResourceLocation, TextureAtlasSprite> textureGetter;
textureGetter = new Function<ResourceLocation, TextureAtlasSprite>()
{
public TextureAtlasSprite apply(ResourceLocation location)
{
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
}
};
IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter);
model.cache.put(name, bakedModel);
return bakedModel;
}
return model.cache.get(name);
}
示例11: apply
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public boolean apply(@Nullable ItemStack stack)
{
if (stack == null)
{
return false;
}
else
{
FluidStack fluidStack = FluidUtil.getFluidContained(stack);
return fluidStack == null && this.fluid == null || fluidStack != null && fluidStack.containsFluid(fluid);
}
}
示例12: 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();
}
示例13: 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);
}
}
}
示例14: addFilledBucket
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
public ContainerBucketFillHandler addFilledBucket(ItemStack filledBucket) {
FluidStack containedFluid = FluidUtil.getFluidContained(filledBucket);
if (containedFluid != null) {
buckets.add(Pair.of(containedFluid.copy(), filledBucket.copy()));
} else {
Log.warn("Item %s is not a filled bucket", filledBucket);
}
return this;
}
示例15: isItemValid
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public boolean isItemValid(@Nonnull ItemStack stack) {
FluidStack fluidStack = FluidUtil.getFluidContained(stack);
return fluidStack != null && fluidStack.amount > 0;
}