Commit f709bce873f6962328d398e1b91aa323210efc18
1 parent
1dd64987
adding PlayerInteractionListener
Showing
11 changed files
with
452 additions
and
13 deletions
.classpath
| ... | ... | @@ -18,7 +18,7 @@ |
| 18 | 18 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar"/> |
| 19 | 19 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/com/mojang/authlib/1.5.17/authlib-1.5.17.jar"/> |
| 20 | 20 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/org/lwjgl/lwjgl/lwjgl/2.9.1/lwjgl-2.9.1.jar"/> |
| 21 | - <classpathentry exported="true" kind="lib" path="lib/asm-debug-all-5.0.3.jar"/> | |
| 21 | + <classpathentry exported="true" kind="lib" path="lib/asm-debug-all-5.0.3.jar" sourcepath="/ASM/src"/> | |
| 22 | 22 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.1/lwjgl_util-2.9.1.jar"/> |
| 23 | 23 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/com/mojang/realms/1.5.5/realms-1.5.5.jar"/> |
| 24 | 24 | <classpathentry kind="output" path="bin"/> | ... | ... |
java/client/com/mumfrey/liteloader/client/CallbackProxyClient.java
| ... | ... | @@ -14,15 +14,27 @@ import net.minecraft.client.shader.Framebuffer; |
| 14 | 14 | import net.minecraft.entity.Entity; |
| 15 | 15 | import net.minecraft.entity.player.EntityPlayer; |
| 16 | 16 | import net.minecraft.entity.player.EntityPlayerMP; |
| 17 | +import net.minecraft.item.ItemStack; | |
| 18 | +import net.minecraft.network.NetHandlerPlayServer; | |
| 17 | 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; | |
| 18 | 25 | import net.minecraft.server.integrated.IntegratedServer; |
| 26 | +import net.minecraft.server.management.ItemInWorldManager; | |
| 19 | 27 | import net.minecraft.server.management.ServerConfigurationManager; |
| 28 | +import net.minecraft.util.BlockPos; | |
| 29 | +import net.minecraft.util.EnumFacing; | |
| 20 | 30 | import net.minecraft.util.IChatComponent; |
| 21 | 31 | import net.minecraft.util.ScreenShotHelper; |
| 22 | 32 | import net.minecraft.util.Session; |
| 33 | +import net.minecraft.world.World; | |
| 23 | 34 | import net.minecraft.world.WorldSettings; |
| 24 | 35 | |
| 25 | 36 | import com.mojang.authlib.GameProfile; |
| 37 | +import com.mumfrey.liteloader.core.LiteLoaderEventBroker.InteractType; | |
| 26 | 38 | import com.mumfrey.liteloader.transformers.event.EventInfo; |
| 27 | 39 | import com.mumfrey.liteloader.transformers.event.ReturnEventInfo; |
| 28 | 40 | |
| ... | ... | @@ -207,6 +219,80 @@ public class CallbackProxyClient |
| 207 | 219 | CallbackProxyClient.eventBroker.onPostRenderEntity(e.getSource(), entity, xPos, yPos, zPos, yaw, partialTicks, render); |
| 208 | 220 | } |
| 209 | 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 | + } | |
| 294 | + } | |
| 295 | + | |
| 210 | 296 | /** |
| 211 | 297 | * Compatiblbe behaviour with FML, this method is called to generate a consistent offline UUID between client and server |
| 212 | 298 | * for a given username. | ... | ... |
java/common/com/mumfrey/liteloader/PlayerInteractionListener.java
0 → 100644
| 1 | +package com.mumfrey.liteloader; | |
| 2 | + | |
| 3 | +import net.minecraft.entity.player.EntityPlayerMP; | |
| 4 | +import net.minecraft.util.BlockPos; | |
| 5 | +import net.minecraft.util.EnumFacing; | |
| 6 | +import net.minecraft.util.MovingObjectPosition.MovingObjectType; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Interface for mods which want to observe the player's "interaction" status (player mouse clicks), allows block interaction | |
| 10 | + * events to be cancelled. | |
| 11 | + * | |
| 12 | + * @author Adam Mummery-Smith | |
| 13 | + */ | |
| 14 | +public interface PlayerInteractionListener extends LiteMod | |
| 15 | +{ | |
| 16 | + /** | |
| 17 | + * Mouse buttons | |
| 18 | + */ | |
| 19 | + public static enum MouseButton | |
| 20 | + { | |
| 21 | + LEFT, | |
| 22 | + RIGHT | |
| 23 | + } | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * Called when the player clicks but does not "hit" a block, the trace position is raytraced to the player's current view | |
| 27 | + * distance and represents the block which the player is "looking at". This method is NOT called when the player right clicks | |
| 28 | + * with an empty hand. | |
| 29 | + * | |
| 30 | + * @param player Player | |
| 31 | + * @param button Mouse button the user clicked | |
| 32 | + * @param tracePos Raytraced location of the block which was hit | |
| 33 | + * @param traceSideHit Raytraced side hit | |
| 34 | + * @param traceHitType Type of hit, will be MISS if the trace expired without hitting anything (eg. the player clicked the sky) | |
| 35 | + */ | |
| 36 | + public abstract void onPlayerClickedAir(EntityPlayerMP player, MouseButton button, BlockPos tracePos, EnumFacing traceSideHit, MovingObjectType traceHitType); | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Calls when the player clicks and hits a block, usually indicates that the player is digging or placing a block, although | |
| 40 | + * a block placement does not necessarily succeed. Return true from this callback to allow the action to proceed, or false to | |
| 41 | + * cancel the action. Cancelling the action does not prevent further handlers from receiving the event. | |
| 42 | + * | |
| 43 | + * @param player Player | |
| 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) | |
| 46 | + * @param sideHit Side of the block which was hit | |
| 47 | + * @return | |
| 48 | + */ | |
| 49 | + public abstract boolean onPlayerClickedBlock(EntityPlayerMP player, MouseButton button, BlockPos hitPos, EnumFacing sideHit); | |
| 50 | +} | ... | ... |
java/common/com/mumfrey/liteloader/common/transformers/LiteLoaderEventTransformer.java
| 1 | 1 | package com.mumfrey.liteloader.common.transformers; |
| 2 | 2 | |
| 3 | 3 | import static com.mumfrey.liteloader.core.runtime.Methods.*; |
| 4 | +import static com.mumfrey.liteloader.transformers.event.InjectionPoint.*; | |
| 4 | 5 | |
| 5 | 6 | import com.mumfrey.liteloader.core.runtime.Obf; |
| 6 | 7 | import com.mumfrey.liteloader.transformers.event.Event; |
| 7 | 8 | import com.mumfrey.liteloader.transformers.event.EventInjectionTransformer; |
| 8 | 9 | import com.mumfrey.liteloader.transformers.event.InjectionPoint; |
| 9 | 10 | import com.mumfrey.liteloader.transformers.event.MethodInfo; |
| 11 | +import com.mumfrey.liteloader.transformers.event.inject.BeforeInvoke; | |
| 10 | 12 | import com.mumfrey.liteloader.transformers.event.inject.BeforeNew; |
| 11 | 13 | import com.mumfrey.liteloader.transformers.event.inject.BeforeReturn; |
| 14 | +import com.mumfrey.liteloader.transformers.event.inject.MethodHead; | |
| 12 | 15 | |
| 13 | 16 | /** |
| 14 | 17 | * Injector for LiteLoader's common events |
| ... | ... | @@ -28,18 +31,32 @@ public abstract class LiteLoaderEventTransformer extends EventInjectionTransform |
| 28 | 31 | Event onPlayerLogout = Event.getOrCreate("onPlayerLogout", false); |
| 29 | 32 | Event onSpawnPlayer = Event.getOrCreate("onSpawnPlayer", false); |
| 30 | 33 | Event onRespawnPlayer = Event.getOrCreate("onRespawnPlayer", false); |
| 34 | + Event onServerTick = Event.getOrCreate("onServerTick", false); | |
| 35 | + Event onBlockClickedEvent = Event.getOrCreate("onBlockClicked", true); | |
| 36 | + Event onActivateBlockOrUseItem = Event.getOrCreate("onActivateBlockOrUseItem", true); | |
| 37 | + Event onPlayerDigging = Event.getOrCreate("onPlayerDigging", true); | |
| 38 | + Event onPlaceBlock = Event.getOrCreate("onPlaceBlock", true); | |
| 39 | + Event onClickedAir = Event.getOrCreate("onClickedAir", true); | |
| 31 | 40 | Event onSessionProfileBad = Event.getOrCreate("onSessionProfileBad", true); |
| 32 | 41 | |
| 33 | 42 | // Injection Points |
| 43 | + InjectionPoint methodHead = new MethodHead(); | |
| 34 | 44 | InjectionPoint methodReturn = new BeforeReturn(); |
| 35 | 45 | InjectionPoint beforeNewGameProfile = new BeforeNew(1, Obf.GameProfile); |
| 46 | + InjectionPoint beforeThreadMarshall = new BeforeInvoke(checkThreadAndEnqueue); | |
| 36 | 47 | |
| 37 | 48 | // Hooks |
| 38 | - this.add(onInitializePlayerConnection, initPlayerConnection, (methodReturn), "onInitializePlayerConnection"); | |
| 39 | - this.add(onPlayerLogin, playerLoggedIn, (methodReturn), "onPlayerLogin"); | |
| 40 | - this.add(onPlayerLogout, playerLoggedOut, (methodReturn), "onPlayerLogout"); | |
| 41 | - this.add(onSpawnPlayer, spawnPlayer, (methodReturn), "onSpawnPlayer"); | |
| 42 | - this.add(onRespawnPlayer, respawnPlayer, (methodReturn), "onRespawnPlayer"); | |
| 49 | + this.add(onInitializePlayerConnection, initPlayerConnection, (methodReturn), "onInitializePlayerConnection"); | |
| 50 | + this.add(onPlayerLogin, playerLoggedIn, (methodReturn), "onPlayerLogin"); | |
| 51 | + this.add(onPlayerLogout, playerLoggedOut, (methodReturn), "onPlayerLogout"); | |
| 52 | + this.add(onSpawnPlayer, spawnPlayer, (methodReturn), "onSpawnPlayer"); | |
| 53 | + this.add(onRespawnPlayer, respawnPlayer, (methodReturn), "onRespawnPlayer"); | |
| 54 | + this.add(onServerTick, serverJobs, (methodHead), "onServerTick"); | |
| 55 | + this.add(onBlockClickedEvent, onBlockClicked, (methodHead), "onBlockClicked"); | |
| 56 | + this.add(onActivateBlockOrUseItem, activateBlockOrUseItem, (methodHead), "onUseItem"); | |
| 57 | + this.add(onPlaceBlock, processBlockPlacement, after(beforeThreadMarshall) , "onPlaceBlock"); | |
| 58 | + this.add(onClickedAir, handleAnimation, after(beforeThreadMarshall), "onClickedAir"); | |
| 59 | + this.add(onPlayerDigging, processPlayerDigging, after(beforeThreadMarshall), "onPlayerDigging"); | |
| 43 | 60 | |
| 44 | 61 | // Compatibility handlers |
| 45 | 62 | this.add(onSessionProfileBad, getProfile, (beforeNewGameProfile), "generateOfflineUUID"); | ... | ... |
java/common/com/mumfrey/liteloader/common/transformers/PacketEvent.java
| ... | ... | @@ -45,7 +45,7 @@ public class PacketEvent extends Event |
| 45 | 45 | * @see com.mumfrey.liteloader.transformers.event.Event#invokeEventInfoConstructor(org.objectweb.asm.tree.InsnList, boolean) |
| 46 | 46 | */ |
| 47 | 47 | @Override |
| 48 | - protected int invokeEventInfoConstructor(InsnList insns, boolean cancellable) | |
| 48 | + protected int invokeEventInfoConstructor(InsnList insns, boolean cancellable, boolean pushReturnValue, int marshallVar) | |
| 49 | 49 | { |
| 50 | 50 | int ctorMAXS = 0; |
| 51 | 51 | ... | ... |
java/common/com/mumfrey/liteloader/core/IEventState.java
0 → 100644
java/common/com/mumfrey/liteloader/core/LiteLoaderEventBroker.java
| 1 | 1 | package com.mumfrey.liteloader.core; |
| 2 | 2 | |
| 3 | +import java.util.HashMap; | |
| 4 | +import java.util.Map; | |
| 5 | +import java.util.UUID; | |
| 6 | + | |
| 3 | 7 | import net.minecraft.command.ICommandManager; |
| 4 | 8 | import net.minecraft.command.ServerCommandManager; |
| 5 | 9 | import net.minecraft.entity.player.EntityPlayerMP; |
| 6 | 10 | import net.minecraft.network.NetworkManager; |
| 11 | +import net.minecraft.network.play.client.C15PacketClientSettings; | |
| 7 | 12 | import net.minecraft.profiler.Profiler; |
| 8 | 13 | import net.minecraft.server.MinecraftServer; |
| 9 | 14 | import net.minecraft.server.management.ServerConfigurationManager; |
| 15 | +import net.minecraft.util.BlockPos; | |
| 16 | +import net.minecraft.util.EnumFacing; | |
| 17 | +import net.minecraft.util.MovingObjectPosition.MovingObjectType; | |
| 10 | 18 | import net.minecraft.world.World; |
| 11 | 19 | import net.minecraft.world.WorldSettings; |
| 12 | 20 | |
| 13 | 21 | import com.mojang.authlib.GameProfile; |
| 14 | 22 | import com.mumfrey.liteloader.LiteMod; |
| 23 | +import com.mumfrey.liteloader.PlayerInteractionListener; | |
| 24 | +import com.mumfrey.liteloader.PlayerInteractionListener.MouseButton; | |
| 15 | 25 | import com.mumfrey.liteloader.PluginChannelListener; |
| 16 | 26 | import com.mumfrey.liteloader.ServerCommandProvider; |
| 17 | 27 | import com.mumfrey.liteloader.ServerPlayerListener; |
| ... | ... | @@ -21,8 +31,11 @@ import com.mumfrey.liteloader.api.Listener; |
| 21 | 31 | import com.mumfrey.liteloader.common.GameEngine; |
| 22 | 32 | import com.mumfrey.liteloader.common.LoadingProgress; |
| 23 | 33 | import com.mumfrey.liteloader.core.event.HandlerList; |
| 34 | +import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp; | |
| 24 | 35 | import com.mumfrey.liteloader.interfaces.FastIterable; |
| 36 | +import com.mumfrey.liteloader.interfaces.FastIterableDeque; | |
| 25 | 37 | import com.mumfrey.liteloader.launch.LoaderProperties; |
| 38 | +import com.mumfrey.liteloader.util.PrivateFields; | |
| 26 | 39 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 27 | 40 | |
| 28 | 41 | /** |
| ... | ... | @@ -69,6 +82,20 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 69 | 82 | } |
| 70 | 83 | } |
| 71 | 84 | |
| 85 | + public static enum InteractType | |
| 86 | + { | |
| 87 | + RIGHT_CLICK, | |
| 88 | + LEFT_CLICK, | |
| 89 | + LEFT_CLICK_BLOCK, | |
| 90 | + PLACE_BLOCK_MAYBE, | |
| 91 | + DIG_BLOCK_MAYBE | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Singleton | |
| 96 | + */ | |
| 97 | + static LiteLoaderEventBroker<?, ?> broker; | |
| 98 | + | |
| 72 | 99 | /** |
| 73 | 100 | * Reference to the loader instance |
| 74 | 101 | */ |
| ... | ... | @@ -86,6 +113,9 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 86 | 113 | |
| 87 | 114 | protected LiteLoaderMods mods; |
| 88 | 115 | |
| 116 | + private Map<UUID, PlayerEventState> playerStates = new HashMap<UUID, PlayerEventState>(); | |
| 117 | + private FastIterableDeque<IEventState> playerStateList = new HandlerList<IEventState>(IEventState.class); | |
| 118 | + | |
| 89 | 119 | /** |
| 90 | 120 | * List of mods which provide server commands |
| 91 | 121 | */ |
| ... | ... | @@ -97,6 +127,11 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 97 | 127 | private FastIterable<ServerPlayerListener> serverPlayerListeners = new HandlerList<ServerPlayerListener>(ServerPlayerListener.class); |
| 98 | 128 | |
| 99 | 129 | /** |
| 130 | + * List of mods which handle player interaction events | |
| 131 | + */ | |
| 132 | + private FastIterable<PlayerInteractionListener> playerInteractionListeners = new HandlerList<PlayerInteractionListener>(PlayerInteractionListener.class, ReturnLogicOp.AND); | |
| 133 | + | |
| 134 | + /** | |
| 100 | 135 | * ctor |
| 101 | 136 | * |
| 102 | 137 | * @param loader |
| ... | ... | @@ -108,6 +143,8 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 108 | 143 | this.loader = loader; |
| 109 | 144 | this.engine = engine; |
| 110 | 145 | this.profiler = engine.getProfiler(); |
| 146 | + | |
| 147 | + LiteLoaderEventBroker.broker = this; | |
| 111 | 148 | } |
| 112 | 149 | |
| 113 | 150 | /** |
| ... | ... | @@ -149,6 +186,7 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 149 | 186 | { |
| 150 | 187 | delegate.registerInterface(ServerCommandProvider.class); |
| 151 | 188 | delegate.registerInterface(ServerPlayerListener.class); |
| 189 | + delegate.registerInterface(PlayerInteractionListener.class); | |
| 152 | 190 | delegate.registerInterface(CommonPluginChannelListener.class); |
| 153 | 191 | } |
| 154 | 192 | |
| ... | ... | @@ -180,6 +218,14 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 180 | 218 | { |
| 181 | 219 | this.serverPlayerListeners.add(serverPlayerListener); |
| 182 | 220 | } |
| 221 | + | |
| 222 | + /** | |
| 223 | + * @param playerInteractionListener | |
| 224 | + */ | |
| 225 | + public void addPlayerInteractionListener(PlayerInteractionListener playerInteractionListener) | |
| 226 | + { | |
| 227 | + this.playerInteractionListeners.add(playerInteractionListener); | |
| 228 | + } | |
| 183 | 229 | |
| 184 | 230 | /** |
| 185 | 231 | * @param instance |
| ... | ... | @@ -198,6 +244,8 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 198 | 244 | } |
| 199 | 245 | |
| 200 | 246 | LiteLoader.getServerPluginChannels().onServerStartup(); |
| 247 | + | |
| 248 | + this.playerStates.clear(); | |
| 201 | 249 | } |
| 202 | 250 | |
| 203 | 251 | /** |
| ... | ... | @@ -208,6 +256,8 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 208 | 256 | public void onSpawnPlayer(ServerConfigurationManager scm, EntityPlayerMP player, GameProfile profile) |
| 209 | 257 | { |
| 210 | 258 | this.serverPlayerListeners.all().onPlayerConnect(player, profile); |
| 259 | + PlayerEventState playerState = this.getPlayerState(player); | |
| 260 | + playerState.onSpawned(); | |
| 211 | 261 | } |
| 212 | 262 | |
| 213 | 263 | /** |
| ... | ... | @@ -248,6 +298,7 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 248 | 298 | public void onPlayerLogout(ServerConfigurationManager scm, EntityPlayerMP player) |
| 249 | 299 | { |
| 250 | 300 | this.serverPlayerListeners.all().onPlayerLogout(player); |
| 301 | + this.removePlayer(player); | |
| 251 | 302 | } |
| 252 | 303 | |
| 253 | 304 | /** |
| ... | ... | @@ -274,4 +325,51 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 274 | 325 | { |
| 275 | 326 | this.loader.onWorldChanged(world); |
| 276 | 327 | } |
| 328 | + | |
| 329 | + public void onServerTick(MinecraftServer minecraftServer) | |
| 330 | + { | |
| 331 | + this.playerStateList.all().onTick(); | |
| 332 | + } | |
| 333 | + | |
| 334 | + public boolean onPlayerInteract(InteractType action, EntityPlayerMP player, BlockPos position, EnumFacing side) | |
| 335 | + { | |
| 336 | + PlayerEventState eventState = this.getPlayerState(player); | |
| 337 | + return eventState.onPlayerInteract(action, player, position, side); | |
| 338 | + } | |
| 339 | + | |
| 340 | + void onPlayerClickedAir(EntityPlayerMP player, MouseButton button, BlockPos tracePos, EnumFacing traceSideHit, MovingObjectType traceHitType) | |
| 341 | + { | |
| 342 | + this.playerInteractionListeners.all().onPlayerClickedAir(player, button, tracePos, traceSideHit, traceHitType); | |
| 343 | + } | |
| 344 | + | |
| 345 | + boolean onPlayerClickedBlock(EntityPlayerMP player, MouseButton button, BlockPos hitPos, EnumFacing sideHit) | |
| 346 | + { | |
| 347 | + return this.playerInteractionListeners.all().onPlayerClickedBlock(player, button, hitPos, sideHit); | |
| 348 | + } | |
| 349 | + | |
| 350 | + void onPlayerSettingsReceived(EntityPlayerMP player, C15PacketClientSettings packet) | |
| 351 | + { | |
| 352 | + this.getPlayerState(player).setTraceDistance(PrivateFields.viewDistance.get(packet)); | |
| 353 | + } | |
| 354 | + | |
| 355 | + protected PlayerEventState getPlayerState(EntityPlayerMP player) | |
| 356 | + { | |
| 357 | + PlayerEventState playerState = this.playerStates.get(player.getUniqueID()); | |
| 358 | + if (playerState == null) | |
| 359 | + { | |
| 360 | + playerState = new PlayerEventState(player, this); | |
| 361 | + this.playerStates.put(player.getUniqueID(), playerState); | |
| 362 | + this.playerStateList.add(playerState); | |
| 363 | + } | |
| 364 | + return playerState; | |
| 365 | + } | |
| 366 | + | |
| 367 | + protected void removePlayer(EntityPlayerMP player) | |
| 368 | + { | |
| 369 | + PlayerEventState playerState = this.playerStates.remove(player.getUniqueID()); | |
| 370 | + if (playerState != null) | |
| 371 | + { | |
| 372 | + this.playerStateList.remove(playerState); | |
| 373 | + } | |
| 374 | + } | |
| 277 | 375 | } | ... | ... |
java/common/com/mumfrey/liteloader/core/PacketEvents.java
| ... | ... | @@ -8,6 +8,7 @@ import net.minecraft.network.NetHandlerPlayServer; |
| 8 | 8 | import net.minecraft.network.Packet; |
| 9 | 9 | import net.minecraft.network.login.server.S02PacketLoginSuccess; |
| 10 | 10 | import net.minecraft.network.play.client.C01PacketChatMessage; |
| 11 | +import net.minecraft.network.play.client.C15PacketClientSettings; | |
| 11 | 12 | import net.minecraft.network.play.client.C17PacketCustomPayload; |
| 12 | 13 | import net.minecraft.network.play.server.S01PacketJoinGame; |
| 13 | 14 | import net.minecraft.network.play.server.S02PacketChat; |
| ... | ... | @@ -49,12 +50,13 @@ public abstract class PacketEvents implements InterfaceProvider |
| 49 | 50 | |
| 50 | 51 | private FastIterable<ServerChatFilter> serverChatFilters = new HandlerList<ServerChatFilter>(ServerChatFilter.class, ReturnLogicOp.AND_BREAK_ON_FALSE); |
| 51 | 52 | |
| 52 | - private final int loginSuccessPacketId = Packets.S02PacketLoginSuccess.getIndex(); | |
| 53 | - private final int serverChatPacketId = Packets.S02PacketChat.getIndex(); | |
| 54 | - private final int clientChatPacketId = Packets.C01PacketChatMessage.getIndex(); | |
| 55 | - private final int joinGamePacketId = Packets.S01PacketJoinGame.getIndex(); | |
| 56 | - private final int serverPayloadPacketId = Packets.S3FPacketCustomPayload.getIndex(); | |
| 57 | - private final int clientPayloadPacketId = Packets.C17PacketCustomPayload.getIndex(); | |
| 53 | + private final int loginSuccessPacketId = Packets.S02PacketLoginSuccess.getIndex(); | |
| 54 | + private final int serverChatPacketId = Packets.S02PacketChat.getIndex(); | |
| 55 | + private final int clientChatPacketId = Packets.C01PacketChatMessage.getIndex(); | |
| 56 | + private final int joinGamePacketId = Packets.S01PacketJoinGame.getIndex(); | |
| 57 | + private final int serverPayloadPacketId = Packets.S3FPacketCustomPayload.getIndex(); | |
| 58 | + private final int clientPayloadPacketId = Packets.C17PacketCustomPayload.getIndex(); | |
| 59 | + private final int clientSettingsPacketId = Packets.C15PacketClientSettings.getIndex(); | |
| 58 | 60 | |
| 59 | 61 | public PacketEvents() |
| 60 | 62 | { |
| ... | ... | @@ -192,6 +194,12 @@ public abstract class PacketEvents implements InterfaceProvider |
| 192 | 194 | return true; |
| 193 | 195 | } |
| 194 | 196 | |
| 197 | + if (packetId == this.clientSettingsPacketId) | |
| 198 | + { | |
| 199 | + this.handlePacket(e, netHandler, (C15PacketClientSettings)packet); | |
| 200 | + return true; | |
| 201 | + } | |
| 202 | + | |
| 195 | 203 | return false; |
| 196 | 204 | } |
| 197 | 205 | |
| ... | ... | @@ -258,4 +266,23 @@ public abstract class PacketEvents implements InterfaceProvider |
| 258 | 266 | { |
| 259 | 267 | LiteLoader.getServerPluginChannels().onPluginChannelMessage(netHandler, packet); |
| 260 | 268 | } |
| 269 | + | |
| 270 | + /** | |
| 271 | + * C15PacketClientSettings::processPacket() | |
| 272 | + * | |
| 273 | + * @param e | |
| 274 | + * @param netHandler | |
| 275 | + * @param packet | |
| 276 | + */ | |
| 277 | + private void handlePacket(PacketEventInfo<Packet> e, INetHandler netHandler, C15PacketClientSettings packet) | |
| 278 | + { | |
| 279 | + if (netHandler instanceof NetHandlerPlayServer) | |
| 280 | + { | |
| 281 | + LiteLoaderEventBroker.broker.onPlayerSettingsReceived(((NetHandlerPlayServer)netHandler).playerEntity, packet); | |
| 282 | + } | |
| 283 | + else | |
| 284 | + { | |
| 285 | + System.err.println("ACTUALLY: handler is " + netHandler); | |
| 286 | + } | |
| 287 | + } | |
| 261 | 288 | } | ... | ... |
java/common/com/mumfrey/liteloader/core/PlayerEventState.java
0 → 100644
| 1 | +package com.mumfrey.liteloader.core; | |
| 2 | + | |
| 3 | +import java.lang.ref.WeakReference; | |
| 4 | + | |
| 5 | +import net.minecraft.entity.player.EntityPlayerMP; | |
| 6 | +import net.minecraft.util.BlockPos; | |
| 7 | +import net.minecraft.util.EnumFacing; | |
| 8 | +import net.minecraft.util.MovingObjectPosition; | |
| 9 | +import net.minecraft.util.MovingObjectPosition.MovingObjectType; | |
| 10 | + | |
| 11 | +import com.mumfrey.liteloader.PlayerInteractionListener.MouseButton; | |
| 12 | +import com.mumfrey.liteloader.core.LiteLoaderEventBroker.InteractType; | |
| 13 | +import com.mumfrey.liteloader.util.EntityUtilities; | |
| 14 | + | |
| 15 | +public class PlayerEventState implements IEventState | |
| 16 | +{ | |
| 17 | + private static long MISS = new BlockPos(-1, -1, -1).toLong(); | |
| 18 | + | |
| 19 | + private WeakReference<EntityPlayerMP> playerRef; | |
| 20 | + | |
| 21 | + private final LiteLoaderEventBroker<?, ?> broker; | |
| 22 | + | |
| 23 | + private double traceDistance = 256.0; | |
| 24 | + | |
| 25 | + private int suppressLeftTicks; | |
| 26 | + private int suppressRightTicks; | |
| 27 | + private boolean leftClick; | |
| 28 | + private boolean rightClick; | |
| 29 | + | |
| 30 | + private MovingObjectPosition hit; | |
| 31 | + | |
| 32 | + public PlayerEventState(EntityPlayerMP player, LiteLoaderEventBroker<?, ?> broker) | |
| 33 | + { | |
| 34 | + this.playerRef = new WeakReference<EntityPlayerMP>(player); | |
| 35 | + this.broker = broker; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public void setTraceDistance(int renderDistance) | |
| 39 | + { | |
| 40 | + this.traceDistance = renderDistance * 16.0; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public EntityPlayerMP getPlayer() | |
| 44 | + { | |
| 45 | + return this.playerRef.get(); | |
| 46 | + } | |
| 47 | + | |
| 48 | + public void onSpawned() | |
| 49 | + { | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public void onTick() | |
| 54 | + { | |
| 55 | + if (this.leftClick && this.suppressLeftTicks == 0) | |
| 56 | + { | |
| 57 | + this.broker.onPlayerClickedAir(this.getPlayer(), MouseButton.LEFT, this.hit.getBlockPos(), this.hit.sideHit, this.hit.typeOfHit); | |
| 58 | + } | |
| 59 | + | |
| 60 | + if (this.rightClick && this.suppressRightTicks == 0) | |
| 61 | + { | |
| 62 | + this.broker.onPlayerClickedAir(this.getPlayer(), MouseButton.RIGHT, this.hit.getBlockPos(), this.hit.sideHit, this.hit.typeOfHit); | |
| 63 | + } | |
| 64 | + | |
| 65 | + if (this.suppressLeftTicks > 0) this.suppressLeftTicks--; | |
| 66 | + if (this.suppressRightTicks > 0) this.suppressRightTicks--; | |
| 67 | + | |
| 68 | + this.leftClick = false; | |
| 69 | + this.rightClick = false; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public boolean onPlayerInteract(InteractType action, EntityPlayerMP player, BlockPos position, EnumFacing side) | |
| 73 | + { | |
| 74 | + this.hit = EntityUtilities.rayTraceFromEntity(player, this.traceDistance, 0.0F); | |
| 75 | + | |
| 76 | + if (action == InteractType.LEFT_CLICK) | |
| 77 | + { | |
| 78 | + this.leftClick = true; | |
| 79 | + return true; | |
| 80 | + } | |
| 81 | + | |
| 82 | + if (action == InteractType.RIGHT_CLICK) | |
| 83 | + { | |
| 84 | + this.rightClick = true; | |
| 85 | + return true; | |
| 86 | + } | |
| 87 | + | |
| 88 | + if ((action == InteractType.LEFT_CLICK_BLOCK || action == InteractType.DIG_BLOCK_MAYBE) && this.suppressLeftTicks == 0) | |
| 89 | + { | |
| 90 | + this.suppressLeftTicks += 2; | |
| 91 | + return this.broker.onPlayerClickedBlock(player, MouseButton.LEFT, position, side); | |
| 92 | + } | |
| 93 | + | |
| 94 | + if (action == InteractType.PLACE_BLOCK_MAYBE) | |
| 95 | + { | |
| 96 | + if (this.suppressRightTicks > 0) | |
| 97 | + { | |
| 98 | + return true; | |
| 99 | + } | |
| 100 | + | |
| 101 | + if (position.toLong() == PlayerEventState.MISS) | |
| 102 | + { | |
| 103 | + MovingObjectPosition actualHit = EntityUtilities.rayTraceFromEntity(player, player.capabilities.isCreativeMode ? 5.0 : 4.5, 0.0F); | |
| 104 | + if (actualHit.typeOfHit == MovingObjectType.MISS) | |
| 105 | + { | |
| 106 | + this.rightClick = true; | |
| 107 | + return true; | |
| 108 | + } | |
| 109 | + } | |
| 110 | + | |
| 111 | + this.suppressRightTicks++; | |
| 112 | + this.suppressLeftTicks++; | |
| 113 | + return this.broker.onPlayerClickedBlock(player, MouseButton.RIGHT, position, side); | |
| 114 | + } | |
| 115 | + | |
| 116 | + return true; | |
| 117 | + } | |
| 118 | +} | ... | ... |
java/common/com/mumfrey/liteloader/core/runtime/Methods.java
| ... | ... | @@ -42,6 +42,13 @@ public abstract class Methods |
| 42 | 42 | public static final MethodInfo doRenderShadowAndFire = new MethodInfo(Obf.Render, Obf.doRenderShadowAndFire, Void.TYPE, Obf.Entity, Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); |
| 43 | 43 | public static final MethodInfo realmsPlay = new MethodInfo(Obf.RealmsMainScreen, "play", Void.TYPE, Long.TYPE); |
| 44 | 44 | public static final MethodInfo realmsStopFetcher = new MethodInfo(Obf.RealmsMainScreen, "stopRealmsFetcherAndPinger", Void.TYPE); |
| 45 | + public static final MethodInfo onBlockClicked = new MethodInfo(Obf.ItemInWorldManager, Obf.onBlockClicked, Void.TYPE, Obf.BlockPos, Obf.EnumFacing); | |
| 46 | + public static final MethodInfo activateBlockOrUseItem = new MethodInfo(Obf.ItemInWorldManager, Obf.activateBlockOrUseItem, Boolean.TYPE, Obf.EntityPlayer, Obf.World, Obf.ItemStack, Obf.BlockPos, Obf.EnumFacing, Float.TYPE, Float.TYPE, Float.TYPE); | |
| 47 | + public static final MethodInfo processBlockPlacement = new MethodInfo(Obf.NetHandlerPlayServer, Obf.processPlayerBlockPlacement, Void.TYPE, Packets.C08PacketPlayerBlockPlacement); | |
| 48 | + public static final MethodInfo handleAnimation = new MethodInfo(Obf.NetHandlerPlayServer, Obf.handleAnimation, Void.TYPE, Packets.C0APacketAnimation); | |
| 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); | |
| 51 | + public static final MethodInfo checkThreadAndEnqueue = new MethodInfo(Obf.PacketThreadUtil, Obf.checkThreadAndEnqueue); | |
| 45 | 52 | |
| 46 | 53 | // Profiler |
| 47 | 54 | public static final MethodInfo startSection = new MethodInfo(Obf.Profiler, Obf.startSection, Void.TYPE, String.class); | ... | ... |
java/common/com/mumfrey/liteloader/util/EntityUtilities.java
0 → 100644
| 1 | +package com.mumfrey.liteloader.util; | |
| 2 | + | |
| 3 | +import net.minecraft.entity.Entity; | |
| 4 | +import net.minecraft.util.MovingObjectPosition; | |
| 5 | +import net.minecraft.util.Vec3; | |
| 6 | + | |
| 7 | +public abstract class EntityUtilities | |
| 8 | +{ | |
| 9 | + public static MovingObjectPosition rayTraceFromEntity(Entity entity, double traceDistance, float partialTicks) | |
| 10 | + { | |
| 11 | + Vec3 var4 = EntityUtilities.getPositionEyes(entity, partialTicks); | |
| 12 | + Vec3 var5 = entity.getLook(partialTicks); | |
| 13 | + Vec3 var6 = var4.addVector(var5.xCoord * traceDistance, var5.yCoord * traceDistance, var5.zCoord * traceDistance); | |
| 14 | + return entity.worldObj.rayTraceBlocks(var4, var6, false, false, true); | |
| 15 | + } | |
| 16 | + | |
| 17 | + public static Vec3 getPositionEyes(Entity entity, float partialTicks) | |
| 18 | + { | |
| 19 | + if (partialTicks == 1.0F) | |
| 20 | + { | |
| 21 | + return new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ); | |
| 22 | + } | |
| 23 | + | |
| 24 | + double interpX = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks; | |
| 25 | + double interpY = entity.prevPosY + (entity.posY - entity.prevPosY) * partialTicks + entity.getEyeHeight(); | |
| 26 | + double interpZ = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks; | |
| 27 | + return new Vec3(interpX, interpY, interpZ); | |
| 28 | + } | |
| 29 | +} | ... | ... |