Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef<Seed> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult) {
private int setSpawn(Random random, int bounds, Operation<Integer> original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef<Seed> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult, @Share("newRandomValue") LocalRef<Integer> newRandomValue) {
int originalResult = original.call(random, bounds);

if (((MinecraftServerExtended) this.server).setspawnmod$shouldModifySpawn()) {
Expand All @@ -54,8 +54,9 @@ private int setSpawn(Random random, int bounds, Operation<Integer> 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.";
Expand All @@ -64,7 +65,7 @@ private int setSpawn(Random random, int bounds, Operation<Integer> 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> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult) {
private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 2) int k, @Local(ordinal = 4) LocalIntRef o, @Share("seed") LocalRef<Seed> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult, @Share("newRandomValue") LocalRef<Integer> 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) {
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef<Seed> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult) {
private int setSpawn(Random random, int bounds, Operation<Integer> original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef<Seed> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult, @Share("newRandomValue") LocalRef<Integer> newRandomValue) {
int originalResult = original.call(random, bounds);

if (((MinecraftServerExtended) this.server).setspawnmod$shouldModifySpawn()) {
Expand All @@ -53,8 +53,9 @@ private int setSpawn(Random random, int bounds, Operation<Integer> 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.";
Expand All @@ -63,7 +64,7 @@ private int setSpawn(Random random, int bounds, Operation<Integer> 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> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult) {
private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 2) int k, @Local(ordinal = 4) LocalIntRef o, @Share("seed") LocalRef<Seed> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult, @Share("newRandomValue") LocalRef<Integer> 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) {
Expand All @@ -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;
}

Expand All @@ -84,22 +93,23 @@ private void failOnNonRandomSpawns(CallbackInfo ci, @Share("seed") LocalRef<Seed
}

@Group(min = 1, max = 1)
// 1.14-1.16.5
@Inject(method = "onSpawn", at = @At("TAIL"), require = 0)
private void sendErrorMessage(CallbackInfo ci) {
if (this.setSpawnError != null) {
// it is not possible to fix this without more subprojects. you are warned.
this.sendMessage(new LiteralText("§c" + this.setSpawnError + " This run is not verifiable."), false);
this.setSpawnError = null;
}
}

@Dynamic
@Group
// 1.17-1.18.2
@Inject(method = "method_14235(Lnet/minecraft/class_1703;)V", at = @At("TAIL"), require = 0, remap = false)
private void sendErrorMessage2(CallbackInfo ci) {
if (this.setSpawnError != null) {
// MutableText#formatted moved from BaseText in 1.16, can't compile against it
BaseText message = new LiteralText(this.setSpawnError + " This run is not verifiable.");
this.sendMessage(message.setStyle(message.getStyle().withFormatting(Formatting.RED)), false);
this.sendMessage(new LiteralText(this.setSpawnError + " This run is not verifiable.").formatted(Formatting.RED), false);
this.setSpawnError = null;
}
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class ServerPlayerEntityMixin {

@Dynamic
@WrapOperation(method = {"moveToSpawn", "method_14245(Lnet/minecraft/class_3218;Lnet/minecraft/class_2338;)Lnet/minecraft/class_2338;"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;nextInt(I)I"))
private int setSpawn(Random random, int bounds, Operation<Integer> original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef<Seed> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult, @Share("isRandomSpawn") LocalBooleanRef isRandomSpawn) {
private int setSpawn(Random random, int bounds, Operation<Integer> original, @Local(ordinal = 0) BlockPos worldSpawn, @Local(ordinal = 0) int spawnRadius, @Share("seed") LocalRef<Seed> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult, @Share("isRandomSpawn") LocalBooleanRef isRandomSpawn, @Share("newRandomValue") LocalRef<Integer> newRandomValue) {
// fallback for 1.21 with no else statement in the skylight check
isRandomSpawn.set(true);
int originalResult = original.call(random, bounds);
Expand All @@ -57,6 +57,7 @@ private int setSpawn(Random random, int bounds, Operation<Integer> 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 {
Expand All @@ -67,7 +68,7 @@ private int setSpawn(Random random, int bounds, Operation<Integer> 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> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult) {
private int fallbackOnInvalidSpawn(int p, @Local(ordinal = 2) int k, @Local(ordinal = 4) LocalIntRef o, @Share("seed") LocalRef<Seed> seed, @Share("originalRandomResult") LocalRef<Integer> originalRandomResult, @Share("newRandomValue") LocalRef<Integer> 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) {
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"