Skip to content

Commit cab321a

Browse files
committed
initial multiversion support and config subsystem reworking
1 parent bec7a16 commit cab321a

File tree

81 files changed

+1760
-277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1760
-277
lines changed

1.12/build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
plugins {
2+
id "loom"
3+
id "legacy-looming"
4+
}
5+
6+
loom {
7+
legacyLooming {
8+
intermediaryVersion.set(2)
9+
}
10+
}
11+
12+
dependencies {
13+
minecraft "com.mojang:minecraft:$minecraft_version"
14+
mappings(legacy.yarn(minecraft_version, yarn_build))
15+
include implementation(project(path: ":", configuration: "namedElements"))
16+
}

1.12/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minecraft_version=1.12
2+
yarn_build=542
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.set.spawn.mod.mixin;
2+
3+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
4+
import com.llamalad7.mixinextras.sugar.Share;
5+
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
6+
import net.minecraft.client.MinecraftClient;
7+
import net.minecraft.server.integrated.IntegratedServer;
8+
import net.minecraft.world.level.LevelInfo;
9+
import net.set.spawn.mod.interfaces.MinecraftServerExtended;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.injection.*;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
@Mixin(MinecraftClient.class)
15+
public abstract class MinecraftClientMixin {
16+
@Inject(method = "startIntegratedServer", at = @At("HEAD"))
17+
private void markIfNewWorld(String worldName, String levelName, LevelInfo levelInfo, CallbackInfo ci, @Share("newWorld") LocalBooleanRef newWorld) {
18+
newWorld.set(levelInfo != null);
19+
}
20+
21+
@ModifyExpressionValue(method = "startIntegratedServer", at = @At(value = "NEW", target = "net/minecraft/server/integrated/IntegratedServer"))
22+
private IntegratedServer createIntegratedServer(IntegratedServer original, @Share("newWorld") LocalBooleanRef newWorld) {
23+
((MinecraftServerExtended) original).setspawnmod$setShouldModifySpawn(newWorld.get());
24+
return original;
25+
}
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package net.set.spawn.mod.mixin;
2+
3+
import net.minecraft.server.MinecraftServer;
4+
import net.set.spawn.mod.interfaces.MinecraftServerExtended;
5+
import org.spongepowered.asm.mixin.*;
6+
7+
@Mixin(MinecraftServer.class)
8+
public abstract class MinecraftServerMixin implements MinecraftServerExtended {
9+
@Unique
10+
private boolean shouldModifySpawn = false;
11+
12+
@Override
13+
public boolean setspawnmod$shouldModifySpawn() {
14+
return shouldModifySpawn;
15+
}
16+
17+
@Override
18+
public void setspawnmod$setShouldModifySpawn(boolean shouldModifySpawn) {
19+
this.shouldModifySpawn = shouldModifySpawn;
20+
}
21+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package net.set.spawn.mod.mixin;
2+
3+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.*;
5+
import com.llamalad7.mixinextras.sugar.*;
6+
import com.llamalad7.mixinextras.sugar.ref.*;
7+
import net.minecraft.server.MinecraftServer;
8+
import net.minecraft.server.network.ServerPlayerEntity;
9+
import net.minecraft.text.*;
10+
import net.minecraft.util.Formatting;
11+
import net.minecraft.util.math.*;
12+
import net.set.spawn.mod.*;
13+
import net.set.spawn.mod.interfaces.MinecraftServerExtended;
14+
import org.spongepowered.asm.mixin.*;
15+
import org.spongepowered.asm.mixin.injection.*;
16+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
17+
18+
import java.util.Random;
19+
20+
@Mixin(ServerPlayerEntity.class)
21+
public abstract class ServerPlayerEntityMixin {
22+
@Unique
23+
private String setSpawnError;
24+
25+
@Shadow
26+
public abstract void sendMessage(Text text);
27+
28+
@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I", ordinal = 0))
29+
private int setSpawnX(Random random, int bounds, Operation<Integer> original, @Local(argsOnly = true) MinecraftServer server, @Local BlockPos worldSpawn, @Local int spawnRadius, @Share("seed") LocalRef<Seed> seed, @Share("zCoord") LocalRef<Integer> zCoord, @Share("isRandomSpawn") LocalBooleanRef isRandomSpawn) {
30+
isRandomSpawn.set(true);
31+
int originalResult = original.call(random, bounds);
32+
33+
if (((MinecraftServerExtended) server).setspawnmod$shouldModifySpawn()) {
34+
((MinecraftServerExtended) server).setspawnmod$setShouldModifySpawn(false);
35+
seed.set(SetSpawn.findSeedObjectFromLong(server.method_0_6351().method_8412()));
36+
}
37+
Seed seedObject = seed.get();
38+
if (seedObject == null) {
39+
return originalResult;
40+
}
41+
42+
// Transform x and z coordinates into correct Random#nextInt result.
43+
int resultX = MathHelper.floor(seedObject.getX()) - worldSpawn.getX() + spawnRadius;
44+
int resultZ = MathHelper.floor(seedObject.getZ()) - worldSpawn.getZ() + spawnRadius;
45+
46+
if (resultX >= 0 && resultX < bounds && resultZ >= 0 && resultZ < bounds) {
47+
zCoord.set(resultZ);
48+
System.out.println("Setting spawn");
49+
return resultX;
50+
} else {
51+
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.";
52+
}
53+
return originalResult;
54+
}
55+
56+
@ModifyExpressionValue(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I", ordinal = 1))
57+
private int setSpawnZ(int original, @Share("zCoord") LocalRef<Integer> zCoord) {
58+
// if zCoord is not null, it has been validated in the method
59+
return zCoord.get() != null ? zCoord.get() : original;
60+
}
61+
62+
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;refreshPositionAndAngles(Lnet/minecraft/util/math/BlockPos;FF)V"))
63+
private void failOnNonRandomSpawns(CallbackInfo ci, @Share("seed") LocalRef<Seed> seed, @Share("isRandomSpawn") LocalBooleanRef isRandomSpawn) {
64+
if (!isRandomSpawn.get() && seed.get() != null) {
65+
this.setSpawnError = "Failed to apply SetSpawn configuration because the spawn was not random. Not overriding player spawnpoint.";
66+
}
67+
}
68+
69+
@Inject(method = "onSpawn", at = @At("TAIL"))
70+
private void sendErrorMessage(CallbackInfo ci) {
71+
if (this.setSpawnError != null) {
72+
this.sendMessage(new LiteralTextContent(this.setSpawnError + " This run is not verifiable.").setStyle(new Style().withColor(Formatting.RED)));
73+
this.setSpawnError = null;
74+
}
75+
}
76+
}
44.9 KB
Loading
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"schemaVersion": 1,
3+
"id": "setspawnmod",
4+
"version": "${version}",
5+
"name": "Set Spawn",
6+
"description": "Sets the player's spawnpoint in SSG to specified coordinates.",
7+
"authors": [
8+
{
9+
"name": "bdamja",
10+
"contact": {
11+
"homepage": "https://github.com/bdamja"
12+
}
13+
}
14+
],
15+
"contributors": [
16+
"Void_X_Walker",
17+
"jan-leila",
18+
"RedLime",
19+
"tildejustin",
20+
"contaria"
21+
],
22+
"license": "LGPL-3.0-only",
23+
"icon": "assets/setspawnmod/icon.png",
24+
"environment": "*",
25+
"mixins": [
26+
"setspawnmod.mixins.json"
27+
],
28+
"depends": {
29+
"fabricloader": ">=0.15.0",
30+
"minecraft": [
31+
"1.12",
32+
"1.9.2-rv+trendy"
33+
]
34+
},
35+
"breaks": {
36+
"worldpreview": "*"
37+
}
38+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"required": true,
3+
"minVersion": "0.8",
4+
"package": "net.set.spawn.mod.mixin",
5+
"compatibilityLevel": "JAVA_8",
6+
"mixins": [
7+
"MinecraftServerMixin",
8+
"ServerPlayerEntityMixin"
9+
],
10+
"client": [
11+
"MinecraftClientMixin"
12+
],
13+
"injectors": {
14+
"defaultRequire": 1
15+
},
16+
"overwrites": {
17+
"conformVisibility": true,
18+
"requireAnnotations": true
19+
}
20+
}

1.13.x/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins {
2+
id "loom"
3+
id "legacy-looming"
4+
}
5+
6+
dependencies {
7+
minecraft "com.mojang:minecraft:$minecraft_version"
8+
mappings(legacy.yarn(minecraft_version, yarn_build))
9+
include implementation(project(path: ":", configuration: "namedElements"))
10+
}

1.13.x/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minecraft_version=1.13.2
2+
yarn_build=541

0 commit comments

Comments
 (0)