Commit ad484f3c22a4d4c168fc6375dd05ccd260754674
1 parent
7ed373de
Remaining legacy tabs -> spaces
Showing
2 changed files
with
372 additions
and
372 deletions
src/main/java/com/examplemod/Clock.java
| @@ -19,223 +19,223 @@ import java.util.Calendar; | @@ -19,223 +19,223 @@ import java.util.Calendar; | ||
| 19 | */ | 19 | */ |
| 20 | public class Clock | 20 | public class Clock |
| 21 | { | 21 | { |
| 22 | - /** | ||
| 23 | - * This is the clock face resource, you need to create a resource location | ||
| 24 | - * for any assets that you wish to use. It is best to make these static to | ||
| 25 | - * avoid new instances being created for every instance of the referencing | ||
| 26 | - * object, this also means they will only be garbage collected when the | ||
| 27 | - * class is garbage collected or when no instances of the class are left. | ||
| 28 | - * | ||
| 29 | - * <p>The first parameter for the resource location is the "domain" and this | ||
| 30 | - * should normally be your mod's name. The domain MUST be lower case! The | ||
| 31 | - * second is the resource "path" and represents the path to the resource | ||
| 32 | - * within the domain. It is convention that the path always start with the | ||
| 33 | - * resource type, such as "textures" in this case.</p> | ||
| 34 | - * | ||
| 35 | - * <p>Resources are always stored in a path of the form | ||
| 36 | - * "assets/{domain}/{path}" which makes the appropriate path to the | ||
| 37 | - * CLOCKFACE resource: "/assets/example/textures/clock/face.png"</p> | ||
| 38 | - */ | ||
| 39 | - private static final ResourceLocation CLOCKFACE = new ResourceLocation("example", "textures/clock/face.png"); | ||
| 40 | - | ||
| 41 | - /** | ||
| 42 | - * Angles for the hands | ||
| 43 | - */ | ||
| 44 | - private float smallHandAngle, largeHandAngle, secondHandAngle; | ||
| 45 | - | ||
| 46 | - /** | ||
| 47 | - * Sizes for each of the hands | ||
| 48 | - */ | ||
| 49 | - private float smallHandSize, largeHandSize, secondHandSize; | ||
| 50 | - | ||
| 51 | - /** | ||
| 52 | - * Width of the hands | ||
| 53 | - */ | ||
| 54 | - private float handWidth = 1.0F; | ||
| 55 | - | ||
| 56 | - /** | ||
| 57 | - * Colours for each of the hands | ||
| 58 | - */ | ||
| 59 | - private ReadableColor smallHandColour, largeHandColour, secondHandColour; | ||
| 60 | - | ||
| 61 | - /** | ||
| 62 | - * Size and position for the clock | ||
| 63 | - */ | ||
| 64 | - private int xPos, yPos, size; | ||
| 65 | - | ||
| 66 | - /** | ||
| 67 | - * Whether the clock is currently visible | ||
| 68 | - */ | ||
| 69 | - private boolean visible = true; | ||
| 70 | - | ||
| 71 | - /** | ||
| 72 | - * @param xPos X position for the clock | ||
| 73 | - * @param yPos Y position for the clock | ||
| 74 | - */ | ||
| 75 | - public Clock(int xPos, int yPos) | ||
| 76 | - { | ||
| 77 | - this.setPosition(xPos, yPos); | ||
| 78 | - this.setSize(64); | ||
| 79 | - | ||
| 80 | - this.largeHandColour = ReadableColor.WHITE; | ||
| 81 | - this.smallHandColour = ReadableColor.GREY; | ||
| 82 | - this.secondHandColour = ReadableColor.ORANGE; | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - /** | ||
| 86 | - * @param xPos | ||
| 87 | - * @param yPos | ||
| 88 | - */ | ||
| 89 | - public void setPosition(int xPos, int yPos) | ||
| 90 | - { | ||
| 91 | - this.xPos = Math.max(0, xPos); | ||
| 92 | - this.yPos = Math.max(0, yPos); | ||
| 93 | - } | ||
| 94 | - | ||
| 95 | - /** | ||
| 96 | - * Set the size of the clock | ||
| 97 | - * | ||
| 98 | - * @param size new size (min is 32) | ||
| 99 | - */ | ||
| 100 | - public void setSize(int size) | ||
| 101 | - { | ||
| 102 | - this.size = Math.max(32, size); | ||
| 103 | - | ||
| 104 | - this.smallHandSize = this.size * 0.25F; | ||
| 105 | - this.largeHandSize = this.size * 0.38F; | ||
| 106 | - this.secondHandSize = this.size * 0.35F; | ||
| 107 | - | ||
| 108 | - this.handWidth = this.size / 64.0F; | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - /** | ||
| 112 | - * Get the current size | ||
| 113 | - */ | ||
| 114 | - public int getSize() | ||
| 115 | - { | ||
| 116 | - return this.size; | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - /** | ||
| 120 | - * Get whether the clock is currently visible | ||
| 121 | - */ | ||
| 122 | - public boolean isVisible() | ||
| 123 | - { | ||
| 124 | - return this.visible; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - /** | ||
| 128 | - * Set whether the clock should be visible | ||
| 129 | - * | ||
| 130 | - * @param visible new visibility setting | ||
| 131 | - */ | ||
| 132 | - public void setVisible(boolean visible) | ||
| 133 | - { | ||
| 134 | - this.visible = visible; | ||
| 135 | - } | ||
| 136 | - | ||
| 137 | - /** | ||
| 138 | - * Render the clock at its current position, unless hidden | ||
| 139 | - * | ||
| 140 | - * @param minecraft Minecraft game instance | ||
| 141 | - */ | ||
| 142 | - public void render(Minecraft minecraft) | ||
| 143 | - { | ||
| 144 | - if (this.isVisible()) | ||
| 145 | - { | ||
| 146 | - // First, update the hand angles | ||
| 147 | - this.calculateAngles(); | ||
| 148 | - | ||
| 149 | - // Then render the actual clock | ||
| 150 | - this.renderClock(minecraft); | ||
| 151 | - } | ||
| 152 | - } | ||
| 153 | - | ||
| 154 | - /** | ||
| 155 | - * Gets the current time and calculates the angles for the clock hands | ||
| 156 | - */ | ||
| 157 | - private void calculateAngles() | ||
| 158 | - { | ||
| 159 | - Calendar calendar = Calendar.getInstance(); | ||
| 160 | - | ||
| 161 | - int hour = calendar.get(Calendar.HOUR); | ||
| 162 | - int minute = calendar.get(Calendar.MINUTE); | ||
| 163 | - int second = calendar.get(Calendar.SECOND); | ||
| 164 | - | ||
| 165 | - this.smallHandAngle = 360.0F * (0.0833F * hour + 0.00138F * minute); | ||
| 166 | - this.largeHandAngle = 360.0F * (0.0166F * minute); | ||
| 167 | - this.secondHandAngle = 360.0F * (0.0166F * second); | ||
| 168 | - } | ||
| 169 | - | ||
| 170 | - /** | ||
| 171 | - * Renders the clock | ||
| 172 | - * | ||
| 173 | - * @param minecraft Minecraft game instance | ||
| 174 | - */ | ||
| 175 | - private void renderClock(Minecraft minecraft) | ||
| 176 | - { | ||
| 177 | - // Render the face | ||
| 178 | - this.renderClockFace(minecraft); | ||
| 179 | - | ||
| 180 | - // Render each of the hands | ||
| 181 | - this.renderClockHand(this.largeHandAngle, this.largeHandSize, this.handWidth * 1.2F, this.largeHandColour); | ||
| 182 | - this.renderClockHand(this.smallHandAngle, this.smallHandSize, this.handWidth * 2.0F, this.smallHandColour); | ||
| 183 | - this.renderClockHand(this.secondHandAngle, this.secondHandSize, this.handWidth * 1.2F, this.secondHandColour); | ||
| 184 | - } | ||
| 185 | - | ||
| 186 | - /** | ||
| 187 | - * Renders the clock face texture using the texture resource | ||
| 188 | - * | ||
| 189 | - * @param minecraft Minecraft game instance | ||
| 190 | - */ | ||
| 191 | - private void renderClockFace(Minecraft minecraft) | ||
| 192 | - { | ||
| 193 | - // Bind the texture resource | ||
| 194 | - minecraft.getTextureManager().bindTexture(Clock.CLOCKFACE); | ||
| 195 | - | ||
| 196 | - // Draw a rectangle using the currently bound texture | ||
| 197 | - glDrawTexturedRect(this.xPos, this.yPos, this.size, this.size, 1, 1, 511, 511); | ||
| 198 | - } | ||
| 199 | - | ||
| 200 | - /** | ||
| 201 | - * Render one of the hands | ||
| 202 | - */ | ||
| 203 | - private void renderClockHand(float angle, float length, float width, ReadableColor colour) | ||
| 204 | - { | ||
| 205 | - // Push the current transform onto the stack | ||
| 206 | - glPushMatrix(); | ||
| 207 | - | ||
| 208 | - // Transform to the mid point of the clock | ||
| 209 | - glTranslatef(this.xPos + (this.size / 2), this.yPos + (this.size / 2), 0); | ||
| 210 | - | ||
| 211 | - // and rotate by the hand angle | ||
| 212 | - glRotatef(angle, 0.0F, 0.0F, 1.0F); | ||
| 213 | - | ||
| 214 | - // then draw the hand (straight up of course) | ||
| 215 | - glDrawRect(width * -0.5F, length * 0.2F, width * 0.5F, -length, colour); | ||
| 216 | - | ||
| 217 | - // and finally restore the current transform | ||
| 218 | - glPopMatrix(); | ||
| 219 | - } | ||
| 220 | - | 22 | + /** |
| 23 | + * This is the clock face resource, you need to create a resource location | ||
| 24 | + * for any assets that you wish to use. It is best to make these static to | ||
| 25 | + * avoid new instances being created for every instance of the referencing | ||
| 26 | + * object, this also means they will only be garbage collected when the | ||
| 27 | + * class is garbage collected or when no instances of the class are left. | ||
| 28 | + * | ||
| 29 | + * <p>The first parameter for the resource location is the "domain" and this | ||
| 30 | + * should normally be your mod's name. The domain MUST be lower case! The | ||
| 31 | + * second is the resource "path" and represents the path to the resource | ||
| 32 | + * within the domain. It is convention that the path always start with the | ||
| 33 | + * resource type, such as "textures" in this case.</p> | ||
| 34 | + * | ||
| 35 | + * <p>Resources are always stored in a path of the form | ||
| 36 | + * "assets/{domain}/{path}" which makes the appropriate path to the | ||
| 37 | + * CLOCKFACE resource: "/assets/example/textures/clock/face.png"</p> | ||
| 38 | + */ | ||
| 39 | + private static final ResourceLocation CLOCKFACE = new ResourceLocation("example", "textures/clock/face.png"); | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Angles for the hands | ||
| 43 | + */ | ||
| 44 | + private float smallHandAngle, largeHandAngle, secondHandAngle; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * Sizes for each of the hands | ||
| 48 | + */ | ||
| 49 | + private float smallHandSize, largeHandSize, secondHandSize; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * Width of the hands | ||
| 53 | + */ | ||
| 54 | + private float handWidth = 1.0F; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * Colours for each of the hands | ||
| 58 | + */ | ||
| 59 | + private ReadableColor smallHandColour, largeHandColour, secondHandColour; | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * Size and position for the clock | ||
| 63 | + */ | ||
| 64 | + private int xPos, yPos, size; | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * Whether the clock is currently visible | ||
| 68 | + */ | ||
| 69 | + private boolean visible = true; | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * @param xPos X position for the clock | ||
| 73 | + * @param yPos Y position for the clock | ||
| 74 | + */ | ||
| 75 | + public Clock(int xPos, int yPos) | ||
| 76 | + { | ||
| 77 | + this.setPosition(xPos, yPos); | ||
| 78 | + this.setSize(64); | ||
| 79 | + | ||
| 80 | + this.largeHandColour = ReadableColor.WHITE; | ||
| 81 | + this.smallHandColour = ReadableColor.GREY; | ||
| 82 | + this.secondHandColour = ReadableColor.ORANGE; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * @param xPos | ||
| 87 | + * @param yPos | ||
| 88 | + */ | ||
| 89 | + public void setPosition(int xPos, int yPos) | ||
| 90 | + { | ||
| 91 | + this.xPos = Math.max(0, xPos); | ||
| 92 | + this.yPos = Math.max(0, yPos); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * Set the size of the clock | ||
| 97 | + * | ||
| 98 | + * @param size new size (min is 32) | ||
| 99 | + */ | ||
| 100 | + public void setSize(int size) | ||
| 101 | + { | ||
| 102 | + this.size = Math.max(32, size); | ||
| 103 | + | ||
| 104 | + this.smallHandSize = this.size * 0.25F; | ||
| 105 | + this.largeHandSize = this.size * 0.38F; | ||
| 106 | + this.secondHandSize = this.size * 0.35F; | ||
| 107 | + | ||
| 108 | + this.handWidth = this.size / 64.0F; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * Get the current size | ||
| 113 | + */ | ||
| 114 | + public int getSize() | ||
| 115 | + { | ||
| 116 | + return this.size; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * Get whether the clock is currently visible | ||
| 121 | + */ | ||
| 122 | + public boolean isVisible() | ||
| 123 | + { | ||
| 124 | + return this.visible; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * Set whether the clock should be visible | ||
| 129 | + * | ||
| 130 | + * @param visible new visibility setting | ||
| 131 | + */ | ||
| 132 | + public void setVisible(boolean visible) | ||
| 133 | + { | ||
| 134 | + this.visible = visible; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + /** | ||
| 138 | + * Render the clock at its current position, unless hidden | ||
| 139 | + * | ||
| 140 | + * @param minecraft Minecraft game instance | ||
| 141 | + */ | ||
| 142 | + public void render(Minecraft minecraft) | ||
| 143 | + { | ||
| 144 | + if (this.isVisible()) | ||
| 145 | + { | ||
| 146 | + // First, update the hand angles | ||
| 147 | + this.calculateAngles(); | ||
| 148 | + | ||
| 149 | + // Then render the actual clock | ||
| 150 | + this.renderClock(minecraft); | ||
| 151 | + } | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * Gets the current time and calculates the angles for the clock hands | ||
| 156 | + */ | ||
| 157 | + private void calculateAngles() | ||
| 158 | + { | ||
| 159 | + Calendar calendar = Calendar.getInstance(); | ||
| 160 | + | ||
| 161 | + int hour = calendar.get(Calendar.HOUR); | ||
| 162 | + int minute = calendar.get(Calendar.MINUTE); | ||
| 163 | + int second = calendar.get(Calendar.SECOND); | ||
| 164 | + | ||
| 165 | + this.smallHandAngle = 360.0F * (0.0833F * hour + 0.00138F * minute); | ||
| 166 | + this.largeHandAngle = 360.0F * (0.0166F * minute); | ||
| 167 | + this.secondHandAngle = 360.0F * (0.0166F * second); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * Renders the clock | ||
| 172 | + * | ||
| 173 | + * @param minecraft Minecraft game instance | ||
| 174 | + */ | ||
| 175 | + private void renderClock(Minecraft minecraft) | ||
| 176 | + { | ||
| 177 | + // Render the face | ||
| 178 | + this.renderClockFace(minecraft); | ||
| 179 | + | ||
| 180 | + // Render each of the hands | ||
| 181 | + this.renderClockHand(this.largeHandAngle, this.largeHandSize, this.handWidth * 1.2F, this.largeHandColour); | ||
| 182 | + this.renderClockHand(this.smallHandAngle, this.smallHandSize, this.handWidth * 2.0F, this.smallHandColour); | ||
| 183 | + this.renderClockHand(this.secondHandAngle, this.secondHandSize, this.handWidth * 1.2F, this.secondHandColour); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + /** | ||
| 187 | + * Renders the clock face texture using the texture resource | ||
| 188 | + * | ||
| 189 | + * @param minecraft Minecraft game instance | ||
| 190 | + */ | ||
| 191 | + private void renderClockFace(Minecraft minecraft) | ||
| 192 | + { | ||
| 193 | + // Bind the texture resource | ||
| 194 | + minecraft.getTextureManager().bindTexture(Clock.CLOCKFACE); | ||
| 195 | + | ||
| 196 | + // Draw a rectangle using the currently bound texture | ||
| 197 | + glDrawTexturedRect(this.xPos, this.yPos, this.size, this.size, 1, 1, 511, 511); | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + /** | ||
| 201 | + * Render one of the hands | ||
| 202 | + */ | ||
| 203 | + private void renderClockHand(float angle, float length, float width, ReadableColor colour) | ||
| 204 | + { | ||
| 205 | + // Push the current transform onto the stack | ||
| 206 | + glPushMatrix(); | ||
| 207 | + | ||
| 208 | + // Transform to the mid point of the clock | ||
| 209 | + glTranslatef(this.xPos + (this.size / 2), this.yPos + (this.size / 2), 0); | ||
| 210 | + | ||
| 211 | + // and rotate by the hand angle | ||
| 212 | + glRotatef(angle, 0.0F, 0.0F, 1.0F); | ||
| 213 | + | ||
| 214 | + // then draw the hand (straight up of course) | ||
| 215 | + glDrawRect(width * -0.5F, length * 0.2F, width * 0.5F, -length, colour); | ||
| 216 | + | ||
| 217 | + // and finally restore the current transform | ||
| 218 | + glPopMatrix(); | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | /** | 221 | /** |
| 222 | * Draw a rectangle using the currently bound texture | 222 | * Draw a rectangle using the currently bound texture |
| 223 | */ | 223 | */ |
| 224 | private static void glDrawTexturedRect(int x, int y, int width, int height, int u, int v, int u2, int v2) | 224 | private static void glDrawTexturedRect(int x, int y, int width, int height, int u, int v, int u2, int v2) |
| 225 | { | 225 | { |
| 226 | - // Set the appropriate OpenGL modes | ||
| 227 | - glDisableLighting(); | 226 | + // Set the appropriate OpenGL modes |
| 227 | + glDisableLighting(); | ||
| 228 | glDisableBlend(); | 228 | glDisableBlend(); |
| 229 | - glAlphaFunc(GL_GREATER, 0.01F); | ||
| 230 | - glEnableTexture2D(); | ||
| 231 | - glColor4f(1.0F, 1.0F, 1.0F, 1.0F); | ||
| 232 | - | ||
| 233 | - float texMapScale = 0.001953125F; // 512px | 229 | + glAlphaFunc(GL_GREATER, 0.01F); |
| 230 | + glEnableTexture2D(); | ||
| 231 | + glColor4f(1.0F, 1.0F, 1.0F, 1.0F); | ||
| 232 | + | ||
| 233 | + float texMapScale = 0.001953125F; // 512px | ||
| 234 | 234 | ||
| 235 | // We use the tessellator rather than drawing individual quads because | 235 | // We use the tessellator rather than drawing individual quads because |
| 236 | - // it uses vertex arrays to draw the quads more efficiently. | ||
| 237 | - Tessellator tessellator = Tessellator.getInstance(); | ||
| 238 | - BufferBuilder worldRenderer = tessellator.getBuffer(); | 236 | + // it uses vertex arrays to draw the quads more efficiently. |
| 237 | + Tessellator tessellator = Tessellator.getInstance(); | ||
| 238 | + BufferBuilder worldRenderer = tessellator.getBuffer(); | ||
| 239 | worldRenderer.begin(GL_QUADS, POSITION_TEX); | 239 | worldRenderer.begin(GL_QUADS, POSITION_TEX); |
| 240 | worldRenderer.pos(x + 0, y + height, 0).tex(u * texMapScale, v2 * texMapScale).endVertex(); | 240 | worldRenderer.pos(x + 0, y + height, 0).tex(u * texMapScale, v2 * texMapScale).endVertex(); |
| 241 | worldRenderer.pos(x + width, y + height, 0).tex(u2 * texMapScale, v2 * texMapScale).endVertex(); | 241 | worldRenderer.pos(x + width, y + height, 0).tex(u2 * texMapScale, v2 * texMapScale).endVertex(); |
| @@ -243,13 +243,13 @@ public class Clock | @@ -243,13 +243,13 @@ public class Clock | ||
| 243 | worldRenderer.pos(x + 0, y + 0, 0).tex(u * texMapScale, v * texMapScale).endVertex(); | 243 | worldRenderer.pos(x + 0, y + 0, 0).tex(u * texMapScale, v * texMapScale).endVertex(); |
| 244 | tessellator.draw(); | 244 | tessellator.draw(); |
| 245 | } | 245 | } |
| 246 | - | ||
| 247 | - /** | ||
| 248 | - * Draw an opaque rectangle | ||
| 249 | - */ | ||
| 250 | - private static void glDrawRect(float x1, float y1, float x2, float y2, ReadableColor colour) | 246 | + |
| 247 | + /** | ||
| 248 | + * Draw an opaque rectangle | ||
| 249 | + */ | ||
| 250 | + private static void glDrawRect(float x1, float y1, float x2, float y2, ReadableColor colour) | ||
| 251 | { | 251 | { |
| 252 | - // Set GL modes | 252 | + // Set GL modes |
| 253 | glDisableBlend(); | 253 | glDisableBlend(); |
| 254 | glDisableTexture2D(); | 254 | glDisableTexture2D(); |
| 255 | glDisableCulling(); | 255 | glDisableCulling(); |
| @@ -257,8 +257,8 @@ public class Clock | @@ -257,8 +257,8 @@ public class Clock | ||
| 257 | glColor4f(colour.getRed(), colour.getGreen(), colour.getBlue(), 1.0F); | 257 | glColor4f(colour.getRed(), colour.getGreen(), colour.getBlue(), 1.0F); |
| 258 | 258 | ||
| 259 | // Draw the quad | 259 | // Draw the quad |
| 260 | - Tessellator tessellator = Tessellator.getInstance(); | ||
| 261 | - BufferBuilder worldRenderer = tessellator.getBuffer(); | 260 | + Tessellator tessellator = Tessellator.getInstance(); |
| 261 | + BufferBuilder worldRenderer = tessellator.getBuffer(); | ||
| 262 | worldRenderer.begin(GL_QUADS, POSITION); | 262 | worldRenderer.begin(GL_QUADS, POSITION); |
| 263 | worldRenderer.pos(x1, y2, 0).endVertex(); | 263 | worldRenderer.pos(x1, y2, 0).endVertex(); |
| 264 | worldRenderer.pos(x2, y2, 0).endVertex(); | 264 | worldRenderer.pos(x2, y2, 0).endVertex(); |
src/main/java/com/examplemod/LiteModExample.java
| @@ -26,167 +26,167 @@ import java.io.File; | @@ -26,167 +26,167 @@ import java.io.File; | ||
| 26 | @ExposableOptions(strategy = ConfigStrategy.Versioned, filename="examplemod.json") | 26 | @ExposableOptions(strategy = ConfigStrategy.Versioned, filename="examplemod.json") |
| 27 | public class LiteModExample implements Tickable, PreRenderListener, Configurable | 27 | public class LiteModExample implements Tickable, PreRenderListener, Configurable |
| 28 | { | 28 | { |
| 29 | - /** | ||
| 30 | - * This is our instance of Clock which we will draw every tick | ||
| 31 | - */ | ||
| 32 | - private Clock clock = new Clock(10, 10); | ||
| 33 | - | ||
| 34 | - /** | ||
| 35 | - * This is a keybinding that we will register with the game and use to | ||
| 36 | - * toggle the clock | ||
| 37 | - * | ||
| 38 | - * Notice that we specify the key name as an *unlocalised* string. The | ||
| 39 | - * localisation is provided from the included resource file. | ||
| 40 | - */ | ||
| 41 | - private static KeyBinding clockKeyBinding = new KeyBinding("key.clock.toggle", Keyboard.KEY_F12, "key.categories.litemods"); | ||
| 42 | - | ||
| 43 | - @Expose | ||
| 44 | - @SerializedName("clock_size") | ||
| 45 | - private int clockSize = 64; | ||
| 46 | - | ||
| 47 | - @Expose | ||
| 48 | - @SerializedName("clock_visible") | ||
| 49 | - private boolean clockVisible = true; | ||
| 50 | - | ||
| 51 | - /** | ||
| 52 | - * Default constructor. All LiteMods must have a default constructor. In | ||
| 53 | - * general you should do very little in the mod constructor EXCEPT for | ||
| 54 | - * initialising any non-game-interfacing components or performing sanity | ||
| 55 | - * checking prior to initialisation | ||
| 56 | - */ | ||
| 57 | - public LiteModExample() | ||
| 58 | - { | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - /** | ||
| 62 | - * getName() should be used to return the display name of your mod and MUST | ||
| 63 | - * NOT return null | ||
| 64 | - * | ||
| 65 | - * @see com.mumfrey.liteloader.LiteMod#getName() | ||
| 66 | - */ | ||
| 67 | - @Override | ||
| 68 | - public String getName() | ||
| 69 | - { | ||
| 70 | - return "Example Mod"; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - /** | ||
| 74 | - * getVersion() should return the same version string present in the mod | ||
| 75 | - * metadata, although this is not a strict requirement. | ||
| 76 | - * | ||
| 77 | - * @see com.mumfrey.liteloader.LiteMod#getVersion() | ||
| 78 | - */ | ||
| 79 | - @Override | ||
| 80 | - public String getVersion() | ||
| 81 | - { | ||
| 82 | - return "0.0.0"; | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - @Override | ||
| 86 | - public Class<? extends ConfigPanel> getConfigPanelClass() | ||
| 87 | - { | ||
| 88 | - return ExampleModConfigPanel.class; | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - /** | ||
| 92 | - * init() is called very early in the initialisation cycle, before the game | ||
| 93 | - * is fully initialised, this means that it is important that your mod does | ||
| 94 | - * not interact with the game in any way at this point. | ||
| 95 | - * | ||
| 96 | - * @see com.mumfrey.liteloader.LiteMod#init(java.io.File) | ||
| 97 | - */ | ||
| 98 | - @Override | ||
| 99 | - public void init(File configPath) | ||
| 100 | - { | ||
| 101 | - // The key binding declared above won't do anything unless we register | ||
| 102 | - // it, LiteLoader's Input manager provides a convenience method for this | ||
| 103 | - LiteLoader.getInput().registerKeyBinding(LiteModExample.clockKeyBinding); | ||
| 104 | - | ||
| 105 | - this.clock.setSize(this.clockSize); | ||
| 106 | - this.clock.setVisible(this.clockVisible); | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | - /** | ||
| 110 | - * upgradeSettings is used to notify a mod that its version-specific | ||
| 111 | - * settings are being migrated | ||
| 112 | - * | ||
| 113 | - * @see com.mumfrey.liteloader.LiteMod#upgradeSettings(java.lang.String, | ||
| 114 | - * java.io.File, java.io.File) | ||
| 115 | - */ | ||
| 116 | - @Override | ||
| 117 | - public void upgradeSettings(String version, File configPath, File oldConfigPath) | ||
| 118 | - { | ||
| 119 | - } | ||
| 120 | - | ||
| 121 | - @Override | ||
| 122 | - public void onTick(Minecraft minecraft, float partialTicks, boolean inGame, boolean clock) | ||
| 123 | - { | ||
| 124 | - // The three checks here are critical to ensure that we only draw the | ||
| 125 | - // clock as part of the "HUD" and don't draw it over active GUI's or | ||
| 126 | - // other elements | ||
| 127 | - if (inGame && minecraft.currentScreen == null && Minecraft.isGuiEnabled()) | ||
| 128 | - { | ||
| 129 | - if (LiteModExample.clockKeyBinding.isPressed()) | ||
| 130 | - { | ||
| 131 | - if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) | ||
| 132 | - { | ||
| 133 | - this.clockSize = (this.clockSize << 1) & 0x1FF; | ||
| 134 | - this.clock.setSize(this.clockSize); | ||
| 135 | - this.clockSize = this.clock.getSize(); | ||
| 136 | - } | ||
| 137 | - else | ||
| 138 | - { | ||
| 139 | - this.clock.setVisible(!this.clock.isVisible()); | ||
| 140 | - this.clockVisible = this.clock.isVisible(); | ||
| 141 | - } | ||
| 142 | - | ||
| 143 | - // Our @Expose annotations control what properties get saved, | ||
| 144 | - // this tells liteloader to actually write properties to disk | ||
| 145 | - LiteLoader.getInstance().writeConfig(this); | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - // Render the clock | ||
| 149 | - this.clock.render(minecraft); | ||
| 150 | - } | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | - boolean getClockVisibility() | ||
| 154 | - { | ||
| 155 | - return this.clock.isVisible(); | ||
| 156 | - } | ||
| 157 | - | ||
| 158 | - void setClockVisibility(boolean visible) | 29 | + /** |
| 30 | + * This is our instance of Clock which we will draw every tick | ||
| 31 | + */ | ||
| 32 | + private Clock clock = new Clock(10, 10); | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * This is a keybinding that we will register with the game and use to | ||
| 36 | + * toggle the clock | ||
| 37 | + * | ||
| 38 | + * Notice that we specify the key name as an *unlocalised* string. The | ||
| 39 | + * localisation is provided from the included resource file. | ||
| 40 | + */ | ||
| 41 | + private static KeyBinding clockKeyBinding = new KeyBinding("key.clock.toggle", Keyboard.KEY_F12, "key.categories.litemods"); | ||
| 42 | + | ||
| 43 | + @Expose | ||
| 44 | + @SerializedName("clock_size") | ||
| 45 | + private int clockSize = 64; | ||
| 46 | + | ||
| 47 | + @Expose | ||
| 48 | + @SerializedName("clock_visible") | ||
| 49 | + private boolean clockVisible = true; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * Default constructor. All LiteMods must have a default constructor. In | ||
| 53 | + * general you should do very little in the mod constructor EXCEPT for | ||
| 54 | + * initialising any non-game-interfacing components or performing sanity | ||
| 55 | + * checking prior to initialisation | ||
| 56 | + */ | ||
| 57 | + public LiteModExample() | ||
| 58 | + { | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * getName() should be used to return the display name of your mod and MUST | ||
| 63 | + * NOT return null | ||
| 64 | + * | ||
| 65 | + * @see com.mumfrey.liteloader.LiteMod#getName() | ||
| 66 | + */ | ||
| 67 | + @Override | ||
| 68 | + public String getName() | ||
| 69 | + { | ||
| 70 | + return "Example Mod"; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * getVersion() should return the same version string present in the mod | ||
| 75 | + * metadata, although this is not a strict requirement. | ||
| 76 | + * | ||
| 77 | + * @see com.mumfrey.liteloader.LiteMod#getVersion() | ||
| 78 | + */ | ||
| 79 | + @Override | ||
| 80 | + public String getVersion() | ||
| 81 | + { | ||
| 82 | + return "0.0.0"; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Override | ||
| 86 | + public Class<? extends ConfigPanel> getConfigPanelClass() | ||
| 87 | + { | ||
| 88 | + return ExampleModConfigPanel.class; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * init() is called very early in the initialisation cycle, before the game | ||
| 93 | + * is fully initialised, this means that it is important that your mod does | ||
| 94 | + * not interact with the game in any way at this point. | ||
| 95 | + * | ||
| 96 | + * @see com.mumfrey.liteloader.LiteMod#init(java.io.File) | ||
| 97 | + */ | ||
| 98 | + @Override | ||
| 99 | + public void init(File configPath) | ||
| 100 | + { | ||
| 101 | + // The key binding declared above won't do anything unless we register | ||
| 102 | + // it, LiteLoader's Input manager provides a convenience method for this | ||
| 103 | + LiteLoader.getInput().registerKeyBinding(LiteModExample.clockKeyBinding); | ||
| 104 | + | ||
| 105 | + this.clock.setSize(this.clockSize); | ||
| 106 | + this.clock.setVisible(this.clockVisible); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * upgradeSettings is used to notify a mod that its version-specific | ||
| 111 | + * settings are being migrated | ||
| 112 | + * | ||
| 113 | + * @see com.mumfrey.liteloader.LiteMod#upgradeSettings(java.lang.String, | ||
| 114 | + * java.io.File, java.io.File) | ||
| 115 | + */ | ||
| 116 | + @Override | ||
| 117 | + public void upgradeSettings(String version, File configPath, File oldConfigPath) | ||
| 118 | + { | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + @Override | ||
| 122 | + public void onTick(Minecraft minecraft, float partialTicks, boolean inGame, boolean clock) | ||
| 123 | + { | ||
| 124 | + // The three checks here are critical to ensure that we only draw the | ||
| 125 | + // clock as part of the "HUD" and don't draw it over active GUI's or | ||
| 126 | + // other elements | ||
| 127 | + if (inGame && minecraft.currentScreen == null && Minecraft.isGuiEnabled()) | ||
| 128 | + { | ||
| 129 | + if (LiteModExample.clockKeyBinding.isPressed()) | ||
| 130 | + { | ||
| 131 | + if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) | ||
| 132 | + { | ||
| 133 | + this.clockSize = (this.clockSize << 1) & 0x1FF; | ||
| 134 | + this.clock.setSize(this.clockSize); | ||
| 135 | + this.clockSize = this.clock.getSize(); | ||
| 136 | + } | ||
| 137 | + else | ||
| 138 | + { | ||
| 139 | + this.clock.setVisible(!this.clock.isVisible()); | ||
| 140 | + this.clockVisible = this.clock.isVisible(); | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + // Our @Expose annotations control what properties get saved, | ||
| 144 | + // this tells liteloader to actually write properties to disk | ||
| 145 | + LiteLoader.getInstance().writeConfig(this); | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + // Render the clock | ||
| 149 | + this.clock.render(minecraft); | ||
| 150 | + } | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + boolean getClockVisibility() | ||
| 154 | + { | ||
| 155 | + return this.clock.isVisible(); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + void setClockVisibility(boolean visible) | ||
| 159 | { | 159 | { |
| 160 | this.clock.setVisible(this.clockVisible = visible); | 160 | this.clock.setVisible(this.clockVisible = visible); |
| 161 | } | 161 | } |
| 162 | - | ||
| 163 | - @Override | ||
| 164 | - public void onRenderWorld(float partialTicks) | ||
| 165 | - { | 162 | + |
| 163 | + @Override | ||
| 164 | + public void onRenderWorld(float partialTicks) | ||
| 165 | + { | ||
| 166 | // System.err.printf(">> onRenderWorld!\n"); | 166 | // System.err.printf(">> onRenderWorld!\n"); |
| 167 | - } | ||
| 168 | - | ||
| 169 | - @Override | ||
| 170 | - public void onSetupCameraTransform(float partialTicks, int pass, long timeSlice) | ||
| 171 | - { | 167 | + } |
| 168 | + | ||
| 169 | + @Override | ||
| 170 | + public void onSetupCameraTransform(float partialTicks, int pass, long timeSlice) | ||
| 171 | + { | ||
| 172 | // System.err.printf(">> onSetupCameraTransform %s, %d, %d!\n", partialTicks, pass, timeSlice); | 172 | // System.err.printf(">> onSetupCameraTransform %s, %d, %d!\n", partialTicks, pass, timeSlice); |
| 173 | - } | ||
| 174 | - | ||
| 175 | - @Override | ||
| 176 | - public void onRenderSky(float partialTicks, int pass) | ||
| 177 | - { | 173 | + } |
| 174 | + | ||
| 175 | + @Override | ||
| 176 | + public void onRenderSky(float partialTicks, int pass) | ||
| 177 | + { | ||
| 178 | // System.err.printf(">> onRenderSky %s, %d!\n", partialTicks, pass); | 178 | // System.err.printf(">> onRenderSky %s, %d!\n", partialTicks, pass); |
| 179 | - } | ||
| 180 | - | ||
| 181 | - @Override | ||
| 182 | - public void onRenderClouds(float partialTicks, int pass, RenderGlobal renderGlobal) | ||
| 183 | - { | 179 | + } |
| 180 | + | ||
| 181 | + @Override | ||
| 182 | + public void onRenderClouds(float partialTicks, int pass, RenderGlobal renderGlobal) | ||
| 183 | + { | ||
| 184 | // System.err.printf(">> onRenderClouds %s, %d!\n", partialTicks, pass); | 184 | // System.err.printf(">> onRenderClouds %s, %d!\n", partialTicks, pass); |
| 185 | - } | ||
| 186 | - | ||
| 187 | - @Override | ||
| 188 | - public void onRenderTerrain(float partialTicks, int pass) | ||
| 189 | - { | 185 | + } |
| 186 | + | ||
| 187 | + @Override | ||
| 188 | + public void onRenderTerrain(float partialTicks, int pass) | ||
| 189 | + { | ||
| 190 | // System.err.printf(">> onRenderTerrain %s, %d!\n", partialTicks, pass); | 190 | // System.err.printf(">> onRenderTerrain %s, %d!\n", partialTicks, pass); |
| 191 | - } | 191 | + } |
| 192 | } | 192 | } |