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 Jan 18, 2023
1 parent 324f74d commit 9dae2df
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 81 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ org.gradle.jvmargs=-Xmx1G

# Your project's version
group=net.kjp12
projectVersion=0.0.2
projectVersion=0.1.0
modrinthId=z23qey0b
minecraftCompatible=1.19,1.19.1,1.19.2
minecraftCompatible=1.19.3
16 changes: 5 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +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"
yarn = "1.19.2+build.28"
minecraft_version = "1.19.3"
minecraft_required = ">=1.19.3"
quilt_loader = "0.17.+"
quilt_mappings = "1.19.2+build.21"
quilted_fabric_api = "4.0.0-beta.9+0.60.0-1.19.2"
quilted_fabric_api = "5.0.0-alpha.9+0.72.0-1.19.3"

# Plugins
loom = "1.+"
Expand All @@ -24,10 +22,6 @@ minotaur = "2.+"
# Minecraft & Quilt
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft_version" }
quilt_loader = { module = "org.quiltmc:quilt-loader", version.ref = "quilt_loader" }
quilt_mappings = { module = "org.quiltmc:quilt-mappings", version.ref = "quilt_mappings" }

# Yarn mappings if needed.
yarn = { module = "net.fabricmc:yarn", version.ref = "yarn" }

# Libraries
annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" }
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/kjp12/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
53 changes: 53 additions & 0 deletions src/main/java/net/kjp12/musicmoods/client/WidgetAttachment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright 2023 KJP12
*
* 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 net.kjp12.musicmoods.client;// Created 2023-17-01T20:34:47

import net.kjp12.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 KJP12
* @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);
}
}
28 changes: 28 additions & 0 deletions src/main/java/net/kjp12/musicmoods/mixin/MixinMinecraft.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright 2023 KJP12
*
* 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 net.kjp12.musicmoods.mixin;// Created 2023-17-01T21:38:15

import net.kjp12.musicmoods.client.WidgetAttachment;
import net.minecraft.client.Minecraft;
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;

/**
* Late-init hook because Quilt hooks in too early for what we need.
*
* @author KJP12
* @since 0.1.0
**/
@Mixin(Minecraft.class)
public class MixinMinecraft {
@Inject(method = "<init>", at = @At("RETURN"))
private void musicmoods$returnHook(CallbackInfo ci) {
WidgetAttachment.init((Minecraft) (Object) this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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 @@ -179,7 +179,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 @@ -195,6 +195,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 KJP12
*
* 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 net.kjp12.musicmoods.mixin;// Created 2023-17-01T20:06:21

import net.kjp12.musicmoods.Config;
import net.kjp12.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 KJP12
* @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.

3 changes: 2 additions & 1 deletion src/main/resources/music-moods.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"package": "net.kjp12.musicmoods.mixin",
"compatibilityLevel": "JAVA_17",
"client": [
"MixinMinecraft",
"MixinMusicManager",
"MixinSoundOptionsScreen",
"MixinOptionsListEntry",
"MixinWeighedSoundEvents"
],
"injectors": {
Expand Down

0 comments on commit 9dae2df

Please sign in to comment.