RedPxnda / RespawnObelisks

MIT License
5 stars 3 forks source link

[BUG] secondarySpawnMode IF_OBELISK does not function correctly. #20

Closed Nereithr closed 2 months ago

Nereithr commented 3 months ago

Describe the bug IF_OBELISK does not prevent selecting a secondary spawn point when your last respawn point is NOT an obelisk.

To Reproduce Steps to reproduce the behavior:

  1. Set secondarySpawnMode to IF_OBELISK
  2. Set spawn a couple of times, prioritize something that is NOT an obelisk.
  3. /kill. You will be able to select any secondary spawn point even if your last selected spawn point was NOT an obelisk.

Expected behavior IF_OBELISK prevents selecting a secondary spawn point unless your last spawn point is an OBELISK

Notes Did not test with worldSpawnMode. IF_CHARGED works properly, it's just IF_OBELISK that appears to be broken.

Versions

Additional notes

There is an additional problem with the overall max respawn points, filing that as a separate issue.

RedPxnda commented 3 months ago

Do you have the config option enabled that forces specific blocks to always be higher in priority than others?

Nereithr commented 3 months ago

Do you have the config option enabled that forces specific blocks to always be higher in priority than others?

No, these are the settings I'm using in the secondary spawn section (secondary spawn mode notwithstanding, since that is the topic). Also, this does even if worldSpawnMode is set to "NEVER".

"secondarySpawnPoints": {
        // Whether secondary spawn points should be enabled. Secondary respawn points can be used to have multiple respawn points, triggered at various times.
        "enableSecondarySpawnPoints": true,
        // Determines the overall maximum amount of secondary respawn points you can have. -1 is infinite.
        "overallMaxPoints": 2,
        /*
        Determines a per-block cap on the amount of respawn points you can have. -1 is infinite.
        Tags(which get treated as a single entry) are supported by beginning the entry with a #.
        Example: {"#minecraft:beds": 5, "respawnobelisks:respawn_obelisk": 5} // this would allow you to have 5 bed respawn points and 5 obelisk respawn points
        */
        "maxPointsPerBlock": {
            "#minecraft:beds": 1,
            "respawnobelisks:respawn_obelisk": 1
        },
        // Determines the maximum amount of secondary respawn points you can have at any block not specified in 'maxPointsPerBlock'. -1 is infinite.
        "defaultMaxPoints": 1,
        // Whether players can forcefully change the order of their secondary respawn points by shift right clicking a respawn point.
        "allowPriorityShifting": false,
        // Whether blocks should be given a specific order for respawning. This will not work well with 'allowPriorityShifting.'
        "enableBlockPriorities": false,
        /*
        Determines a per-block priority in which to order secondary respawn points. Default value is 0. Higher numbers have higher priority.
        Tags(which get treated as a single entry) are supported by beginning the entry with a #.
        */
        "blockPriorities": {},
        // Whether attempting to set your spawn point when you are unable to overrides an existing spawn point.
        "forceSpawnSetting": true,
        /*
        When players are allowed to choose to spawn at a secondary respawn point.
        NEVER: Players can never choose.
        ALWAYS: Players can always choose.
        IF_CHARGED: Players can only choose if their respawn point is an obelisk that has charge.
        UNLESS_CHARGED: Players can only choose if their respawn point is an obelisk that does not have charge.
        UNLESS_CHARGED_OBELISK: Players can only choose if their obelisk does not have charge, or if their respawn point isn't an obelisk.
        IF_OBELISK: Players can only choose if their respawn point is an obelisk.
        UNLESS_OBELISK: Players can only choose if their respawn point is not an obelisk.
        */
        "secondarySpawnMode": "IF_CHARGED",
        /*
        When players are allowed to choose to respawn at world spawn.
        NEVER: Players can never choose.
        ALWAYS: Players can always choose.
        IF_CHARGED: Players can only choose if their respawn point is an obelisk that has charge.
        UNLESS_CHARGED: Players can only choose if their respawn point is an obelisk that does not have charge.
        UNLESS_CHARGED_OBELISK: Players can only choose if their obelisk does not have charge, or if their respawn point isn't an obelisk.
        IF_OBELISK: Players can only choose if their respawn point is an obelisk.
        UNLESS_OBELISK: Players can only choose if their respawn point is not an obelisk.
        */
        "worldSpawnMode": "ALWAYS"
    }, 
RedPxnda commented 3 months ago

Alright. I guess I didn't setup so that choosing a respawn point prioritizes it, doing that might have some side effects I'll have to see. Will be fixed next update.

Nereithr commented 3 months ago

Oh no, the priority does appear to be set up properly (you spawn on the obelisk and everything), plus everything works with IF_CHARGED.

My guess is just that the cases for IF_OBELISK and UNLESS_OBELISK are not yet implemented in SecondarySpawnPointConfig.java while the recommended enums are already present in the config, so it defaults to the ALWAYS/default scenario:

public boolean evaluate(SpawnPoint point, ServerPlayerEntity player) {
            return switch (this) {
                case IF_CHARGED -> point != null && player.getServer().getWorld(point.dimension()).getBlockEntity(point.pos()) instanceof RespawnObeliskBlockEntity robe && robe.getCharge(player)-robe.getCost(player) >= 0;
                case UNLESS_CHARGED_OBELISK -> point == null || !(player.getServer().getWorld(point.dimension()).getBlockEntity(point.pos()) instanceof RespawnObeliskBlockEntity robe) || robe.getCharge(player)-robe.getCost(player) < 0;
                case UNLESS_CHARGED -> point != null && player.getServer().getWorld(point.dimension()).getBlockEntity(point.pos()) instanceof RespawnObeliskBlockEntity robe && robe.getCharge(player)-robe.getCost(player) < 0;
                case NEVER -> false;
                default -> true;
            };
        }
RedPxnda commented 3 months ago

Welp, guess I forgot to add them there lol.

RedPxnda commented 2 months ago

Fixed as of 2.5-d.