From d1e93e5f20263172e44425eceac5a2231ef4b4fc Mon Sep 17 00:00:00 2001 From: Yoghurt4C Date: Wed, 30 Oct 2024 01:42:15 +0300 Subject: [PATCH 1/5] private Iterator dontCountSpectatorsAsAwake(List instance, Operation> original) --- .../configuration/configs/ConfigMixins.java | 2 + .../core/handlers/ServerEventHandler.java | 5 ++ .../gamerule/PlayersSleepingPercentage.java | 21 +++++ .../mixinplugin/EtFuturumEarlyMixins.java | 4 + .../MixinWorldServer.java | 77 +++++++++++++++++++ .../assets/etfuturum/lang/en_US.lang | 3 + 6 files changed, 112 insertions(+) create mode 100644 src/main/java/ganymedes01/etfuturum/gamerule/PlayersSleepingPercentage.java create mode 100644 src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java diff --git a/src/main/java/ganymedes01/etfuturum/configuration/configs/ConfigMixins.java b/src/main/java/ganymedes01/etfuturum/configuration/configs/ConfigMixins.java index 65c86b58..cb60547f 100644 --- a/src/main/java/ganymedes01/etfuturum/configuration/configs/ConfigMixins.java +++ b/src/main/java/ganymedes01/etfuturum/configuration/configs/ConfigMixins.java @@ -44,6 +44,7 @@ public class ConfigMixins extends ConfigBase { public static boolean fireproofItems; public static boolean thinPanes; public static boolean colorGrassBlockItemSides; + public static boolean enablePlayersSleepingPecentageGamerule; static final String catBackport = "backported features"; static final String catOptimization = "optimizations"; @@ -113,5 +114,6 @@ protected void syncConfigOptions() { arrowFallingFix = getBoolean("arrowFallingFix", catFixes, true, "Prevents arrows from falling off of blocks too easily\nModified classes: net.minecraft.entity.EntityArrow"); collidedThrowableFix = getBoolean("collidedThrowableFix", catFixes, true, "Fixes EntityThrowable entities not calling onEntityCollidedWithBlock, causing them to not trigger target blocks or chime amethyst.\nModified classes: net.minecraft.entity.projectile.EntityThrowable"); hideSingleLevelEnchants = getBoolean("hideSingleLevelEnchants", catFixes, true, "Fixes enchantments with only one possible level displaying a level in their name. E.G. \"Silk Touch I\" becomes \"Silk Touch\".\nModified Classes: net.minecraft.enchantment.Enchantment"); + enablePlayersSleepingPecentageGamerule = getBoolean("enablePlayersSleepingPecentageGamerule", catBackport, true, "You nappa, you get slappa"); } } \ No newline at end of file diff --git a/src/main/java/ganymedes01/etfuturum/core/handlers/ServerEventHandler.java b/src/main/java/ganymedes01/etfuturum/core/handlers/ServerEventHandler.java index 4a5059eb..4c0e5ed4 100644 --- a/src/main/java/ganymedes01/etfuturum/core/handlers/ServerEventHandler.java +++ b/src/main/java/ganymedes01/etfuturum/core/handlers/ServerEventHandler.java @@ -32,6 +32,7 @@ import ganymedes01.etfuturum.entities.*; import ganymedes01.etfuturum.entities.ai.EntityAIOpenCustomDoor; import ganymedes01.etfuturum.gamerule.DoWeatherCycle; +import ganymedes01.etfuturum.gamerule.PlayersSleepingPercentage; import ganymedes01.etfuturum.gamerule.RandomTickSpeed; import ganymedes01.etfuturum.items.ItemArrowTipped; import ganymedes01.etfuturum.lib.Reference; @@ -1782,6 +1783,10 @@ public void loadWorldEvent(WorldEvent.Load event) { if (ConfigMixins.enableDoWeatherCycle) { DoWeatherCycle.registerGamerule(event.world); } + + if (ConfigMixins.enablePlayersSleepingPecentageGamerule) { + PlayersSleepingPercentage.registerGamerule(event.world); + } if(ConfigMixins.enableRandomTickSpeed) { RandomTickSpeed.registerGamerule(event.world); diff --git a/src/main/java/ganymedes01/etfuturum/gamerule/PlayersSleepingPercentage.java b/src/main/java/ganymedes01/etfuturum/gamerule/PlayersSleepingPercentage.java new file mode 100644 index 00000000..655bc7e1 --- /dev/null +++ b/src/main/java/ganymedes01/etfuturum/gamerule/PlayersSleepingPercentage.java @@ -0,0 +1,21 @@ +package ganymedes01.etfuturum.gamerule; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.List; + +public class PlayersSleepingPercentage { + public static final PlayersSleepingPercentage INSTANCE = new PlayersSleepingPercentage(); + public static final String GAMERULE_NAME = "playersSleepingPercentage"; + public static final String DEFAULT_VALUE = "100"; + + public List sleepyPlayers = new ArrayList<>(); + + public static void registerGamerule(World world) { + if (!world.isRemote && !world.getGameRules().hasRule(GAMERULE_NAME)) { + world.getGameRules().addGameRule(GAMERULE_NAME, DEFAULT_VALUE); + } + } +} diff --git a/src/main/java/ganymedes01/etfuturum/mixinplugin/EtFuturumEarlyMixins.java b/src/main/java/ganymedes01/etfuturum/mixinplugin/EtFuturumEarlyMixins.java index 6f90ecdc..389cc354 100644 --- a/src/main/java/ganymedes01/etfuturum/mixinplugin/EtFuturumEarlyMixins.java +++ b/src/main/java/ganymedes01/etfuturum/mixinplugin/EtFuturumEarlyMixins.java @@ -267,6 +267,10 @@ public List getMixins(Set loadedCoreMods) { } } + if (ConfigMixins.enablePlayersSleepingPecentageGamerule) { + mixins.add("playerssleepingpercentage.MixinWorldServer"); + } + return mixins; } diff --git a/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java new file mode 100644 index 00000000..9794c509 --- /dev/null +++ b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java @@ -0,0 +1,77 @@ +package ganymedes01.etfuturum.mixins.early.playerssleepingpercentage; + +import ganymedes01.etfuturum.spectator.SpectatorMode; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.profiler.Profiler; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; +import net.minecraft.world.WorldProvider; +import net.minecraft.world.WorldServer; +import net.minecraft.world.WorldSettings; +import net.minecraft.world.storage.ISaveHandler; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.Iterator; +import java.util.List; + +import static ganymedes01.etfuturum.gamerule.PlayersSleepingPercentage.GAMERULE_NAME; +import static ganymedes01.etfuturum.gamerule.PlayersSleepingPercentage.INSTANCE; + +@Mixin(WorldServer.class) +public abstract class MixinWorldServer extends World { + @Shadow + private boolean allPlayersSleeping; + + public MixinWorldServer(ISaveHandler p_i45368_1_, String p_i45368_2_, WorldProvider p_i45368_3_, WorldSettings p_i45368_4_, Profiler p_i45368_5_) { + super(p_i45368_1_, p_i45368_2_, p_i45368_3_, p_i45368_4_, p_i45368_5_); + throw new ArithmeticException("2 + 2 = 5 ???"); + } + + @Inject(method = "updateAllPlayersSleepingFlag", at = @At("HEAD"), cancellable = true) + public void hhheheheheeh(CallbackInfo ctx) { + int percentrillo = Integer.parseInt(this.getGameRules().getGameRuleStringValue(GAMERULE_NAME)); + if (percentrillo > 100) { + this.allPlayersSleeping = false; + ctx.cancel(/* /r/nosleep, vanilla behaviour */); + } else if (percentrillo < 100) { + INSTANCE.sleepyPlayers.clear(); + int cap = (int) (this.playerEntities.size() * Math.ceil(percentrillo * 0.01f)); + for (EntityPlayer player : this.playerEntities) { + if (player.isPlayerSleeping() || SpectatorMode.isSpectator(player)) { + INSTANCE.sleepyPlayers.add(player); + if (INSTANCE.sleepyPlayers.size() >= cap) { + this.allPlayersSleeping = true; + break; + } + } + } + + if (!INSTANCE.sleepyPlayers.isEmpty()) { + for (EntityPlayer paypiggy : this.playerEntities) { + paypiggy.addChatMessage(new ChatComponentText(I18n.format("sleep.players_sleeping", INSTANCE.sleepyPlayers.size(), cap))); + } + } + ctx.cancel(); + } + } + + @Redirect(method = "areAllPlayersAsleep", at = @At(value = "FIELD", target = "Lnet/minecraft/world/WorldServer;playerEntities:Ljava/util/List;", opcode = Opcodes.GETFIELD)) + public List baited(WorldServer instance) { + return INSTANCE.sleepyPlayers; + } + + @Inject(method = "wakeAllPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;wakeUpPlayer(ZZZ)V"), locals = LocalCapture.CAPTURE_FAILHARD) + public void broadcast(CallbackInfo ctx, Iterator iterator, EntityPlayer player) { + if (!this.getGameRules().getGameRuleStringValue(GAMERULE_NAME).equals("101")) { + player.addChatMessage(new ChatComponentText(I18n.format("sleep.skipping_night"))); + } + } +} diff --git a/src/main/resources/assets/etfuturum/lang/en_US.lang b/src/main/resources/assets/etfuturum/lang/en_US.lang index f3d6a96d..1ef21eb6 100755 --- a/src/main/resources/assets/etfuturum/lang/en_US.lang +++ b/src/main/resources/assets/etfuturum/lang/en_US.lang @@ -27,6 +27,9 @@ commands.etfuturum.fill.usage=/fill commands.etfuturum.fill.outOfWorld=Cannot place blocks outside of world commands.etfuturum.fill.success=Successfully filled %d block(s) +sleep.players_sleeping=%s/%s players sleeping +sleep.skipping_night=Sleeping through this night + # Containers/GUI container.enchant.lapis.one=1 Lapis Lazuli container.enchant.lapis.many=%d Lapis Lazuli From a8f6b9ea8223726108b0b0a0a2fdc384ef1c3ab8 Mon Sep 17 00:00:00 2001 From: Yoghurt4C Date: Wed, 30 Oct 2024 02:07:44 +0300 Subject: [PATCH 2/5] underping the derping --- .../MixinWorldServer.java | 7 +-- .../early/spectator/MixinWorldServer.java | 62 +++++++++++++++---- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java index 9794c509..6acad48e 100644 --- a/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java +++ b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java @@ -1,10 +1,9 @@ package ganymedes01.etfuturum.mixins.early.playerssleepingpercentage; import ganymedes01.etfuturum.spectator.SpectatorMode; -import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.profiler.Profiler; -import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; import net.minecraft.world.WorldProvider; import net.minecraft.world.WorldServer; @@ -56,7 +55,7 @@ public void hhheheheheeh(CallbackInfo ctx) { if (!INSTANCE.sleepyPlayers.isEmpty()) { for (EntityPlayer paypiggy : this.playerEntities) { - paypiggy.addChatMessage(new ChatComponentText(I18n.format("sleep.players_sleeping", INSTANCE.sleepyPlayers.size(), cap))); + paypiggy.addChatMessage(new ChatComponentTranslation("sleep.players_sleeping", INSTANCE.sleepyPlayers.size(), cap)); } } ctx.cancel(); @@ -71,7 +70,7 @@ public List baited(WorldServer instance) { @Inject(method = "wakeAllPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;wakeUpPlayer(ZZZ)V"), locals = LocalCapture.CAPTURE_FAILHARD) public void broadcast(CallbackInfo ctx, Iterator iterator, EntityPlayer player) { if (!this.getGameRules().getGameRuleStringValue(GAMERULE_NAME).equals("101")) { - player.addChatMessage(new ChatComponentText(I18n.format("sleep.skipping_night"))); + player.addChatMessage(new ChatComponentTranslation("sleep.skipping_night")); } } } diff --git a/src/main/java/ganymedes01/etfuturum/mixins/early/spectator/MixinWorldServer.java b/src/main/java/ganymedes01/etfuturum/mixins/early/spectator/MixinWorldServer.java index 5fc6ddfa..48ac98c6 100644 --- a/src/main/java/ganymedes01/etfuturum/mixins/early/spectator/MixinWorldServer.java +++ b/src/main/java/ganymedes01/etfuturum/mixins/early/spectator/MixinWorldServer.java @@ -2,6 +2,8 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; import ganymedes01.etfuturum.spectator.SpectatorMode; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.profiler.Profiler; @@ -13,25 +15,61 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + @Mixin(WorldServer.class) public abstract class MixinWorldServer extends World { public MixinWorldServer(ISaveHandler p_i45368_1_, String p_i45368_2_, WorldProvider p_i45368_3_, WorldSettings p_i45368_4_, Profiler p_i45368_5_) { super(p_i45368_1_, p_i45368_2_, p_i45368_3_, p_i45368_4_, p_i45368_5_); } - @WrapOperation(method = "areAllPlayersAsleep", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;isPlayerFullyAsleep()Z")) - private boolean dontCountSpectatorsAsAwake(EntityPlayer instance, Operation original) { - if(SpectatorMode.isSpectator(instance)) { - return true; - } - return original.call(instance); + /** + * Filters spectators out of the provided list. + * @param list + * @return + */ + private static List getListWithoutSpectators(List list) { + return list.stream().filter(entity -> !SpectatorMode.isSpectator(entity)).collect(Collectors.toList()); + } + + /** + * Filters spectators out of the playerEntities list before it is checked by areAllPlayersAsleep. + * Uses original.call to create the iterator to maintain compatibility with any other mixins + * @param instance + * @param original + * @return + */ + @WrapOperation(method = "areAllPlayersAsleep", at = @At(value = "INVOKE", target = "Ljava/util/List;iterator()Ljava/util/Iterator;")) + private Iterator dontCountSpectatorsForSleepListCheck(List instance, Operation> original) { + return original.call(getListWithoutSpectators(instance)); + } + + /** + * Filters spectators out of the playerEntities list before it is checked by updateAllPlayersSleepingFlag. + * Uses original.call to check if empty to maintain compatibility with any other mixins + * @param instance + * @param original + * @return + */ + @WrapOperation(method = "updateAllPlayersSleepingFlag", at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z")) + private boolean filterSleepList(List instance, Operation original, + @Share("nonSpectatingPlayers") LocalRef> nonSpectatingPlayers) { + List list = getListWithoutSpectators(instance); + nonSpectatingPlayers.set(list); + return original.call(list); } - @WrapOperation(method = "updateAllPlayersSleepingFlag", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;isPlayerSleeping()Z")) - private boolean dontCountSpectatorsAsAwakeForFlag(EntityPlayer instance, Operation original) { - if(SpectatorMode.isSpectator(instance)) { - return true; - } - return original.call(instance); + /** + * Use the filtered list to create the iterator instead of the main one. + * @param instance + * @param original + * @return + */ + @WrapOperation(method = "updateAllPlayersSleepingFlag", at = @At(value = "INVOKE", target = "Ljava/util/List;iterator()Ljava/util/Iterator;")) + private Iterator dontCountSpectatorsForSleepListFlag(List instance, Operation> original, + @Share("nonSpectatingPlayers") LocalRef> nonSpectatingPlayers) { + return original.call(nonSpectatingPlayers.get()); } } From d406b36f54ee788c7f4925a9d7c6046cd9b3b7ae Mon Sep 17 00:00:00 2001 From: Yoghurt4C Date: Wed, 30 Oct 2024 08:40:24 +0300 Subject: [PATCH 3/5] assorted fixes --- .../ganymedes01/etfuturum/core/utils/Utils.java | 12 ++++++++++++ .../MixinWorldServer.java | 14 +++++++++----- .../mixins/early/spectator/MixinWorldServer.java | 11 ++--------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/ganymedes01/etfuturum/core/utils/Utils.java b/src/main/java/ganymedes01/etfuturum/core/utils/Utils.java index 2c260e19..c9cb6565 100644 --- a/src/main/java/ganymedes01/etfuturum/core/utils/Utils.java +++ b/src/main/java/ganymedes01/etfuturum/core/utils/Utils.java @@ -8,8 +8,10 @@ import ganymedes01.etfuturum.configuration.configs.ConfigModCompat; import ganymedes01.etfuturum.configuration.configs.ConfigSounds; import ganymedes01.etfuturum.lib.Reference; +import ganymedes01.etfuturum.spectator.SpectatorMode; import net.minecraft.block.Block; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; @@ -28,6 +30,7 @@ import java.util.*; import java.util.function.Predicate; +import java.util.stream.Collectors; public class Utils { @@ -596,4 +599,13 @@ public static boolean listGeneralModdedRawOre(String oreDict) { return !ConfigModCompat.moddedRawOresBlacklist.contains(oreDict.replace("ingot", "ore")) && !OreDictionary.getOres(oreDict).isEmpty() && !OreDictionary.getOres(oreDict.replace("ingot", "ore")).isEmpty(); } + + /** + * Filters spectators out of the provided list. + * @param list + * @return + */ + public static List getListWithoutSpectators(List list) { + return list.stream().filter(entity -> !SpectatorMode.isSpectator(entity)).collect(Collectors.toList()); + } } \ No newline at end of file diff --git a/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java index 6acad48e..b7af4365 100644 --- a/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java +++ b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java @@ -1,5 +1,6 @@ package ganymedes01.etfuturum.mixins.early.playerssleepingpercentage; +import ganymedes01.etfuturum.core.utils.Utils; import ganymedes01.etfuturum.spectator.SpectatorMode; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.profiler.Profiler; @@ -17,6 +18,7 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import scala.tools.cmd.Spec; import java.util.Iterator; import java.util.List; @@ -42,18 +44,19 @@ public void hhheheheheeh(CallbackInfo ctx) { ctx.cancel(/* /r/nosleep, vanilla behaviour */); } else if (percentrillo < 100) { INSTANCE.sleepyPlayers.clear(); - int cap = (int) (this.playerEntities.size() * Math.ceil(percentrillo * 0.01f)); + List real = Utils.getListWithoutSpectators(this.playerEntities); + int cap = (int) Math.ceil(real.size() * percentrillo * 0.015f); for (EntityPlayer player : this.playerEntities) { - if (player.isPlayerSleeping() || SpectatorMode.isSpectator(player)) { + if (player.isPlayerSleeping()) { INSTANCE.sleepyPlayers.add(player); - if (INSTANCE.sleepyPlayers.size() >= cap) { + if (INSTANCE.sleepyPlayers.size() >= real.size()) { this.allPlayersSleeping = true; break; } } } - if (!INSTANCE.sleepyPlayers.isEmpty()) { + if (!INSTANCE.sleepyPlayers.isEmpty() && cap > 0) { for (EntityPlayer paypiggy : this.playerEntities) { paypiggy.addChatMessage(new ChatComponentTranslation("sleep.players_sleeping", INSTANCE.sleepyPlayers.size(), cap)); } @@ -69,7 +72,8 @@ public List baited(WorldServer instance) { @Inject(method = "wakeAllPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;wakeUpPlayer(ZZZ)V"), locals = LocalCapture.CAPTURE_FAILHARD) public void broadcast(CallbackInfo ctx, Iterator iterator, EntityPlayer player) { - if (!this.getGameRules().getGameRuleStringValue(GAMERULE_NAME).equals("101")) { + int rule = Integer.parseInt(this.getGameRules().getGameRuleStringValue(GAMERULE_NAME)); + if (rule > 0 && rule < 101) { player.addChatMessage(new ChatComponentTranslation("sleep.skipping_night")); } } diff --git a/src/main/java/ganymedes01/etfuturum/mixins/early/spectator/MixinWorldServer.java b/src/main/java/ganymedes01/etfuturum/mixins/early/spectator/MixinWorldServer.java index 48ac98c6..8cd6707d 100644 --- a/src/main/java/ganymedes01/etfuturum/mixins/early/spectator/MixinWorldServer.java +++ b/src/main/java/ganymedes01/etfuturum/mixins/early/spectator/MixinWorldServer.java @@ -19,21 +19,14 @@ import java.util.List; import java.util.stream.Collectors; +import static ganymedes01.etfuturum.core.utils.Utils.getListWithoutSpectators; + @Mixin(WorldServer.class) public abstract class MixinWorldServer extends World { public MixinWorldServer(ISaveHandler p_i45368_1_, String p_i45368_2_, WorldProvider p_i45368_3_, WorldSettings p_i45368_4_, Profiler p_i45368_5_) { super(p_i45368_1_, p_i45368_2_, p_i45368_3_, p_i45368_4_, p_i45368_5_); } - /** - * Filters spectators out of the provided list. - * @param list - * @return - */ - private static List getListWithoutSpectators(List list) { - return list.stream().filter(entity -> !SpectatorMode.isSpectator(entity)).collect(Collectors.toList()); - } - /** * Filters spectators out of the playerEntities list before it is checked by areAllPlayersAsleep. * Uses original.call to create the iterator to maintain compatibility with any other mixins From eab32c4c30e95b90d800c2efd65cb9b8ad71e659 Mon Sep 17 00:00:00 2001 From: Yoghurt4C Date: Wed, 30 Oct 2024 08:41:53 +0300 Subject: [PATCH 4/5] no cap all derp --- .../early/playerssleepingpercentage/MixinWorldServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java index b7af4365..74b41d6b 100644 --- a/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java +++ b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java @@ -49,7 +49,7 @@ public void hhheheheheeh(CallbackInfo ctx) { for (EntityPlayer player : this.playerEntities) { if (player.isPlayerSleeping()) { INSTANCE.sleepyPlayers.add(player); - if (INSTANCE.sleepyPlayers.size() >= real.size()) { + if (INSTANCE.sleepyPlayers.size() >= cap) { this.allPlayersSleeping = true; break; } From 0216b4f35b7c97b636717b30667fe2ef4cbe60d6 Mon Sep 17 00:00:00 2001 From: Yoghurt4C Date: Wed, 30 Oct 2024 08:58:03 +0300 Subject: [PATCH 5/5] and just maybe you're gonna be the one that saves me --- .../gamerule/PlayersSleepingPercentage.java | 1 + .../MixinWorldServer.java | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/ganymedes01/etfuturum/gamerule/PlayersSleepingPercentage.java b/src/main/java/ganymedes01/etfuturum/gamerule/PlayersSleepingPercentage.java index 655bc7e1..6f5be58a 100644 --- a/src/main/java/ganymedes01/etfuturum/gamerule/PlayersSleepingPercentage.java +++ b/src/main/java/ganymedes01/etfuturum/gamerule/PlayersSleepingPercentage.java @@ -11,6 +11,7 @@ public class PlayersSleepingPercentage { public static final String GAMERULE_NAME = "playersSleepingPercentage"; public static final String DEFAULT_VALUE = "100"; + public int percentrillo = 100; public List sleepyPlayers = new ArrayList<>(); public static void registerGamerule(World world) { diff --git a/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java index 74b41d6b..3a601f54 100644 --- a/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java +++ b/src/main/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java @@ -1,7 +1,6 @@ package ganymedes01.etfuturum.mixins.early.playerssleepingpercentage; import ganymedes01.etfuturum.core.utils.Utils; -import ganymedes01.etfuturum.spectator.SpectatorMode; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.profiler.Profiler; import net.minecraft.util.ChatComponentTranslation; @@ -17,8 +16,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import scala.tools.cmd.Spec; import java.util.Iterator; import java.util.List; @@ -38,14 +37,14 @@ public MixinWorldServer(ISaveHandler p_i45368_1_, String p_i45368_2_, WorldProvi @Inject(method = "updateAllPlayersSleepingFlag", at = @At("HEAD"), cancellable = true) public void hhheheheheeh(CallbackInfo ctx) { - int percentrillo = Integer.parseInt(this.getGameRules().getGameRuleStringValue(GAMERULE_NAME)); - if (percentrillo > 100) { + INSTANCE.percentrillo = Integer.parseInt(this.getGameRules().getGameRuleStringValue(GAMERULE_NAME)); + if (INSTANCE.percentrillo > 100) { this.allPlayersSleeping = false; ctx.cancel(/* /r/nosleep, vanilla behaviour */); - } else if (percentrillo < 100) { + } else if (INSTANCE.percentrillo < 100) { INSTANCE.sleepyPlayers.clear(); List real = Utils.getListWithoutSpectators(this.playerEntities); - int cap = (int) Math.ceil(real.size() * percentrillo * 0.015f); + int cap = (int) Math.ceil(real.size() * INSTANCE.percentrillo * 0.01f); for (EntityPlayer player : this.playerEntities) { if (player.isPlayerSleeping()) { INSTANCE.sleepyPlayers.add(player); @@ -70,10 +69,14 @@ public List baited(WorldServer instance) { return INSTANCE.sleepyPlayers; } + @Inject(method = "areAllPlayersAsleep", at = @At(value = "INVOKE", target = "Ljava/util/List;iterator()Ljava/util/Iterator;"), cancellable = true) + public void turbofast(CallbackInfoReturnable ctx) { + if (INSTANCE.percentrillo < 1) ctx.setReturnValue(true); + } + @Inject(method = "wakeAllPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;wakeUpPlayer(ZZZ)V"), locals = LocalCapture.CAPTURE_FAILHARD) public void broadcast(CallbackInfo ctx, Iterator iterator, EntityPlayer player) { - int rule = Integer.parseInt(this.getGameRules().getGameRuleStringValue(GAMERULE_NAME)); - if (rule > 0 && rule < 101) { + if (INSTANCE.percentrillo > 0 && INSTANCE.percentrillo < 101) { player.addChatMessage(new ChatComponentTranslation("sleep.skipping_night")); } }