Skip to content

Commit

Permalink
Merge branch '1.20.2' into 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Aug 16, 2024
2 parents 9dc87f3 + 3bdffdc commit f1e534c
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 84 deletions.
51 changes: 26 additions & 25 deletions common/src/main/java/xaeroplus/Globals.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
package xaeroplus;

import com.google.common.base.Suppliers;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import xaero.hud.HudSession;
import xaero.map.core.XaeroWorldMapCore;
import xaeroplus.event.ClientPlaySessionFinalizedEvent;
import xaeroplus.feature.render.DrawManager;
import xaeroplus.settings.XaeroPlusSetting;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Supplier;
import java.util.zip.ZipInputStream;

import static net.minecraft.world.level.Level.OVERWORLD;

/**
* static variables and functions to share or persist across mixins
*/
public class Globals {

public static DrawManager drawManager = new DrawManager();
// Map gui follow mode
public static boolean FOLLOW = false;
// cache and only update this on new world loads
Expand All @@ -52,8 +46,6 @@ public static ResourceKey<Level> getCurrentDimensionId() {
return OVERWORLD;
}
}
public static String waypointsSearchFilter = "";
public static List<Button> guiMapButtonTempList = Lists.<Button>newArrayList();
// This can only be shared under the assumption region and texture cache writes are non-concurrent
// sharing the underlying byte array reduces GC spam
// at cost of a few MB higher idle RAM usage
Expand All @@ -66,16 +58,16 @@ public static ResourceKey<Level> getCurrentDimensionId() {
.setDaemon(true)
.build()));

public static final ResourceLocation xpGuiTextures = new ResourceLocation("xaeroplus", "gui/xpgui.png");

public static DrawManager drawManager = new DrawManager();

