Skip to content

Commit

Permalink
one dot twenty one
Browse files Browse the repository at this point in the history
  • Loading branch information
imreallybadatnames committed Jun 14, 2024
1 parent 75b9968 commit d87d9c8
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 55 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

loom {
accessWidenerPath = file("src/main/resources/globalspawn.accesswidener")
}

repositories {
maven { url "https://maven.shedaniel.me/" } // cloth config
maven { url "https://maven.terraformersmc.com/" } // mod menu
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
org.gradle.jvmargs = -Xmx2G

# Fabric Properties
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.3
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11

# Mod Properties
mod_version = 1.7.0+1.20.6
mod_version = 1.7.0+1.21
maven_group = de.dafuqs.globalspawn
archives_base_name = globalspawn

# Dependencies
fabric_version=0.100.0+1.20.6
fabric_version=0.100.1+1.21
# https://shedaniel.gitbook.io/cloth-config/setup-cloth-config/cloth-config-fabric
cloth_config_version=14.0.126
modmenu_version=10.0.0-beta.1
cloth_config_version=15.0.127
modmenu_version=11.0.0-beta.1
2 changes: 1 addition & 1 deletion src/main/java/de/dafuqs/globalspawn/GlobalSpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void onInitialize() {

LOGGER.info("Registering Commands...");
ArgumentTypeRegistry.registerArgumentType(
new Identifier(MOD_ID, "spawn_criterion"),
Identifier.of(MOD_ID, "spawn_criterion"),
SpawnCriterionArgumentType.class,
ConstantArgumentSerializer.of(SpawnCriterionArgumentType::criterion)
);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/dafuqs/globalspawn/GlobalSpawnManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class GlobalSpawnManager {
// GENERAL
public static void initialize(MinecraftServer server) {
boolean shouldRespawnPointBeActive = GlobalSpawn.GLOBAL_SPAWN_CONFIG.globalRespawnPointActive;
RegistryKey<World> globalSpawnWorldKey = RegistryKey.of(RegistryKeys.WORLD, new Identifier(GlobalSpawn.GLOBAL_SPAWN_CONFIG.globalRespawnDimension));
RegistryKey<World> globalSpawnWorldKey = RegistryKey.of(RegistryKeys.WORLD, Identifier.of(GlobalSpawn.GLOBAL_SPAWN_CONFIG.globalRespawnDimension));
if (shouldRespawnPointBeActive && existsWorld(server, globalSpawnWorldKey)) {
int x = GlobalSpawn.GLOBAL_SPAWN_CONFIG.globalRespawnPositionX;
int y = GlobalSpawn.GLOBAL_SPAWN_CONFIG.globalRespawnPositionY;
Expand All @@ -29,7 +29,7 @@ public static void initialize(MinecraftServer server) {
}

boolean shouldInitialSpawnPointBeActive = GlobalSpawn.GLOBAL_SPAWN_CONFIG.initialSpawnPointActive;
RegistryKey<World> initialSpawnWorldKey = RegistryKey.of(RegistryKeys.WORLD, new Identifier(GlobalSpawn.GLOBAL_SPAWN_CONFIG.initialSpawnPointDimension));
RegistryKey<World> initialSpawnWorldKey = RegistryKey.of(RegistryKeys.WORLD, Identifier.of(GlobalSpawn.GLOBAL_SPAWN_CONFIG.initialSpawnPointDimension));
if (shouldInitialSpawnPointBeActive && existsWorld(server, initialSpawnWorldKey)) {
int x = GlobalSpawn.GLOBAL_SPAWN_CONFIG.initialSpawnPositionX;
int y = GlobalSpawn.GLOBAL_SPAWN_CONFIG.initialSpawnPositionY;
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/de/dafuqs/globalspawn/GlobalSpawnMixinHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,6 @@ public static NbtCompound modifySpawnRegistryPositionAndDimensionForExistingPlay
}
}

/**
* Moving a newly joined player to the world spawn
* @param serverPlayerEntity The player
*/
public static boolean movePlayerToSpawn(ServerPlayerEntity serverPlayerEntity) {
@Nullable BlockPos spawnBlockPos = null;
float angle = 0.0F;

if (GlobalSpawnManager.isInitialSpawnPointActive(serverPlayerEntity.server) && isNewPlayer(serverPlayerEntity)) {
spawnBlockPos = GlobalSpawnManager.getInitialSpawnPoint().getFinalSpawnPos(serverPlayerEntity.server);
angle = GlobalSpawnManager.getGlobalRespawnPoint().getAngle();
} else if (GlobalSpawnManager.isGlobalSpawnPointActive(serverPlayerEntity.server)) {
spawnBlockPos = GlobalSpawnManager.getGlobalRespawnPoint().getFinalSpawnPos(serverPlayerEntity.server);
angle = GlobalSpawnManager.getGlobalRespawnPoint().getAngle();
}

if (spawnBlockPos == null) {
return false;
}

serverPlayerEntity.refreshPositionAndAngles(spawnBlockPos, angle, 0.0F);
serverPlayerEntity.updatePosition(spawnBlockPos.getX() + 0.5F, spawnBlockPos.getY(), spawnBlockPos.getZ() + 0.5F);

return true;
}

public static boolean isNewPlayer(ServerPlayerEntity serverPlayerEntity) {
return serverPlayerEntity.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Stats.DEATHS)) == 0
&& serverPlayerEntity.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Stats.WALK_ONE_CM)) == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ public Optional<NbtCompound> loadPlayerData(Optional<NbtCompound> original, Serv
}
return Optional.of(nbt);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,18 @@ public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile
}
}

/**
* Called on spawn of a player
* @param world The default world
* @param callbackInfo CallbackInfo
*/
@Inject(method = "moveToSpawn", at = @At("HEAD"), cancellable = true)
private void globalspawn$moveToSpawn(ServerWorld world, CallbackInfo callbackInfo) {
if (GlobalSpawnMixinHandler.movePlayerToSpawn((ServerPlayerEntity) (Object) this)) {
callbackInfo.cancel();
}
}

@Unique
private boolean globalspawn$shouldOverrideRespawn() {
if(!GlobalSpawnManager.isGlobalSpawnPointActive(this.server)) {
return false;
}
if(!GlobalSpawnManager.isGlobalSpawnPointActive(this.server)) {
return false;
}

BlockPos blockPos = this.spawnPointPosition;
ServerWorld serverWorld = this.server.getWorld(spawnPointDimension);
if (serverWorld != null && blockPos != null) {
return PlayerEntity.findRespawnPosition(serverWorld, blockPos, this.spawnAngle, this.spawnForced, true).isEmpty();
return ServerPlayerEntity.findRespawnPosition(serverWorld, blockPos, this.spawnAngle, this.spawnForced, true).isEmpty();
} else {
return true;
}
}

}
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"mixins": [
"globalspawn.mixins.json"
],
"accessWidener": "globalspawn.accesswidener",
"depends": {
"minecraft": ">=1.20.5",
"minecraft": ">=1.21",
"fabricloader": "*",
"fabric": "*",
"cloth-config2": "*"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/globalspawn.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessWidener v2 named
accessible class net/minecraft/server/network/ServerPlayerEntity$RespawnPos
accessible method net/minecraft/server/network/ServerPlayerEntity findRespawnPosition (Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;FZZ)Ljava/util/Optional;

0 comments on commit d87d9c8

Please sign in to comment.