Skip to content

Commit

Permalink
Allow Disabling Advancements + Narrator
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 19, 2024
1 parent adc6735 commit d3923c6
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ public static class Advanced {
@Config.LangKey("config.nomilabs.advanced.disable_xp_scaling")
public boolean disableXpScaling = false;

@Config.Comment({"Whether to disable Advancements.",
"Increases Load Speed, and reduces log errors.",
"[default: false]"})
@Config.LangKey("config.nomilabs.advanced.disable_advancements")
public boolean disableAdvancements = false;

@Config.Comment({"Whether to disable the Narrator.",
"Fixes Crashes in Arm Macs, in some very specific environments.",
"If your game is crashing, try enabling this!",
"[default: false]"})
@Config.LangKey("config.nomilabs.advanced.disable_narrator")
public boolean disableNarrator = false;

@Config.Comment({"Whether to enable Nomi-CEu data fixes.",
"This is used for Nomi-CEu, for players coming from before core-mod.",
"If this mod is being used in other scenarios, leave this at false, as this may break worlds!",
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/core/LabsCore.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.nomiceu.nomilabs.core;

import com.google.common.collect.ImmutableList;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import org.jetbrains.annotations.Nullable;
import zone.rong.mixinbooter.IEarlyMixinLoader;

import java.util.List;
import java.util.Map;

@IFMLLoadingPlugin.Name("LabsCore")
@IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion)
@IFMLLoadingPlugin.SortingIndex(1001)
public class LabsCore implements IFMLLoadingPlugin, IEarlyMixinLoader {
@Override
public String[] getASMTransformerClass() {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/mixin/AdvancementListMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.nomiceu.nomilabs.mixin;

import com.nomiceu.nomilabs.config.LabsConfig;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementList;
import net.minecraft.util.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Map;

@Mixin(value = AdvancementList.class)
public class AdvancementListMixin {
@Inject(method = "loadAdvancements(Ljava/util/Map;)V", at = @At("HEAD"), cancellable = true)
public void cancelAdvancements(Map<ResourceLocation, Advancement.Builder> advancementsIn, CallbackInfo ci) {
if (LabsConfig.advanced.disableAdvancements) ci.cancel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.nomiceu.nomilabs.mixin;

import com.nomiceu.nomilabs.config.LabsConfig;
import net.minecraft.advancements.AdvancementList;
import net.minecraft.advancements.AdvancementManager;
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.CallbackInfo;

@Mixin(value = AdvancementManager.class)
public class AdvancementManagerMixin {
@Shadow
@Final
private static AdvancementList ADVANCEMENT_LIST;

@Inject(method = "reload()V", at = @At("HEAD"), cancellable = true)
public void reloadWithoutAdvancements(CallbackInfo ci) {
if (!LabsConfig.advanced.disableAdvancements) return;
ADVANCEMENT_LIST.clear();
ci.cancel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.nomiceu.nomilabs.mixin;

import com.nomiceu.nomilabs.config.LabsConfig;
import net.minecraft.advancements.AdvancementList;
import net.minecraft.client.multiplayer.ClientAdvancementManager;
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.CallbackInfo;

@Mixin(value = ClientAdvancementManager.class)
public class ClientAdvancementManagerMixin {
@Shadow
@Final
private AdvancementList advancementList;

@Inject(method = "read(Lnet/minecraft/network/play/server/SPacketAdvancementInfo;)V", at = @At("HEAD"), cancellable = true)
public void reloadWithoutAdvancements(CallbackInfo ci) {
if (!LabsConfig.advanced.disableAdvancements) return;
advancementList.clear();
ci.cancel();
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/mixin/NarratorMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nomiceu.nomilabs.mixin;

import com.mojang.text2speech.Narrator;
import com.mojang.text2speech.NarratorDummy;
import com.nomiceu.nomilabs.config.LabsConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@SuppressWarnings("PublicStaticMixinMember")
@Mixin(value = Narrator.class, remap = false)
public interface NarratorMixin {
@Inject(method = "getNarrator", at = @At("HEAD"), cancellable = true, remap = false)
static void getDummyNarrator(CallbackInfoReturnable<Narrator> cir) {
if (LabsConfig.advanced.disableNarrator) cir.setReturnValue(new NarratorDummy());
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/nomilabs/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ config.nomilabs.mod_integration.draconicevolution.auto_destructor_speed=Auto Des
config.nomilabs.advanced=Advanced Settings
config.nomilabs.advanced.allow_other_modes=Allow Other Modes
config.nomilabs.advanced.disable_xp_scaling=Disable Anvil XP Scaling
config.nomilabs.advanced.disable_advancements=Disable Advancements
config.nomilabs.advanced.disable_narrator=Disable Narrator
config.nomilabs.advanced.enable_nomi_ceu_data_fixes=Enable Nomi-CEu Specific Data Fixes
config.nomilabs.advanced.ignore_items=ITEM Missing Registry Ignore List
config.nomilabs.advanced.ignore_blocks=BLOCK Missing Registry Ignore List
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/mixins.nomilabs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"AdvancementListMixin",
"AdvancementManagerMixin",
"ItemStackMixin",
"NarratorMixin",
"WorldLoadHandler"
],
"client": [],
"client": [
"ClientAdvancementManagerMixin"
],
"server": []
}

0 comments on commit d3923c6

Please sign in to comment.