Class ClientUtils
java.lang.Object
me.desht.pneumaticcraft.client.util.ClientUtils
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddDroneToHudHandler(DroneEntity drone, net.minecraft.core.BlockPos pos) static voidaddGuiContextSensitiveTooltip(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 floatcalculateViewScaling(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 voidcloseContainerGui(net.minecraft.client.gui.screens.Screen parentScreen) Close a container-based GUI, and restore the player's openContainer.static voidemitParticles(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.particles.ParticleOptions particle) static voidemitParticles(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.BlockEntitygetBlockEntity(net.minecraft.core.BlockPos pos) Get a BE client-side.static net.minecraft.world.level.LevelFor use where we can't reference Minecraft directly, e.g.static net.minecraft.world.entity.player.Playerstatic intgetLightAt(net.minecraft.core.BlockPos pos) static Optional<net.minecraft.world.level.Level>static Optional<net.minecraft.world.entity.player.Player>static intGet the render distance based on current game settingsstatic floatgetStatSizeMultiplier(double dist) static intgetStringWidth(String line) static float[]getTextureUV(net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.Direction face) static net.minecraft.world.item.ItemStackgetWornArmor(net.minecraft.world.entity.EquipmentSlot slot) static booleanstatic booleanintersects(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 booleanstatic booleanisGuiOpen(net.minecraft.world.level.block.entity.BlockEntity te) static booleanisKeyDown(int keyCode) static booleanFor the programmer GUIstatic voidopenContainerGui(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 voidspawnEntityClientside(net.minecraft.world.entity.Entity e) static voidsyncViaOpenContainerScreen(int syncId, Object value) Called from PacketUpdateGui to sync data from the server-side block entity via open containerstatic StringtranslateDirection(net.minecraft.core.Direction d) static net.minecraft.network.chat.ComponenttranslateDirectionComponent(net.minecraft.core.Direction d) static net.minecraft.network.chat.ComponenttranslateKeyBind(net.minecraft.client.KeyMapping keyBinding) Because keyBinding.getTranslationKey() doesn't work that well...
-
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 worldpos- the block posparticle- 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
-
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 callcloseContainerGui(Screen)from the opened GUI'sonClose()method to restore the player's openContainer to the correct container. Therefore the GUI being opened should remember the previous open GUI, and callcloseContainerGui(Screen)with that GUI as an argument.- Parameters:
type- the container type to opendisplayString- 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. SeeopenContainerGui(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
-
getClientPlayer
@Nonnull public static net.minecraft.world.entity.player.Player getClientPlayer() -
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 rectanglex- x coordy- y coordw- widthh- 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
-
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
-
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 stacktooltip- 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
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'dvalue- value to sync
-