Skip to content
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
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ org.gradle.configuration-cache=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.10
yarn_mappings=1.21.10+build.3
minecraft_version=1.21.11
yarn_mappings=1.21.11+build.4
loader_version=0.19.2
loom_version=1.16.1

Expand All @@ -17,4 +17,4 @@ mod_version=2.2.2
maven_group=de.rettichlp

# Dependencies
fabric_api_version=0.138.4+1.21.10
fabric_api_version=0.141.3+1.21.11
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;

import static net.minecraft.text.Text.empty;
import static net.minecraft.text.Text.translatable;

public class ItemButtonWidget extends ButtonWidget {

private final Item item;

public ItemButtonWidget(String key, Item item, PressAction onPress) {
super(0, 0, 20, 20, Text.empty(), onPress, DEFAULT_NARRATION_SUPPLIER);
super(0, 0, 20, 20, empty(), onPress, DEFAULT_NARRATION_SUPPLIER);
this.item = item;
setTooltip(Tooltip.of(translatable(key)));
}

@Override
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
super.renderWidget(context, mouseX, mouseY, delta);
protected void drawIcon(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
drawButton(context);

int x = getX() + (getWidth() / 2) - 8;
int y = getY() + (getHeight() / 2) - 8;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package de.rettichlp.ucutils.common.gui.screens.components;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.input.AbstractInput;
import net.minecraft.text.Text;

import java.util.function.Consumer;

import static net.minecraft.client.gui.DrawContext.HoverType.NONE;
import static net.minecraft.screen.ScreenTexts.OFF;
import static net.minecraft.screen.ScreenTexts.ON;
import static net.minecraft.text.Text.empty;
Expand All @@ -16,11 +17,11 @@

public class ToggleButtonWidget extends ButtonWidget {

private final Text text;
private final net.minecraft.text.Text text;
private final Consumer<Boolean> changeListener;
private boolean state;

public ToggleButtonWidget(Text text, Consumer<Boolean> changeListener, boolean defaultState) {
public ToggleButtonWidget(net.minecraft.text.Text text, Consumer<Boolean> changeListener, boolean defaultState) {
super(0, 0, 150, 20, empty(), button -> {}, DEFAULT_NARRATION_SUPPLIER);
this.text = text;
this.changeListener = changeListener;
Expand All @@ -36,11 +37,17 @@ public void onPress(AbstractInput input) {
setMessage(getText());
}

@Override
protected void drawIcon(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
drawButton(context);
drawLabel(context.getHoverListener(this, NONE));
}

public void updateText() {
setMessage(getText());
}

private Text getText() {
private net.minecraft.text.Text getText() {
return this.text.copy()
.append(of(":").copy().formatted(GRAY)).append(" ")
.append(this.state ? ON.copy().formatted(GREEN) : OFF.copy().formatted(RED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ public void initBody() {

stream(Faction.values())
.filter(faction -> faction != NULL)
.map(faction -> new CyclingButtonWidget.Builder<>(Color::getDisplayName)
.values(Color.values())
.initially(configuration.getOptions().nameTag().highlightFactions().getOrDefault(faction, WHITE))
.build(of(faction.getDisplayName()), (button, value) -> configuration.getOptions().nameTag().highlightFactions().put(faction, value)))
.map(faction -> {
Color initialValue = configuration.getOptions().nameTag().highlightFactions().getOrDefault(faction, WHITE);
return new CyclingButtonWidget.Builder<>(Color::getDisplayName, () -> initialValue)
.values(Color.values())
.build(of(faction.getDisplayName()), (button, value) -> configuration.getOptions().nameTag().highlightFactions().put(faction, value));
})
.forEach(adder::add);

return gridWidget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ public static class Configuration extends UCUtilsWidgetConfiguration implements

@Override
public Widget optionsWidget() {
return CyclingButtonWidget.builder(Style::getDisplayName)
return CyclingButtonWidget.builder(Style::getDisplayName, this.style)
.values(Style.values())
.initially(this.style)
.tooltip(Style::getTooltip)
.build(WIDGETS_CAR_LOCKED_OPTIONS_STYLE_NAME, (button, style) -> this.style = style);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/rettichlp/ucutils/common/models/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.jetbrains.annotations.NotNull;

import static de.rettichlp.ucutils.UCUtils.configuration;
import static net.minecraft.client.sound.PositionedSoundInstance.master;
import static net.minecraft.client.sound.PositionedSoundInstance.ui;

@Getter
@AllArgsConstructor
Expand All @@ -36,14 +36,14 @@ public enum Sound {

public void play() {
if (configuration.getOptions().customSounds()) {
PositionedSoundInstance positionedSoundInstance = master(getSoundEvent(), 1.0F, 1.0F);
PositionedSoundInstance positionedSoundInstance = ui(getSoundEvent(), 1.0F, 1.0F);
MinecraftClient.getInstance().getSoundManager().play(positionedSoundInstance);
}
}

public void play(float pitch, float volume) {
if (configuration.getOptions().customSounds()) {
PositionedSoundInstance positionedSoundInstance = master(getSoundEvent(), pitch, volume);
PositionedSoundInstance positionedSoundInstance = ui(getSoundEvent(), pitch, volume);
MinecraftClient.getInstance().getSoundManager().play(positionedSoundInstance);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import static java.util.stream.StreamSupport.stream;
import static net.minecraft.client.font.TextRenderer.TextLayerType.SEE_THROUGH;
import static net.minecraft.client.gui.widget.DirectionalLayoutWidget.horizontal;
import static net.minecraft.client.render.RenderLayer.getDebugQuads;
import static net.minecraft.client.render.RenderLayer.getLines;
import static net.minecraft.client.render.RenderLayers.debugQuads;
import static net.minecraft.client.render.RenderLayers.lines;
import static net.minecraft.item.Items.COMPARATOR;
import static net.minecraft.util.math.RotationAxis.POSITIVE_Y;
import static org.atteo.classindex.ClassIndex.getAnnotated;
Expand Down Expand Up @@ -73,9 +73,9 @@ public void drawOutline(@NotNull MatrixStack matrices,
double z2,
Color color) {
Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera();
double camX = camera.getPos().x;
double camY = camera.getPos().y;
double camZ = camera.getPos().z;
double camX = camera.getCameraPos().x;
double camY = camera.getCameraPos().y;
double camZ = camera.getCameraPos().z;

float minX = (float) (x1 - camX);
float minY = (float) (y1 - camY);
Expand All @@ -84,7 +84,7 @@ public void drawOutline(@NotNull MatrixStack matrices,
float maxY = (float) (y2 - camY);
float maxZ = (float) (z2 - camZ);

VertexConsumer consumer = vertexConsumers.getBuffer(getLines());
VertexConsumer consumer = vertexConsumers.getBuffer(lines());
Matrix4f matrix = matrices.peek().getPositionMatrix();

drawLine(consumer, matrix, minX, minY, minZ, maxX, minY, minZ, color);
Expand All @@ -111,15 +111,15 @@ public void drawArea(@NotNull MatrixStack matrices,
float z,
@NotNull Color color) {
Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera();
double camX = camera.getPos().x;
double camY = camera.getPos().y;
double camZ = camera.getPos().z;
double camX = camera.getCameraPos().x;
double camY = camera.getCameraPos().y;
double camZ = camera.getCameraPos().z;

float modifiedX = (float) (x - camX);
float modifiedY = (float) (y - camY);
float modifiedZ = (float) (z - camZ);

VertexConsumer consumer = vertexConsumers.getBuffer(getDebugQuads());
VertexConsumer consumer = vertexConsumers.getBuffer(debugQuads());
Matrix4f matrix = matrices.peek().getPositionMatrix();

Color alphaColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);
Expand Down Expand Up @@ -215,9 +215,9 @@ public void renderTextAt(@NotNull MatrixStack matrices,
matrices.push();

Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera();
double camX = camera.getPos().x;
double camY = camera.getPos().y;
double camZ = camera.getPos().z;
double camX = camera.getCameraPos().x;
double camY = camera.getCameraPos().y;
double camZ = camera.getCameraPos().z;

matrices.translate(x - camX, y - camY, z - camZ);

Expand Down Expand Up @@ -278,9 +278,9 @@ public <E extends CyclingButtonEntry> void addCyclingButton(@NotNull Directional
BiConsumer<Options, E> onValueChange,
@NotNull Function<Options, E> currentValue,
int width) {
CyclingButtonWidget<E> cyclingButton = CyclingButtonWidget.builder(displayNameFunction)
E initialValue = currentValue.apply(configuration.getOptions());
CyclingButtonWidget<E> cyclingButton = CyclingButtonWidget.builder(displayNameFunction, initialValue)
.values(values)
.initially(currentValue.apply(configuration.getOptions()))
.tooltip(CyclingButtonEntry::getTooltip)
.build(name, (button, value) -> onValueChange.accept(configuration.getOptions(), value));

Expand Down