Skip to content

Commit

Permalink
Update to Minecraft 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ampflower committed Jun 29, 2024
1 parent 9f1cfe1 commit 2f5e61d
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 75 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ org.gradle.jvmargs=-Xmx1G
group=gay.ampflower
projectVersion=0.4.0
modrinthId=z23qey0b
minecraftCompatible=1.19,1.19.1,1.19.2
minecraftCompatible=1.19.3
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ annotations = "23.0.0"
lazydfu = "0.1.3"

# https://github.com/LambdAurora/SpruceUI
spruceui = "4.0.0+1.19"
modmenu = "4.1.1"
spruceui = "4.1.0+1.19.3"
modmenu = "5.0.2"

# Minecraft
minecraft_version = "1.19.2"
minecraft_required = ">=1.19 <=1.19.2"
minecraft_version = "1.19.3"
minecraft_required = "1.19.3"
fabric_loader = "0.15.+"
fabric_api = "0.77.0+1.19.2"
fabric_api = "0.72.0+1.19.3"

# Plugins
loom = "1.+"
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gay/ampflower/musicmoods/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public final class Constants {
public static final int twoColumnButtonOffset = 5;

public static final int smallButtonWidth = 20;
public static final int smallButtonOffset = 24;
public static final int smallButtonPlacementOffset = 4;
public static final int smallButtonOffset = smallButtonWidth + smallButtonPlacementOffset;

public static final int primaryButtonLeftOffset = buttonWidth + twoColumnButtonOffset;
public static final int primaryButtonRightOffset = primaryButtonLeftOffset + twoColumnButtonOffset;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright 2023 Ampflower
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package gay.ampflower.musicmoods.client;// Created 2023-17-01T20:34:47

import gay.ampflower.musicmoods.Constants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.OptionInstance;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.sounds.SoundSource;

import java.util.HashMap;
import java.util.Map;

/**
* @author Ampflower
* @since 0.1.0
**/
public final class WidgetAttachment {
public static final Map<OptionInstance<?>, WidgetFactory> binding = new HashMap<>();

public static void add(OptionInstance<?> instance, WidgetFactory factory) {
binding.put(instance, factory);
}

public static void init(final Minecraft minecraft) {
WidgetAttachment.add(minecraft.options.getSoundSourceOptionInstance(SoundSource.MUSIC), (widget, first) -> {
final int x = deriveX(widget, first, Constants.smallButtonWidth, Constants.smallButtonPlacementOffset);
final int y = widget.getY();

return new ImageButton(x, y, Constants.smallButtonWidth, Constants.smallButtonWidth, 0, 0,
Constants.smallButtonWidth, Constants.moodsResource, Constants.atlasSize, Constants.atlasSize,
button -> minecraft.setScreen(new ConfigurationScreen(minecraft.screen)));
});
}

public static int deriveX(final AbstractWidget reference, final boolean before, final int width, final int offset) {
if (before) {
return reference.getX() - width - offset;
} else {
return reference.getX() + reference.getWidth() + offset;
}
}

@FunctionalInterface
public interface WidgetFactory {
AbstractWidget createWidget(AbstractWidget widget, boolean first);
}
}
13 changes: 13 additions & 0 deletions src/main/java/gay/ampflower/musicmoods/mixin/MixinMinecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package gay.ampflower.musicmoods.mixin;// Created 2023-17-01T21:38:15

import gay.ampflower.musicmoods.client.WidgetAttachment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.sounds.MusicManager;
Expand All @@ -14,8 +15,10 @@
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.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* @author Ampflower
Expand All @@ -27,6 +30,16 @@ public abstract class MixinMinecraft {
@Nullable
public LocalPlayer player;

/**
* Late-init hook because Quilt hooks in too early for what we need.
*
* @since 0.1.0
*/
@Inject(method = "<init>", at = @At("RETURN"))
private void musicmoods$returnHook(CallbackInfo ci) {
WidgetAttachment.init((Minecraft) (Object) this);
}

/**
* Fixes underwater music constantly playing when set to always playing or
* replacing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public abstract class MixinMusicManager {
@Overwrite
public void tick() {
final var music = this.minecraft.getSituationalMusic();
final var musicLocation = music.getEvent().getLocation();
final var musicLocation = music.getEvent().value().getLocation();
// Cache the sound manager in a local.
final var soundManager = this.minecraft.getSoundManager();
var oldFadingOutMusic = this.fadingOutMusic;
Expand Down Expand Up @@ -150,7 +150,7 @@ private boolean isLoudAndCompatible(final MusicSoundInstance instance, final Res
@Unique
private boolean shouldReplace(final Music music) {
return (Config.situationalMusicReplacing == Replacing.always || music.replaceCurrentMusic())
&& this.isReplaceable(this.currentMusic, music.getEvent().getLocation());
&& this.isReplaceable(this.currentMusic, music.getEvent().value().getLocation());
}

@Unique
Expand Down Expand Up @@ -186,7 +186,7 @@ private int decrementSongDelay(int maxDelay) {
*/
@Unique
private void startPlayingFadeIn(Music music) {
this.currentMusic = new MusicSoundInstance(music.getEvent(), Config.fadeInTicks);
this.currentMusic = new MusicSoundInstance(music.getEvent().value(), Config.fadeInTicks);
if (this.currentMusic.getSound() != SoundManager.EMPTY_SOUND) {
this.minecraft.getSoundManager().play(this.currentMusic);
}
Expand All @@ -202,6 +202,6 @@ private void startPlayingFadeIn(Music music) {
@Redirect(method = "startPlaying", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sounds/MusicManager;currentMusic:Lnet/minecraft/client/resources/sounds/SoundInstance;", opcode = Opcodes.PUTFIELD))
private void musicmoods$setCustomSoundInstance(final MusicManager self, final SoundInstance value,
final Music music) {
this.currentMusic = new MusicSoundInstance(music.getEvent());
this.currentMusic = new MusicSoundInstance(music.getEvent().value());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* Copyright 2023 Ampflower
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package gay.ampflower.musicmoods.mixin;// Created 2023-17-01T20:06:21

import gay.ampflower.musicmoods.Config;
import gay.ampflower.musicmoods.client.WidgetAttachment;
import net.minecraft.client.OptionInstance;
import net.minecraft.client.gui.components.AbstractWidget;
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.ModifyArg;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

/**
* @author Ampflower
* @since 0.1.0
**/
@Mixin(targets = "net.minecraft.client.gui.components.OptionsList$Entry")
public class MixinOptionsListEntry {
@Shadow
@Final
Map<OptionInstance<?>, AbstractWidget> options;

@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableList;copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableList;"))
private Collection<AbstractWidget> musicmoods$modifyListBeforeSet(Collection<AbstractWidget> collection) {
if (!Config.injectUiComponents || collection.size() > 2 || collection.isEmpty()) {
return collection;
}

final var list = new ArrayList<AbstractWidget>(collection.size() * 2);

final var itr = this.options.entrySet().iterator();

{
final var current = itr.next();
final var value = current.getValue();

final var factory = WidgetAttachment.binding.get(current.getKey());
if (factory != null)
list.add(factory.createWidget(value, true));

list.add(value);
}

if (itr.hasNext()) {
final var current = itr.next();
final var value = current.getValue();

list.add(value);

final var factory = WidgetAttachment.binding.get(current.getKey());
if (factory != null)
list.add(factory.createWidget(value, false));
}

return list;
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/music-moods.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"client": [
"MixinMinecraft",
"MixinMusicManager",
"MixinSoundOptionsScreen",
"MixinOptionsListEntry",
"MixinWeighedSoundEvents"
],
"injectors": {
Expand Down

0 comments on commit 2f5e61d

Please sign in to comment.