Skip to content

Commit

Permalink
Merge branch '1.20.1' into 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Sep 1, 2024
2 parents 690d0cc + ddc66de commit 27cd2cb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 56 deletions.
109 changes: 54 additions & 55 deletions common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Block> blockRegistry,
int distance,
boolean onlyLoad,
Registry<Biome> 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<Boolean> 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<Block> blockRegistry,
int distance,
boolean onlyLoad,
Registry<Biome> 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<Boolean> 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)
Expand Down Expand Up @@ -278,25 +284,18 @@ public ResourceKey<Level> 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<Block> blockRegistry, final int distance, final boolean onlyLoad, final Registry<Biome> 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<Boolean> 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<Block> blockRegistry, final int distance, final boolean onlyLoad, final Registry<Biome> 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<Boolean> 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<Block> blockRegistry, final int distance, final boolean onlyLoad, final Registry<Biome> 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<Boolean> 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<Block> blockRegistry, final int distance, final boolean onlyLoad, final Registry<Biome> 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<Boolean> cir) {
((CustomMapProcessor) mapProcessor).xaeroPlus$getCurrentDimensionActualDimSignal().set(false);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 27cd2cb

Please sign in to comment.