File tree Expand file tree Collapse file tree 4 files changed +65
-1
lines changed
java/io/github/optijava/opt_carpet_addition
mixins/rule/optimizeFakePlayerSpawn Expand file tree Collapse file tree 4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -152,5 +152,11 @@ public class OptCarpetSettings {
152152 category = RuleCategory .BUGFIX
153153 )
154154 public static boolean dropperCrashFix = false ;
155+
156+ @ Rule (
157+ desc = "Always spawn offline fake player to reduce lagging" ,
158+ category = RuleCategory .OPTIMIZATION
159+ )
160+ public static boolean optimizeFakePlayerSpawn = false ;
155161}
156162
Original file line number Diff line number Diff line change 1+ package io .github .optijava .opt_carpet_addition .mixins .rule .optimizeFakePlayerSpawn ;
2+
3+ import carpet .patches .EntityPlayerMPFake ;
4+ import com .mojang .authlib .GameProfile ;
5+ import io .github .optijava .opt_carpet_addition .OptCarpetSettings ;
6+ import net .minecraft .entity .player .PlayerEntity ;
7+ import net .minecraft .util .UserCache ;
8+ import org .spongepowered .asm .mixin .Mixin ;
9+ import org .spongepowered .asm .mixin .injection .At ;
10+ import org .spongepowered .asm .mixin .injection .Redirect ;
11+
12+ import java .util .Optional ;
13+
14+ @ Mixin (EntityPlayerMPFake .class )
15+ public abstract class EntityPlayerMPFake_Mixin {
16+
17+ @ Redirect (
18+ method = "createFake" ,
19+ at = @ At (value = "INVOKE" , target = "Lnet/minecraft/util/UserCache;findByName(Ljava/lang/String;)Ljava/util/Optional;" )
20+ )
21+ private static Optional <GameProfile > redirectCreateFake (UserCache instance , String playerName ) {
22+ if (OptCarpetSettings .optimizeFakePlayerSpawn ) {
23+ return Optional .of (new GameProfile (PlayerEntity .getOfflinePlayerUuid (playerName ), playerName ));
24+ } else {
25+ return instance .findByName (playerName );
26+ }
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package io .github .optijava .opt_carpet_addition .mixins .rule .optimizeFakePlayerSpawn ;
2+
3+ import carpet .commands .PlayerCommand ;
4+ import com .mojang .authlib .GameProfile ;
5+ import io .github .optijava .opt_carpet_addition .OptCarpetSettings ;
6+ import net .minecraft .entity .player .PlayerEntity ;
7+ import net .minecraft .util .UserCache ;
8+ import org .spongepowered .asm .mixin .Mixin ;
9+ import org .spongepowered .asm .mixin .injection .At ;
10+ import org .spongepowered .asm .mixin .injection .Redirect ;
11+
12+ import java .util .Optional ;
13+
14+ @ Mixin (PlayerCommand .class )
15+ public abstract class PlayerCommand_Mixin {
16+
17+ @ Redirect (
18+ method = "cantSpawn" ,
19+ at = @ At (value = "INVOKE" , target = "Lnet/minecraft/util/UserCache;findByName(Ljava/lang/String;)Ljava/util/Optional;" )
20+ )
21+ private static Optional <GameProfile > redirectFindByName (UserCache instance , String playerName ) {
22+ if (OptCarpetSettings .optimizeFakePlayerSpawn ) {
23+ return Optional .of (new GameProfile (PlayerEntity .getOfflinePlayerUuid (playerName ), playerName ));
24+ } else {
25+ return instance .findByName (playerName );
26+ }
27+ }
28+ }
Original file line number Diff line number Diff line change 2222 " rule.disabledNetherPortalSpawn.NetherPortalBlock_Mixin" ,
2323 " rule.disabledUpdateSuppressionErrorStackTrace.ThreadExecutor_Mixin" ,
2424 " rule.dropperCrashFix.DispenserBlock_Mixin" ,
25- " rule.dropperCrashFix.DropperBlock_Mixin"
25+ " rule.dropperCrashFix.DropperBlock_Mixin" ,
26+ " rule.optimizeFakePlayerSpawn.EntityPlayerMPFake_Mixin" ,
27+ " rule.optimizeFakePlayerSpawn.PlayerCommand_Mixin"
2628 ],
2729 "client" : [
2830 " rule.unescapeChatMessage.ChatMessageC2SPacket_Mixin" ,
You can’t perform that action at this time.
0 commit comments