Skip to content

Commit

Permalink
NeoForge: Fixing issue with player save/load mixin not working on ser…
Browse files Browse the repository at this point in the history
…vers
  • Loading branch information
Brian-Wuest committed Nov 28, 2024
1 parent 683229e commit 654a7ce
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
8 changes: 4 additions & 4 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java-library'
id 'maven-publish'
id 'net.neoforged.moddev' version '1.0.17'
id 'net.neoforged.moddev' version '1.0.21'
}

tasks.named('wrapper', Wrapper).configure {
Expand Down Expand Up @@ -169,6 +169,9 @@ var generateModMetadata = tasks.register("generateModMetadata", ProcessResources
// this works with both building through Gradle and the IDE.
sourceSets.main.resources.srcDir generateModMetadata

// To avoid having to run "generateModMetadata" manually, make it run on every project reload
neoForge.ideSyncTask generateModMetadata

sourceSets {
main {
java {
Expand All @@ -181,9 +184,6 @@ sourceSets {
}
}

// To avoid having to run "generateModMetadata" manually, make it run on every project reload
neoForge.ideSyncTask generateModMetadata

// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
Expand Down
6 changes: 3 additions & 3 deletions NeoForge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ mod_version=1.0.1
cloth_config_version=15.0.140

# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=21.1.62
neo_version=21.1.83

#read more on this at https://github.com/neoforged/ModDevGradle?tab=readme-ov-file#better-minecraft-parameter-names--javadoc-parchment
# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started
parchment_minecraft_version=1.21
parchment_mappings_version=2024.07.28
parchment_minecraft_version=1.21.1
parchment_mappings_version=2024.11.13

# Environment Properties
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
Expand Down
4 changes: 2 additions & 2 deletions NeoForge/src/main/resources/prefab.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"package": "com.prefab.mixins",
"refmap": "prefab.refmap.json",
"mixins": [
"SavePlayerDataMixin"
],
"client": [
"RenderIndicatorMixin",
"AnvilScreenHandlerMixin",
"MinecraftClientInitMixin",
"SavePlayerDataMixin"
"MinecraftClientInitMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
25 changes: 16 additions & 9 deletions Shared/src/com/prefab/mixins/SavePlayerDataMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,40 @@ public class SavePlayerDataMixin {

@Inject(method = "addAdditionalSaveData", at = @At("TAIL"))
private void writeCustomDataToTag(CompoundTag tag, CallbackInfo ci) {
UUID prefabPlayerTag = this.gameProfile.getId();
UUID prefabPlayerId = this.gameProfile.getId();
EntityPlayerConfiguration prefabConfiguration;

if (!EntityPlayerConfiguration.playerTagData.containsKey(prefabPlayerTag)) {
if (!EntityPlayerConfiguration.playerTagData.containsKey(prefabPlayerId)) {
prefabConfiguration = new EntityPlayerConfiguration();

} else {
prefabConfiguration = EntityPlayerConfiguration.playerTagData.get(prefabPlayerTag);
prefabConfiguration = EntityPlayerConfiguration.playerTagData.get(prefabPlayerId);
}

tag.put("PrefabTag", prefabConfiguration.createPlayerTag());
CompoundTag prefabTag = prefabConfiguration.createPlayerTag();
tag.put("PrefabTag", prefabTag);
//PrefabBase.logger.info("Saving prefab tag information to player data.", prefabTag);
}

@Inject(method = "readAdditionalSaveData", at = @At("TAIL"))
private void readCustomDataFromTag(CompoundTag tag, CallbackInfo ci) {
UUID prefabPlayerTag = this.gameProfile.getId();
UUID prefabPlayerId = this.gameProfile.getId();

EntityPlayerConfiguration prefabConfiguration = new EntityPlayerConfiguration();

if (tag.contains("PrefabTag")) {
prefabConfiguration.loadFromNBTTagCompound(tag.getCompound("PrefabTag"));
CompoundTag prefabTag = tag.getCompound("PrefabTag");

//PrefabBase.logger.info("Loading prefab tag information from player data.", prefabTag);
prefabConfiguration.loadFromNBTTagCompound(prefabTag);
}

if (!EntityPlayerConfiguration.playerTagData.containsKey(prefabPlayerTag)) {
EntityPlayerConfiguration.playerTagData.put(prefabPlayerTag, prefabConfiguration);
//PrefabBase.logger.info("Placing prefab player config data into static dictionary for player id.");

if (!EntityPlayerConfiguration.playerTagData.containsKey(prefabPlayerId)) {
EntityPlayerConfiguration.playerTagData.put(prefabPlayerId, prefabConfiguration);
} else {
EntityPlayerConfiguration.playerTagData.replace(prefabPlayerTag, prefabConfiguration);
EntityPlayerConfiguration.playerTagData.replace(prefabPlayerId, prefabConfiguration);
}
}
}

1 comment on commit 654a7ce

@Brian-Wuest
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #296

Please sign in to comment.