Class ClientUtils

java.lang.Object
me.desht.pneumaticcraft.client.util.ClientUtils

public class ClientUtils extends Object
Miscellaneous client-side utilities. Used to wrap client-only code in methods safe to call from classes that could be loaded on dedicated server (mainly packet handlers and event handlers, but could be anywhere...)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addDroneToHudHandler(DroneEntity drone, net.minecraft.core.BlockPos pos)
     
    static void
    addGuiContextSensitiveTooltip(net.minecraft.world.item.ItemStack stack, List<net.minecraft.network.chat.Component> tooltip)
    Add some context-sensitive info to an item's tooltip, based on the currently-open GUI.
    static float
    calculateViewScaling(net.minecraft.world.phys.Vec3 targetPos)
    Determine how much to scale a graphic for the target position, based on player's distance and angle (dot product of look vector and offset to pos)
    static void
    closeContainerGui(net.minecraft.client.gui.screens.Screen parentScreen)
    Close a container-based GUI, and restore the player's openContainer.
    static void
    emitParticles(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.particles.ParticleOptions particle)
     
    static void
    emitParticles(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.particles.ParticleOptions particle, double yOffset)
    Emit particles from just above the given blockpos, which is generally a machine or similar.
    static net.minecraft.world.level.block.entity.BlockEntity
    getBlockEntity(net.minecraft.core.BlockPos pos)
    Get a BE client-side.
    static net.minecraft.world.level.Level
    For use where we can't reference Minecraft directly, e.g.
    static net.minecraft.world.entity.player.Player
     
    static int
    getLightAt(net.minecraft.core.BlockPos pos)
     
    static Optional<net.minecraft.world.level.Level>
     
    static Optional<net.minecraft.world.entity.player.Player>
     
    static int
    Get the render distance based on current game settings
    static float
    getStatSizeMultiplier(double dist)
     
    static int
     
    static float[]
    getTextureUV(net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.Direction face)
     
    static net.minecraft.world.item.ItemStack
    getWornArmor(net.minecraft.world.entity.EquipmentSlot slot)
     
    static boolean
     
    static boolean
    intersects(net.minecraft.client.renderer.Rect2i rect, double x, double y, double w, double h)
    Same as AWT Rectangle's intersects() method, but we don't have access to AWT...
    static boolean
     
    static boolean
    isGuiOpen(net.minecraft.world.level.block.entity.BlockEntity te)
     
    static boolean
    isKeyDown(int keyCode)
     
    static boolean
    For the programmer GUI
    static void
    openContainerGui(net.minecraft.world.inventory.MenuType<? extends net.minecraft.world.inventory.AbstractContainerMenu> type, net.minecraft.network.chat.Component displayString)
    Open a container-based GUI client-side.
    static void
    spawnEntityClientside(net.minecraft.world.entity.Entity e)
     
    static void
    syncViaOpenContainerScreen(int syncId, Object value)
    Called from PacketUpdateGui to sync data from the server-side block entity via open container
    static String
    translateDirection(net.minecraft.core.Direction d)
     
    static net.minecraft.network.chat.Component
    translateDirectionComponent(net.minecraft.core.Direction d)
     
    static net.minecraft.network.chat.Component
    translateKeyBind(net.minecraft.client.KeyMapping keyBinding)
    Because keyBinding.getTranslationKey() doesn't work that well...

    Methods inherited from class java.lang.Object

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

    • ClientUtils

      public ClientUtils()
  • Method Details

    • emitParticles

      public static void emitParticles(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.particles.ParticleOptions particle, double yOffset)
      Emit particles from just above the given blockpos, which is generally a machine or similar. Only call this clientside.
      Parameters:
      world - the world
      pos - the block pos
      particle - the particle type
    • emitParticles

      public static void emitParticles(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.particles.ParticleOptions particle)
    • getWornArmor

      @Nonnull public static net.minecraft.world.item.ItemStack getWornArmor(net.minecraft.world.entity.EquipmentSlot slot)
    • addDroneToHudHandler

      public static void addDroneToHudHandler(DroneEntity drone, net.minecraft.core.BlockPos pos)
    • isKeyDown

      public static boolean isKeyDown(int keyCode)
    • openContainerGui

      public static void openContainerGui(net.minecraft.world.inventory.MenuType<? extends net.minecraft.world.inventory.AbstractContainerMenu> type, net.minecraft.network.chat.Component displayString)
      Open a container-based GUI client-side. This is a cheeky hack, but appears to work. However, it is important to call closeContainerGui(Screen) from the opened GUI's onClose() method to restore the player's openContainer to the correct container. Therefore the GUI being opened should remember the previous open GUI, and call closeContainerGui(Screen) with that GUI as an argument.
      Parameters:
      type - the container type to open
      displayString - container's display name
    • closeContainerGui

      public static void closeContainerGui(net.minecraft.client.gui.screens.Screen parentScreen)
      Close a container-based GUI, and restore the player's openContainer. See openContainerGui(MenuType, Component)
      Parameters:
      parentScreen - the previously-opened GUI, which will be re-opened
    • getClientLevel

      @Nonnull public static net.minecraft.world.level.Level getClientLevel()
      For use where we can't reference Minecraft directly, e.g. packet handling code.
      Returns:
      the client world
    • getOptionalClientLevel

      public static Optional<net.minecraft.world.level.Level> getOptionalClientLevel()
    • getClientPlayer

      @Nonnull public static net.minecraft.world.entity.player.Player getClientPlayer()
    • getOptionalClientPlayer

      public static Optional<net.minecraft.world.entity.player.Player> getOptionalClientPlayer()
    • hasShiftDown

      public static boolean hasShiftDown()
    • getBlockEntity

      public static net.minecraft.world.level.block.entity.BlockEntity getBlockEntity(net.minecraft.core.BlockPos pos)
      Get a BE client-side. Convenience method for packet handling code, primarily.
      Returns:
      a block entity or null
    • intersects

      public static boolean intersects(net.minecraft.client.renderer.Rect2i rect, double x, double y, double w, double h)
      Same as AWT Rectangle's intersects() method, but we don't have access to AWT...
      Parameters:
      rect - a rectangle
      x - x coord
      y - y coord
      w - width
      h - height
      Returns:
      true if intersection, false otherwise
    • isScreenHiRes

      public static boolean isScreenHiRes()
      For the programmer GUI
      Returns:
      true if the screen res > 700x512
    • getLightAt

      public static int getLightAt(net.minecraft.core.BlockPos pos)
    • getStringWidth

      public static int getStringWidth(String line)
    • isGuiOpen

      public static boolean isGuiOpen(net.minecraft.world.level.block.entity.BlockEntity te)
    • getTextureUV

      public static float[] getTextureUV(net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.Direction face)
    • spawnEntityClientside

      public static void spawnEntityClientside(net.minecraft.world.entity.Entity e)
    • translateDirection

      public static String translateDirection(net.minecraft.core.Direction d)
    • translateDirectionComponent

      public static net.minecraft.network.chat.Component translateDirectionComponent(net.minecraft.core.Direction d)
    • translateKeyBind

      public static net.minecraft.network.chat.Component translateKeyBind(net.minecraft.client.KeyMapping keyBinding)
      Because keyBinding.getTranslationKey() doesn't work that well...
      Parameters:
      keyBinding - the keybinding
      Returns:
      a human-friendly string representation
    • addGuiContextSensitiveTooltip

      public static void addGuiContextSensitiveTooltip(net.minecraft.world.item.ItemStack stack, List<net.minecraft.network.chat.Component> tooltip)
      Add some context-sensitive info to an item's tooltip, based on the currently-open GUI.
      Parameters:
      stack - the item stack
      tooltip - tooltip to add data to
    • getRenderDistanceThresholdSq

      public static int getRenderDistanceThresholdSq()
      Get the render distance based on current game settings
      Returns:
      the squared render distance, in blocks
    • isFirstPersonCamera

      public static boolean isFirstPersonCamera()
    • calculateViewScaling

      public static float calculateViewScaling(net.minecraft.world.phys.Vec3 targetPos)
      Determine how much to scale a graphic for the target position, based on player's distance and angle (dot product of look vector and offset to pos)
      Parameters:
      targetPos - the position being viewed
      Returns:
      a scaling factor
    • getStatSizeMultiplier

      public static float getStatSizeMultiplier(double dist)
    • syncViaOpenContainerScreen

      public static void syncViaOpenContainerScreen(int syncId, Object value)
      Called from PacketUpdateGui to sync data from the server-side block entity via open container
      Parameters:
      syncId - index of the block entity field to be sync'd
      value - value to sync