public static void onAllSettingsLoaded() {
XaeroPlusSettingsReflectionHax.ALL_SETTINGS.get().forEach(XaeroPlusSetting::init);
nullOverworldDimensionFolder = XaeroPlusSettingRegistry.nullOverworldDimensionFolder.getValue();
dataFolderResolutionMode = XaeroPlusSettingRegistry.dataFolderResolutionMode.getValue();
minimapScaleMultiplier = (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValue();
minimapSizeMultiplier = (int) XaeroPlusSettingRegistry.minimapSizeMultiplierSetting.getValue();
XaeroPlus.EVENT_BUS.registerConsumer((e) -> {
nullOverworldDimensionFolder = XaeroPlusSettingRegistry.nullOverworldDimensionFolder.getValue();
dataFolderResolutionMode = XaeroPlusSettingRegistry.dataFolderResolutionMode.getValue();
}, ClientPlaySessionFinalizedEvent.class);
}

public static void switchToDimension(final ResourceKey<Level> newDimId) {
Expand All @@ -94,16 +86,25 @@ public static void switchToDimension(final ResourceKey<Level> newDimId) {
}
}

public static byte[] decompressZipToBytes(final Path input) {
// overall performance improvement here is not that large
// writing has bigger impact doing it all bytes at once
try (final var in = new ZipInputStream(Files.newInputStream(input))) {
if (in.getNextEntry() != null) { // all xaero zip files (currently) only have 1 entry
return in.readAllBytes();
}
} catch (final IOException e) {
throw new RuntimeException(e);
public static void setNullOverworldDimFolderIfAble(final boolean b) {
try {
var currentWMSession = XaeroWorldMapCore.currentSession;
var currentMMSession = HudSession.getCurrentSession();
if (currentWMSession != null || currentMMSession != null) return;
Globals.nullOverworldDimensionFolder = b;
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Failed setting nullOverworldDimensionFolder", e);
}
}

public static void setDataFolderResolutionModeIfAble(XaeroPlusSettingRegistry.DataFolderResolutionMode mode) {
try {
var currentWMSession = XaeroWorldMapCore.currentSession;
var currentMMSession = HudSession.getCurrentSession();
if (currentWMSession != null || currentMMSession != null) return;
Globals.dataFolderResolutionMode = mode;
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Failed setting data folder resolution mode", e);
}
return new byte[0];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package xaeroplus.event;

public record ClientPlaySessionFinalizedEvent() {
public static ClientPlaySessionFinalizedEvent INSTANCE = new ClientPlaySessionFinalizedEvent();
}
16 changes: 16 additions & 0 deletions common/src/main/java/xaeroplus/mixin/client/MixinClientEvents.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package xaeroplus.mixin.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
Expand All @@ -8,6 +10,8 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import xaero.common.events.ClientEvents;
import xaero.common.minimap.waypoints.WaypointSharingHandler;
import xaeroplus.XaeroPlus;
import xaeroplus.settings.XaeroPlusSettingRegistry;

@Mixin(value = ClientEvents.class, remap = false)
Expand All @@ -29,4 +33,16 @@ public void onPlayerChatReceived(final ChatType.Bound chatType, final Component
cir.setReturnValue(false); // false will show the raw message in chat to the player
}
}

@WrapOperation(method = "handleChatMessage", at = @At(
value = "INVOKE",
target = "Lxaero/common/minimap/waypoints/WaypointSharingHandler;onWaypointReceived(Ljava/lang/String;Ljava/lang/String;)V"
))
public void preventInvalidWpFormattingCrash(final WaypointSharingHandler instance, final String playerName, final String textString, final Operation<Void> original) {
try {
original.call(instance, playerName, textString);
} catch (final Exception e) {
XaeroPlus.LOGGER.info("Caught exception in waypoint sharing handler: ", e);
}
}
}
81 changes: 34 additions & 47 deletions common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xaeroplus.mixin.client;

import com.google.common.collect.Lists;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
Expand Down Expand Up @@ -67,45 +68,31 @@
@Mixin(value = GuiMap.class, remap = false)
public abstract class MixinGuiMap extends ScreenBase implements IRightClickableElement {

Button coordinateGotoButton;
EditBox xTextEntryField;
EditBox zTextEntryField;
Button followButton;
Button switchToNetherButton;
Button switchToOverworldButton;
Button switchToEndButton;
@Shadow
private double cameraX = 0.0;
@Shadow
private double cameraZ = 0.0;
@Shadow
private int[] cameraDestination = null;
@Shadow
private SlowingAnimation cameraDestinationAnimX = null;
@Shadow
private SlowingAnimation cameraDestinationAnimZ = null;
@Shadow
private double scale;
@Shadow
private double prevPlayerDimDiv;
@Shadow
private MapProcessor mapProcessor;
@Shadow
private Button exportButton;
@Shadow
private Button claimsButton;
@Shadow
private Button zoomInButton;
@Shadow
private Button zoomOutButton;
@Shadow
private Button keybindingsButton;
@Shadow
private Button dimensionToggleButton;
@Shadow
private int rightClickX;
@Shadow
private int rightClickZ;
@Unique Button coordinateGotoButton;
@Unique EditBox xTextEntryField;
@Unique EditBox zTextEntryField;
@Unique Button followButton;
@Unique Button switchToNetherButton;
@Unique Button switchToOverworldButton;
@Unique Button switchToEndButton;
@Unique List<Button> guiMapButtonTempList = Lists.<Button>newArrayList();
@Unique ResourceLocation xpGuiTextures = new ResourceLocation("xaeroplus", "gui/xpgui.png");
@Shadow private double cameraX = 0.0;
@Shadow private double cameraZ = 0.0;
@Shadow private int[] cameraDestination = null;
@Shadow private SlowingAnimation cameraDestinationAnimX = null;
@Shadow private SlowingAnimation cameraDestinationAnimZ = null;
@Shadow private double scale;
@Shadow private double prevPlayerDimDiv;
@Shadow private MapProcessor mapProcessor;
@Shadow private Button exportButton;
@Shadow private Button claimsButton;
@Shadow private Button zoomInButton;
@Shadow private Button zoomOutButton;
@Shadow private Button keybindingsButton;
@Shadow private Button dimensionToggleButton;
@Shadow private int rightClickX;
@Shadow private int rightClickZ;

protected MixinGuiMap(final Screen parent, final Screen escape, final Component titleIn) {
super(parent, escape, titleIn);
Expand Down Expand Up @@ -160,15 +147,15 @@ public void customInitGui(CallbackInfo ci) {
this.zoomInButton.setY(this.zoomOutButton.getY() - 20);
}
switchToEndButton = new GuiTexturedButton(this.width - 20, zoomInButton.getY() - 20, 20, 20, 31, 0, 16, 16,
Globals.xpGuiTextures,
this.xpGuiTextures,
(button -> onSwitchDimensionButton(END)),
() -> new CursorBox(Component.translatable("setting.keybinds.switch_to_end")));
switchToOverworldButton = new GuiTexturedButton(this.width - 20, this.switchToEndButton.getY() - 20, 20, 20, 16, 0, 16, 16,
Globals.xpGuiTextures,
this.xpGuiTextures,
(button -> onSwitchDimensionButton(OVERWORLD)),
() -> new CursorBox(Component.translatable("setting.keybinds.switch_to_overworld")));
switchToNetherButton = new GuiTexturedButton(this.width - 20, this.switchToOverworldButton.getY() - 20, 20, 20, 0, 0, 16, 16,
Globals.xpGuiTextures,
this.xpGuiTextures,
(button -> onSwitchDimensionButton(NETHER)),
() -> new CursorBox(Component.translatable("setting.keybinds.switch_to_nether")));
addButton(switchToEndButton);
Expand Down Expand Up @@ -484,17 +471,17 @@ public void hideButtonsOnF1(final GuiGraphics guiGraphics, final int scaledMouse
if (Minecraft.getInstance().options.hideGui) {
List<Button> buttonList = getButtonList();
if (!buttonList.isEmpty()) {
Globals.guiMapButtonTempList.clear();
Globals.guiMapButtonTempList.addAll(buttonList);
this.guiMapButtonTempList.clear();
this.guiMapButtonTempList.addAll(buttonList);
xTextEntryField.setVisible(false);
zTextEntryField.setVisible(false);
clearButtons();
}
} else {
if (!Globals.guiMapButtonTempList.isEmpty()) {
if (!this.guiMapButtonTempList.isEmpty()) {
clearButtons();
Globals.guiMapButtonTempList.forEach(this::addButton);
Globals.guiMapButtonTempList.clear();
this.guiMapButtonTempList.forEach(this::addButton);
this.guiMapButtonTempList.clear();
}
}
}
Expand Down
23 changes: 12 additions & 11 deletions common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -24,7 +25,6 @@
import xaero.common.minimap.waypoints.WaypointsManager;
import xaero.common.minimap.waypoints.WaypointsSort;
import xaero.common.misc.KeySortableByOther;
import xaeroplus.Globals;
import xaeroplus.settings.XaeroPlusSettingRegistry;

import java.util.ArrayList;
Expand All @@ -34,15 +34,16 @@
@Mixin(value = GuiWaypoints.class, remap = false)
public abstract class MixinGuiWaypoints extends ScreenBase {

private final int TOGGLE_ALL_ID = 69;
@Shadow
private WaypointWorld displayedWorld;
@Shadow
private ArrayList<Waypoint> waypointsSorted;
@Shadow
private WaypointsManager waypointsManager;
private EditBox searchField;
private MySmallButton toggleAllButton;
@Unique private EditBox searchField;
@Unique private final int TOGGLE_ALL_ID = 69;
@Unique private MySmallButton toggleAllButton;
@Unique private String waypointsSearchFilter = "";

protected MixinGuiWaypoints(final IXaeroMinimap modMain, final Screen parent, final Screen escape, final Component titleIn) {
super(modMain, parent, escape, titleIn);
Expand All @@ -58,7 +59,7 @@ public void initGui(CallbackInfo ci) {
this.addWidget(searchField);
this.setFocused(this.searchField);

Globals.waypointsSearchFilter = "";
this.waypointsSearchFilter = "";
// todo: this button is a bit larger than i want but cba to figure out exact size rn
this.addRenderableWidget(
this.toggleAllButton = new MySmallButton(
Expand Down Expand Up @@ -111,7 +112,7 @@ public void drawScreenInject(final GuiGraphics guiGraphics, final int mouseX, fi
}
this.searchField.render(guiGraphics, mouseX, mouseY, partial);
if (!this.searchField.isFocused()) {
xaero.map.misc.Misc.setFieldText(this.searchField, Globals.waypointsSearchFilter);
xaero.map.misc.Misc.setFieldText(this.searchField, this.waypointsSearchFilter);
}
}

Expand All @@ -129,8 +130,8 @@ public boolean shareButtonRedirect(final GuiWaypoints instance) {
private void updateSearch() {
if (this.searchField.isFocused()) {
String newValue = this.searchField.getValue();
if (!Objects.equal(Globals.waypointsSearchFilter, newValue)) {
Globals.waypointsSearchFilter = this.searchField.getValue();
if (!Objects.equal(this.waypointsSearchFilter, newValue)) {
this.waypointsSearchFilter = this.searchField.getValue();
updateSortedList();
}
}
Expand All @@ -155,9 +156,9 @@ private void updateSortedList() {
else
enabledWaypoints.add(w);
}
if (!Globals.waypointsSearchFilter.isEmpty()) {
enabledWaypoints.removeIf(waypoint -> !waypoint.getName().toLowerCase().contains(Globals.waypointsSearchFilter.toLowerCase()));
disabledWaypoints.removeIf(waypoint -> !waypoint.getName().toLowerCase().contains(Globals.waypointsSearchFilter.toLowerCase()));
if (!this.waypointsSearchFilter.isEmpty()) {
enabledWaypoints.removeIf(waypoint -> !waypoint.getName().toLowerCase().contains(this.waypointsSearchFilter.toLowerCase()));
disabledWaypoints.removeIf(waypoint -> !waypoint.getName().toLowerCase().contains(this.waypointsSearchFilter.toLowerCase()));
}
this.waypointsSorted = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import xaeroplus.event.ChunkBlockUpdateEvent;
import xaeroplus.event.ChunkBlocksUpdateEvent;
import xaeroplus.event.ChunkDataEvent;
import xaeroplus.event.ClientPlaySessionFinalizedEvent;

@Mixin(ClientPacketListener.class)
public class MixinClientPlayNetworkHandler {
Expand Down Expand Up @@ -56,4 +57,11 @@ public void onChunkBlocksUpdate(final ClientboundSectionBlocksUpdatePacket packe
public void onBlockUpdate(final ClientboundBlockUpdatePacket packet, final CallbackInfo ci) {
XaeroPlus.EVENT_BUS.call(new ChunkBlockUpdateEvent(packet));
}

@Inject(method = "close", at = @At(
"RETURN" // after session is closed, including xaero session closes and mc level ref unset
))
public void onClientSessionClose(final CallbackInfo ci) {
XaeroPlus.EVENT_BUS.call(ClientPlaySessionFinalizedEvent.INSTANCE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,15 @@ public final class XaeroPlusSettingRegistry {
"setting.world_map.null_overworld_dimension_folder",
"setting.world_map.null_overworld_dimension_folder.tooltip",
true,
Globals::setNullOverworldDimFolderIfAble,
SettingLocation.WORLD_MAP_MAIN);
public static final XaeroPlusEnumSetting<DataFolderResolutionMode> dataFolderResolutionMode = XaeroPlusEnumSetting.create(
"Data Dir Mode",
"setting.world_map.data_folder_resolution_mode",
"setting.world_map.data_folder_resolution_mode.tooltip",
DataFolderResolutionMode.values(),
DataFolderResolutionMode.IP,
Globals::setDataFolderResolutionModeIfAble,
SettingLocation.WORLD_MAP_MAIN);

public enum DataFolderResolutionMode implements TranslatableSettingEnum {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/assets/xaeroplus/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"setting.world_map.null_overworld_dimension_folder": "null OW Dim Dir",
"setting.world_map.null_overworld_dimension_folder.tooltip": "Sets whether the overworld WorldMap directory is in DIM0 or null (default) \n MC must be restarted for changes to take effect.",
"setting.world_map.data_folder_resolution_mode": "Data Dir Mode",
"setting.world_map.data_folder_resolution_mode.tooltip": "Sets how the WorldMap and Waypoints data folders are resolved. \n MC must be restarted for changes to take effect. \n IP = Server IP (Xaero Default). Example: .minecraft/XaeroWorldMap/Multiplayer_connect.2b2t.org \n SERVER_NAME = MC Server Entry Name. Example: .minecraft/XaeroWorldMap/Multiplayer_2b2t \n BASE_DOMAIN = Base Server Domain Name. Example: .minecraft/XaeroWorldMap/Multiplayer_2b2t.org",
"setting.world_map.data_folder_resolution_mode.tooltip": "Sets how the WorldMap and Waypoints data folders are resolved. \n You must rejoin the current server for settings to take effect. \n IP = Server IP (Xaero Default). Example: .minecraft/XaeroWorldMap/Multiplayer_connect.2b2t.org \n SERVER_NAME = MC Server Entry Name. Example: .minecraft/XaeroWorldMap/Multiplayer_2b2t \n BASE_DOMAIN = Base Server Domain Name. Example: .minecraft/XaeroWorldMap/Multiplayer_2b2t.org",
"setting.world_map.data_folder_resolution_mode.ip": "IP",
"setting.world_map.data_folder_resolution_mode.server_name": "Server Name",
"setting.world_map.data_folder_resolution_mode.base_domain": "Base Domain",
Expand Down

0 comments on commit f1e534c

Please sign in to comment.