diff --git a/gradle.properties b/gradle.properties index c4dd724..562cfe6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ loader_version=0.15.6-babric.6-bta mod_menu_version=2.0.6 # Mod -mod_version=4.0.7 +mod_version=4.0.8 mod_group=turniplabs mod_name=halplibe diff --git a/src/main/java/turniplabs/halplibe/mixin/accessors/StatListAccessor.java b/src/main/java/turniplabs/halplibe/mixin/accessors/StatListAccessor.java new file mode 100644 index 0000000..724d082 --- /dev/null +++ b/src/main/java/turniplabs/halplibe/mixin/accessors/StatListAccessor.java @@ -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 getStatMap(){ + throw new AssertionError(); + } +} diff --git a/src/main/java/turniplabs/halplibe/mixin/mixins/StatMixin.java b/src/main/java/turniplabs/halplibe/mixin/mixins/StatMixin.java new file mode 100644 index 0000000..d5790a7 --- /dev/null +++ b/src/main/java/turniplabs/halplibe/mixin/mixins/StatMixin.java @@ -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 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)); + } + } +} diff --git a/src/main/java/turniplabs/halplibe/mixin/mixins/registry/MinecraftServerMixin.java b/src/main/java/turniplabs/halplibe/mixin/mixins/registry/MinecraftServerMixin.java index ba5cee3..9868121 100644 --- a/src/main/java/turniplabs/halplibe/mixin/mixins/registry/MinecraftServerMixin.java +++ b/src/main/java/turniplabs/halplibe/mixin/mixins/registry/MinecraftServerMixin.java @@ -21,6 +21,9 @@ public void postInit(CallbackInfo ci) { m.invoke(null); m.setAccessible(false); I18n.initialize("en_US"); + StatList.init(); + StatList.onBlockInit(); + StatList.onItemInit(); } catch (Throwable err) { throw new RuntimeException(err); } diff --git a/src/main/resources/halplibe.mixins.json b/src/main/resources/halplibe.mixins.json index c4d8db7..763b684 100644 --- a/src/main/resources/halplibe.mixins.json +++ b/src/main/resources/halplibe.mixins.json @@ -9,12 +9,14 @@ "accessors.EntityFXAccessor", "accessors.LanguageAccessor", "accessors.RecipeSymbolAccessor", + "accessors.StatListAccessor", "accessors.TileEntityAccessor", "accessors.WeightedRandomBagAccessor", "accessors.WeightedRandomBagEntryAccessor", "mixins.BlockSoundDispatcherMixin", "mixins.ContainerPlayerCreativeMixin", "mixins.I18nMixin", + "mixins.StatMixin", "mixins.commands.CommandsCoreMixin", "mixins.network.PacketMixin", "mixins.registry.BlockMixin",