From fc8d93a5851c9d87a04bed28d666c3ef93ab1b6e Mon Sep 17 00:00:00 2001 From: MrJulsen Date: Sat, 12 Oct 2024 20:10:24 +0200 Subject: [PATCH] Fixed crash on server with fabric --- .../de/mrjulsen/crn/client/ClientWrapper.java | 100 ++++++++++++++++++ .../condition/DynamicDelayCondition.java | 49 +-------- .../instruction/ResetTimingsInstruction.java | 26 +---- .../instruction/TravelSectionInstruction.java | 36 +------ .../crn/mixin/ScheduleScreenMixin.java | 10 +- 5 files changed, 109 insertions(+), 112 deletions(-) diff --git a/common/src/main/java/de/mrjulsen/crn/client/ClientWrapper.java b/common/src/main/java/de/mrjulsen/crn/client/ClientWrapper.java index 7f3637aa..7385ce21 100644 --- a/common/src/main/java/de/mrjulsen/crn/client/ClientWrapper.java +++ b/common/src/main/java/de/mrjulsen/crn/client/ClientWrapper.java @@ -4,21 +4,42 @@ import java.util.function.Supplier; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import com.simibubi.create.content.trains.schedule.ScheduleScreen; +import com.simibubi.create.content.trains.schedule.condition.TimedWaitCondition.TimeUnit; +import com.simibubi.create.foundation.gui.ModularGuiLineBuilder; +import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.Pair; import de.mrjulsen.crn.Constants; import de.mrjulsen.crn.CreateRailwaysNavigator; import de.mrjulsen.crn.block.blockentity.AdvancedDisplayBlockEntity; +import de.mrjulsen.crn.client.gui.ModGuiIcons; import de.mrjulsen.crn.client.gui.NavigatorToast; import de.mrjulsen.crn.client.gui.screen.AdvancedDisplaySettingsScreen; import de.mrjulsen.crn.client.gui.screen.NavigatorScreen; import de.mrjulsen.crn.client.gui.screen.TrainDebugScreen; +import de.mrjulsen.crn.client.gui.screen.TrainSectionSettingsScreen; +import de.mrjulsen.crn.client.gui.widgets.ResizableButton; import de.mrjulsen.crn.client.lang.ELanguage; import de.mrjulsen.crn.config.ModClientConfig; +import de.mrjulsen.crn.data.schedule.condition.DynamicDelayCondition; +import de.mrjulsen.crn.data.schedule.instruction.ResetTimingsInstruction; +import de.mrjulsen.crn.data.schedule.instruction.TravelSectionInstruction; +import de.mrjulsen.crn.mixin.ModularGuiLineBuilderAccessor; +import de.mrjulsen.crn.mixin.ScheduleScreenAccessor; import de.mrjulsen.crn.network.packets.stc.ServerErrorPacket; +import de.mrjulsen.mcdragonlib.DragonLib; import de.mrjulsen.mcdragonlib.client.gui.DLScreen; +import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer; +import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer.AreaStyle; +import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer.ButtonState; import de.mrjulsen.mcdragonlib.client.util.Graphics; +import de.mrjulsen.mcdragonlib.client.util.GuiUtils; +import de.mrjulsen.mcdragonlib.core.EAlignment; import de.mrjulsen.mcdragonlib.util.TextUtils; import dev.architectury.networking.NetworkManager.PacketContext; +import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.MultiLineLabel; @@ -95,4 +116,83 @@ public static void showTrainDebugScreen() { DLScreen.setScreen(new TrainDebugScreen(null)); }); } + + @SuppressWarnings("resource") + public static void initScheduleSectionInstruction(TravelSectionInstruction instruction, ModularGuiLineBuilder builder) { + + ModularGuiLineBuilderAccessor accessor = (ModularGuiLineBuilderAccessor)builder; + + ResizableButton btn = new ResizableButton(accessor.crn$getX(), accessor.crn$getY() - 4, 121, 16, TextUtils.translate(CreateRailwaysNavigator.MOD_ID + ".schedule.instruction." + instruction.getId().getPath() + ".configure"), + (b) -> { + if (Minecraft.getInstance().screen instanceof ScheduleScreen scheduleScreen) { + ((ScheduleScreenAccessor)scheduleScreen).crn$getOnEditorClose().accept(true); + builder.customArea(0, 0).speechBubble(); + Minecraft.getInstance().setScreen(new TrainSectionSettingsScreen(scheduleScreen, instruction.getData())); + } + }) { + @Override + public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + Graphics graphics = new Graphics(poseStack); + DynamicGuiRenderer.renderArea(graphics, x, y, width, height, AreaStyle.GRAY, isActive() ? (isFocused() || isMouseOver(mouseX, mouseY) ? ButtonState.SELECTED : ButtonState.BUTTON) : ButtonState.DISABLED); + int j = isActive() ? DragonLib.NATIVE_BUTTON_FONT_COLOR_ACTIVE : DragonLib.NATIVE_BUTTON_FONT_COLOR_DISABLED; + GuiUtils.drawString(graphics, Minecraft.getInstance().font, x + width / 2, y + (height - 8) / 2, this.getMessage(), j, EAlignment.CENTER, true); + } + }; + accessor.crn$getTarget().add(Pair.of(btn, "config_btn")); + } + + public static void initResetTimingsInstruction(ResetTimingsInstruction instruction, ModularGuiLineBuilder builder) { + ModularGuiLineBuilderAccessor accessor = (ModularGuiLineBuilderAccessor)builder; + ResizableButton btn = new ResizableButton(accessor.crn$getX(), accessor.crn$getY() - 4, 16, 16, TextUtils.empty(), + (b) -> { + Util.getPlatform().openUri(Constants.HELP_PAGE_SCHEDULED_TIMES_AND_REAL_TIME); + }) { + @Override + public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + Graphics graphics = new Graphics(poseStack); + DynamicGuiRenderer.renderArea(graphics, x, y, width, height, AreaStyle.GRAY, isActive() ? (isFocused() || isMouseOver(mouseX, mouseY) ? ButtonState.SELECTED : ButtonState.BUTTON) : ButtonState.DISABLED); + ModGuiIcons.HELP.render(graphics, x, y); + } + }; + accessor.crn$getTarget().add(Pair.of(btn, "help_btn")); + } + + public static void initDynamicDelayCondition(DynamicDelayCondition condition, ModularGuiLineBuilder builder) { + + builder.addScrollInput(0, 26, (i, l) -> { + i.titled(Lang.translateDirect("generic.duration")) + .withShiftStep(15) + .withRange(0, 121); + i.lockedTooltipX = -15; + i.lockedTooltipY = 35; + }, "Value"); + + builder.addScrollInput(26, 26, (i, l) -> { + i.titled(TextUtils.translate(CreateRailwaysNavigator.MOD_ID + ".schedule.condition." + condition.getId().getPath() + ".min_duration")) + .withShiftStep(15) + .withRange(0, 121); + i.lockedTooltipX = -15; + i.lockedTooltipY = 35; + }, DynamicDelayCondition.NBT_MIN); + + builder.addSelectionScrollInput(52, 58, (i, l) -> { + i.forOptions(TimeUnit.translatedOptions()) + .titled(Lang.translateDirect("generic.timeUnit")); + }, "TimeUnit"); + + + ModularGuiLineBuilderAccessor accessor = (ModularGuiLineBuilderAccessor)builder; + ResizableButton btn = new ResizableButton(accessor.crn$getX() + 110, accessor.crn$getY() - 4, 16, 16, TextUtils.empty(), + (b) -> { + Util.getPlatform().openUri(Constants.HELP_PAGE_DYNAMIC_DELAYS); + }) { + @Override + public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + Graphics graphics = new Graphics(poseStack); + DynamicGuiRenderer.renderArea(graphics, x, y, width, height, AreaStyle.GRAY, isActive() ? (isFocused() || isMouseOver(mouseX, mouseY) ? ButtonState.SELECTED : ButtonState.BUTTON) : ButtonState.DISABLED); + ModGuiIcons.HELP.render(graphics, x, y); + } + }; + accessor.crn$getTarget().add(Pair.of(btn, "help_btn")); + } } diff --git a/common/src/main/java/de/mrjulsen/crn/data/schedule/condition/DynamicDelayCondition.java b/common/src/main/java/de/mrjulsen/crn/data/schedule/condition/DynamicDelayCondition.java index b8889efc..48516f9c 100644 --- a/common/src/main/java/de/mrjulsen/crn/data/schedule/condition/DynamicDelayCondition.java +++ b/common/src/main/java/de/mrjulsen/crn/data/schedule/condition/DynamicDelayCondition.java @@ -4,7 +4,6 @@ import java.util.Optional; import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.content.trains.entity.Train; import com.simibubi.create.content.trains.schedule.condition.ScheduledDelay; import com.simibubi.create.foundation.gui.ModularGuiLineBuilder; @@ -12,24 +11,16 @@ import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Pair; -import de.mrjulsen.crn.Constants; import de.mrjulsen.crn.CreateRailwaysNavigator; -import de.mrjulsen.crn.client.gui.ModGuiIcons; -import de.mrjulsen.crn.client.gui.widgets.ResizableButton; +import de.mrjulsen.crn.client.ClientWrapper; import de.mrjulsen.crn.data.train.TrainData; import de.mrjulsen.crn.data.train.TrainListener; import de.mrjulsen.crn.data.train.TrainPrediction; -import de.mrjulsen.crn.mixin.ModularGuiLineBuilderAccessor; import de.mrjulsen.mcdragonlib.DragonLib; -import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer; -import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer.AreaStyle; -import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer.ButtonState; -import de.mrjulsen.mcdragonlib.client.util.Graphics; import de.mrjulsen.mcdragonlib.util.TextUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; -import net.minecraft.Util; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -39,7 +30,7 @@ public class DynamicDelayCondition extends ScheduledDelay { - private static final String NBT_MIN = "Min"; + public static final String NBT_MIN = "Min"; public DynamicDelayCondition() { super(); @@ -108,40 +99,6 @@ public int minWaitTicks() { @Override @Environment(EnvType.CLIENT) public void initConfigurationWidgets(ModularGuiLineBuilder builder) { - builder.addScrollInput(0, 26, (i, l) -> { - i.titled(Lang.translateDirect("generic.duration")) - .withShiftStep(15) - .withRange(0, 121); - i.lockedTooltipX = -15; - i.lockedTooltipY = 35; - }, "Value"); - - builder.addScrollInput(26, 26, (i, l) -> { - i.titled(TextUtils.translate(CreateRailwaysNavigator.MOD_ID + ".schedule.condition." + getId().getPath() + ".min_duration")) - .withShiftStep(15) - .withRange(0, 121); - i.lockedTooltipX = -15; - i.lockedTooltipY = 35; - }, NBT_MIN); - - builder.addSelectionScrollInput(52, 58, (i, l) -> { - i.forOptions(TimeUnit.translatedOptions()) - .titled(Lang.translateDirect("generic.timeUnit")); - }, "TimeUnit"); - - - ModularGuiLineBuilderAccessor accessor = (ModularGuiLineBuilderAccessor)builder; - ResizableButton btn = new ResizableButton(accessor.crn$getX() + 110, accessor.crn$getY() - 4, 16, 16, TextUtils.empty(), - (b) -> { - Util.getPlatform().openUri(Constants.HELP_PAGE_DYNAMIC_DELAYS); - }) { - @Override - public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { - Graphics graphics = new Graphics(poseStack); - DynamicGuiRenderer.renderArea(graphics, x, y, width, height, AreaStyle.GRAY, isActive() ? (isFocused() || isMouseOver(mouseX, mouseY) ? ButtonState.SELECTED : ButtonState.BUTTON) : ButtonState.DISABLED); - ModGuiIcons.HELP.render(graphics, x, y); - } - }; - accessor.crn$getTarget().add(Pair.of(btn, "help_btn")); + ClientWrapper.initDynamicDelayCondition(this, builder); } } diff --git a/common/src/main/java/de/mrjulsen/crn/data/schedule/instruction/ResetTimingsInstruction.java b/common/src/main/java/de/mrjulsen/crn/data/schedule/instruction/ResetTimingsInstruction.java index ca894572..a5b54bac 100644 --- a/common/src/main/java/de/mrjulsen/crn/data/schedule/instruction/ResetTimingsInstruction.java +++ b/common/src/main/java/de/mrjulsen/crn/data/schedule/instruction/ResetTimingsInstruction.java @@ -2,29 +2,20 @@ import java.util.List; -import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.content.trains.entity.Train; import com.simibubi.create.content.trains.schedule.ScheduleRuntime; import com.simibubi.create.content.trains.schedule.destination.ScheduleInstruction; import com.simibubi.create.foundation.gui.ModularGuiLineBuilder; import com.simibubi.create.foundation.utility.Pair; -import de.mrjulsen.crn.Constants; import de.mrjulsen.crn.CreateRailwaysNavigator; -import de.mrjulsen.crn.client.gui.ModGuiIcons; -import de.mrjulsen.crn.client.gui.widgets.ResizableButton; +import de.mrjulsen.crn.client.ClientWrapper; import de.mrjulsen.crn.data.train.TrainData; -import de.mrjulsen.crn.mixin.ModularGuiLineBuilderAccessor; -import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer; -import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer.AreaStyle; -import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer.ButtonState; -import de.mrjulsen.mcdragonlib.client.util.Graphics; import de.mrjulsen.mcdragonlib.util.DLUtils; import de.mrjulsen.mcdragonlib.util.TextUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; -import net.minecraft.Util; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -59,20 +50,7 @@ public List getTitleAs(String type) { @Override @Environment(EnvType.CLIENT) public void initConfigurationWidgets(ModularGuiLineBuilder builder) { - - ModularGuiLineBuilderAccessor accessor = (ModularGuiLineBuilderAccessor)builder; - ResizableButton btn = new ResizableButton(accessor.crn$getX(), accessor.crn$getY() - 4, 16, 16, TextUtils.empty(), - (b) -> { - Util.getPlatform().openUri(Constants.HELP_PAGE_SCHEDULED_TIMES_AND_REAL_TIME); - }) { - @Override - public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { - Graphics graphics = new Graphics(poseStack); - DynamicGuiRenderer.renderArea(graphics, x, y, width, height, AreaStyle.GRAY, isActive() ? (isFocused() || isMouseOver(mouseX, mouseY) ? ButtonState.SELECTED : ButtonState.BUTTON) : ButtonState.DISABLED); - ModGuiIcons.HELP.render(graphics, x, y); - } - }; - accessor.crn$getTarget().add(Pair.of(btn, "help_btn")); + ClientWrapper.initResetTimingsInstruction(this, builder); } @Override diff --git a/common/src/main/java/de/mrjulsen/crn/data/schedule/instruction/TravelSectionInstruction.java b/common/src/main/java/de/mrjulsen/crn/data/schedule/instruction/TravelSectionInstruction.java index 86fd2467..114e8eb2 100644 --- a/common/src/main/java/de/mrjulsen/crn/data/schedule/instruction/TravelSectionInstruction.java +++ b/common/src/main/java/de/mrjulsen/crn/data/schedule/instruction/TravelSectionInstruction.java @@ -3,36 +3,23 @@ import java.util.ArrayList; import java.util.List; -import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.content.trains.entity.Train; import com.simibubi.create.content.trains.schedule.ScheduleRuntime; -import com.simibubi.create.content.trains.schedule.ScheduleScreen; import com.simibubi.create.content.trains.schedule.destination.ScheduleInstruction; import com.simibubi.create.foundation.gui.ModularGuiLineBuilder; import com.simibubi.create.foundation.utility.Pair; import de.mrjulsen.crn.CreateRailwaysNavigator; -import de.mrjulsen.crn.client.gui.screen.TrainSectionSettingsScreen; -import de.mrjulsen.crn.client.gui.widgets.ResizableButton; +import de.mrjulsen.crn.client.ClientWrapper; import de.mrjulsen.crn.data.storage.GlobalSettings; import de.mrjulsen.crn.data.train.TrainData; import de.mrjulsen.crn.data.train.TrainTravelSection; -import de.mrjulsen.crn.mixin.ModularGuiLineBuilderAccessor; -import de.mrjulsen.crn.mixin.ScheduleScreenAccessor; import de.mrjulsen.crn.registry.ModBlocks; -import de.mrjulsen.mcdragonlib.DragonLib; -import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer; -import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer.AreaStyle; -import de.mrjulsen.mcdragonlib.client.render.DynamicGuiRenderer.ButtonState; -import de.mrjulsen.mcdragonlib.client.util.Graphics; -import de.mrjulsen.mcdragonlib.client.util.GuiUtils; -import de.mrjulsen.mcdragonlib.core.EAlignment; import de.mrjulsen.mcdragonlib.util.DLUtils; import de.mrjulsen.mcdragonlib.util.TextUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; @@ -89,27 +76,8 @@ public List getTitleAs(String type) { /** HERE BE DRAGONS! This code is very illegal, but it works... */ @Override @Environment(EnvType.CLIENT) - @SuppressWarnings("resource") public void initConfigurationWidgets(ModularGuiLineBuilder builder) { - ModularGuiLineBuilderAccessor accessor = (ModularGuiLineBuilderAccessor)builder; - - ResizableButton btn = new ResizableButton(accessor.crn$getX(), accessor.crn$getY() - 4, 121, 16, TextUtils.translate(CreateRailwaysNavigator.MOD_ID + ".schedule.instruction." + getId().getPath() + ".configure"), - (b) -> { - if (Minecraft.getInstance().screen instanceof ScheduleScreen scheduleScreen) { - ((ScheduleScreenAccessor)scheduleScreen).crn$getOnEditorClose().accept(true); - builder.customArea(0, 0).speechBubble(); - Minecraft.getInstance().setScreen(new TrainSectionSettingsScreen(scheduleScreen, data)); - } - }) { - @Override - public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { - Graphics graphics = new Graphics(poseStack); - DynamicGuiRenderer.renderArea(graphics, x, y, width, height, AreaStyle.GRAY, isActive() ? (isFocused() || isMouseOver(mouseX, mouseY) ? ButtonState.SELECTED : ButtonState.BUTTON) : ButtonState.DISABLED); - int j = isActive() ? DragonLib.NATIVE_BUTTON_FONT_COLOR_ACTIVE : DragonLib.NATIVE_BUTTON_FONT_COLOR_DISABLED; - GuiUtils.drawString(graphics, Minecraft.getInstance().font, x + width / 2, y + (height - 8) / 2, this.getMessage(), j, EAlignment.CENTER, true); - } - }; - accessor.crn$getTarget().add(Pair.of(btn, "config_btn")); + ClientWrapper.initScheduleSectionInstruction(this, builder); } @Override diff --git a/common/src/main/java/de/mrjulsen/crn/mixin/ScheduleScreenMixin.java b/common/src/main/java/de/mrjulsen/crn/mixin/ScheduleScreenMixin.java index 3acb5b6a..6d737ab3 100644 --- a/common/src/main/java/de/mrjulsen/crn/mixin/ScheduleScreenMixin.java +++ b/common/src/main/java/de/mrjulsen/crn/mixin/ScheduleScreenMixin.java @@ -4,22 +4,14 @@ import java.util.List; 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.At.Shift; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.simibubi.create.content.trains.schedule.DestinationSuggestions; import com.simibubi.create.content.trains.schedule.IScheduleInput; import com.simibubi.create.content.trains.schedule.ScheduleScreen; import com.simibubi.create.foundation.utility.IntAttached; import de.mrjulsen.crn.data.StationTag; import de.mrjulsen.crn.data.storage.GlobalSettings; -import de.mrjulsen.crn.data.schedule.instruction.ICustomSuggestionsInstruction; import de.mrjulsen.crn.data.schedule.instruction.IStationTagInstruction; import de.mrjulsen.crn.data.schedule.instruction.ITrainNameInstruction; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; @Mixin(ScheduleScreen.class) @@ -37,6 +29,7 @@ public int getTopPos() { return ((AbstractContainerScreen)(Object)this).topPos; } + /* @SuppressWarnings("resource") @Inject(method = "updateEditorSubwidgets", remap = false, at = @At(value = "INVOKE", shift = Shift.AFTER, target = "Lcom/simibubi/create/foundation/gui/ModularGuiLine;loadValues(Lnet/minecraft/nbt/CompoundTag;Ljava/util/function/Consumer;Ljava/util/function/Consumer;)V"), cancellable = true) public void onUpdateEditorSubwidgets(IScheduleInput field, CallbackInfo ci) { @@ -52,6 +45,7 @@ public void onUpdateEditorSubwidgets(IScheduleInput field, CallbackInfo ci) { } } + */ public List> onGetViableStations(IScheduleInput field) {