Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(multiplayer sleep) Option to round up instead. #8

Open
technologicalMayhem opened this issue Jul 7, 2019 · 5 comments
Open

(multiplayer sleep) Option to round up instead. #8

technologicalMayhem opened this issue Jul 7, 2019 · 5 comments
Labels
Multiplayer Sleep System This issue references the sleeping system datapack question Further information is requested

Comments

@technologicalMayhem
Copy link

Would it be possible to create an option or a version of the data pack where the amount of players required to sleep is rounded up instead of down?
I tried to make the change myself, but i have a hard time wrapping my head around how data packs work, so pointing me towards the point where the rounding actually takes place, would be appreciated as well.

@Plagiatus Plagiatus added Multiplayer Sleep System This issue references the sleeping system datapack question Further information is requested labels Jul 8, 2019
@Plagiatus
Copy link
Owner

Plagiatus commented Jul 8, 2019

it is calculated in the fittingly named calculate.mcfunction function.
and the rounding down comes from integer division rounding down by default (10/3 is 3.33, so 3). see line 11 in that file.

you could of course always just add 1 to required players after line 11, but that means that you'd also "round up" if there is nothing to round (2 players with 100% would then need 3 players).

So, to enable you to round up, you'd have to check whether the division by 100 would turn out with a rest after the division. i threw this thing together real quick and didn't test it (EDIT: I tested it and it works just as expected), you can replace the calculate function file contents with this and see if that then rounds up properly:

execute store result score @s multSleep.tmp if entity @a[nbt={Dimension:0}]
scoreboard players operation totalPlayers multSleep.count = @s multSleep.tmp

execute store result score @s multSleep.tmp if entity @a[scores={multSleep.count=99..}]
scoreboard players operation sleepingPlayers multSleep.count = @s multSleep.tmp

scoreboard players operation requiredPlayers multSleep.count = totalPlayers multSleep.count

scoreboard players operation #roundup multSleep.tmp = totalPlayers multSleep.count
scoreboard players operation #roundup multSleep.tmp *= requiredPercent multSleep.count
scoreboard players operation #roundup multSleep.tmp %= #100 multSleep.count

scoreboard players operation requiredPlayers multSleep.count *= requiredPercent multSleep.count
scoreboard players operation requiredPlayers multSleep.count /= #100 multSleep.count
execute if score #roundup multSleep.tmp matches 1.. run scoreboard players add requiredPlayers multSleep.count 1
scoreboard players operation requiredPlayers multSleep.count -= sleepingPlayers multSleep.count

scoreboard players operation @s multSleep.tmp = requiredPlayers multSleep.count

@FredrikM97
Copy link

Tried this for minecraft 1.15 and it does not seem to be working.

@Plagiatus
Copy link
Owner

@FredrikM97 sorry for the late reply, but what part of this isn't working? I'll need some more info than just "it isn't working".

Are you using the roundup code I provided or are you referring to something else? Does it not produce the correct amount of people that it should? And if so, too little or too many? Does it break entirely and doesn't produce anything anymore?

@FredrikM97
Copy link

Tried to use the round up code but the datapack stops working (probobly being disabled by the server) in minecraft 1.15. Could potentially be a crash?

@Plagiatus
Copy link
Owner

no, the server doesn't just disable a datapack, at worst it disables a faulty function. Are you on a vanilla server or a third party one (spigot/bukkit/paper/etc)?

because I just did some testing and it works exactly as expected for me on a vanilla server in 1.15.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Multiplayer Sleep System This issue references the sleeping system datapack question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants