Skip to content

Commit

Permalink
Add botsDontSleep rule
Browse files Browse the repository at this point in the history
  • Loading branch information
alikindsys committed Jan 4, 2024
1 parent b36e8f9 commit 9208c87
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/blocovermelho/bvextension/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public class Settings {
categories = {SURVIVAL, EXPERIMENTAL, "bv-extension"}
)
public static boolean carefulBreak = false;

@Rule(
categories = {SURVIVAL, EXPERIMENTAL, "bv-extension"}
)
public static boolean botsDontSleep = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.blocovermelho.bvextension.mixin;

import carpet.CarpetServer;
import carpet.patches.EntityPlayerMPFake;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.server.world.SleepManager;
import org.blocovermelho.bvextension.Settings;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(SleepManager.class)
public class BotsDontSleep {
@ModifyExpressionValue(
method = "getNightSkippingRequirement",
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/server/world/SleepManager;total:I"
))
public int bvext$botsDontSleep(int original) {
if (!Settings.botsDontSleep) {
return original;
}

var players = CarpetServer.minecraft_server.getPlayerManager().getPlayerList();

var bots = (int) players.stream().filter(p -> {
return p instanceof EntityPlayerMPFake;
}).count();

return original - bots;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/bv-extension/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"carpet.rule.carefulBreak.desc": "Places the mined block in the player inventory when sneaking"
"carpet.rule.carefulBreak.desc": "Places the mined block in the player inventory when sneaking",
"carpet.rule.botsDontSleep.desc" : "Makes carpet bots don't count towards playersSleepingPercentage"
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/bv-extension/lang/pt_br.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"carpet.rule.carefulBreak.desc": "Coloca o bloco minerado direto no inventário quando o jogador está agachado"
"carpet.rule.carefulBreak.desc": "Coloca o bloco minerado direto no inventário quando o jogador está agachado",
"carpet.rule.botsDontSleep.desc" : "Faz com que bots do carpet não contem para a gamerule playersSleepingPercentage"
}
3 changes: 2 additions & 1 deletion src/main/resources/bv-extension.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"carefulBreak.BlockMixin",
"carefulBreak.TallBlockMixin",
"carefulBreak.PistonHeadMixin",
"carefulBreak.BedMixin"
"carefulBreak.BedMixin",
"BotsDontSleep"
],
"client": [
],
Expand Down

0 comments on commit 9208c87

Please sign in to comment.