Skip to content
Merged
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: 0 additions & 6 deletions src/main/java/de/rettichlp/ucutils/common/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import java.util.Set;

import static de.rettichlp.ucutils.UCUtils.LOGGER;
import static de.rettichlp.ucutils.UCUtils.storage;
import static de.rettichlp.ucutils.common.Storage.ToggledChat.NONE;
import static de.rettichlp.ucutils.common.models.Faction.NULL;
import static java.util.Optional.ofNullable;
import static net.minecraft.text.Text.translatable;

public class Storage {
Expand Down Expand Up @@ -161,10 +159,6 @@ public void print() {
LOGGER.info("unicaCity: {}", this.unicaCity);
}

public Faction getCachedFaction(String playerName) {
return ofNullable(this.playerFactionCache.get(playerName)).orElseGet(() -> storage.getFaction(playerName));
}

public Faction getFaction(String playerName) {
Faction faction = this.factionEntries.stream()
.filter(factionEntry -> factionEntry.members().stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package de.rettichlp.ucutils.common.gui.screens.options;

import de.rettichlp.ucutils.common.configuration.options.CarOptions;
import de.rettichlp.ucutils.common.gui.screens.OptionsScreen;
import de.rettichlp.ucutils.common.gui.screens.components.ToggleButtonWidget;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.DirectionalLayoutWidget;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.client.gui.widget.MultilineTextWidget;
import net.minecraft.client.gui.widget.Positioner;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.text.Text;

import static de.rettichlp.ucutils.UCUtils.renderService;
import static net.minecraft.client.gui.widget.DirectionalLayoutWidget.horizontal;
import static net.minecraft.client.gui.widget.DirectionalLayoutWidget.vertical;
import static de.rettichlp.ucutils.UCUtils.configuration;
import static net.minecraft.client.gui.widget.Positioner.create;
import static net.minecraft.text.Text.translatable;
import static net.minecraft.util.Formatting.GOLD;

public class CarOptionsScreen extends OptionsScreen {

private static final Text TEXT_CAR = translatable("ucutils.options.text.car");
private static final Text TEXT_GENERAL = translatable("ucutils.options.text.general");
private static final Text TEXT_AUTOMATION = translatable("ucutils.options.text.automation");
private static final Text CAR_PREMIUM_INFO = translatable("ucutils.options.car.premium_info");
private static final Text CAR_GENERAL_FAST_FIND_NAME = translatable("ucutils.options.car.general.fast_find.name");
private static final Text CAR_GENERAL_FAST_FIND_TOOLTIP = translatable("ucutils.options.car.general.fast_find.tooltip");
Expand All @@ -39,30 +37,47 @@ public CarOptionsScreen(Screen parent) {

@Override
public void initBody() {
DirectionalLayoutWidget directionalLayoutWidget = this.layout.addBody(vertical().spacing(4));
GridWidget gridWidget = this.layout.addBody(new GridWidget());
gridWidget.setColumnSpacing(8).setRowSpacing(4);
GridWidget.Adder gridWidgetAdder = gridWidget.createAdder(2);

MultilineTextWidget multilineTextWidget = directionalLayoutWidget.add(new MultilineTextWidget(CAR_PREMIUM_INFO.copy().formatted(GOLD), this.textRenderer), Positioner::alignHorizontalCenter);
multilineTextWidget.setMaxWidth(308);
multilineTextWidget.setCentered(true);
CarOptions carOptions = configuration.getOptions().car();

ToggleButtonWidget toggleButton1 = new ToggleButtonWidget(CAR_GENERAL_HIGHLIGHT_NAME, carOptions::highlight, carOptions.highlight());
toggleButton1.setWidth(150);
toggleButton1.setTooltip(Tooltip.of(CAR_GENERAL_HIGHLIGHT_TOOLTIP));
gridWidgetAdder.add(toggleButton1);

directionalLayoutWidget.add(new TextWidget(TEXT_GENERAL, this.textRenderer), Positioner::alignHorizontalCenter);
ToggleButtonWidget toggleButton2 = new ToggleButtonWidget(CAR_GENERAL_FAST_FIND_NAME, carOptions::fastFind, carOptions.fastFind());
toggleButton2.setWidth(150);
toggleButton2.setTooltip(Tooltip.of(CAR_GENERAL_FAST_FIND_TOOLTIP));
gridWidgetAdder.add(toggleButton2);

DirectionalLayoutWidget directionalLayoutWidget1 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addToggleButton(directionalLayoutWidget1, CAR_GENERAL_FAST_FIND_NAME, CAR_GENERAL_FAST_FIND_TOOLTIP, (options, value) -> options.car().fastFind(value), options -> options.car().fastFind(), 150);
renderService.addToggleButton(directionalLayoutWidget1, CAR_GENERAL_FAST_LOCK_NAME, CAR_GENERAL_FAST_LOCK_TOOLTIP, (options, value) -> options.car().fastLock(value), options -> options.car().fastLock(), 150);
ToggleButtonWidget toggleButton3 = new ToggleButtonWidget(CAR_AUTOMATION_CHECK_KFZ_NAME, carOptions::automatedCheckKfz, carOptions.automatedCheckKfz());
toggleButton3.setWidth(150);
toggleButton3.setTooltip(Tooltip.of(CAR_AUTOMATION_CHECK_KFZ_TOOLTIP));
gridWidgetAdder.add(toggleButton3);

DirectionalLayoutWidget directionalLayoutWidget2 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addToggleButton(directionalLayoutWidget2, CAR_GENERAL_HIGHLIGHT_NAME, CAR_GENERAL_HIGHLIGHT_TOOLTIP, (options, value) -> options.car().highlight(value), options -> options.car().highlight(), 150);
MultilineTextWidget multilineTextWidget = gridWidgetAdder.add(new MultilineTextWidget(CAR_PREMIUM_INFO.copy().formatted(GOLD), this.textRenderer), 2, create().alignHorizontalCenter().marginTop(16));
multilineTextWidget.setMaxWidth(308);
multilineTextWidget.setCentered(true);

directionalLayoutWidget.add(new TextWidget(TEXT_AUTOMATION, this.textRenderer), positioner -> positioner.alignHorizontalCenter().marginTop(16));
ToggleButtonWidget toggleButton4 = new ToggleButtonWidget(CAR_GENERAL_FAST_LOCK_NAME, carOptions::fastLock, carOptions.fastLock());
toggleButton4.setWidth(150);
toggleButton4.setTooltip(Tooltip.of(CAR_GENERAL_FAST_LOCK_TOOLTIP));
gridWidgetAdder.add(toggleButton4);

DirectionalLayoutWidget directionalLayoutWidget3 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addToggleButton(directionalLayoutWidget3, CAR_AUTOMATION_LOCK_NAME, CAR_AUTOMATION_LOCK_TOOLTIP, (options, value) -> options.car().automatedLock(value), options -> options.car().automatedLock(), 150);
renderService.addToggleButton(directionalLayoutWidget3, CAR_AUTOMATION_START_NAME, CAR_AUTOMATION_START_TOOLTIP, (options, value) -> options.car().automatedStart(value), options -> options.car().automatedStart(), 150);
ToggleButtonWidget toggleButton5 = new ToggleButtonWidget(CAR_AUTOMATION_LOCK_NAME, carOptions::automatedLock, carOptions.automatedLock());
toggleButton5.setWidth(150);
toggleButton5.setTooltip(Tooltip.of(CAR_AUTOMATION_LOCK_TOOLTIP));
gridWidgetAdder.add(toggleButton5);

DirectionalLayoutWidget directionalLayoutWidget4 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addToggleButton(directionalLayoutWidget4, CAR_AUTOMATION_CHECK_KFZ_NAME, CAR_AUTOMATION_CHECK_KFZ_TOOLTIP, (options, value) -> options.car().automatedCheckKfz(value), options -> options.car().automatedCheckKfz(), 150);
ToggleButtonWidget toggleButton6 = new ToggleButtonWidget(CAR_AUTOMATION_START_NAME, carOptions::automatedStart, carOptions.automatedStart());
toggleButton6.setWidth(150);
toggleButton6.setTooltip(Tooltip.of(CAR_AUTOMATION_START_TOOLTIP));
gridWidgetAdder.add(toggleButton6);

directionalLayoutWidget.forEachChild(this::addDrawableChild);
gridWidget.refreshPositions();
gridWidget.forEachChild(this::addDrawableChild);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import de.rettichlp.ucutils.common.models.Sound;
import de.rettichlp.ucutils.listener.ICommandSendListener;
import de.rettichlp.ucutils.listener.IEntityRenderListener;
import de.rettichlp.ucutils.listener.IHudRenderListener;
import de.rettichlp.ucutils.listener.IMessageReceiveListener;
import de.rettichlp.ucutils.listener.IMessageSendListener;
Expand All @@ -16,7 +15,6 @@
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;
Expand Down Expand Up @@ -120,8 +118,6 @@ public void registerListeners() {

HudRenderCallback.EVENT.register((drawContext, tickCounter) -> getListenersImplementing(IHudRenderListener.class).forEach(iHudRenderListener -> iHudRenderListener.onHudRender(drawContext, tickCounter)));

WorldRenderEvents.AFTER_ENTITIES.register(context -> getListenersImplementing(IEntityRenderListener.class).forEach(iEntityRenderListener -> iEntityRenderListener.onEntityRender(context)));

// prevent multiple registrations of listeners
this.initialized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
import de.rettichlp.ucutils.common.gui.widgets.base.AbstractUCUtilsWidget;
import de.rettichlp.ucutils.common.gui.widgets.base.UCUtilsWidget;
import lombok.Getter;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.client.gui.widget.DirectionalLayoutWidget;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

Expand All @@ -28,8 +22,6 @@
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toCollection;
import static java.util.stream.StreamSupport.stream;
import static net.minecraft.client.font.TextRenderer.TextLayerType.SEE_THROUGH;
import static net.minecraft.util.math.RotationAxis.POSITIVE_Y;
import static org.atteo.classindex.ClassIndex.getAnnotated;

public class RenderService {
Expand All @@ -39,50 +31,6 @@ public class RenderService {
@Getter
private LinkedHashSet<AbstractUCUtilsWidget<?>> widgets = new LinkedHashSet<>();

public void renderTextAboveEntity(@NotNull MatrixStack matrices,
VertexConsumerProvider vertexConsumers,
@NotNull Entity entity,
Text text,
float scale) {
renderTextAt(matrices, vertexConsumers, entity.getX(), entity.getY() + 1.35, entity.getZ(), text, scale);
}

public void renderTextAt(@NotNull MatrixStack matrices,
VertexConsumerProvider vertexConsumers,
double x,
double y,
double z,
Text text,
float scale) {
// save the current matrix state
matrices.push();

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

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

// make the text face the camera
matrices.multiply(camera.getRotation());
matrices.multiply(POSITIVE_Y.rotationDegrees(180.0F));

// scale the text down so it's not too big
matrices.scale(-scale, -scale, scale);

TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;

// calculate the width of the text to center it
float textWidth = -textRenderer.getWidth(text) / 2.0F;

// render the text
textRenderer.draw(text, textWidth, 0.0F, 0xFFFFFFFF, false, matrices.peek().getPositionMatrix(), vertexConsumers, SEE_THROUGH, 0x55000000, 0xF000F0);

// restore the previous matrix state
matrices.pop();
}

public Color getSecondaryColor(@NotNull Color color) {
return new Color(color.getRed() / 2, color.getGreen() / 2, color.getBlue() / 2, 100);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,48 +1,25 @@
package de.rettichlp.ucutils.listener.impl;

import de.rettichlp.ucutils.common.registry.UCUtilsListener;
import de.rettichlp.ucutils.listener.IEntityRenderListener;
import de.rettichlp.ucutils.listener.IMessageReceiveListener;
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.text.Text;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static de.rettichlp.ucutils.UCUtils.commandService;
import static de.rettichlp.ucutils.UCUtils.configuration;
import static de.rettichlp.ucutils.UCUtils.renderService;
import static de.rettichlp.ucutils.UCUtils.storage;
import static java.lang.Integer.parseInt;
import static java.util.Optional.ofNullable;
import static java.util.regex.Pattern.compile;
import static net.minecraft.util.Formatting.AQUA;

@UCUtilsListener
public class CarListener implements IEntityRenderListener, IMessageReceiveListener {
public class CarListener implements IMessageReceiveListener {

private static final Pattern CAR_UNLOCK_PATTERN = compile("^\\[Car] Du hast deinen .+ aufgeschlossen\\.$");
private static final Pattern CAR_LOCK_PATTERN = compile("^\\[Car] Du hast deinen .+ abgeschlossen\\.$");
private static final Pattern CAR_LOCKED_OWN_PATTERN = compile("^\\[Car] Dein Fahrzeug ist abgeschlossen\\.$");
private static final Pattern CAR_FIND_PATTERN = compile("^\\[Car] Das Fahrzeug befindet sich bei » X: (?<x>-?\\d+) \\| Y: (?<y>-?\\d+) \\| Z: (?<z>-?\\d+)$");

@Override
public void onEntityRender(WorldRenderContext context) {
MatrixStack matrices = context.matrices();
VertexConsumerProvider vertexConsumers = context.consumers();
ClientWorld world = MinecraftClient.getInstance().world;

if (world != null && configuration.getOptions().car().highlight() && !storage.isPremium()) {
ofNullable(storage.getMinecartEntityToHighlight())
.map(minecartEntity -> world.getEntityById(minecartEntity.getId()))
.ifPresent(minecartEntity -> renderService.renderTextAboveEntity(matrices, vertexConsumers, minecartEntity, Text.of("🚗").copy().formatted(AQUA), 0.05F));
}
}

@Override
public boolean onMessageReceive(Text text, String message) {
Matcher carUnlockMatcher = CAR_UNLOCK_PATTERN.matcher(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.rettichlp.ucutils.mixin;

import net.minecraft.client.render.entity.AbstractMinecartEntityRenderer;
import net.minecraft.client.render.entity.state.MinecartEntityRenderState;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
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;

import static de.rettichlp.ucutils.UCUtils.configuration;
import static de.rettichlp.ucutils.UCUtils.storage;

@Mixin(AbstractMinecartEntityRenderer.class)
public class AbstractMinecartEntityRendererMixin<T extends AbstractMinecartEntity, S extends MinecartEntityRenderState> {

@Inject(method = "updateRenderState(Lnet/minecraft/entity/vehicle/AbstractMinecartEntity;Lnet/minecraft/client/render/entity/state/MinecartEntityRenderState;F)V",
at = @At("TAIL"))
private void ucutils$updateRenderStateTail(T entity, S state, float tickDelta, CallbackInfo ci) {
if (!storage.isUnicaCity()) {
return;
}

if (!configuration.getOptions().car().highlight()) {
return;
}

if (storage.getMinecartEntityToHighlight() != null && storage.getMinecartEntityToHighlight().getUuid().equals(entity.getUuid())) {
state.outlineColor = 0xFFFFAA00;
}
}
}
1 change: 0 additions & 1 deletion src/main/resources/assets/ucutils/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"ucutils.notification.player_enter_report": "%s ist jetzt im Report",
"ucutils.notification.player_leave_report": "%s ist nicht mehr im Report",

"ucutils.options.text.automation": "Automatisierung",
"ucutils.options.text.chat": "Chat",
"ucutils.options.text.car": "Auto",
"ucutils.options.text.faction": "Fraktion",
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/ucutils/lang/en_gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"ucutils.notification.player_enter_report": "%s is now in a report",
"ucutils.notification.player_leave_report": "%s is no longer in a report",

"ucutils.options.text.automation": "Automation",
"ucutils.options.text.chat": "Chat",
"ucutils.options.text.car": "Car",
"ucutils.options.text.faction": "Faction",
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/ucutils/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"ucutils.notification.player_enter_report": "%s is now in a report",
"ucutils.notification.player_leave_report": "%s is no longer in a report",

"ucutils.options.text.automation": "Automation",
"ucutils.options.text.chat": "Chat",
"ucutils.options.text.car": "Car",
"ucutils.options.text.faction": "Faction",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/ucutils.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"requireAnnotations": true
},
"client": [
"AbstractMinecartEntityRendererMixin",
"ChatScreenMixin",
"ClientPlayerEntityMixin",
"ClientPlayNetworkHandlerMixin",
Expand Down