Skip to content

Commit 07abeca

Browse files
committed
ref: fake player creation in player utils
1 parent b136579 commit 07abeca

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

common/src/main/kotlin/com/lambda/module/modules/combat/FakePlayer.kt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
package com.lambda.module.modules.combat
1919

20-
import com.lambda.context.SafeContext
2120
import com.lambda.http.Method
2221
import com.lambda.http.request
2322
import com.lambda.module.Module
2423
import com.lambda.module.tag.ModuleTag
2524
import com.lambda.threading.runSafeConcurrent
25+
import com.lambda.util.player.spawnFakePlayer
2626
import com.mojang.authlib.GameProfile
2727
import net.minecraft.client.network.OtherClientPlayerEntity
2828
import net.minecraft.client.network.PlayerListEntry
@@ -41,8 +41,10 @@ object FakePlayer : Module(
4141
init {
4242
onEnable {
4343
// Avoid multiple api requests
44-
if (fakePlayer?.gameProfile?.name == playerName)
45-
return@onEnable spawnPlayer(fakePlayer!!.gameProfile)
44+
if (fakePlayer?.gameProfile?.name == playerName) {
45+
fakePlayer = spawnFakePlayer(fakePlayer!!.gameProfile)
46+
return@onEnable
47+
}
4648

4749
runSafeConcurrent {
4850
val uuid =
@@ -58,7 +60,7 @@ object FakePlayer : Module(
5860

5961
// This is the cache that mc pulls profile data from when it fetches skins.
6062
mc.networkHandler?.playerListEntries?.put(profile.id, PlayerListEntry(profile, false))
61-
spawnPlayer(profile)
63+
spawnFakePlayer(profile)
6264
}
6365
}
6466

@@ -67,18 +69,6 @@ object FakePlayer : Module(
6769
}
6870
}
6971

70-
private fun SafeContext.spawnPlayer(profile: GameProfile) {
71-
fakePlayer = OtherClientPlayerEntity(world, profile)
72-
.apply {
73-
copyFrom(player)
74-
75-
playerListEntry = PlayerListEntry(profile, false)
76-
id = -2024 - 4 - 20
77-
}
78-
79-
world.addEntity(fakePlayer)
80-
}
81-
8272
private fun deletePlayer() {
8373
fakePlayer?.setRemoved(Entity.RemovalReason.DISCARDED)
8474
}
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
package com.lambda.util.player
22

33
import com.lambda.context.SafeContext
4+
import com.lambda.module.modules.combat.FakePlayer.fakePlayer
5+
import com.mojang.authlib.GameProfile
46
import net.minecraft.client.network.ClientPlayerEntity
7+
import net.minecraft.client.network.OtherClientPlayerEntity
8+
import net.minecraft.client.network.PlayerListEntry
59

610
fun SafeContext.copyPlayer(entity: ClientPlayerEntity) =
7-
ClientPlayerEntity(
8-
mc,
9-
world,
10-
mc.networkHandler,
11-
null,
12-
null,
13-
entity.isSneaking,
14-
entity.isSprinting
15-
).apply {
11+
ClientPlayerEntity(mc, world, mc.networkHandler, null, null, entity.isSneaking, entity.isSprinting).apply {
1612
setPos(entity.x, entity.y, entity.z)
1713
setExperience(entity.experienceProgress, entity.totalExperience, entity.experienceLevel)
1814
pitch = entity.pitch
@@ -25,4 +21,17 @@ fun SafeContext.copyPlayer(entity: ClientPlayerEntity) =
2521
isSprinting = entity.isSprinting
2622
isSwimming = entity.isSwimming
2723
isOnGround = entity.isOnGround
28-
}
24+
}
25+
26+
fun SafeContext.spawnFakePlayer(profile: GameProfile): OtherClientPlayerEntity {
27+
val entity = OtherClientPlayerEntity(world, profile).apply {
28+
copyFrom(player)
29+
30+
playerListEntry = PlayerListEntry(profile, false)
31+
id = -2024 - 4 - 20
32+
}
33+
34+
world.addEntity(entity)
35+
36+
return entity
37+
}

0 commit comments

Comments
 (0)