Class PlayerHelper

java.lang.Object
vazkii.botania.common.helper.PlayerHelper

public final class PlayerHelper extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    consumeAmmo(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> ammoFunc)
     
    static net.minecraft.world.item.ItemStack
    getAmmo(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> ammoFunc)
     
    static net.minecraft.world.item.ItemStack
    getFirstHeldItem(net.minecraft.world.entity.LivingEntity living, Predicate<net.minecraft.world.item.ItemStack> pred)
     
    static net.minecraft.world.item.ItemStack
    getFirstHeldItem(net.minecraft.world.entity.LivingEntity living, net.minecraft.world.item.Item item)
     
    static net.minecraft.world.item.ItemStack
    getFirstHeldItemClass(net.minecraft.world.entity.LivingEntity living, Class<?> template)
     
    static net.minecraft.world.item.ItemStack
    getItemClassFromInventory(net.minecraft.world.entity.player.Player player, Class<?> template)
     
    static net.minecraft.world.item.ItemStack
    getItemFromInventory(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> itemPred)
     
    static List<net.minecraft.world.entity.player.Player>
    getRealPlayersIn(net.minecraft.world.level.Level level, net.minecraft.world.phys.AABB aabb)
     
    static void
    grantCriterion(net.minecraft.server.level.ServerPlayer player, net.minecraft.resources.ResourceLocation advancementId, String criterion)
     
    static boolean
    hasAdvancement(net.minecraft.server.level.ServerPlayer player, net.minecraft.resources.ResourceLocation advancementId)
     
    static boolean
    hasAmmo(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> ammoFunc)
     
    static boolean
    hasAnyHeldItem(net.minecraft.world.entity.player.Player player)
     
    static boolean
    hasHeldItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.Item item)
     
    static boolean
    hasHeldItemClass(net.minecraft.world.entity.player.Player player, Class<?> template)
     
    static boolean
    isTruePlayer(@Nullable net.minecraft.world.entity.Entity e)
     
    static void
    setFakePlayerClass(Class<? extends net.minecraft.world.entity.player.Player> fakePlayerClass)
     
    static net.minecraft.world.InteractionResult
    substituteUse(net.minecraft.world.item.context.UseOnContext ctx, net.minecraft.world.item.ItemStack toUse)
     
    static com.mojang.datafixers.util.Pair<net.minecraft.world.InteractionResult,net.minecraft.core.BlockPos>
    substituteUseTrackPos(net.minecraft.world.item.context.UseOnContext ctx, net.minecraft.world.item.ItemStack toUse)
    Temporarily swap toUse into the hand of the player, use it, then swap it back out.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setFakePlayerClass

      public static void setFakePlayerClass(Class<? extends net.minecraft.world.entity.player.Player> fakePlayerClass)
    • isTruePlayer

      public static boolean isTruePlayer(@Nullable @Nullable net.minecraft.world.entity.Entity e)
    • getRealPlayersIn

      public static List<net.minecraft.world.entity.player.Player> getRealPlayersIn(net.minecraft.world.level.Level level, net.minecraft.world.phys.AABB aabb)
    • hasAnyHeldItem

      public static boolean hasAnyHeldItem(net.minecraft.world.entity.player.Player player)
    • hasHeldItem

      public static boolean hasHeldItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.Item item)
    • hasHeldItemClass

      public static boolean hasHeldItemClass(net.minecraft.world.entity.player.Player player, Class<?> template)
    • getFirstHeldItem

      public static net.minecraft.world.item.ItemStack getFirstHeldItem(net.minecraft.world.entity.LivingEntity living, net.minecraft.world.item.Item item)
    • getFirstHeldItem

      public static net.minecraft.world.item.ItemStack getFirstHeldItem(net.minecraft.world.entity.LivingEntity living, Predicate<net.minecraft.world.item.ItemStack> pred)
    • getFirstHeldItemClass

      public static net.minecraft.world.item.ItemStack getFirstHeldItemClass(net.minecraft.world.entity.LivingEntity living, Class<?> template)
    • getAmmo

      public static net.minecraft.world.item.ItemStack getAmmo(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> ammoFunc)
    • hasAmmo

      public static boolean hasAmmo(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> ammoFunc)
    • consumeAmmo

      public static void consumeAmmo(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> ammoFunc)
    • getItemFromInventory

      public static net.minecraft.world.item.ItemStack getItemFromInventory(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> itemPred)
    • getItemClassFromInventory

      public static net.minecraft.world.item.ItemStack getItemClassFromInventory(net.minecraft.world.entity.player.Player player, Class<?> template)
    • hasAdvancement

      public static boolean hasAdvancement(net.minecraft.server.level.ServerPlayer player, net.minecraft.resources.ResourceLocation advancementId)
    • grantCriterion

      public static void grantCriterion(net.minecraft.server.level.ServerPlayer player, net.minecraft.resources.ResourceLocation advancementId, String criterion)
    • substituteUse

      public static net.minecraft.world.InteractionResult substituteUse(net.minecraft.world.item.context.UseOnContext ctx, net.minecraft.world.item.ItemStack toUse)
    • substituteUseTrackPos

      public static com.mojang.datafixers.util.Pair<net.minecraft.world.InteractionResult,net.minecraft.core.BlockPos> substituteUseTrackPos(net.minecraft.world.item.context.UseOnContext ctx, net.minecraft.world.item.ItemStack toUse)
      Temporarily swap toUse into the hand of the player, use it, then swap it back out. This is to ensure that any code in mods' onItemUse that relies on player.getHeldItem(ctx.hand) == ctx.stack will work as intended. Properly handles null players, as long as the Item's onItemUse also handles them.
      Returns:
      The usage result, as well as a properly offset block position pointing at where the block was placed (if the item was a BlockItem)