From 630fe610c5b424bffce6c40581d6a5cfb7cc3c62 Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Sat, 23 Dec 2023 00:14:39 +0100 Subject: [PATCH 1/3] Fix mixin crash, add option to auto fill missing step sounds --- .../java/me/andre111/mambience/config/Config.java | 14 ++++++++++++-- .../mambience/data/loader/FootstepLoader.java | 4 ++++ .../fabric/FootstepBlockMapGenerator.java | 4 ++++ .../mambience/fabric/config/ConfigScreen.java | 5 +++++ .../mambience/fabric/mixin/MixinLivingEntity.java | 4 ++-- .../resources/assets/mambience/lang/en_us.json | 3 ++- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/andre111/mambience/config/Config.java b/src/main/java/me/andre111/mambience/config/Config.java index 07f1745..ca3cf7e 100644 --- a/src/main/java/me/andre111/mambience/config/Config.java +++ b/src/main/java/me/andre111/mambience/config/Config.java @@ -237,10 +237,13 @@ public void setRandomTicks(int randomTicks) { public static class FootstepConfig { public static final boolean DEFAULT_ENABLED = true; public static final float DEFAULT_VOLUME = 0.3f; - + + public static final boolean DEFAULT_APPLY_SUGGESTIONS = true; + private boolean enabled = DEFAULT_ENABLED; private float volume = DEFAULT_VOLUME; - + private boolean applySuggestedSounds = DEFAULT_APPLY_SUGGESTIONS; + public boolean isEnabled() { return enabled; } @@ -253,5 +256,12 @@ public float getVolume() { public void setVolume(float volume) { this.volume = volume; } + + public boolean isApplyingSuggested() { + return applySuggestedSounds; + } + public void setApplySuggested(boolean enabled) { + this.applySuggestedSounds = enabled; + } } } diff --git a/src/main/java/me/andre111/mambience/data/loader/FootstepLoader.java b/src/main/java/me/andre111/mambience/data/loader/FootstepLoader.java index fed1b9a..c3c6f91 100644 --- a/src/main/java/me/andre111/mambience/data/loader/FootstepLoader.java +++ b/src/main/java/me/andre111/mambience/data/loader/FootstepLoader.java @@ -44,4 +44,8 @@ private static void loadToMap(Map> map, JsonObject obj) map.put(e.getKey(), Arrays.stream(e.getValue().getAsString().split(",")).map(id -> MaterialLoader.getMaterial(id)).toList()); } } + + public static void addBlock(String block, String type) { + BLOCK_MAP.put(block, Arrays.stream(type.split(",")).map(id -> MaterialLoader.getMaterial(id)).toList()); + } } diff --git a/src/main/java/me/andre111/mambience/fabric/FootstepBlockMapGenerator.java b/src/main/java/me/andre111/mambience/fabric/FootstepBlockMapGenerator.java index 9b78892..ab7cbaf 100644 --- a/src/main/java/me/andre111/mambience/fabric/FootstepBlockMapGenerator.java +++ b/src/main/java/me/andre111/mambience/fabric/FootstepBlockMapGenerator.java @@ -20,6 +20,7 @@ import me.andre111.mambience.MAmbience; import me.andre111.mambience.data.loader.FootstepLoader; +import me.andre111.mambience.config.Config; import net.minecraft.registry.Registries; import net.minecraft.sound.BlockSoundGroup; @@ -128,6 +129,9 @@ public static void scanForMissingBlockMapEntries() { if(!FootstepLoader.BLOCK_MAP.containsKey(id)) { String type = DEFAULT_SOUND_MAP.get(block.getSoundGroup(block.getDefaultState())); MAmbience.getLogger().error("\""+id+"\" is missing a footstep type entry - suggested: \""+type+"\""); + if (Config.footsteps().isApplyingSuggested() && type != null) { + FootstepLoader.addBlock(id, type); + } } }); } diff --git a/src/main/java/me/andre111/mambience/fabric/config/ConfigScreen.java b/src/main/java/me/andre111/mambience/fabric/config/ConfigScreen.java index 1114ee2..7e3e42d 100644 --- a/src/main/java/me/andre111/mambience/fabric/config/ConfigScreen.java +++ b/src/main/java/me/andre111/mambience/fabric/config/ConfigScreen.java @@ -133,6 +133,11 @@ public ConfigScreenFactory getModConfigScreenFactory() { .startIntSlider(Text.translatable("mambience.config.volume"), (int) (Config.footsteps().getVolume()*100), 0, 100) .setDefaultValue((int) (Config.FootstepConfig.DEFAULT_VOLUME*100)) .setSaveConsumer(i -> { Config.footsteps().setVolume(i/100.0f); }) + .build()) + .addEntry(entryBuilder + .startBooleanToggle(Text.translatable("mambience.config.apply_suggested"), Config.footsteps().isApplyingSuggested()) + .setDefaultValue(Config.FootstepConfig.DEFAULT_APPLY_SUGGESTIONS) + .setSaveConsumer(Config.footsteps()::setApplySuggested) .build()); // Scanner diff --git a/src/main/java/me/andre111/mambience/fabric/mixin/MixinLivingEntity.java b/src/main/java/me/andre111/mambience/fabric/mixin/MixinLivingEntity.java index 3e3dcaf..7a50195 100644 --- a/src/main/java/me/andre111/mambience/fabric/mixin/MixinLivingEntity.java +++ b/src/main/java/me/andre111/mambience/fabric/mixin/MixinLivingEntity.java @@ -41,8 +41,8 @@ public MixinLivingEntity(EntityType type, World world) { } @SuppressWarnings("resource") - @Inject(at = @At(value = "HEAD"), method = "swingHand(Lnet/minecraft/util/Hand;Z)V", cancellable = true) - public void swingHand(Hand hand, boolean fromServerPlayer, CallbackInfo ci) { + @Inject(at = @At(value = "HEAD"), method = "method_23667", require = 0) + private void swingHand(Hand hand, boolean fromServerPlayer, CallbackInfo ci) { if(!this.handSwinging && hand == Hand.MAIN_HAND && (Object) this instanceof PlayerEntity) { if(this.getWorld().isClient && !MAmbienceFabric.instance.runClientSide) return; diff --git a/src/main/resources/assets/mambience/lang/en_us.json b/src/main/resources/assets/mambience/lang/en_us.json index 93a0ee9..718aaf0 100644 --- a/src/main/resources/assets/mambience/lang/en_us.json +++ b/src/main/resources/assets/mambience/lang/en_us.json @@ -3,7 +3,8 @@ "mambience.config.enable": "Enabled", "mambience.config.volume": "Volume Multiplier", - + "mambience.config.apply_suggested": "Apply Suggested Sounds", + "mambience.config.sizex": "Size X", "mambience.config.sizex.tooltip": "Area centered around the player", "mambience.config.sizey": "Size Y", From 80afa9da97ecd01aabd964105851eaa5807f38b9 Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Sat, 10 Feb 2024 10:40:11 +0100 Subject: [PATCH 2/3] Rollback this change --- .../me/andre111/mambience/fabric/mixin/MixinLivingEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/andre111/mambience/fabric/mixin/MixinLivingEntity.java b/src/main/java/me/andre111/mambience/fabric/mixin/MixinLivingEntity.java index 7a50195..75a6e4a 100644 --- a/src/main/java/me/andre111/mambience/fabric/mixin/MixinLivingEntity.java +++ b/src/main/java/me/andre111/mambience/fabric/mixin/MixinLivingEntity.java @@ -41,7 +41,7 @@ public MixinLivingEntity(EntityType type, World world) { } @SuppressWarnings("resource") - @Inject(at = @At(value = "HEAD"), method = "method_23667", require = 0) + @Inject(at = @At(value = "HEAD"), method = "swingHand(Lnet/minecraft/util/Hand;Z)V", cancellable = true) private void swingHand(Hand hand, boolean fromServerPlayer, CallbackInfo ci) { if(!this.handSwinging && hand == Hand.MAIN_HAND && (Object) this instanceof PlayerEntity) { if(this.getWorld().isClient && !MAmbienceFabric.instance.runClientSide) return; From 3fec1b1d87249cd528fb837305971b9572798af2 Mon Sep 17 00:00:00 2001 From: Patbox Date: Sun, 19 May 2024 13:09:01 +0200 Subject: [PATCH 3/3] Merge upstream --- src/main/java/me/andre111/mambience/config/Config.java | 2 +- .../mambience/fabric/FootstepBlockMapGenerator.java | 5 +++-- .../me/andre111/mambience/fabric/config/ConfigScreen.java | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/andre111/mambience/config/Config.java b/src/main/java/me/andre111/mambience/config/Config.java index 23e4e98..62915d3 100644 --- a/src/main/java/me/andre111/mambience/config/Config.java +++ b/src/main/java/me/andre111/mambience/config/Config.java @@ -312,7 +312,7 @@ public void setVolume(float volume) { this.volume = volume; } - public boolean isApplyingSuggested() { + public boolean applySuggested() { return applySuggestedSounds; } public void setApplySuggested(boolean enabled) { diff --git a/src/main/java/me/andre111/mambience/fabric/FootstepBlockMapGenerator.java b/src/main/java/me/andre111/mambience/fabric/FootstepBlockMapGenerator.java index 0a7cf11..2f5ba4f 100644 --- a/src/main/java/me/andre111/mambience/fabric/FootstepBlockMapGenerator.java +++ b/src/main/java/me/andre111/mambience/fabric/FootstepBlockMapGenerator.java @@ -128,9 +128,10 @@ public static void scanForMissingBlockMapEntries() { String id = Registries.BLOCK.getId(block).toString(); if(!FootstepLoader.BLOCK_MAP.containsKey(id)) { String type = DEFAULT_SOUND_MAP.get(block.getDefaultState().getSoundGroup()); - MAmbience.getLogger().error("\""+id+"\" is missing a footstep type entry - suggested: \""+type+"\""); - if (Config.footsteps().isApplyingSuggested() && type != null) { + if (Config.movement().applySuggested() && type != null) { FootstepLoader.addBlock(id, type); + } else { + MAmbience.getLogger().error("\""+id+"\" is missing a footstep type entry - suggested: \""+type+"\""); } } }); diff --git a/src/main/java/me/andre111/mambience/fabric/config/ConfigScreen.java b/src/main/java/me/andre111/mambience/fabric/config/ConfigScreen.java index dd12f3e..ba60a7c 100644 --- a/src/main/java/me/andre111/mambience/fabric/config/ConfigScreen.java +++ b/src/main/java/me/andre111/mambience/fabric/config/ConfigScreen.java @@ -155,9 +155,9 @@ public ConfigScreenFactory getModConfigScreenFactory() { .setSaveConsumer(i -> { Config.movement().setVolume(i/100.0f); }) .build()) .addEntry(entryBuilder - .startBooleanToggle(Text.translatable("mambience.config.apply_suggested"), Config.footsteps().isApplyingSuggested()) - .setDefaultValue(Config.FootstepConfig.DEFAULT_APPLY_SUGGESTIONS) - .setSaveConsumer(Config.footsteps()::setApplySuggested) + .startBooleanToggle(Text.translatable("mambience.config.apply_suggested"), Config.movement().applySuggested()) + .setDefaultValue(Config.MovementConfig.DEFAULT_APPLY_SUGGESTIONS) + .setSaveConsumer(Config.movement()::setApplySuggested) .build()); // Scanner