LiteModExample.java
4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.examplemod;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.mumfrey.liteloader.PreRenderListener;
import com.mumfrey.liteloader.Tickable;
import com.mumfrey.liteloader.core.LiteLoader;
import com.mumfrey.liteloader.modconfig.ConfigStrategy;
import com.mumfrey.liteloader.modconfig.ExposableOptions;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.input.Keyboard;
import java.io.File;
/**
* This is a very simple example LiteMod, it draws an analogue clock on the minecraft HUD using
* a traditional onTick hook supplied by LiteLoader's "Tickable" interface.
*
* @author Adam Mummery-Smith
*/
@ExposableOptions(strategy = ConfigStrategy.Versioned, filename="examplemod.json")
public class LiteModExample implements Tickable, PreRenderListener
{
/**
* This is our instance of Clock which we will draw every tick
*/
private Clock clock = new Clock(10, 10);
/**
* This is a keybinding that we will register with the game and use to toggle the clock
*
* Notice that we specify the key name as an *unlocalised* string. The localisation is provided from the included resource file
*/
private static KeyBinding clockKeyBinding = new KeyBinding("key.clock.toggle", Keyboard.KEY_F12, "key.categories.litemods");
@Expose
@SerializedName("clock_size")
private int clockSize = 64;
@Expose
@SerializedName("clock_visible")
private boolean clockVisible = true;
/**
* Default constructor. All LiteMods must have a default constructor. In general you should do very little
* in the mod constructor EXCEPT for initialising any non-game-interfacing components or performing
* sanity checking prior to initialisation
*/
public LiteModExample()
{
}
/**
* getName() should be used to return the display name of your mod and MUST NOT return null
*
* @see com.mumfrey.liteloader.LiteMod#getName()
*/
@Override
public String getName()
{
return "Example Mod";
}
/**
* getVersion() should return the same version string present in the mod metadata, although this is
* not a strict requirement.
*
* @see com.mumfrey.liteloader.LiteMod#getVersion()
*/
@Override
public String getVersion()
{
return "0.0.0";
}
/**
* init() is called very early in the initialisation cycle, before the game is fully initialised, this
* means that it is important that your mod does not interact with the game in any way at this point.
*
* @see com.mumfrey.liteloader.LiteMod#init(java.io.File)
*/
@Override
public void init(File configPath)
{
// The key binding declared above won't do anything unless we register it, ModUtilties provides
// a convenience method for this
LiteLoader.getInput().registerKeyBinding(LiteModExample.clockKeyBinding);
this.clock.setSize(this.clockSize);
this.clock.setVisible(this.clockVisible);
}
/**
* upgradeSettings is used to notify a mod that its version-specific settings are being migrated
*
* @see com.mumfrey.liteloader.LiteMod#upgradeSettings(java.lang.String, java.io.File, java.io.File)
*/
@Override
public void upgradeSettings(String version, File configPath, File oldConfigPath)
{
}
@Override
public void onTick(Minecraft minecraft, float partialTicks, boolean inGame, boolean clock)
{
// The three checks here are critical to ensure that we only draw the clock as part of the "HUD"
// and don't draw it over active GUI's or other elements
if (inGame && minecraft.currentScreen == null && Minecraft.isGuiEnabled())
{
if (LiteModExample.clockKeyBinding.isPressed())
{
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT))
{
this.clockSize = (this.clockSize << 1) & 0x1FF;
this.clock.setSize(this.clockSize);
this.clockSize = this.clock.getSize();
}
else
{
this.clock.setVisible(!this.clock.isVisible());
this.clockVisible = this.clock.isVisible();
}
// Our @Expose annotations control what properties get saved, this tells liteloader to
// actually write the properties to disk
LiteLoader.getInstance().writeConfig(this);
}
// Render the clock
this.clock.render(minecraft);
}
}
@Override
public void onRenderWorld(float partialTicks)
{
// System.err.printf(">> onRenderWorld!\n");
}
@Override
public void onSetupCameraTransform(float partialTicks, int pass, long timeSlice)
{
// System.err.printf(">> onSetupCameraTransform %s, %d, %d!\n", partialTicks, pass, timeSlice);
}
@Override
public void onRenderSky(float partialTicks, int pass)
{
// System.err.printf(">> onRenderSky %s, %d!\n", partialTicks, pass);
}
@Override
public void onRenderClouds(float partialTicks, int pass, RenderGlobal renderGlobal)
{
// System.err.printf(">> onRenderClouds %s, %d!\n", partialTicks, pass);
}
@Override
public void onRenderTerrain(float partialTicks, int pass)
{
// System.err.printf(">> onRenderTerrain %s, %d!\n", partialTicks, pass);
}
}