Project Expansion

Project Expansion

4M Downloads

`emc get` should actually return the target's EMC for `execute store result`

James103 opened this issue · 7 comments

commented

Project Expansion adds the emc remove command, which allows the player to gain negative emc if emc remove is called with a value greater than the player's current EMC total.

Instead of the command setting the EMC negative, it should fail, with the result encoding whether the player had enough EMC to take the hit (1) or not (0).

To reproduce, create a new world with cheats enabled, then run the following commands in order:

scoreboard objectives add a dummy
scoreboard objectives setdisplay sidebar a
emc add @s 100

# Returns 1 and deducts 64 from your EMC, leaving 36 EMC.
execute store result score @s a run emc remove @s 64

# Not enough EMC to take the hit, so this should fail, return 0, and leave your EMC unchanged.
# But, it instead succeeds, returns 1, and sets your EMC negative.
execute store result score @s a run emc remove @s 64
commented

All commands tied behind the emc prefix is admin only, I don't see how this would being a problem as it's not meant for regular use, I'd like to know your reasoning as to why the admin only command needs to have additional restrictions on top of it?

Could easily make it so it can't go below zero but default down to zero if negative, I just want to know your reasonings to why it needs to be changed.

commented

Keep the current behavior for emc add/remove/set, but make emc get actually return the target's current EMC (clamped to a 32-bit signed integer) instead of always returning 1.

That way, smaller EMC values (up to 2.147 Billion) can be directly compared, while larger EMC values may be subtracted from the target's EMC, the sign of the result checked, then (optionally) the EMC that was subtracted is added back.

The following examples assume that the scoreboard objective emc exists and is writable.

scoreboard objectives add emc dummy
scoreboard objectives setdisplay sidebar emc

Check that the player's EMC value is at least 1,000 (or some integer N within the range -231 ≤ N < 231):

execute store result score @s emc run emc get @s
execute if score @s emc matches 1000.. run function do:something

Check that the player's EMC value is at least 1 trillion (or some integer N outside the range -231 ≤ N < 231):

emc remove @s 1000000000000
execute store result score @s emc run emc get @s
execute if score @s emc matches 0.. run function do:something
emc add @s 1000000000000
commented

I think the problem here lies with the fact that Minecraft Scoreboard Objectives are specifically written up to be within the Signed Int32 range, meanwhile EMC as a whole was always written up to be a BigInteger which has it's range in the Double range which is ~1.7e308

Our command simply returns a formatted value of whatever ProjectE delivers to us currently through their API to read the players available EMC in their Network. And with how rapidly a player would slip outside the Scoreboard range, I'm not entirely sure how one would implement this to be properly functional without doing a lot of hacky workarounds.

commented

The negative emc bit might be looked into fixing, but it's nowhere near a priority

As far as returning the emc for scoreboards, I'm not going to do that because as has been pointed out, the values easily exceed the maximum returnable value and I don't see the point

commented

negative emc bit is being fixed in the next update, along with the addition of a new subcommand: test

it accepts a value to test against the users emc, the value will be subtracted and will return a 0/1 along with text if the user could have had the emc removed

2022-05-13_23 42 41
2022-05-13_23 42 57

commented

The following examples assume the scoreboard objective has_enough_emc exists and is writable.

scoreboard objectives add has_enough_emc dummy
scoreboard objectives setdisplay sidebar has_enough_emc

Example 1: Check if the player has enough EMC to do something, without subtracting the EMC.
"Do something. Requires: 1000 EMC"

execute store result score @s has_enough_emc run emc test @s 1000
execute if score @s has_enough_emc matches 1.. run function do:something

Example 2: Check if the player has enough EMC to do something. If the check passes, the EMC is subtracted.
"Do something. Cost: 1000 EMC"

execute store result score @s has_enough_emc run emc remove @s 1000
execute if score @s has_enough_emc matches 1.. run function do:something
commented

seems to work well enough, it'll be in the next release

2022-05-13_23 52 28
2022-05-13_23 55 25