Commit ae0c58670b3b3c0feae8bca0171fc8cb617334d4
1 parent
1b0e9c50
adding PlayerMoveListener
Showing
11 changed files
with
409 additions
and
157 deletions
java/client/com/mumfrey/liteloader/client/CallbackProxyClient.java
@@ -13,28 +13,14 @@ import net.minecraft.client.renderer.entity.RenderManager; | @@ -13,28 +13,14 @@ import net.minecraft.client.renderer.entity.RenderManager; | ||
13 | import net.minecraft.client.shader.Framebuffer; | 13 | import net.minecraft.client.shader.Framebuffer; |
14 | import net.minecraft.entity.Entity; | 14 | import net.minecraft.entity.Entity; |
15 | import net.minecraft.entity.player.EntityPlayer; | 15 | import net.minecraft.entity.player.EntityPlayer; |
16 | -import net.minecraft.entity.player.EntityPlayerMP; | ||
17 | -import net.minecraft.item.ItemStack; | ||
18 | -import net.minecraft.network.NetHandlerPlayServer; | ||
19 | -import net.minecraft.network.NetworkManager; | ||
20 | -import net.minecraft.network.play.client.C07PacketPlayerDigging; | ||
21 | -import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; | ||
22 | -import net.minecraft.network.play.client.C0APacketAnimation; | ||
23 | -import net.minecraft.network.play.server.S23PacketBlockChange; | ||
24 | -import net.minecraft.server.MinecraftServer; | ||
25 | import net.minecraft.server.integrated.IntegratedServer; | 16 | import net.minecraft.server.integrated.IntegratedServer; |
26 | -import net.minecraft.server.management.ItemInWorldManager; | ||
27 | -import net.minecraft.server.management.ServerConfigurationManager; | ||
28 | -import net.minecraft.util.BlockPos; | ||
29 | -import net.minecraft.util.EnumFacing; | ||
30 | import net.minecraft.util.IChatComponent; | 17 | import net.minecraft.util.IChatComponent; |
31 | import net.minecraft.util.ScreenShotHelper; | 18 | import net.minecraft.util.ScreenShotHelper; |
32 | import net.minecraft.util.Session; | 19 | import net.minecraft.util.Session; |
33 | -import net.minecraft.world.World; | ||
34 | import net.minecraft.world.WorldSettings; | 20 | import net.minecraft.world.WorldSettings; |
35 | 21 | ||
36 | import com.mojang.authlib.GameProfile; | 22 | import com.mojang.authlib.GameProfile; |
37 | -import com.mumfrey.liteloader.core.LiteLoaderEventBroker.InteractType; | 23 | +import com.mumfrey.liteloader.core.CallbackProxyCommon; |
38 | import com.mumfrey.liteloader.transformers.event.EventInfo; | 24 | import com.mumfrey.liteloader.transformers.event.EventInfo; |
39 | import com.mumfrey.liteloader.transformers.event.ReturnEventInfo; | 25 | import com.mumfrey.liteloader.transformers.event.ReturnEventInfo; |
40 | 26 | ||
@@ -45,29 +31,33 @@ import com.mumfrey.liteloader.transformers.event.ReturnEventInfo; | @@ -45,29 +31,33 @@ import com.mumfrey.liteloader.transformers.event.ReturnEventInfo; | ||
45 | * | 31 | * |
46 | * @author Adam Mummery-Smith | 32 | * @author Adam Mummery-Smith |
47 | */ | 33 | */ |
48 | -public class CallbackProxyClient | 34 | +public abstract class CallbackProxyClient extends CallbackProxyCommon |
49 | { | 35 | { |
50 | - private static LiteLoaderEventBrokerClient eventBroker; | 36 | + private static LiteLoaderEventBrokerClient clientEventBroker; |
51 | 37 | ||
52 | private static boolean fboEnabled; | 38 | private static boolean fboEnabled; |
53 | 39 | ||
54 | private static boolean renderingFBO; | 40 | private static boolean renderingFBO; |
55 | 41 | ||
42 | + private CallbackProxyClient() {} | ||
43 | + | ||
56 | public static void onStartupComplete(EventInfo<Minecraft> e) | 44 | public static void onStartupComplete(EventInfo<Minecraft> e) |
57 | { | 45 | { |
58 | - CallbackProxyClient.eventBroker = LiteLoaderEventBrokerClient.getInstance(); | 46 | + CallbackProxyCommon.onStartupComplete(); |
47 | + | ||
48 | + CallbackProxyClient.clientEventBroker = LiteLoaderEventBrokerClient.getInstance(); | ||
59 | 49 | ||
60 | - if (CallbackProxyClient.eventBroker == null) | 50 | + if (CallbackProxyClient.clientEventBroker == null) |
61 | { | 51 | { |
62 | throw new RuntimeException("LiteLoader failed to start up properly. The game is in an unstable state and must shut down now. Check the developer log for startup errors"); | 52 | throw new RuntimeException("LiteLoader failed to start up properly. The game is in an unstable state and must shut down now. Check the developer log for startup errors"); |
63 | } | 53 | } |
64 | 54 | ||
65 | - CallbackProxyClient.eventBroker.onStartupComplete(); | 55 | + CallbackProxyClient.clientEventBroker.onStartupComplete(); |
66 | } | 56 | } |
67 | 57 | ||
68 | public static void onTimerUpdate(EventInfo<Minecraft> e) | 58 | public static void onTimerUpdate(EventInfo<Minecraft> e) |
69 | { | 59 | { |
70 | - CallbackProxyClient.eventBroker.onTimerUpdate(); | 60 | + CallbackProxyClient.clientEventBroker.onTimerUpdate(); |
71 | } | 61 | } |
72 | 62 | ||
73 | public static void newTick(EventInfo<Minecraft> e) | 63 | public static void newTick(EventInfo<Minecraft> e) |
@@ -76,124 +66,99 @@ public class CallbackProxyClient | @@ -76,124 +66,99 @@ public class CallbackProxyClient | ||
76 | 66 | ||
77 | public static void onTick(EventInfo<Minecraft> e) | 67 | public static void onTick(EventInfo<Minecraft> e) |
78 | { | 68 | { |
79 | - CallbackProxyClient.eventBroker.onTick(); | 69 | + CallbackProxyClient.clientEventBroker.onTick(); |
80 | } | 70 | } |
81 | 71 | ||
82 | public static void onRender(EventInfo<Minecraft> e) | 72 | public static void onRender(EventInfo<Minecraft> e) |
83 | { | 73 | { |
84 | - CallbackProxyClient.eventBroker.onRender(); | 74 | + CallbackProxyClient.clientEventBroker.onRender(); |
85 | } | 75 | } |
86 | 76 | ||
87 | public static void preRenderGUI(EventInfo<EntityRenderer> e, float partialTicks) | 77 | public static void preRenderGUI(EventInfo<EntityRenderer> e, float partialTicks) |
88 | { | 78 | { |
89 | - CallbackProxyClient.eventBroker.preRenderGUI(partialTicks); | 79 | + CallbackProxyClient.clientEventBroker.preRenderGUI(partialTicks); |
90 | } | 80 | } |
91 | 81 | ||
92 | public static void onSetupCameraTransform(EventInfo<EntityRenderer> e, int pass, float partialTicks, long timeSlice) | 82 | public static void onSetupCameraTransform(EventInfo<EntityRenderer> e, int pass, float partialTicks, long timeSlice) |
93 | { | 83 | { |
94 | - CallbackProxyClient.eventBroker.onSetupCameraTransform(partialTicks, timeSlice); | 84 | + CallbackProxyClient.clientEventBroker.onSetupCameraTransform(partialTicks, timeSlice); |
95 | } | 85 | } |
96 | 86 | ||
97 | public static void postRenderEntities(EventInfo<EntityRenderer> e, int pass, float partialTicks, long timeSlice) | 87 | public static void postRenderEntities(EventInfo<EntityRenderer> e, int pass, float partialTicks, long timeSlice) |
98 | { | 88 | { |
99 | - CallbackProxyClient.eventBroker.postRenderEntities(partialTicks, timeSlice); | 89 | + CallbackProxyClient.clientEventBroker.postRenderEntities(partialTicks, timeSlice); |
100 | } | 90 | } |
101 | 91 | ||
102 | public static void postRender(EventInfo<EntityRenderer> e, float partialTicks, long timeSlice) | 92 | public static void postRender(EventInfo<EntityRenderer> e, float partialTicks, long timeSlice) |
103 | { | 93 | { |
104 | - CallbackProxyClient.eventBroker.postRender(partialTicks, timeSlice); | 94 | + CallbackProxyClient.clientEventBroker.postRender(partialTicks, timeSlice); |
105 | } | 95 | } |
106 | 96 | ||
107 | public static void onRenderHUD(EventInfo<EntityRenderer> e, float partialTicks) | 97 | public static void onRenderHUD(EventInfo<EntityRenderer> e, float partialTicks) |
108 | { | 98 | { |
109 | - CallbackProxyClient.eventBroker.onRenderHUD(partialTicks); | 99 | + CallbackProxyClient.clientEventBroker.onRenderHUD(partialTicks); |
110 | } | 100 | } |
111 | 101 | ||
112 | public static void onRenderChat(EventInfo<GuiIngame> e, float partialTicks) | 102 | public static void onRenderChat(EventInfo<GuiIngame> e, float partialTicks) |
113 | { | 103 | { |
114 | - CallbackProxyClient.eventBroker.onRenderChat(e.getSource().getChatGUI(), partialTicks); | 104 | + CallbackProxyClient.clientEventBroker.onRenderChat(e.getSource().getChatGUI(), partialTicks); |
115 | } | 105 | } |
116 | 106 | ||
117 | public static void postRenderChat(EventInfo<GuiIngame> e, float partialTicks) | 107 | public static void postRenderChat(EventInfo<GuiIngame> e, float partialTicks) |
118 | { | 108 | { |
119 | - CallbackProxyClient.eventBroker.postRenderChat(e.getSource().getChatGUI(), partialTicks); | 109 | + CallbackProxyClient.clientEventBroker.postRenderChat(e.getSource().getChatGUI(), partialTicks); |
120 | } | 110 | } |
121 | 111 | ||
122 | public static void postRenderHUD(EventInfo<EntityRenderer> e, float partialTicks) | 112 | public static void postRenderHUD(EventInfo<EntityRenderer> e, float partialTicks) |
123 | { | 113 | { |
124 | - CallbackProxyClient.eventBroker.postRenderHUD(partialTicks); | 114 | + CallbackProxyClient.clientEventBroker.postRenderHUD(partialTicks); |
125 | } | 115 | } |
126 | 116 | ||
127 | public static void IntegratedServerCtor(EventInfo<IntegratedServer> e, Minecraft minecraft, String folderName, String worldName, WorldSettings worldSettings) | 117 | public static void IntegratedServerCtor(EventInfo<IntegratedServer> e, Minecraft minecraft, String folderName, String worldName, WorldSettings worldSettings) |
128 | { | 118 | { |
129 | - CallbackProxyClient.eventBroker.onStartServer(e.getSource(), folderName, worldName, worldSettings); | ||
130 | - } | ||
131 | - | ||
132 | - public static void onInitializePlayerConnection(EventInfo<ServerConfigurationManager> e, NetworkManager netManager, EntityPlayerMP player) | ||
133 | - { | ||
134 | - CallbackProxyClient.eventBroker.onInitializePlayerConnection(e.getSource(), netManager, player); | ||
135 | - } | ||
136 | - | ||
137 | - public static void onPlayerLogin(EventInfo<ServerConfigurationManager> e, EntityPlayerMP player) | ||
138 | - { | ||
139 | - CallbackProxyClient.eventBroker.onPlayerLogin(e.getSource(), player); | ||
140 | - } | ||
141 | - | ||
142 | - public static void onPlayerLogout(EventInfo<ServerConfigurationManager> e, EntityPlayerMP player) | ||
143 | - { | ||
144 | - CallbackProxyClient.eventBroker.onPlayerLogout(e.getSource(), player); | ||
145 | - } | ||
146 | - | ||
147 | - public static void onSpawnPlayer(ReturnEventInfo<ServerConfigurationManager, EntityPlayerMP> e, GameProfile profile) | ||
148 | - { | ||
149 | - CallbackProxyClient.eventBroker.onSpawnPlayer(e.getSource(), e.getReturnValue(), profile); | ||
150 | - } | ||
151 | - | ||
152 | - public static void onRespawnPlayer(ReturnEventInfo<ServerConfigurationManager, EntityPlayerMP> e, EntityPlayerMP oldPlayer, int dimension, boolean won) | ||
153 | - { | ||
154 | - CallbackProxyClient.eventBroker.onRespawnPlayer(e.getSource(), e.getReturnValue(), oldPlayer, dimension, won); | 119 | + CallbackProxyClient.clientEventBroker.onStartServer(e.getSource(), folderName, worldName, worldSettings); |
155 | } | 120 | } |
156 | 121 | ||
157 | public static void onOutboundChat(EventInfo<EntityPlayerSP> e, String message) | 122 | public static void onOutboundChat(EventInfo<EntityPlayerSP> e, String message) |
158 | { | 123 | { |
159 | - CallbackProxyClient.eventBroker.onSendChatMessage(e, message); | 124 | + CallbackProxyClient.clientEventBroker.onSendChatMessage(e, message); |
160 | } | 125 | } |
161 | 126 | ||
162 | public static void onResize(EventInfo<Minecraft> e) | 127 | public static void onResize(EventInfo<Minecraft> e) |
163 | { | 128 | { |
164 | - if (CallbackProxyClient.eventBroker == null) return; | ||
165 | - CallbackProxyClient.eventBroker.onResize(e.getSource()); | 129 | + if (CallbackProxyClient.clientEventBroker == null) return; |
130 | + CallbackProxyClient.clientEventBroker.onResize(e.getSource()); | ||
166 | } | 131 | } |
167 | 132 | ||
168 | public static void preRenderFBO(EventInfo<Minecraft> e) | 133 | public static void preRenderFBO(EventInfo<Minecraft> e) |
169 | { | 134 | { |
170 | - if (CallbackProxyClient.eventBroker == null) return; | 135 | + if (CallbackProxyClient.clientEventBroker == null) return; |
171 | CallbackProxyClient.fboEnabled = OpenGlHelper.isFramebufferEnabled(); | 136 | CallbackProxyClient.fboEnabled = OpenGlHelper.isFramebufferEnabled(); |
172 | 137 | ||
173 | if (CallbackProxyClient.fboEnabled) | 138 | if (CallbackProxyClient.fboEnabled) |
174 | { | 139 | { |
175 | CallbackProxyClient.renderingFBO = true; | 140 | CallbackProxyClient.renderingFBO = true; |
176 | - CallbackProxyClient.eventBroker.preRenderFBO(e.getSource().getFramebuffer()); | 141 | + CallbackProxyClient.clientEventBroker.preRenderFBO(e.getSource().getFramebuffer()); |
177 | } | 142 | } |
178 | } | 143 | } |
179 | 144 | ||
180 | public static void postRenderFBO(EventInfo<Minecraft> e) | 145 | public static void postRenderFBO(EventInfo<Minecraft> e) |
181 | { | 146 | { |
182 | - if (CallbackProxyClient.eventBroker == null) return; | 147 | + if (CallbackProxyClient.clientEventBroker == null) return; |
183 | CallbackProxyClient.renderingFBO = false; | 148 | CallbackProxyClient.renderingFBO = false; |
184 | 149 | ||
185 | if (CallbackProxyClient.fboEnabled) | 150 | if (CallbackProxyClient.fboEnabled) |
186 | { | 151 | { |
187 | - CallbackProxyClient.eventBroker.postRenderFBO(e.getSource().getFramebuffer()); | 152 | + CallbackProxyClient.clientEventBroker.postRenderFBO(e.getSource().getFramebuffer()); |
188 | } | 153 | } |
189 | } | 154 | } |
190 | 155 | ||
191 | public static void renderFBO(EventInfo<Framebuffer> e, int width, int height, boolean flag) | 156 | public static void renderFBO(EventInfo<Framebuffer> e, int width, int height, boolean flag) |
192 | { | 157 | { |
193 | - if (CallbackProxyClient.eventBroker == null) return; | 158 | + if (CallbackProxyClient.clientEventBroker == null) return; |
194 | if (CallbackProxyClient.renderingFBO) | 159 | if (CallbackProxyClient.renderingFBO) |
195 | { | 160 | { |
196 | - CallbackProxyClient.eventBroker.onRenderFBO(e.getSource(), width, height); | 161 | + CallbackProxyClient.clientEventBroker.onRenderFBO(e.getSource(), width, height); |
197 | } | 162 | } |
198 | 163 | ||
199 | CallbackProxyClient.renderingFBO = false; | 164 | CallbackProxyClient.renderingFBO = false; |
@@ -201,96 +166,22 @@ public class CallbackProxyClient | @@ -201,96 +166,22 @@ public class CallbackProxyClient | ||
201 | 166 | ||
202 | public static void onRenderWorld(EventInfo<EntityRenderer> e, float partialTicks, long timeSlice) | 167 | public static void onRenderWorld(EventInfo<EntityRenderer> e, float partialTicks, long timeSlice) |
203 | { | 168 | { |
204 | - CallbackProxyClient.eventBroker.onRenderWorld(partialTicks, timeSlice); | 169 | + CallbackProxyClient.clientEventBroker.onRenderWorld(partialTicks, timeSlice); |
205 | } | 170 | } |
206 | 171 | ||
207 | public static void onSaveScreenshot(ReturnEventInfo<ScreenShotHelper, IChatComponent> e, File gameDir, String name, int width, int height, Framebuffer fbo) | 172 | public static void onSaveScreenshot(ReturnEventInfo<ScreenShotHelper, IChatComponent> e, File gameDir, String name, int width, int height, Framebuffer fbo) |
208 | { | 173 | { |
209 | - CallbackProxyClient.eventBroker.onScreenshot(e, name, width, height, fbo); | 174 | + CallbackProxyClient.clientEventBroker.onScreenshot(e, name, width, height, fbo); |
210 | } | 175 | } |
211 | 176 | ||
212 | public static void onRenderEntity(ReturnEventInfo<RenderManager, Boolean> e, Entity entity, double xPos, double yPos, double zPos, float yaw, float partialTicks, boolean hideBoundingBox, Render render) | 177 | public static void onRenderEntity(ReturnEventInfo<RenderManager, Boolean> e, Entity entity, double xPos, double yPos, double zPos, float yaw, float partialTicks, boolean hideBoundingBox, Render render) |
213 | { | 178 | { |
214 | - CallbackProxyClient.eventBroker.onRenderEntity(e.getSource(), entity, xPos, yPos, zPos, yaw, partialTicks, render); | 179 | + CallbackProxyClient.clientEventBroker.onRenderEntity(e.getSource(), entity, xPos, yPos, zPos, yaw, partialTicks, render); |
215 | } | 180 | } |
216 | 181 | ||
217 | public static void onPostRenderEntity(ReturnEventInfo<RenderManager, Boolean> e, Entity entity, double xPos, double yPos, double zPos, float yaw, float partialTicks, boolean hideBoundingBox, Render render) | 182 | public static void onPostRenderEntity(ReturnEventInfo<RenderManager, Boolean> e, Entity entity, double xPos, double yPos, double zPos, float yaw, float partialTicks, boolean hideBoundingBox, Render render) |
218 | { | 183 | { |
219 | - CallbackProxyClient.eventBroker.onPostRenderEntity(e.getSource(), entity, xPos, yPos, zPos, yaw, partialTicks, render); | ||
220 | - } | ||
221 | - | ||
222 | - public static void onServerTick(EventInfo<MinecraftServer> e) | ||
223 | - { | ||
224 | - CallbackProxyClient.eventBroker.onServerTick(e.getSource()); | ||
225 | - } | ||
226 | - | ||
227 | - public static void onPlaceBlock(EventInfo<NetHandlerPlayServer> e, C08PacketPlayerBlockPlacement packet) | ||
228 | - { | ||
229 | - NetHandlerPlayServer netHandler = e.getSource(); | ||
230 | - | ||
231 | - EntityPlayerMP playerMP = netHandler.playerEntity; | ||
232 | - BlockPos pos = packet.getPosition(); | ||
233 | - EnumFacing facing = EnumFacing.getFront(packet.getPlacedBlockDirection()); | ||
234 | - if (!CallbackProxyClient.eventBroker.onPlayerInteract(InteractType.PLACE_BLOCK_MAYBE, playerMP, pos, facing)) | ||
235 | - { | ||
236 | - S23PacketBlockChange cancellation = new S23PacketBlockChange(playerMP.worldObj, pos.offset(facing)); | ||
237 | - netHandler.playerEntity.playerNetServerHandler.sendPacket(cancellation); | ||
238 | - playerMP.sendContainerToPlayer(playerMP.inventoryContainer); | ||
239 | - e.cancel(); | ||
240 | - } | ||
241 | - } | ||
242 | - | ||
243 | - public static void onClickedAir(EventInfo<NetHandlerPlayServer> e, C0APacketAnimation packet) | ||
244 | - { | ||
245 | - NetHandlerPlayServer netHandler = e.getSource(); | ||
246 | - if (!CallbackProxyClient.eventBroker.onPlayerInteract(InteractType.LEFT_CLICK, netHandler.playerEntity, null, EnumFacing.SOUTH)) | ||
247 | - { | ||
248 | - e.cancel(); | ||
249 | - } | ||
250 | - } | ||
251 | - | ||
252 | - public static void onPlayerDigging(EventInfo<NetHandlerPlayServer> e, C07PacketPlayerDigging packet) | ||
253 | - { | ||
254 | - if (packet.getStatus() == C07PacketPlayerDigging.Action.START_DESTROY_BLOCK) | ||
255 | - { | ||
256 | - NetHandlerPlayServer netHandler = e.getSource(); | ||
257 | - BlockPos pos = packet.func_179715_a(); | ||
258 | - EntityPlayerMP playerMP = netHandler.playerEntity; | ||
259 | - if (!CallbackProxyClient.eventBroker.onPlayerInteract(InteractType.DIG_BLOCK_MAYBE, playerMP, pos, EnumFacing.SOUTH)) | ||
260 | - { | ||
261 | - S23PacketBlockChange cancellation = new S23PacketBlockChange(playerMP.worldObj, pos); | ||
262 | - netHandler.playerEntity.playerNetServerHandler.sendPacket(cancellation); | ||
263 | - e.cancel(); | ||
264 | - } | ||
265 | - } | ||
266 | - } | ||
267 | - | ||
268 | - public static void onUseItem(ReturnEventInfo<ItemInWorldManager, Boolean> e, EntityPlayer player, World world, ItemStack itemStack, BlockPos pos, EnumFacing side, float par8, float par9, float par10) | ||
269 | - { | ||
270 | - if (player instanceof EntityPlayerMP) | ||
271 | - { | ||
272 | - EntityPlayerMP playerMP = (EntityPlayerMP)player; | ||
273 | - | ||
274 | - if (!CallbackProxyClient.eventBroker.onPlayerInteract(InteractType.PLACE_BLOCK_MAYBE, playerMP, pos, side)) | ||
275 | - { | ||
276 | - System.err.println(pos); | ||
277 | - S23PacketBlockChange cancellation = new S23PacketBlockChange(playerMP.worldObj, pos); | ||
278 | - playerMP.playerNetServerHandler.sendPacket(cancellation); | ||
279 | - e.setReturnValue(false); | ||
280 | - } | ||
281 | - } | ||
282 | - } | ||
283 | - | ||
284 | - public static void onBlockClicked(EventInfo<ItemInWorldManager> e, BlockPos pos, EnumFacing side) | ||
285 | - { | ||
286 | - ItemInWorldManager manager = e.getSource(); | ||
287 | - | ||
288 | - if (!CallbackProxyClient.eventBroker.onPlayerInteract(InteractType.LEFT_CLICK_BLOCK, manager.thisPlayerMP, pos, side)) | ||
289 | - { | ||
290 | - S23PacketBlockChange cancellation = new S23PacketBlockChange(manager.theWorld, pos); | ||
291 | - manager.thisPlayerMP.playerNetServerHandler.sendPacket(cancellation); | ||
292 | - e.cancel(); | ||
293 | - } | 184 | + CallbackProxyClient.clientEventBroker.onPostRenderEntity(e.getSource(), entity, xPos, yPos, zPos, yaw, partialTicks, render); |
294 | } | 185 | } |
295 | 186 | ||
296 | /** | 187 | /** |
java/common/com/mumfrey/liteloader/PlayerInteractionListener.java
@@ -44,7 +44,7 @@ public interface PlayerInteractionListener extends LiteMod | @@ -44,7 +44,7 @@ public interface PlayerInteractionListener extends LiteMod | ||
44 | * @param button Mouse button that was pressed (left = dig, right = interact/place) | 44 | * @param button Mouse button that was pressed (left = dig, right = interact/place) |
45 | * @param hitPos Block which was *hit*. Note that block placement will normally be at hitPos.offset(sideHit) | 45 | * @param hitPos Block which was *hit*. Note that block placement will normally be at hitPos.offset(sideHit) |
46 | * @param sideHit Side of the block which was hit | 46 | * @param sideHit Side of the block which was hit |
47 | - * @return | 47 | + * @return true to allow the action to be processed (another listener may still inhibit the action), return false to cancel the action (other listeners will still be notified) |
48 | */ | 48 | */ |
49 | public abstract boolean onPlayerClickedBlock(EntityPlayerMP player, MouseButton button, BlockPos hitPos, EnumFacing sideHit); | 49 | public abstract boolean onPlayerClickedBlock(EntityPlayerMP player, MouseButton button, BlockPos hitPos, EnumFacing sideHit); |
50 | } | 50 | } |
java/common/com/mumfrey/liteloader/PlayerMoveListener.java
0 → 100644
1 | +package com.mumfrey.liteloader; | ||
2 | + | ||
3 | +import net.minecraft.entity.player.EntityPlayerMP; | ||
4 | + | ||
5 | +import com.mumfrey.liteloader.core.LiteLoaderEventBroker.ReturnValue; | ||
6 | +import com.mumfrey.liteloader.util.Position; | ||
7 | + | ||
8 | +/** | ||
9 | + * Interface for mods which want to monitor or control player movements | ||
10 | + * | ||
11 | + * @author Adam Mummery-Smith | ||
12 | + */ | ||
13 | +public interface PlayerMoveListener extends LiteMod | ||
14 | +{ | ||
15 | + /** | ||
16 | + * Called when a movement/look packet is received from the client. | ||
17 | + * | ||
18 | + * @param playerMP Player moving | ||
19 | + * @param from Player's previous recorded position | ||
20 | + * @param to Position the player is attempting to move to | ||
21 | + * @param newPos Set this position to teleport the player to newPos instead of processing the original move | ||
22 | + * | ||
23 | + * @return false to cancel the event or true to allow the movement to be processed as normal or newPos to be applied | ||
24 | + */ | ||
25 | + public abstract boolean onPlayerMove(EntityPlayerMP playerMP, Position from, Position to, ReturnValue<Position> newPos); | ||
26 | +} |
java/common/com/mumfrey/liteloader/common/GameEngine.java
@@ -50,7 +50,7 @@ public interface GameEngine<TClient, TServer extends MinecraftServer> | @@ -50,7 +50,7 @@ public interface GameEngine<TClient, TServer extends MinecraftServer> | ||
50 | public abstract TServer getServer(); | 50 | public abstract TServer getServer(); |
51 | 51 | ||
52 | /** | 52 | /** |
53 | - * @return | 53 | + * Get the resources manager |
54 | */ | 54 | */ |
55 | public abstract Resources<?, ?> getResources(); | 55 | public abstract Resources<?, ?> getResources(); |
56 | 56 |
java/common/com/mumfrey/liteloader/common/transformers/LiteLoaderEventTransformer.java
@@ -3,11 +3,14 @@ package com.mumfrey.liteloader.common.transformers; | @@ -3,11 +3,14 @@ package com.mumfrey.liteloader.common.transformers; | ||
3 | import static com.mumfrey.liteloader.core.runtime.Methods.*; | 3 | import static com.mumfrey.liteloader.core.runtime.Methods.*; |
4 | import static com.mumfrey.liteloader.transformers.event.InjectionPoint.*; | 4 | import static com.mumfrey.liteloader.transformers.event.InjectionPoint.*; |
5 | 5 | ||
6 | +import org.objectweb.asm.Opcodes; | ||
7 | + | ||
6 | import com.mumfrey.liteloader.core.runtime.Obf; | 8 | import com.mumfrey.liteloader.core.runtime.Obf; |
7 | import com.mumfrey.liteloader.transformers.event.Event; | 9 | import com.mumfrey.liteloader.transformers.event.Event; |
8 | import com.mumfrey.liteloader.transformers.event.EventInjectionTransformer; | 10 | import com.mumfrey.liteloader.transformers.event.EventInjectionTransformer; |
9 | import com.mumfrey.liteloader.transformers.event.InjectionPoint; | 11 | import com.mumfrey.liteloader.transformers.event.InjectionPoint; |
10 | import com.mumfrey.liteloader.transformers.event.MethodInfo; | 12 | import com.mumfrey.liteloader.transformers.event.MethodInfo; |
13 | +import com.mumfrey.liteloader.transformers.event.inject.BeforeFieldAccess; | ||
11 | import com.mumfrey.liteloader.transformers.event.inject.BeforeInvoke; | 14 | import com.mumfrey.liteloader.transformers.event.inject.BeforeInvoke; |
12 | import com.mumfrey.liteloader.transformers.event.inject.BeforeNew; | 15 | import com.mumfrey.liteloader.transformers.event.inject.BeforeNew; |
13 | import com.mumfrey.liteloader.transformers.event.inject.BeforeReturn; | 16 | import com.mumfrey.liteloader.transformers.event.inject.BeforeReturn; |
@@ -25,7 +28,7 @@ public abstract class LiteLoaderEventTransformer extends EventInjectionTransform | @@ -25,7 +28,7 @@ public abstract class LiteLoaderEventTransformer extends EventInjectionTransform | ||
25 | @Override | 28 | @Override |
26 | protected void addEvents() | 29 | protected void addEvents() |
27 | { | 30 | { |
28 | - // Event declaraions | 31 | + // Event declarations |
29 | Event onInitializePlayerConnection = Event.getOrCreate("onInitializePlayerConnection", false); | 32 | Event onInitializePlayerConnection = Event.getOrCreate("onInitializePlayerConnection", false); |
30 | Event onPlayerLogin = Event.getOrCreate("onPlayerLogin", false); | 33 | Event onPlayerLogin = Event.getOrCreate("onPlayerLogin", false); |
31 | Event onPlayerLogout = Event.getOrCreate("onPlayerLogout", false); | 34 | Event onPlayerLogout = Event.getOrCreate("onPlayerLogout", false); |
@@ -38,12 +41,14 @@ public abstract class LiteLoaderEventTransformer extends EventInjectionTransform | @@ -38,12 +41,14 @@ public abstract class LiteLoaderEventTransformer extends EventInjectionTransform | ||
38 | Event onPlaceBlock = Event.getOrCreate("onPlaceBlock", true); | 41 | Event onPlaceBlock = Event.getOrCreate("onPlaceBlock", true); |
39 | Event onClickedAir = Event.getOrCreate("onClickedAir", true); | 42 | Event onClickedAir = Event.getOrCreate("onClickedAir", true); |
40 | Event onSessionProfileBad = Event.getOrCreate("onSessionProfileBad", true); | 43 | Event onSessionProfileBad = Event.getOrCreate("onSessionProfileBad", true); |
44 | + Event onPlayerMoved = Event.getOrCreate("onPlayerMoved", true); | ||
41 | 45 | ||
42 | // Injection Points | 46 | // Injection Points |
43 | InjectionPoint methodHead = new MethodHead(); | 47 | InjectionPoint methodHead = new MethodHead(); |
44 | InjectionPoint methodReturn = new BeforeReturn(); | 48 | InjectionPoint methodReturn = new BeforeReturn(); |
45 | InjectionPoint beforeNewGameProfile = new BeforeNew(1, Obf.GameProfile); | 49 | InjectionPoint beforeNewGameProfile = new BeforeNew(1, Obf.GameProfile); |
46 | InjectionPoint beforeThreadMarshall = new BeforeInvoke(checkThreadAndEnqueue); | 50 | InjectionPoint beforeThreadMarshall = new BeforeInvoke(checkThreadAndEnqueue); |
51 | + InjectionPoint beforeGetPosY = new BeforeFieldAccess(Opcodes.GETFIELD, Obf.entityPosY, Obf.EntityPlayerMP, 4).setCaptureLocals(true); | ||
47 | 52 | ||
48 | // Hooks | 53 | // Hooks |
49 | this.add(onInitializePlayerConnection, initPlayerConnection, (methodReturn), "onInitializePlayerConnection"); | 54 | this.add(onInitializePlayerConnection, initPlayerConnection, (methodReturn), "onInitializePlayerConnection"); |
@@ -57,9 +62,10 @@ public abstract class LiteLoaderEventTransformer extends EventInjectionTransform | @@ -57,9 +62,10 @@ public abstract class LiteLoaderEventTransformer extends EventInjectionTransform | ||
57 | this.add(onPlaceBlock, processBlockPlacement, after(beforeThreadMarshall) , "onPlaceBlock"); | 62 | this.add(onPlaceBlock, processBlockPlacement, after(beforeThreadMarshall) , "onPlaceBlock"); |
58 | this.add(onClickedAir, handleAnimation, after(beforeThreadMarshall), "onClickedAir"); | 63 | this.add(onClickedAir, handleAnimation, after(beforeThreadMarshall), "onClickedAir"); |
59 | this.add(onPlayerDigging, processPlayerDigging, after(beforeThreadMarshall), "onPlayerDigging"); | 64 | this.add(onPlayerDigging, processPlayerDigging, after(beforeThreadMarshall), "onPlayerDigging"); |
65 | + this.add(onPlayerMoved, processPlayer, (beforeGetPosY), "onPlayerMoved"); | ||
60 | 66 | ||
61 | // Compatibility handlers | 67 | // Compatibility handlers |
62 | - this.add(onSessionProfileBad, getProfile, (beforeNewGameProfile), "generateOfflineUUID"); | 68 | + this.add(onSessionProfileBad, getProfile, (beforeNewGameProfile), "generateOfflineUUID"); |
63 | } | 69 | } |
64 | 70 | ||
65 | protected final Event add(Event event, MethodInfo targetMethod, InjectionPoint injectionPoint, String callback) | 71 | protected final Event add(Event event, MethodInfo targetMethod, InjectionPoint injectionPoint, String callback) |
java/common/com/mumfrey/liteloader/core/CallbackProxyCommon.java
0 → 100644
1 | +package com.mumfrey.liteloader.core; | ||
2 | + | ||
3 | +import net.minecraft.entity.player.EntityPlayer; | ||
4 | +import net.minecraft.entity.player.EntityPlayerMP; | ||
5 | +import net.minecraft.item.ItemStack; | ||
6 | +import net.minecraft.network.NetHandlerPlayServer; | ||
7 | +import net.minecraft.network.NetworkManager; | ||
8 | +import net.minecraft.network.play.client.C03PacketPlayer; | ||
9 | +import net.minecraft.network.play.client.C07PacketPlayerDigging; | ||
10 | +import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; | ||
11 | +import net.minecraft.network.play.client.C0APacketAnimation; | ||
12 | +import net.minecraft.server.MinecraftServer; | ||
13 | +import net.minecraft.server.management.ItemInWorldManager; | ||
14 | +import net.minecraft.server.management.ServerConfigurationManager; | ||
15 | +import net.minecraft.util.BlockPos; | ||
16 | +import net.minecraft.util.EnumFacing; | ||
17 | +import net.minecraft.world.World; | ||
18 | +import net.minecraft.world.WorldServer; | ||
19 | + | ||
20 | +import com.mojang.authlib.GameProfile; | ||
21 | +import com.mumfrey.liteloader.transformers.event.EventInfo; | ||
22 | +import com.mumfrey.liteloader.transformers.event.ReturnEventInfo; | ||
23 | + | ||
24 | +public abstract class CallbackProxyCommon | ||
25 | +{ | ||
26 | + private static LiteLoaderEventBroker<?, ?> eventBroker; | ||
27 | + | ||
28 | + protected CallbackProxyCommon() {} | ||
29 | + | ||
30 | + protected static void onStartupComplete() | ||
31 | + { | ||
32 | + CallbackProxyCommon.eventBroker = LiteLoaderEventBroker.broker; | ||
33 | + | ||
34 | + if (CallbackProxyCommon.eventBroker == null) | ||
35 | + { | ||
36 | + throw new RuntimeException("LiteLoader failed to start up properly. The game is in an unstable state and must shut down now. Check the developer log for startup errors"); | ||
37 | + } | ||
38 | + } | ||
39 | + | ||
40 | + public static void onInitializePlayerConnection(EventInfo<ServerConfigurationManager> e, NetworkManager netManager, EntityPlayerMP player) | ||
41 | + { | ||
42 | + CallbackProxyCommon.eventBroker.onInitializePlayerConnection(e.getSource(), netManager, player); | ||
43 | + } | ||
44 | + | ||
45 | + public static void onPlayerLogin(EventInfo<ServerConfigurationManager> e, EntityPlayerMP player) | ||
46 | + { | ||
47 | + CallbackProxyCommon.eventBroker.onPlayerLogin(e.getSource(), player); | ||
48 | + } | ||
49 | + | ||
50 | + public static void onPlayerLogout(EventInfo<ServerConfigurationManager> e, EntityPlayerMP player) | ||
51 | + { | ||
52 | + CallbackProxyCommon.eventBroker.onPlayerLogout(e.getSource(), player); | ||
53 | + } | ||
54 | + | ||
55 | + public static void onSpawnPlayer(ReturnEventInfo<ServerConfigurationManager, EntityPlayerMP> e, GameProfile profile) | ||
56 | + { | ||
57 | + CallbackProxyCommon.eventBroker.onSpawnPlayer(e.getSource(), e.getReturnValue(), profile); | ||
58 | + } | ||
59 | + | ||
60 | + public static void onRespawnPlayer(ReturnEventInfo<ServerConfigurationManager, EntityPlayerMP> e, EntityPlayerMP oldPlayer, int dimension, boolean won) | ||
61 | + { | ||
62 | + CallbackProxyCommon.eventBroker.onRespawnPlayer(e.getSource(), e.getReturnValue(), oldPlayer, dimension, won); | ||
63 | + } | ||
64 | + | ||
65 | + public static void onServerTick(EventInfo<MinecraftServer> e) | ||
66 | + { | ||
67 | + CallbackProxyCommon.eventBroker.onServerTick(e.getSource()); | ||
68 | + } | ||
69 | + | ||
70 | + public static void onPlaceBlock(EventInfo<NetHandlerPlayServer> e, C08PacketPlayerBlockPlacement packet) | ||
71 | + { | ||
72 | + NetHandlerPlayServer netHandler = e.getSource(); | ||
73 | + if (!CallbackProxyCommon.eventBroker.onPlaceBlock(netHandler, netHandler.playerEntity, packet.getPosition(), EnumFacing.getFront(packet.getPlacedBlockDirection()))) | ||
74 | + { | ||
75 | + e.cancel(); | ||
76 | + } | ||
77 | + } | ||
78 | + | ||
79 | + public static void onClickedAir(EventInfo<NetHandlerPlayServer> e, C0APacketAnimation packet) | ||
80 | + { | ||
81 | + if (!CallbackProxyCommon.eventBroker.onClickedAir(e.getSource())) | ||
82 | + { | ||
83 | + e.cancel(); | ||
84 | + } | ||
85 | + } | ||
86 | + | ||
87 | + public static void onPlayerDigging(EventInfo<NetHandlerPlayServer> e, C07PacketPlayerDigging packet) | ||
88 | + { | ||
89 | + if (packet.getStatus() == C07PacketPlayerDigging.Action.START_DESTROY_BLOCK) | ||
90 | + { | ||
91 | + NetHandlerPlayServer netHandler = e.getSource(); | ||
92 | + if (!CallbackProxyCommon.eventBroker.onPlayerDigging(netHandler, packet.func_179715_a(), netHandler.playerEntity)) | ||
93 | + { | ||
94 | + e.cancel(); | ||
95 | + } | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + public static void onUseItem(ReturnEventInfo<ItemInWorldManager, Boolean> e, EntityPlayer player, World world, ItemStack itemStack, BlockPos pos, EnumFacing side, float par8, float par9, float par10) | ||
100 | + { | ||
101 | + if (!(player instanceof EntityPlayerMP)) | ||
102 | + { | ||
103 | + return; | ||
104 | + } | ||
105 | + | ||
106 | + if (!CallbackProxyCommon.eventBroker.onUseItem(pos, side, (EntityPlayerMP)player)) | ||
107 | + { | ||
108 | + e.setReturnValue(false); | ||
109 | + } | ||
110 | + } | ||
111 | + | ||
112 | + public static void onBlockClicked(EventInfo<ItemInWorldManager> e, BlockPos pos, EnumFacing side) | ||
113 | + { | ||
114 | + ItemInWorldManager manager = e.getSource(); | ||
115 | + | ||
116 | + if (!CallbackProxyCommon.eventBroker.onBlockClicked(pos, side, manager)) | ||
117 | + { | ||
118 | + e.cancel(); | ||
119 | + } | ||
120 | + } | ||
121 | + | ||
122 | + public static void onPlayerMoved(EventInfo<NetHandlerPlayServer> e, C03PacketPlayer packet, WorldServer world, double oldPosX, double oldPosY, double oldPosZ) | ||
123 | + { | ||
124 | + NetHandlerPlayServer netHandler = e.getSource(); | ||
125 | + if (!CallbackProxyCommon.eventBroker.onPlayerMove(netHandler, packet, netHandler.playerEntity, world)) | ||
126 | + { | ||
127 | + e.cancel(); | ||
128 | + } | ||
129 | + } | ||
130 | + | ||
131 | + public static void onPlayerMoved(EventInfo<NetHandlerPlayServer> e, C03PacketPlayer packet, WorldServer world, double oldPosX, double oldPosY, double oldPosZ, double deltaMoveSq, double deltaX, double deltaY, double deltaZ) | ||
132 | + { | ||
133 | + NetHandlerPlayServer netHandler = e.getSource(); | ||
134 | + if (!CallbackProxyCommon.eventBroker.onPlayerMove(netHandler, packet, netHandler.playerEntity, world)) | ||
135 | + { | ||
136 | + e.cancel(); | ||
137 | + } | ||
138 | + } | ||
139 | +} |
java/common/com/mumfrey/liteloader/core/LiteLoaderEventBroker.java
1 | package com.mumfrey.liteloader.core; | 1 | package com.mumfrey.liteloader.core; |
2 | 2 | ||
3 | +import java.util.Collections; | ||
3 | import java.util.HashMap; | 4 | import java.util.HashMap; |
4 | import java.util.Map; | 5 | import java.util.Map; |
5 | import java.util.UUID; | 6 | import java.util.UUID; |
@@ -7,21 +8,28 @@ import java.util.UUID; | @@ -7,21 +8,28 @@ import java.util.UUID; | ||
7 | import net.minecraft.command.ICommandManager; | 8 | import net.minecraft.command.ICommandManager; |
8 | import net.minecraft.command.ServerCommandManager; | 9 | import net.minecraft.command.ServerCommandManager; |
9 | import net.minecraft.entity.player.EntityPlayerMP; | 10 | import net.minecraft.entity.player.EntityPlayerMP; |
11 | +import net.minecraft.network.NetHandlerPlayServer; | ||
10 | import net.minecraft.network.NetworkManager; | 12 | import net.minecraft.network.NetworkManager; |
13 | +import net.minecraft.network.play.client.C03PacketPlayer; | ||
11 | import net.minecraft.network.play.client.C15PacketClientSettings; | 14 | import net.minecraft.network.play.client.C15PacketClientSettings; |
15 | +import net.minecraft.network.play.server.S08PacketPlayerPosLook; | ||
16 | +import net.minecraft.network.play.server.S23PacketBlockChange; | ||
12 | import net.minecraft.profiler.Profiler; | 17 | import net.minecraft.profiler.Profiler; |
13 | import net.minecraft.server.MinecraftServer; | 18 | import net.minecraft.server.MinecraftServer; |
19 | +import net.minecraft.server.management.ItemInWorldManager; | ||
14 | import net.minecraft.server.management.ServerConfigurationManager; | 20 | import net.minecraft.server.management.ServerConfigurationManager; |
15 | import net.minecraft.util.BlockPos; | 21 | import net.minecraft.util.BlockPos; |
16 | import net.minecraft.util.EnumFacing; | 22 | import net.minecraft.util.EnumFacing; |
17 | import net.minecraft.util.MovingObjectPosition.MovingObjectType; | 23 | import net.minecraft.util.MovingObjectPosition.MovingObjectType; |
18 | import net.minecraft.world.World; | 24 | import net.minecraft.world.World; |
25 | +import net.minecraft.world.WorldServer; | ||
19 | import net.minecraft.world.WorldSettings; | 26 | import net.minecraft.world.WorldSettings; |
20 | 27 | ||
21 | import com.mojang.authlib.GameProfile; | 28 | import com.mojang.authlib.GameProfile; |
22 | import com.mumfrey.liteloader.LiteMod; | 29 | import com.mumfrey.liteloader.LiteMod; |
23 | import com.mumfrey.liteloader.PlayerInteractionListener; | 30 | import com.mumfrey.liteloader.PlayerInteractionListener; |
24 | import com.mumfrey.liteloader.PlayerInteractionListener.MouseButton; | 31 | import com.mumfrey.liteloader.PlayerInteractionListener.MouseButton; |
32 | +import com.mumfrey.liteloader.PlayerMoveListener; | ||
25 | import com.mumfrey.liteloader.PluginChannelListener; | 33 | import com.mumfrey.liteloader.PluginChannelListener; |
26 | import com.mumfrey.liteloader.ServerCommandProvider; | 34 | import com.mumfrey.liteloader.ServerCommandProvider; |
27 | import com.mumfrey.liteloader.ServerPlayerListener; | 35 | import com.mumfrey.liteloader.ServerPlayerListener; |
@@ -35,6 +43,7 @@ import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp; | @@ -35,6 +43,7 @@ import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp; | ||
35 | import com.mumfrey.liteloader.interfaces.FastIterable; | 43 | import com.mumfrey.liteloader.interfaces.FastIterable; |
36 | import com.mumfrey.liteloader.interfaces.FastIterableDeque; | 44 | import com.mumfrey.liteloader.interfaces.FastIterableDeque; |
37 | import com.mumfrey.liteloader.launch.LoaderProperties; | 45 | import com.mumfrey.liteloader.launch.LoaderProperties; |
46 | +import com.mumfrey.liteloader.util.Position; | ||
38 | import com.mumfrey.liteloader.util.PrivateFields; | 47 | import com.mumfrey.liteloader.util.PrivateFields; |
39 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; | 48 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
40 | 49 | ||
@@ -132,6 +141,11 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | @@ -132,6 +141,11 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | ||
132 | private FastIterable<PlayerInteractionListener> playerInteractionListeners = new HandlerList<PlayerInteractionListener>(PlayerInteractionListener.class, ReturnLogicOp.AND); | 141 | private FastIterable<PlayerInteractionListener> playerInteractionListeners = new HandlerList<PlayerInteractionListener>(PlayerInteractionListener.class, ReturnLogicOp.AND); |
133 | 142 | ||
134 | /** | 143 | /** |
144 | + * List of mods which handle player movement events | ||
145 | + */ | ||
146 | + private FastIterable<PlayerMoveListener> playerMoveListeners = new HandlerList<PlayerMoveListener>(PlayerMoveListener.class, ReturnLogicOp.AND_BREAK_ON_FALSE); | ||
147 | + | ||
148 | + /** | ||
135 | * ctor | 149 | * ctor |
136 | * | 150 | * |
137 | * @param loader | 151 | * @param loader |
@@ -187,6 +201,7 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | @@ -187,6 +201,7 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | ||
187 | delegate.registerInterface(ServerCommandProvider.class); | 201 | delegate.registerInterface(ServerCommandProvider.class); |
188 | delegate.registerInterface(ServerPlayerListener.class); | 202 | delegate.registerInterface(ServerPlayerListener.class); |
189 | delegate.registerInterface(PlayerInteractionListener.class); | 203 | delegate.registerInterface(PlayerInteractionListener.class); |
204 | + delegate.registerInterface(PlayerMoveListener.class); | ||
190 | delegate.registerInterface(CommonPluginChannelListener.class); | 205 | delegate.registerInterface(CommonPluginChannelListener.class); |
191 | } | 206 | } |
192 | 207 | ||
@@ -226,6 +241,14 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | @@ -226,6 +241,14 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | ||
226 | { | 241 | { |
227 | this.playerInteractionListeners.add(playerInteractionListener); | 242 | this.playerInteractionListeners.add(playerInteractionListener); |
228 | } | 243 | } |
244 | + | ||
245 | + /** | ||
246 | + * @param playerMoveListener | ||
247 | + */ | ||
248 | + public void addPlayerMoveListener(PlayerMoveListener playerMoveListener) | ||
249 | + { | ||
250 | + this.playerMoveListeners.add(playerMoveListener); | ||
251 | + } | ||
229 | 252 | ||
230 | /** | 253 | /** |
231 | * @param instance | 254 | * @param instance |
@@ -331,6 +354,60 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | @@ -331,6 +354,60 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | ||
331 | this.playerStateList.all().onTick(); | 354 | this.playerStateList.all().onTick(); |
332 | } | 355 | } |
333 | 356 | ||
357 | + public boolean onPlaceBlock(NetHandlerPlayServer netHandler, EntityPlayerMP playerMP, BlockPos pos, EnumFacing facing) | ||
358 | + { | ||
359 | + if (!this.onPlayerInteract(InteractType.PLACE_BLOCK_MAYBE, playerMP, pos, facing)) | ||
360 | + { | ||
361 | + S23PacketBlockChange cancellation = new S23PacketBlockChange(playerMP.worldObj, pos.offset(facing)); | ||
362 | + netHandler.playerEntity.playerNetServerHandler.sendPacket(cancellation); | ||
363 | + playerMP.sendContainerToPlayer(playerMP.inventoryContainer); | ||
364 | + return false; | ||
365 | + } | ||
366 | + | ||
367 | + return true; | ||
368 | + } | ||
369 | + | ||
370 | + public boolean onClickedAir(NetHandlerPlayServer netHandler) | ||
371 | + { | ||
372 | + return this.onPlayerInteract(InteractType.LEFT_CLICK, netHandler.playerEntity, null, EnumFacing.SOUTH); | ||
373 | + } | ||
374 | + | ||
375 | + public boolean onPlayerDigging(NetHandlerPlayServer netHandler, BlockPos pos, EntityPlayerMP playerMP) | ||
376 | + { | ||
377 | + if (!this.onPlayerInteract(InteractType.DIG_BLOCK_MAYBE, playerMP, pos, EnumFacing.SOUTH)) | ||
378 | + { | ||
379 | + S23PacketBlockChange cancellation = new S23PacketBlockChange(playerMP.worldObj, pos); | ||
380 | + netHandler.playerEntity.playerNetServerHandler.sendPacket(cancellation); | ||
381 | + return false; | ||
382 | + } | ||
383 | + | ||
384 | + return true; | ||
385 | + } | ||
386 | + | ||
387 | + public boolean onUseItem(BlockPos pos, EnumFacing side, EntityPlayerMP playerMP) | ||
388 | + { | ||
389 | + if (!this.onPlayerInteract(InteractType.PLACE_BLOCK_MAYBE, playerMP, pos, side)) | ||
390 | + { | ||
391 | + S23PacketBlockChange cancellation = new S23PacketBlockChange(playerMP.worldObj, pos); | ||
392 | + playerMP.playerNetServerHandler.sendPacket(cancellation); | ||
393 | + return false; | ||
394 | + } | ||
395 | + | ||
396 | + return true; | ||
397 | + } | ||
398 | + | ||
399 | + public boolean onBlockClicked(BlockPos pos, EnumFacing side, ItemInWorldManager manager) | ||
400 | + { | ||
401 | + if (!this.onPlayerInteract(InteractType.LEFT_CLICK_BLOCK, manager.thisPlayerMP, pos, side)) | ||
402 | + { | ||
403 | + S23PacketBlockChange cancellation = new S23PacketBlockChange(manager.theWorld, pos); | ||
404 | + manager.thisPlayerMP.playerNetServerHandler.sendPacket(cancellation); | ||
405 | + return false; | ||
406 | + } | ||
407 | + | ||
408 | + return true; | ||
409 | + } | ||
410 | + | ||
334 | public boolean onPlayerInteract(InteractType action, EntityPlayerMP player, BlockPos position, EnumFacing side) | 411 | public boolean onPlayerInteract(InteractType action, EntityPlayerMP player, BlockPos position, EnumFacing side) |
335 | { | 412 | { |
336 | PlayerEventState eventState = this.getPlayerState(player); | 413 | PlayerEventState eventState = this.getPlayerState(player); |
@@ -346,7 +423,50 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | @@ -346,7 +423,50 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe | ||
346 | { | 423 | { |
347 | return this.playerInteractionListeners.all().onPlayerClickedBlock(player, button, hitPos, sideHit); | 424 | return this.playerInteractionListeners.all().onPlayerClickedBlock(player, button, hitPos, sideHit); |
348 | } | 425 | } |
349 | - | 426 | + |
427 | + public boolean onPlayerMove(NetHandlerPlayServer netHandler, C03PacketPlayer packet, EntityPlayerMP playerMP, WorldServer world) | ||
428 | + { | ||
429 | + Position from = new Position(playerMP, true); | ||
430 | + | ||
431 | + double toX = playerMP.posX; | ||
432 | + double toY = playerMP.posY; | ||
433 | + double toZ = playerMP.posZ; | ||
434 | + float toYaw = playerMP.rotationYaw; | ||
435 | + float toPitch = playerMP.rotationPitch; | ||
436 | + | ||
437 | + if (packet.isMoving()) | ||
438 | + { | ||
439 | + toX = packet.getPositionX(); | ||
440 | + toY = packet.getPositionY(); | ||
441 | + toZ = packet.getPositionZ(); | ||
442 | + } | ||
443 | + | ||
444 | + if (packet.getRotating()) | ||
445 | + { | ||
446 | + toYaw = packet.getYaw(); | ||
447 | + toPitch = packet.getPitch(); | ||
448 | + } | ||
449 | + | ||
450 | + Position to = new Position(toX, toY, toZ, toYaw, toPitch); | ||
451 | + ReturnValue<Position> pos = new ReturnValue<Position>(to); | ||
452 | + | ||
453 | + if (!this.playerMoveListeners.all().onPlayerMove(playerMP, from, to, pos)) | ||
454 | + { | ||
455 | + playerMP.setPositionAndRotation(from.xCoord, from.yCoord, from.zCoord, playerMP.prevRotationYaw, playerMP.prevRotationPitch); | ||
456 | + playerMP.playerNetServerHandler.sendPacket(new S08PacketPlayerPosLook(from.xCoord, from.yCoord, from.zCoord, playerMP.prevRotationYaw, playerMP.prevRotationPitch, Collections.emptySet())); | ||
457 | + return false; | ||
458 | + } | ||
459 | + | ||
460 | + if (pos.isSet()) | ||
461 | + { | ||
462 | + Position newPos = pos.get(); | ||
463 | + netHandler.setPlayerLocation(newPos.xCoord, newPos.yCoord, newPos.zCoord, newPos.yaw, newPos.pitch); | ||
464 | + return false; | ||
465 | + } | ||
466 | + | ||
467 | + return true; | ||
468 | + } | ||
469 | + | ||
350 | void onPlayerSettingsReceived(EntityPlayerMP player, C15PacketClientSettings packet) | 470 | void onPlayerSettingsReceived(EntityPlayerMP player, C15PacketClientSettings packet) |
351 | { | 471 | { |
352 | this.getPlayerState(player).setTraceDistance(PrivateFields.viewDistance.get(packet)); | 472 | this.getPlayerState(player).setTraceDistance(PrivateFields.viewDistance.get(packet)); |
java/common/com/mumfrey/liteloader/core/runtime/Methods.java
@@ -49,6 +49,7 @@ public abstract class Methods | @@ -49,6 +49,7 @@ public abstract class Methods | ||
49 | public static final MethodInfo processPlayerDigging = new MethodInfo(Obf.NetHandlerPlayServer, Obf.processPlayerDigging, Void.TYPE, Packets.C07PacketPlayerDigging); | 49 | public static final MethodInfo processPlayerDigging = new MethodInfo(Obf.NetHandlerPlayServer, Obf.processPlayerDigging, Void.TYPE, Packets.C07PacketPlayerDigging); |
50 | public static final MethodInfo serverJobs = new MethodInfo(Obf.MinecraftServer, Obf.updateTimeLightAndEntities, Void.TYPE); | 50 | public static final MethodInfo serverJobs = new MethodInfo(Obf.MinecraftServer, Obf.updateTimeLightAndEntities, Void.TYPE); |
51 | public static final MethodInfo checkThreadAndEnqueue = new MethodInfo(Obf.PacketThreadUtil, Obf.checkThreadAndEnqueue); | 51 | public static final MethodInfo checkThreadAndEnqueue = new MethodInfo(Obf.PacketThreadUtil, Obf.checkThreadAndEnqueue); |
52 | + public static final MethodInfo processPlayer = new MethodInfo(Obf.NetHandlerPlayServer, Obf.processPlayer, Void.TYPE, Packets.C03PacketPlayer); | ||
52 | 53 | ||
53 | // Profiler | 54 | // Profiler |
54 | public static final MethodInfo startSection = new MethodInfo(Obf.Profiler, Obf.startSection, Void.TYPE, String.class); | 55 | public static final MethodInfo startSection = new MethodInfo(Obf.Profiler, Obf.startSection, Void.TYPE, String.class); |
java/common/com/mumfrey/liteloader/transformers/event/EventTransformer.java
1 | package com.mumfrey.liteloader.transformers.event; | 1 | package com.mumfrey.liteloader.transformers.event; |
2 | 2 | ||
3 | +import java.io.File; | ||
4 | +import java.io.IOException; | ||
3 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
4 | import java.util.Collection; | 6 | import java.util.Collection; |
5 | import java.util.HashMap; | 7 | import java.util.HashMap; |
@@ -9,6 +11,8 @@ import java.util.Map.Entry; | @@ -9,6 +11,8 @@ import java.util.Map.Entry; | ||
9 | import java.util.Set; | 11 | import java.util.Set; |
10 | import java.util.TreeSet; | 12 | import java.util.TreeSet; |
11 | 13 | ||
14 | +import org.apache.commons.io.FileUtils; | ||
15 | +import org.apache.logging.log4j.core.helpers.Booleans; | ||
12 | import org.objectweb.asm.ClassWriter; | 16 | import org.objectweb.asm.ClassWriter; |
13 | import org.objectweb.asm.Type; | 17 | import org.objectweb.asm.Type; |
14 | import org.objectweb.asm.tree.AbstractInsnNode; | 18 | import org.objectweb.asm.tree.AbstractInsnNode; |
@@ -17,6 +21,7 @@ import org.objectweb.asm.tree.LocalVariableNode; | @@ -17,6 +21,7 @@ import org.objectweb.asm.tree.LocalVariableNode; | ||
17 | import org.objectweb.asm.tree.MethodNode; | 21 | import org.objectweb.asm.tree.MethodNode; |
18 | import org.objectweb.asm.util.CheckClassAdapter; | 22 | import org.objectweb.asm.util.CheckClassAdapter; |
19 | 23 | ||
24 | +import com.mumfrey.liteloader.core.runtime.Obf; | ||
20 | import com.mumfrey.liteloader.transformers.ByteCodeUtilities; | 25 | import com.mumfrey.liteloader.transformers.ByteCodeUtilities; |
21 | import com.mumfrey.liteloader.transformers.ClassTransformer; | 26 | import com.mumfrey.liteloader.transformers.ClassTransformer; |
22 | import com.mumfrey.liteloader.transformers.ObfProvider; | 27 | import com.mumfrey.liteloader.transformers.ObfProvider; |
@@ -52,6 +57,10 @@ import com.mumfrey.liteloader.util.log.LiteLoaderLogger; | @@ -52,6 +57,10 @@ import com.mumfrey.liteloader.util.log.LiteLoaderLogger; | ||
52 | */ | 57 | */ |
53 | public final class EventTransformer extends ClassTransformer | 58 | public final class EventTransformer extends ClassTransformer |
54 | { | 59 | { |
60 | + public static final boolean DUMP = Booleans.parseBoolean(System.getProperty("liteloader.debug.dump"), false); | ||
61 | + | ||
62 | + public static final boolean VALIDATE = Booleans.parseBoolean(System.getProperty("liteloader.debug.validate"), false); | ||
63 | + | ||
55 | /** | 64 | /** |
56 | * Multidimensional map of class names -> target method signatures -> events to inject | 65 | * Multidimensional map of class names -> target method signatures -> events to inject |
57 | */ | 66 | */ |
@@ -59,11 +68,6 @@ public final class EventTransformer extends ClassTransformer | @@ -59,11 +68,6 @@ public final class EventTransformer extends ClassTransformer | ||
59 | 68 | ||
60 | private static AccessorTransformer accessorTransformer; | 69 | private static AccessorTransformer accessorTransformer; |
61 | 70 | ||
62 | - /** | ||
63 | - * Runs the validator on the generated classes, only for debugging purposes | ||
64 | - */ | ||
65 | - private final boolean runValidator = false; | ||
66 | - | ||
67 | private int globalEventID = 0; | 71 | private int globalEventID = 0; |
68 | 72 | ||
69 | static class Injection | 73 | static class Injection |
@@ -246,13 +250,24 @@ public final class EventTransformer extends ClassTransformer | @@ -246,13 +250,24 @@ public final class EventTransformer extends ClassTransformer | ||
246 | EventTransformer.accessorTransformer.apply(name, transformedName, basicClass, classNode); | 250 | EventTransformer.accessorTransformer.apply(name, transformedName, basicClass, classNode); |
247 | } | 251 | } |
248 | 252 | ||
249 | - if (this.runValidator) | 253 | + if (EventTransformer.VALIDATE) |
250 | { | 254 | { |
251 | ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); | 255 | ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); |
252 | classNode.accept(new CheckClassAdapter(writer)); | 256 | classNode.accept(new CheckClassAdapter(writer)); |
253 | } | 257 | } |
254 | 258 | ||
255 | - return this.writeClass(classNode); | 259 | + byte[] bytes = this.writeClass(classNode); |
260 | + | ||
261 | + if (EventTransformer.DUMP) | ||
262 | + { | ||
263 | + try | ||
264 | + { | ||
265 | + FileUtils.writeByteArrayToFile(new File(".classes" + Obf.lookupMCPName(transformedName).replace('.', '/') + ".class"), bytes); | ||
266 | + } | ||
267 | + catch (IOException ex) {} | ||
268 | + } | ||
269 | + | ||
270 | + return bytes; | ||
256 | } | 271 | } |
257 | 272 | ||
258 | /** | 273 | /** |
java/common/com/mumfrey/liteloader/util/Position.java
0 → 100644
1 | +package com.mumfrey.liteloader.util; | ||
2 | + | ||
3 | +import net.minecraft.entity.Entity; | ||
4 | +import net.minecraft.util.Vec3; | ||
5 | + | ||
6 | +/** | ||
7 | + * A 3D vector position with rotation as well | ||
8 | + * | ||
9 | + * @author Adam Mummery-Smith | ||
10 | + */ | ||
11 | +public class Position extends Vec3 | ||
12 | +{ | ||
13 | + public final float yaw; | ||
14 | + | ||
15 | + public final float pitch; | ||
16 | + | ||
17 | + public Position(double x, double y, double z) | ||
18 | + { | ||
19 | + this(x, y, z, 0.0F, 0.0F); | ||
20 | + } | ||
21 | + | ||
22 | + public Position(double x, double y, double z, float yaw, float pitch) | ||
23 | + { | ||
24 | + super(x, y, z); | ||
25 | + | ||
26 | + this.yaw = yaw; | ||
27 | + this.pitch = pitch; | ||
28 | + } | ||
29 | + | ||
30 | + public Position(Entity entity) | ||
31 | + { | ||
32 | + this(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch); | ||
33 | + } | ||
34 | + | ||
35 | + public Position(Entity entity, boolean usePrevious) | ||
36 | + { | ||
37 | + this(usePrevious ? entity.prevPosX : entity.posX, usePrevious ? entity.prevPosY : entity.posY, usePrevious ? entity.prevPosZ : entity.posZ, usePrevious ? entity.prevRotationYaw : entity.rotationYaw, usePrevious ? entity.prevRotationPitch : entity.rotationPitch); | ||
38 | + } | ||
39 | + | ||
40 | + public void applyTo(Entity entity) | ||
41 | + { | ||
42 | + entity.posX = this.xCoord; | ||
43 | + entity.posY = this.yCoord; | ||
44 | + entity.posZ = this.zCoord; | ||
45 | + entity.rotationYaw = this.yaw; | ||
46 | + entity.rotationPitch = this.pitch; | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public String toString() | ||
51 | + { | ||
52 | + return "(" + this.xCoord + ", " + this.yCoord + ", " + this.zCoord + ", " + this.yaw + ", " + this.pitch + ")"; | ||
53 | + } | ||
54 | +} |
java/common/com/mumfrey/liteloader/util/PrivateFields.java
@@ -37,7 +37,7 @@ public class PrivateFields<P, T> | @@ -37,7 +37,7 @@ public class PrivateFields<P, T> | ||
37 | protected PrivateFields(Class<P> owner, Obf obf) | 37 | protected PrivateFields(Class<P> owner, Obf obf) |
38 | { | 38 | { |
39 | this.parentClass = owner; | 39 | this.parentClass = owner; |
40 | - this.fieldName = Obf.getObfuscatedFieldName(obf); | 40 | + this.fieldName = ObfuscationUtilities.getObfuscatedFieldName(obf); |
41 | } | 41 | } |
42 | 42 | ||
43 | /** | 43 | /** |