From 707fca6204e39985865c8d55af7e575e8820f09a Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:07:40 -0700 Subject: [PATCH 1/2] add click to open to `/xaeroDataDir` command --- .../main/java/xaeroplus/util/DataFolderResolveUtil.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/xaeroplus/util/DataFolderResolveUtil.java b/common/src/main/java/xaeroplus/util/DataFolderResolveUtil.java index fc433493..fefdc434 100644 --- a/common/src/main/java/xaeroplus/util/DataFolderResolveUtil.java +++ b/common/src/main/java/xaeroplus/util/DataFolderResolveUtil.java @@ -1,8 +1,10 @@ package xaeroplus.util; import com.google.common.net.InternetDomainName; +import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import xaero.map.MapProcessor; @@ -71,7 +73,12 @@ public static Component getCurrentDataDirPath() { MapProcessor mapProcessor = currentSession.getMapProcessor(); String mainId = mapProcessor.getMapWorld().getMainId(); Path rootFolder = MapSaveLoad.getRootFolder(mainId); - return (Component.literal(rootFolder.toString())); + return Component.literal(rootFolder.toString()) + .append(Component.literal(" (") + .append(Component.literal("Click To Open").withStyle(style -> style + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, rootFolder.toString())) + .withColor(ChatFormatting.GOLD))) + .append(Component.literal(")"))); } catch (final Throwable e) { XaeroPlus.LOGGER.error("Failed to get data directory", e); return Component.literal("Failed to get data directory"); From ddc66dea684f22adfca070a4a7f9560ecccc6e26 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Sat, 31 Aug 2024 23:55:11 -0700 Subject: [PATCH 2/2] avoid mixin on writeChunk completely --- .../mixin/client/MixinMapWriter.java | 109 +++++++++--------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java b/common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java index fb717bee..03cbee87 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java @@ -28,7 +28,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import xaero.map.MapProcessor; import xaero.map.MapWriter; import xaero.map.biome.BiomeColorCalculator; @@ -204,46 +203,53 @@ public long removeWriteTimeLimiterPerFrame(long original) { return original; } - @Inject(method = "writeChunk", at = @At(value = "HEAD"), cancellable = true, remap = false) - public void writeChunk( - Level world, - Registry blockRegistry, - int distance, - boolean onlyLoad, - Registry biomeRegistry, - OverlayManager overlayManager, - boolean loadChunks, - boolean updateChunks, - boolean ignoreHeightmaps, - boolean flowers, - boolean detailedDebug, - BlockPos.MutableBlockPos mutableBlockPos3, - BlockTintProvider blockTintProvider, - int caveDepth, - int caveStart, - int layerToWrite, - int tileChunkX, - int tileChunkZ, - int tileChunkLocalX, - int tileChunkLocalZ, - int chunkX, - int chunkZ, - final CallbackInfoReturnable cir) { - if (!XaeroPlusSettingRegistry.fastMapSetting.getValue()) return; - if (this.mapProcessor.getCurrentCaveLayer() != Integer.MAX_VALUE) return; - - final Long cacheable = ChunkUtils.chunkPosToLong(chunkX, chunkZ); - final Long cacheValue = tileUpdateCache.getIfPresent(cacheable); - if (nonNull(cacheValue)) { - if (cacheValue < System.currentTimeMillis() - (long) XaeroPlusSettingRegistry.fastMapWriterDelaySetting.getValue()) { - tileUpdateCache.put(cacheable, System.currentTimeMillis()); - } else { - cir.setReturnValue(false); - cir.cancel(); + @WrapOperation(method = "writeMap", at = @At( + value = "INVOKE", + target = "Lxaero/map/MapWriter;writeChunk(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/Registry;IZLnet/minecraft/core/Registry;Lxaero/map/region/OverlayManager;ZZZZZLnet/minecraft/core/BlockPos$MutableBlockPos;Lxaero/map/biome/BlockTintProvider;IIIIIIIII)Z" + ), remap = true) // $REMAP + public boolean fastMap(final MapWriter instance, + Level world, + Registry blockRegistry, + int distance, + boolean onlyLoad, + Registry biomeRegistry, + OverlayManager overlayManager, + boolean loadChunks, + boolean updateChunks, + boolean ignoreHeightmaps, + boolean flowers, + boolean detailedDebug, + BlockPos.MutableBlockPos mutableBlockPos3, + BlockTintProvider blockTintProvider, + int caveDepth, + int caveStart, + int layerToWrite, + int tileChunkX, + int tileChunkZ, + int tileChunkLocalX, + int tileChunkLocalZ, + int chunkX, + int chunkZ, + final Operation original) { + if (XaeroPlusSettingRegistry.fastMapSetting.getValue()) { + if (this.mapProcessor.getCurrentCaveLayer() == Integer.MAX_VALUE) { + final Long cacheable = ChunkUtils.chunkPosToLong(chunkX, chunkZ); + final Long cacheValue = tileUpdateCache.getIfPresent(cacheable); + if (nonNull(cacheValue)) { + if (cacheValue < System.currentTimeMillis() - (long) XaeroPlusSettingRegistry.fastMapWriterDelaySetting.getValue()) { + tileUpdateCache.put(cacheable, System.currentTimeMillis()); + } else { + return false; + } + } else { + tileUpdateCache.put(cacheable, System.currentTimeMillis()); + } } - } else { - tileUpdateCache.put(cacheable, System.currentTimeMillis()); } + return original.call(instance, world, blockRegistry, distance, onlyLoad, biomeRegistry, + overlayManager, loadChunks, updateChunks, ignoreHeightmaps, flowers, detailedDebug, + mutableBlockPos3, blockTintProvider, caveDepth, caveStart, layerToWrite, tileChunkX, + tileChunkZ, tileChunkLocalX, tileChunkLocalZ, chunkX, chunkZ); } @Inject(method = "loadPixel", at = @At("HEAD"), remap = false) @@ -278,25 +284,18 @@ public ResourceKey removeCustomDimSwitchWriterPrevention(final MapWorld m * if writeChunk or a method down the stack throws an exception it is possible for the signal not to be reset, although signals won't cross thread barriers */ - @Inject(method = "writeChunk", at = @At("HEAD")) - public void getActualMapRegionDimSignalHead(final Level world, final Registry blockRegistry, final int distance, final boolean onlyLoad, final Registry biomeRegistry, final OverlayManager overlayManager, final boolean loadChunks, final boolean updateChunks, final boolean ignoreHeightmaps, final boolean flowers, final boolean detailedDebug, final BlockPos.MutableBlockPos mutableBlockPos3, final BlockTintProvider blockTintProvider, final int caveDepth, final int caveStart, final int layerToWrite, final int tileChunkX, final int tileChunkZ, final int tileChunkLocalX, final int tileChunkLocalZ, final int chunkX, final int chunkZ, final CallbackInfoReturnable cir) { - ((CustomMapProcessor) mapProcessor).xaeroPlus$getLeafRegionActualDimSignal().set(XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() && mapProcessor.getMapWorld().isMultiplayer()); + @Inject(method = "onRender", at = @At("HEAD")) + public void setCrossDimWriteSignals(final BiomeColorCalculator biomeColorCalculator, final OverlayManager overlayManager, final CallbackInfo ci) { + boolean signal = XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() + && mapProcessor.getWorld() != null + && mapProcessor.getMapWorld().isMultiplayer(); + ((CustomMapProcessor) mapProcessor).xaeroPlus$getLeafRegionActualDimSignal().set(signal); + ((CustomMapProcessor) mapProcessor).xaeroPlus$getCurrentDimensionActualDimSignal().set(signal); } - @Inject(method = "writeChunk", at = @At("RETURN")) - public void getActualMapRegionDimSignalReturn(final Level world, final Registry blockRegistry, final int distance, final boolean onlyLoad, final Registry biomeRegistry, final OverlayManager overlayManager, final boolean loadChunks, final boolean updateChunks, final boolean ignoreHeightmaps, final boolean flowers, final boolean detailedDebug, final BlockPos.MutableBlockPos mutableBlockPos3, final BlockTintProvider blockTintProvider, final int caveDepth, final int caveStart, final int layerToWrite, final int tileChunkX, final int tileChunkZ, final int tileChunkLocalX, final int tileChunkLocalZ, final int chunkX, final int chunkZ, final CallbackInfoReturnable cir) { + @Inject(method = "onRender", at = @At("RETURN")) + public void resetSignals(final BiomeColorCalculator biomeColorCalculator, final OverlayManager overlayManager, final CallbackInfo ci) { ((CustomMapProcessor) mapProcessor).xaeroPlus$getLeafRegionActualDimSignal().set(false); - } - - @Inject(method = "writeChunk", at = @At("HEAD")) - public void setGetCurrentDimActualDimSignalHead(final Level world, final Registry blockRegistry, final int distance, final boolean onlyLoad, final Registry biomeRegistry, final OverlayManager overlayManager, final boolean loadChunks, final boolean updateChunks, final boolean ignoreHeightmaps, final boolean flowers, final boolean detailedDebug, final BlockPos.MutableBlockPos mutableBlockPos3, final BlockTintProvider blockTintProvider, final int caveDepth, final int caveStart, final int layerToWrite, final int tileChunkX, final int tileChunkZ, final int tileChunkLocalX, final int tileChunkLocalZ, final int chunkX, final int chunkZ, final CallbackInfoReturnable cir) { - var mapWorld = mapProcessor.getWorld(); - var setSignal = XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() && mapWorld != null && mapProcessor.getMapWorld().isMultiplayer(); - ((CustomMapProcessor) mapProcessor).xaeroPlus$getCurrentDimensionActualDimSignal().set(setSignal); - } - - @Inject(method = "writeChunk", at = @At("RETURN")) - public void setGetCurrentDimActualDimSignalTail(final Level world, final Registry blockRegistry, final int distance, final boolean onlyLoad, final Registry biomeRegistry, final OverlayManager overlayManager, final boolean loadChunks, final boolean updateChunks, final boolean ignoreHeightmaps, final boolean flowers, final boolean detailedDebug, final BlockPos.MutableBlockPos mutableBlockPos3, final BlockTintProvider blockTintProvider, final int caveDepth, final int caveStart, final int layerToWrite, final int tileChunkX, final int tileChunkZ, final int tileChunkLocalX, final int tileChunkLocalZ, final int chunkX, final int chunkZ, final CallbackInfoReturnable cir) { ((CustomMapProcessor) mapProcessor).xaeroPlus$getCurrentDimensionActualDimSignal().set(false); }