-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
146 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/gay/ampflower/musicmoods/client/WidgetAttachment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/gay/ampflower/musicmoods/mixin/MixinOptionsListEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
63 changes: 0 additions & 63 deletions
63
src/main/java/gay/ampflower/musicmoods/mixin/MixinSoundOptionsScreen.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters