8 | * If the screen gets resized, the new dimensions should be set using {@link 9 | * Position#updateScreenSize} 10 | * before calling the {@link Position#getX} or {@link Position#getY} methods again. 11 | */ 12 | public class Position { 13 | 14 | private int x; 15 | private int y; 16 | private int screenWidth; 17 | private int screenHeight; 18 | private boolean rightAligned; 19 | private boolean bottomAligned; 20 | 21 | /** 22 | * This method should be called when the screen is resized, to ensure {@link Position#getX} or 23 | * {@link Position#getY} still return the correct coordinates. 24 | * 25 | * @param width The new screen width 26 | * @param height The new screen height 27 | */ 28 | public void updateScreenSize(int width, int height) { 29 | screenWidth = width; 30 | screenHeight = height; 31 | 32 | // run alignment checks again 33 | setX(getX()); 34 | setY(getY()); 35 | } 36 | 37 | /** 38 | * Translates the position by the given offsets. 39 | * 40 | * @param dx The offset across the X axis 41 | * @param dy The offset across the Y axis 42 | */ 43 | public void translate(int dx, int dy) { 44 | setX(getX() + dx); 45 | setY(getY() + dy); 46 | } 47 | 48 | /** 49 | * Gets the absolute X coordinate of this position. 50 | * 51 | * @return The X coordinate 52 | */ 53 | public int getX() { 54 | return rightAligned ? screenWidth - x : x; 55 | } 56 | 57 | /** 58 | * Sets the absolute X coordinate of this position 59 | * 60 | * @param x The X coordinate 61 | */ 62 | public void setX(int x) { 63 | // if the X coordinate is closer to the right side of the screen, store the position 64 | // relative to the right side instead 65 | if (x > screenWidth / 2) { 66 | this.x = screenWidth - x; 67 | rightAligned = true; 68 | } else { 69 | this.x = x; 70 | rightAligned = false; 71 | } 72 | } 73 | 74 | /** 75 | * Gets the absolute Y coordinate of this position. 76 | * 77 | * @return The Y coordinate 78 | */ 79 | public int getY() { 80 | return bottomAligned ? screenHeight - y : y; 81 | } 82 | 83 | /** 84 | * Sets the absolute X coordinate of this position 85 | * 86 | * @param y The Y coordinate 87 | */ 88 | public void setY(int y) { 89 | // if the Y coordinate is closer to the bottom of the screen, store the position relative 90 | // to the bottom instead 91 | if (y > screenHeight / 2) { 92 | this.y = screenHeight - y; 93 | bottomAligned = true; 94 | } else { 95 | this.y = y; 96 | bottomAligned = false; 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid": "keystrokesmod", 4 | "name": "KeystrokesMod", 5 | "description": "KeystrokesMod", 6 | "version": "v5", 7 | "mcversion": "1.7.10", 8 | "url": "https://github.com/GitFyu/KeystrokesBase", 9 | "updateUrl": "", 10 | "authorList": ["Fyu"], 11 | "credits": "", 12 | "logoFile": "", 13 | "screenshots": [], 14 | "dependencies": [] 15 | } 16 | ] 17 | --------------------------------------------------------------------------------