-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from kyrptonaught/master
Add support for syncing advancements
- Loading branch information
Showing
10 changed files
with
192 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
plugins { | ||
id 'fabric-loom' version '0.10.64' | ||
id 'fabric-loom' version '0.11-SNAPSHOT' | ||
id 'maven-publish' | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
# Done to increase the memory available to gradle. | ||
org.gradle.jvmargs=-Xmx1G | ||
org.gradle.jvmargs=-Xmx4G | ||
# Fabric Properties | ||
# check these on https://modmuss50.me/fabric.html | ||
|
||
# check these on https://fabricmc.net/develop/ | ||
minecraft_version=1.18.1 | ||
yarn_mappings=1.18.1+build.2 | ||
loader_version=0.12.12 | ||
yarn_mappings=1.18.1+build.22 | ||
loader_version=0.13.3 | ||
|
||
# Mod Properties | ||
mod_version=v2.1.3 | ||
mod_version=v2.2.0 | ||
maven_group=mrnavastar | ||
archives_base_name=invsync | ||
|
||
# Dependencies | ||
# check this on https://modmuss50.me/fabric.html | ||
fabric_version=0.43.1+1.18 | ||
fabric_version=0.46.6+1.18 | ||
sqlib_version=v1.2.1 | ||
cloth_version=6.0.42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package mrnavastar.invsync; | ||
|
||
import com.google.gson.JsonElement; | ||
import net.minecraft.server.ServerAdvancementLoader; | ||
|
||
public interface InvSyncPATAddon { | ||
|
||
void INVSYNC$load(ServerAdvancementLoader advancementLoader, JsonElement advancementData); | ||
|
||
JsonElement INVSYNC$save(); | ||
} |
103 changes: 103 additions & 0 deletions
103
src/main/java/mrnavastar/invsync/mixin/PlayerAdvancementTrackerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package mrnavastar.invsync.mixin; | ||
|
||
import com.google.common.collect.Maps; | ||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.reflect.TypeToken; | ||
import mrnavastar.invsync.InvSyncPATAddon; | ||
import net.minecraft.advancement.Advancement; | ||
import net.minecraft.advancement.AdvancementProgress; | ||
import net.minecraft.advancement.PlayerAdvancementTracker; | ||
import net.minecraft.server.ServerAdvancementLoader; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
@Mixin(PlayerAdvancementTracker.class) | ||
public abstract class PlayerAdvancementTrackerMixin implements InvSyncPATAddon { | ||
|
||
@Shadow | ||
public abstract void clearCriteria(); | ||
|
||
@Shadow | ||
@Final | ||
private Map<Advancement, AdvancementProgress> advancementToProgress; | ||
|
||
@Shadow | ||
@Final | ||
private Set<Advancement> visibleAdvancements; | ||
|
||
@Shadow | ||
@Final | ||
private Set<Advancement> visibilityUpdates; | ||
|
||
@Shadow | ||
@Final | ||
private Set<Advancement> progressUpdates; | ||
|
||
@Shadow | ||
private boolean dirty; | ||
|
||
@Shadow | ||
private @Nullable Advancement currentDisplayTab; | ||
|
||
@Shadow | ||
protected abstract void initProgress(Advancement advancement, AdvancementProgress progress); | ||
|
||
@Shadow | ||
protected abstract void rewardEmptyAdvancements(ServerAdvancementLoader advancementLoader); | ||
|
||
@Shadow | ||
protected abstract void updateCompleted(); | ||
|
||
@Shadow | ||
protected abstract void beginTrackingAllAdvancements(ServerAdvancementLoader advancementLoader); | ||
|
||
@Shadow | ||
@Final | ||
private static Gson GSON; | ||
|
||
@Shadow | ||
@Final | ||
private static TypeToken<Map<Identifier, AdvancementProgress>> JSON_TYPE; | ||
|
||
@Override | ||
public void INVSYNC$load(ServerAdvancementLoader advancementLoader, JsonElement advancementData) { | ||
this.clearCriteria(); | ||
this.advancementToProgress.clear(); | ||
this.visibleAdvancements.clear(); | ||
this.visibilityUpdates.clear(); | ||
this.progressUpdates.clear(); | ||
this.dirty = true; | ||
this.currentDisplayTab = null; | ||
|
||
Map<Identifier, AdvancementProgress> map = GSON.getAdapter(JSON_TYPE).fromJsonTree(advancementData); | ||
Stream<Map.Entry<Identifier, AdvancementProgress>> stream = map.entrySet().stream().sorted(Map.Entry.comparingByValue()); | ||
for (Map.Entry<Identifier, AdvancementProgress> entry : stream.toList()) { | ||
Advancement advancement = advancementLoader.get(entry.getKey()); | ||
if (advancement == null) continue; | ||
this.initProgress(advancement, entry.getValue()); | ||
} | ||
this.rewardEmptyAdvancements(advancementLoader); | ||
this.updateCompleted(); | ||
this.beginTrackingAllAdvancements(advancementLoader); | ||
} | ||
|
||
@Override | ||
public JsonElement INVSYNC$save() { | ||
HashMap<Identifier, AdvancementProgress> map = Maps.newHashMap(); | ||
for (Map.Entry<Advancement, AdvancementProgress> entry : this.advancementToProgress.entrySet()) { | ||
AdvancementProgress advancementProgress = entry.getValue(); | ||
if (!advancementProgress.isAnyObtained()) continue; | ||
map.put(entry.getKey().getId(), advancementProgress); | ||
} | ||
return GSON.toJsonTree(map); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"required": true, | ||
"package": "mrnavastar.invsync.mixin", | ||
"compatibilityLevel": "JAVA_17", | ||
"mixins": [ | ||
"PlayerAdvancementTrackerMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |