Skip to content

Commit

Permalink
Fixed crash on server with fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterJulsen committed Oct 12, 2024
1 parent d9007d8 commit fc8d93a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 112 deletions.
100 changes: 100 additions & 0 deletions common/src/main/java/de/mrjulsen/crn/client/ClientWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,23 @@
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;
import com.simibubi.create.foundation.utility.Components;
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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,20 +50,7 @@ public List<Component> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,27 +76,8 @@ public List<Component> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -52,6 +45,7 @@ public void onUpdateEditorSubwidgets(IScheduleInput field, CallbackInfo ci) {
}
}
*/


public List<IntAttached<String>> onGetViableStations(IScheduleInput field) {
Expand Down

0 comments on commit fc8d93a

Please sign in to comment.