diff --git a/1.13.x/src/main/java/net/set/spawn/mod/mixin/ServerPlayerEntityMixin.java b/1.13.x/src/main/java/net/set/spawn/mod/mixin/ServerPlayerEntityMixin.java index 2e9c538..f110c70 100644 --- a/1.13.x/src/main/java/net/set/spawn/mod/mixin/ServerPlayerEntityMixin.java +++ b/1.13.x/src/main/java/net/set/spawn/mod/mixin/ServerPlayerEntityMixin.java @@ -33,7 +33,7 @@ public abstract class ServerPlayerEntityMixin { public abstract ServerWorld getServerWorld(); @WrapOperation(method = "method_21281", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I")) - private int setSpawn(Random random, int bounds, Operation original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult) { + private int setSpawn(Random random, int bounds, Operation original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult, @Share("newRandomValue") LocalRef newRandomValue) { int originalResult = original.call(random, bounds); if (((MinecraftServerExtended) this.server).setspawnmod$shouldModifySpawn()) { @@ -54,8 +54,9 @@ private int setSpawn(Random random, int bounds, Operation original, @Lo if (xLocal >=0 && xLocal < spawnDiameter && result >= 0 && result < bounds) { // we save the original result in case the set spawn is invalid, see fallbackOnInvalidSpawn - System.out.println("Setting spawn"); originalRandomResult.set(originalResult); + newRandomValue.set(result); + System.out.println("Setting spawn"); return result; } else { this.setSpawnError = "The X or Z coordinates given (" + seed.get().getX() + ", " + seed.get().getZ() + ") are more than the worlds spawn radius (" + spawnRadius + " blocks) away from the world spawn. Not overriding player spawnpoint."; @@ -64,7 +65,7 @@ private int setSpawn(Random random, int bounds, Operation original, @Lo } @ModifyVariable(method = "method_21281", at = @At(value = "LOAD", ordinal = 0), ordinal = 5) - private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 4) LocalIntRef o, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult) { + private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 2) int k, @Local(ordinal = 4) LocalIntRef o, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult, @Share("newRandomValue") LocalRef newRandomValue) { // checks if the for loop is on its second iteration (p == 1), meaning the setspawn given spawn was invalid // and restores the original result of Random#nextInt if (p == 1 && originalRandomResult.get() != null) { @@ -74,6 +75,14 @@ private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 4) LocalIntRef o, @Sh this.setSpawnError = "There is no valid spawning location at the specified coordinates (" + seed.get().getX() + ", " + seed.get().getZ() + "). Not overriding player spawnpoint."; } + // if we made it to the end of the loop after an obstructed spawn and didn't find another non-obstructed spawn + // redo the last iteration of the loop with the choice obstructed spawn + if (p == k && originalRandomResult.get() == null && newRandomValue.get() != null) { + o.set(newRandomValue.get()); + newRandomValue.set(null); + p = k - 1; + this.setSpawnError = null; + } return p; } diff --git a/1.14-1.18.2/src/main/java/net/set/spawn/mod/mixin/ServerPlayerEntityMixin.java b/1.14-1.18.2/src/main/java/net/set/spawn/mod/mixin/ServerPlayerEntityMixin.java index 2708a7b..9dda76b 100644 --- a/1.14-1.18.2/src/main/java/net/set/spawn/mod/mixin/ServerPlayerEntityMixin.java +++ b/1.14-1.18.2/src/main/java/net/set/spawn/mod/mixin/ServerPlayerEntityMixin.java @@ -33,7 +33,7 @@ public abstract class ServerPlayerEntityMixin { public abstract ServerWorld getServerWorld(); @WrapOperation(method = "moveToSpawn", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I")) - private int setSpawn(Random random, int bounds, Operation original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult) { + private int setSpawn(Random random, int bounds, Operation original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult, @Share("newRandomValue") LocalRef newRandomValue) { int originalResult = original.call(random, bounds); if (((MinecraftServerExtended) this.server).setspawnmod$shouldModifySpawn()) { @@ -53,8 +53,9 @@ private int setSpawn(Random random, int bounds, Operation original, @Lo if (xLocal >=0 && xLocal < spawnDiameter && result >= 0 && result < bounds) { // we save the original result in case the set spawn is invalid, see fallbackOnInvalidSpawn - System.out.println("Setting spawn"); originalRandomResult.set(originalResult); + newRandomValue.set(result); + System.out.println("Setting spawn"); return result; } else { this.setSpawnError = "The X or Z coordinates given (" + seed.get().getX() + ", " + seed.get().getZ() + ") are more than the worlds spawn radius (" + spawnRadius + " blocks) away from the world spawn. Not overriding player spawnpoint."; @@ -63,7 +64,7 @@ private int setSpawn(Random random, int bounds, Operation original, @Lo } @ModifyVariable(method = "moveToSpawn", at = @At(value = "LOAD", ordinal = 0), ordinal = 5) - private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 4) LocalIntRef o, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult) { + private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 2) int k, @Local(ordinal = 4) LocalIntRef o, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult, @Share("newRandomValue") LocalRef newRandomValue) { // checks if the for loop is on its second iteration (p == 1), meaning the setspawn given spawn was invalid // and restores the original result of Random#nextInt if (p == 1 && originalRandomResult.get() != null) { @@ -73,6 +74,14 @@ private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 4) LocalIntRef o, @Sh this.setSpawnError = "There is no valid spawning location at the specified coordinates (" + seed.get().getX() + ", " + seed.get().getZ() + "). Not overriding player spawnpoint."; } + // if we made it to the end of the loop after an obstructed spawn and didn't find another non-obstructed spawn + // redo the last iteration of the loop with the choice obstructed spawn + if (p == k && originalRandomResult.get() == null && newRandomValue.get() != null) { + o.set(newRandomValue.get()); + newRandomValue.set(null); + p = k - 1; + this.setSpawnError = null; + } return p; } @@ -84,9 +93,11 @@ private void failOnNonRandomSpawns(CallbackInfo ci, @Share("seed") LocalRef original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult, @Share("isRandomSpawn") LocalBooleanRef isRandomSpawn) { + private int setSpawn(Random random, int bounds, Operation original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult, @Share("isRandomSpawn") LocalBooleanRef isRandomSpawn, @Share("newRandomValue") LocalRef newRandomValue) { // fallback for 1.21 with no else statement in the skylight check isRandomSpawn.set(true); int originalResult = original.call(random, bounds); @@ -57,6 +57,7 @@ private int setSpawn(Random random, int bounds, Operation original, @Lo if (xLocal >=0 && xLocal < spawnDiameter && result >= 0 && result < bounds) { // we save the original result in case the set spawn is invalid, see fallbackOnInvalidSpawn originalRandomResult.set(originalResult); + newRandomValue.set(result); System.out.println("Setting spawn"); return result; } else { @@ -67,7 +68,7 @@ private int setSpawn(Random random, int bounds, Operation original, @Lo @Dynamic @ModifyVariable(method = {"moveToSpawn", "method_14245(Lnet/minecraft/class_3218;Lnet/minecraft/class_2338;)Lnet/minecraft/class_2338;"}, at = @At(value = "LOAD", ordinal = 0), ordinal = 5) - private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 4) LocalIntRef o, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult) { + private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 2) int k, @Local(ordinal = 4) LocalIntRef o, @Share("seed") LocalRef seed, @Share("originalRandomResult") LocalRef originalRandomResult, @Share("newRandomValue") LocalRef newRandomValue) { // checks if the for loop is on its second iteration (p == 1), meaning the setspawn given spawn was invalid // and restores the original result of Random#nextInt if (p == 1 && originalRandomResult.get() != null) { @@ -77,6 +78,14 @@ private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 4) LocalIntRef o, @Sh this.setSpawnError = "There is no valid spawning location at the specified coordinates (" + seed.get().getX() + ", " + seed.get().getZ() + "). Not overriding player spawnpoint."; } + // if we made it to the end of the loop after an obstructed spawn and didn't find another non-obstructed spawn + // redo the last iteration of the loop with the choice obstructed spawn + if (p == k && originalRandomResult.get() == null && newRandomValue.get() != null) { + o.set(newRandomValue.get()); + newRandomValue.set(null); + p = k - 1; + this.setSpawnError = null; + } return p; } diff --git a/1.19-1.21.4/src/main/resources/assets/setspawnmod/icon.png b/1.19-1.21.6/src/main/resources/assets/setspawnmod/icon.png similarity index 100% rename from 1.19-1.21.4/src/main/resources/assets/setspawnmod/icon.png rename to 1.19-1.21.6/src/main/resources/assets/setspawnmod/icon.png diff --git a/1.19-1.21.4/src/main/resources/fabric.mod.json b/1.19-1.21.6/src/main/resources/fabric.mod.json similarity index 100% rename from 1.19-1.21.4/src/main/resources/fabric.mod.json rename to 1.19-1.21.6/src/main/resources/fabric.mod.json diff --git a/1.19-1.21.4/src/main/resources/setspawnmod.mixins.json b/1.19-1.21.6/src/main/resources/setspawnmod.mixins.json similarity index 100% rename from 1.19-1.21.4/src/main/resources/setspawnmod.mixins.json rename to 1.19-1.21.6/src/main/resources/setspawnmod.mixins.json diff --git a/gradle.properties b/gradle.properties index cb04c5c..1c509cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx2G org.gradle.parallel = true org.gradle.caching = true -mod_version = 4.1.2 +mod_version = 4.2.0 archives_name = setspawnmod base_archives_name = setspawnmod-common maven_group = me.bdamja diff --git a/settings.gradle b/settings.gradle index 2037117..3567d71 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,4 +16,4 @@ include "1.12" include "1.8-1.12.2" include "1.13.x" include "1.14-1.18.2" -include "1.19-1.21.4" +include "1.19-1.21.6"