-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent crash with duplicate stat ids, instead return the old one.
- Loading branch information
1 parent
5b3b01e
commit 5d47518
Showing
5 changed files
with
50 additions
and
1 deletion.
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
17 changes: 17 additions & 0 deletions
17
src/main/java/turniplabs/halplibe/mixin/accessors/StatListAccessor.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,17 @@ | ||
package turniplabs.halplibe.mixin.accessors; | ||
|
||
import net.minecraft.core.achievement.stat.Stat; | ||
import net.minecraft.core.achievement.stat.StatList; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import java.util.Map; | ||
|
||
@Mixin(value = StatList.class,remap = false) | ||
public interface StatListAccessor { | ||
|
||
@Accessor | ||
static Map<Integer, Stat> getStatMap(){ | ||
throw new AssertionError(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/turniplabs/halplibe/mixin/mixins/StatMixin.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,27 @@ | ||
package turniplabs.halplibe.mixin.mixins; | ||
|
||
import net.minecraft.core.achievement.stat.Stat; | ||
import net.minecraft.core.achievement.stat.StatList; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import turniplabs.halplibe.mixin.accessors.StatListAccessor; | ||
|
||
@Mixin(value = Stat.class,remap = false) | ||
public class StatMixin{ | ||
|
||
@Shadow @Final public int statId; | ||
|
||
@Shadow @Final String statName; | ||
|
||
@Inject(method = "registerStat",at = @At("HEAD"), cancellable = true) | ||
public void registerStat(CallbackInfoReturnable<Stat> cir) { | ||
if (StatListAccessor.getStatMap().containsKey(this.statId)) { | ||
System.err.println("Duplicate stat id: \"" + (StatListAccessor.getStatMap().get(this.statId)).getStatName() + "\" and \"" + this.statName + "\" at id " + this.statId); | ||
cir.setReturnValue(StatListAccessor.getStatMap().get(this.statId)); | ||
} | ||
} | ||
} |
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