[Memory-opti:fix leak] fix world client from keybind handler (#43)

This commit is contained in:
Alexdoru authored and GitHub committed 2026-04-30 11:13:22 +02:00
1 parent 732f64a1b4
commit d3054211db
2 files changed
+11 -13

No files matched your search

@@ -18,10 +18,17 @@ object ControlKeyModifer {
implicit def playerControlValue(p: EntityPlayer) = new ControlKeyValue(p)
class ControlKeyValue(p: EntityPlayer) {
def isControlDown = map(p)
def isControlDown = {
if (p.worldObj.isRemote) {
isClientPressing
} else {
map(p)
}
}
}
val map = HashMap[EntityPlayer, Boolean]().withDefaultValue(false)
var isClientPressing = false;
/** Implicit static for Java users.
*/
@@ -38,7 +45,6 @@ object ControlKeyHandler
) {
import ControlKeyModifer._
var wasPressed = false
var oldPlayer: EntityPlayer = null
@SubscribeEvent
@SideOnly(Side.CLIENT)
@@ -47,19 +53,11 @@ object ControlKeyHandler
if (pressed != wasPressed) {
wasPressed = pressed
if (Minecraft.getMinecraft.getNetHandler != null) {
map.put(Minecraft.getMinecraft.thePlayer, pressed)
isClientPressing = pressed
val packet = new PacketCustom(MultipartCPH.channel, 1)
packet.writeBoolean(pressed)
packet.sendToServer()
}
}
if (oldPlayer != null) {
if (oldPlayer != Minecraft.getMinecraft.thePlayer) {
map.remove(oldPlayer)
oldPlayer = Minecraft.getMinecraft.thePlayer
}
} else {
oldPlayer = Minecraft.getMinecraft.thePlayer
}
}
}
@@ -9,8 +9,7 @@ import cpw.mods.fml.common.event.{
FMLServerStoppedEvent
}
import cpw.mods.fml.common.Mod.EventHandler
import codechicken.multipart.MultiPartRegistry
import codechicken.multipart.Tags
import codechicken.multipart.{ControlKeyModifer, MultiPartRegistry, Tags}
@Mod(
modid = "ForgeMultipart",
@@ -46,5 +45,6 @@ object MultipartMod {
@EventHandler
def serverStopped(event: FMLServerStoppedEvent) {
MultipartSaveLoad.loadingWorld = null;
ControlKeyModifer.map.clear();
}
}