Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport changes to 1.20.1 #90

Open
wants to merge 4 commits into
base: MC/fabric/1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/org/orecruncher/dsurround/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ public static class EntityEffects {
@Property
@RestartRequired(client = false)
@Comment("Enable/disable player toolbar sound effects")
public boolean enablePlayerToolbarEffect = false;
public boolean enablePlayerToolbarEffect = true;

@Property
@RestartRequired(client = false)
@Comment("Enable/disable item swing sound effects from players and mobs")
public boolean enableSwingEffect = false;
public boolean enableSwingEffect = true;

@Property
@RestartRequired(client = false)
Expand Down Expand Up @@ -276,11 +276,11 @@ public static class ParticleTweaks {
public static class CompassAndClockOptions {
@Property
@Comment("Enable/disable display of the clock display when holding a clock item")
public boolean enableClock = false;
public boolean enableClock = true;

@Property
@Comment("Enable/disable display of the compass display when holding a compass item")
public boolean enableCompass = false;
public boolean enableCompass = true;

@Property
@Comment("Style of compass rendering")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class BiomeLibrary implements IBiomeLibrary {
private final Map<SyntheticBiome, BiomeInfo> internalBiomes = new EnumMap<>(SyntheticBiome.class);

// Cached list of biome config rules. Need to hold onto them
// because they may be needed to handle dynamic biome load.
// because they may be needed to handle a dynamic biome load.
private final ObjectArray<BiomeConfigRule> biomeConfigs = new ObjectArray<>(64);

// Current version of the configs that are loaded. Used to detect when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.sounds.SoundSource;
import org.orecruncher.dsurround.eventing.ClientEventHooks;
import org.orecruncher.dsurround.eventing.CollectDiagnosticsEvent;
import org.orecruncher.dsurround.gui.overlay.IDiagnosticPlugin;
import org.orecruncher.dsurround.lib.GameUtils;
import org.orecruncher.dsurround.lib.events.HandlerPriority;
import org.orecruncher.dsurround.lib.gui.ColorPalette;
import org.orecruncher.dsurround.mixins.audio.MixinSoundManagerAccessor;
import org.orecruncher.dsurround.mixins.audio.MixinSoundEngineAccessor;

Expand All @@ -16,18 +19,29 @@
public class SoundEngineDiagnosticsPlugin implements IDiagnosticPlugin {

private static final String FMT_DBG_SOUND = "%s: %d";
private static final Style OFF_STYLE = Style.EMPTY.withColor(ColorPalette.RED);

public SoundEngineDiagnosticsPlugin() {
ClientEventHooks.COLLECT_DIAGNOSTICS.register(this::onCollect, HandlerPriority.LOW);
}

public void onCollect(CollectDiagnosticsEvent event) {
var soundManager = GameUtils.getSoundManager();
var panelText = event.getSectionText(CollectDiagnosticsEvent.Section.Sounds);

// Check the sound source volume settings because they can disable sounds
for (var category : SoundSource.values()) {
var volumeSettings = GameUtils.getGameSettings().getSoundSourceVolume(category);
if (Float.compare(volumeSettings, 0F) == 0) {
var text = Component.literal("%s is OFF".formatted(category.name())).withStyle(OFF_STYLE);
panelText.add(text);
}
}

MixinSoundManagerAccessor manager = (MixinSoundManagerAccessor) soundManager;
MixinSoundEngineAccessor accessors = (MixinSoundEngineAccessor) manager.dsurround_getSoundSystem();
var sources = accessors.dsurround_getSources();
var str = Component.literal(soundManager.getDebugString());
var panelText = event.getSectionText(CollectDiagnosticsEvent.Section.Sounds);
panelText.add(str);

if (!sources.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.orecruncher.dsurround.config.IndividualSoundConfigEntry;
import org.orecruncher.dsurround.config.libraries.ISoundLibrary;
import org.orecruncher.dsurround.lib.GameUtils;
import org.orecruncher.dsurround.lib.di.ContainerManager;

import java.util.*;
Expand Down Expand Up @@ -53,6 +53,11 @@ public int getRowWidth() {
return this.width;
}

public void setRowWidth(int width) {
this.width = width - 40; // 40 for scrollbar
this.children().forEach(c -> c.setWidth(this.width));
}

@Override
protected int getScrollbarPosition() {
return (this.parent.width + this.getRowWidth()) / 2 + 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.util.FormattedCharSequence;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -19,14 +21,12 @@
import org.orecruncher.dsurround.lib.di.ContainerManager;
import org.orecruncher.dsurround.lib.gui.ColorPalette;
import org.orecruncher.dsurround.lib.gui.GuiHelpers;
import org.orecruncher.dsurround.lib.gui.TextWidget;
import org.orecruncher.dsurround.lib.platform.IPlatform;
import org.orecruncher.dsurround.sound.IAudioPlayer;
import org.orecruncher.dsurround.sound.SoundMetadata;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.*;

public class IndividualSoundControlListEntry extends ContainerObjectSelectionList.Entry<IndividualSoundControlListEntry> implements AutoCloseable {

Expand All @@ -53,6 +53,7 @@ public class IndividualSoundControlListEntry extends ContainerObjectSelectionLis
private static final int CONTROL_SPACING = 3;

private final IndividualSoundConfigEntry config;
private final TextWidget label;
private final VolumeSliderControl volume;
private final BlockButton blockButton;
private final CullButton cullButton;
Expand All @@ -65,6 +66,10 @@ public class IndividualSoundControlListEntry extends ContainerObjectSelectionLis

public IndividualSoundControlListEntry(final IndividualSoundConfigEntry data, final boolean enablePlay) {
this.config = data;

this.label = new TextWidget(0, 0, 200, GameUtils.getTextRenderer().lineHeight, Component.literal(data.soundEventId.toString()), GameUtils.getTextRenderer());
this.children.add(this.label);

this.volume = new VolumeSliderControl(this, 0, 0);
this.children.add(this.volume);

Expand All @@ -83,13 +88,23 @@ public IndividualSoundControlListEntry(final IndividualSoundConfigEntry data, fi
}

public int getWidth() {
int width = GameUtils.getTextRenderer().width(this.config.soundEventId.toString());
int width = this.label.getWidth();
width += this.cullButton.getWidth() + this.blockButton.getWidth() + this.volume.getWidth() + 4 * CONTROL_SPACING;
if (this.playButton != null)
width += this.playButton.getWidth() + CONTROL_SPACING;
return width;
}

public void setWidth(int width) {
var fixedWidth = this.cullButton.getWidth() + this.blockButton.getWidth() + this.volume.getWidth() + 4 * CONTROL_SPACING;
if (this.playButton != null)
fixedWidth += this.playButton.getWidth() + CONTROL_SPACING;
width -= fixedWidth;
if (width < 100)
width = 100;
this.label.setWidth(width);
}

public void mouseMoved(double mouseX, double mouseY) {
AbstractWidget child = this.findChild(mouseX, mouseY);
if (child != null)
Expand Down Expand Up @@ -147,11 +162,12 @@ private AbstractWidget findChild(double mouseX, double mouseY) {
}

@Override
public void render(final GuiGraphics context, int index, int rowTop, int rowLeft, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean mouseOver, float partialTick_) {
public void render(final @NotNull GuiGraphics context, int index, int rowTop, int rowLeft, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean mouseOver, float partialTick_) {
final var font = GameUtils.getTextRenderer();
final int labelY = rowTop + (rowHeight - font.lineHeight) / 2;
final String text = this.config.soundEventIdProjected;
context.drawString(font, text, rowLeft, labelY, ColorPalette.MC_WHITE.getValue(), false);

this.label.setX(rowLeft);
this.label.setY(labelY);

// Need to position the other controls appropriately
int rightMargin = rowLeft + rowWidth;
Expand Down Expand Up @@ -232,7 +248,7 @@ protected List<FormattedCharSequence> getToolTip(final int mouseX, final int mou
// Cache the static part of the tooltip if needed
if (this.cachedToolTip.isEmpty()) {
ResourceLocation id = this.config.soundEventId;
PLATFORM.getModDisplayName(id.getNamespace())
this.resolveDisplayName(id.getNamespace())
.ifPresent(name -> {
FormattedCharSequence modName = FormattedCharSequence.forward(Objects.requireNonNull(ChatFormatting.stripFormatting(name)), STYLE_MOD_NAME);
this.cachedToolTip.add(modName);
Expand Down Expand Up @@ -293,6 +309,18 @@ protected List<FormattedCharSequence> getToolTip(final int mouseX, final int mou
return generatedTip;
}

private Optional<String> resolveDisplayName(String namespace) {
var displayName = PLATFORM.getModDisplayName(namespace);
if (displayName.isPresent())
return displayName;

// Could be a resource pack
return GameUtils.getResourceManager().listPacks()
.filter(pack -> pack.getNamespaces(PackType.CLIENT_RESOURCES).contains(namespace))
.map(PackResources::packId)
.findAny();
}

/**
* Retrieves the updated data from the entry
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.util.Mth;
import org.orecruncher.dsurround.lib.GameUtils;
import org.orecruncher.dsurround.lib.gui.ColorPalette;

Expand Down Expand Up @@ -133,6 +134,8 @@ public boolean charTyped(char codePoint, int modifiers) {
}

public void render(final GuiGraphics context, int mouseX, int mouseY, float partialTicks) {
var renderWidth = Mth.clamp(context.guiWidth() - 20, 200, SELECTION_WIDTH);
this.soundConfigList.setRowWidth(renderWidth);
if (this.parent == null)
this.renderBackground(context);
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.orecruncher.dsurround.gui.sound;

import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.Music;
import org.orecruncher.dsurround.config.libraries.ISoundLibrary;
import org.orecruncher.dsurround.lib.GameUtils;
import org.orecruncher.dsurround.lib.di.ContainerManager;
import org.orecruncher.dsurround.lib.gui.ColorPalette;
import org.orecruncher.dsurround.lib.gui.WarmToast;

public class SoundToast {

private static final WarmToast.Profile SOUND_TOAST_PROFILE = new WarmToast.Profile(new ResourceLocation("toast/advancement"), 5000, ColorPalette.PUMPKIN_ORANGE, ColorPalette.WHEAT);

public static void create(Music music) {
var soundLibrary = ContainerManager.resolve(ISoundLibrary.class);
var metadata = soundLibrary.getSoundMetadata(music.getEvent().value().getLocation());
Expand All @@ -18,7 +22,7 @@ public static void create(Music music) {
var author = metadata.getCredits().get(0).author();
var titleLine = Component.translatable("dsurround.text.toast.music.title", title);
var authorLine = Component.translatable("dsurround.text.toast.music.author", author);
var toast = WarmToast.multiline(GameUtils.getMC(), titleLine, authorLine);
var toast = WarmToast.multiline(GameUtils.getMC(), SOUND_TOAST_PROFILE, titleLine, authorLine);
GameUtils.getMC().getToasts().addToast(toast);
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/orecruncher/dsurround/lib/gui/TextWidget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.orecruncher.dsurround.lib.gui;

import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractStringWidget;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;

public class TextWidget extends AbstractStringWidget {

public TextWidget(int x, int y, int width, int height, Component component, Font font) {
super(x, y, width, height, component, font);
}

@Override
protected void renderWidget(@NotNull GuiGraphics guiGraphics, int i, int j, float f) {
int y = getY();

int nameWidth = this.getFont().width(this.getMessage());
if (nameWidth > getWidth()) {
renderScrollingString(guiGraphics, this.getFont(), this.getMessage(), getX(), y, getX() + getWidth(), y + this.getFont().lineHeight, -1);
} else {
guiGraphics.drawString(this.getFont(), this.getMessage(), getX(), y, 0xFFFFFF);
}
}
}
Loading
Loading