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 Jul 16, 2024
2 parents 2ed0eed + b660c93 commit 8e4d64d
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package xaeroplus.feature.extensions;

public interface CustomMapProcessor {
ThreadLocal<Boolean> xaeroPlus$getLeafRegionActualDimSignal();
}
110 changes: 109 additions & 1 deletion common/src/main/java/xaeroplus/mixin/client/MixinMapProcessor.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package xaeroplus.mixin.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
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;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import xaero.map.MapProcessor;
import xaero.map.region.MapRegion;
import xaero.map.world.MapDimension;
import xaero.map.world.MapWorld;
import xaeroplus.Globals;
import xaeroplus.XaeroPlus;
import xaeroplus.event.XaeroWorldChangeEvent;
import xaeroplus.feature.extensions.CustomMapProcessor;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.util.DataFolderResolveUtil;

import java.nio.file.Path;
Expand All @@ -22,10 +37,23 @@
import static xaeroplus.Globals.LOCK_ID;

@Mixin(value = MapProcessor.class, remap = false)
public abstract class MixinMapProcessor {
public abstract class MixinMapProcessor implements CustomMapProcessor {
@Shadow private String currentWorldId;
@Shadow private String currentDimId;
@Shadow private String currentMWId;
@Unique private String xaeroPlus$prevWorldId;
@Unique private String xaeroPlus$prevDimId;
@Unique private String xaeroPlus$prevMWId;
@Shadow private ClientLevel world;

@Unique
private static final ThreadLocal<Boolean> xaeroPlus$getLeafRegionActualDimSignal = ThreadLocal.withInitial(() -> false);
@Override
public ThreadLocal<Boolean> xaeroPlus$getLeafRegionActualDimSignal() {
return xaeroPlus$getLeafRegionActualDimSignal;
}

@Shadow public abstract String getDimensionName(final ResourceKey<Level> id);

@Inject(method = "getMainId", at = @At("HEAD"), cancellable = true, remap = false)
private void getMainId(final boolean rootFolderFormat, boolean preIP6Fix, final ClientPacketListener connection, final CallbackInfoReturnable<String> cir) {
Expand Down Expand Up @@ -65,4 +93,84 @@ public Path replaceLockPath(final Path instance, final String other) {
public void fireWorldChangedEvent(final CallbackInfo ci) {
XaeroPlus.EVENT_BUS.call(new XaeroWorldChangeEvent(this.currentWorldId, this.currentDimId, this.currentMWId));
}

@Inject(method = "getLeafMapRegion", at = @At("HEAD"))
public void signalToLocalShare(final int caveLayer, final int regX, final int regZ, final boolean create, final CallbackInfoReturnable<MapRegion> cir,
@Share("signal") LocalBooleanRef signal) {
signal.set(xaeroPlus$getLeafRegionActualDimSignal().get());
xaeroPlus$getLeafRegionActualDimSignal().set(false); // reset
}

@WrapOperation(method = "getLeafMapRegion", at = @At(
value = "INVOKE",
target = "Lxaero/map/world/MapWorld;getCurrentDimension()Lxaero/map/world/MapDimension;",
ordinal = 0
))
public MapDimension getLeafMapRegionActualDimensionIfSignalled(final MapWorld instance, final Operation<MapDimension> original,
@Share("signal") LocalBooleanRef signal) {
var world = this.world;
if (signal.get() && world != null && xaeroPlus$prevDimId != null && xaeroPlus$prevDimId.equals(getDimensionName(world.dimension()))) {
return instance.getDimension(world.dimension());
} else return original.call(instance);
}

@WrapOperation(method = "getLeafMapRegion", at = @At(
value = "NEW",
target = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lxaero/map/world/MapDimension;IIIIZLnet/minecraft/core/Registry;)Lxaero/map/region/MapRegion;"
), remap = true) // $REMAP
public MapRegion createMapRegionInActualDimensionIfSignalled(String worldId, String dimId, String mwId, MapDimension dim, int x, int z, int caveLayer, int initialVersion, boolean normalMapData, Registry<Biome> biomeRegistry, Operation<MapRegion> original,
@Share("signal") LocalBooleanRef signal) {
var world = this.world;
if (signal.get() && world != null && xaeroPlus$prevDimId != null && xaeroPlus$prevDimId.equals(getDimensionName(world.dimension()))) {
worldId = xaeroPlus$prevWorldId;
dimId = xaeroPlus$prevDimId;
mwId = xaeroPlus$prevMWId;
}
return original.call(
worldId,
dimId,
mwId,
dim,
x,
z,
caveLayer,
initialVersion,
normalMapData,
biomeRegistry);
}

@WrapOperation(method = "updateWorldSynced", at = @At(
value = "INVOKE",
target = "Lxaero/map/world/MapWorld;getCurrentDimension()Lxaero/map/world/MapDimension;",
ordinal = 0
),
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lxaero/map/MapProcessor;releaseLocksIfNeeded()V",
ordinal = 0
)
))
public MapDimension updateWorldSyncedGetActualDimension(final MapWorld mapWorld, final Operation<MapDimension> original) {
var world = this.world;
return XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() && world != null
? mapWorld.getDimension(world.dimension())
: original.call(mapWorld);
}

@WrapOperation(method = "updateWorldSynced", at = @At(
value = "FIELD",
target = "Lxaero/map/MapProcessor;currentWorldId:Ljava/lang/String;",
opcode = Opcodes.PUTFIELD,
ordinal = 0
))
public void storePrevWorldVarStates(final MapProcessor instance, final String value, final Operation<Void> original) {
var world = this.world;
if (world != null && getDimensionName(world.dimension()).equals(currentDimId)) {
this.xaeroPlus$prevWorldId = this.currentWorldId;
this.xaeroPlus$prevDimId = this.currentDimId;
this.xaeroPlus$prevMWId = this.currentMWId;
}
original.call(instance, value);
}
}
58 changes: 58 additions & 0 deletions common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
Expand All @@ -33,8 +34,11 @@
import xaero.map.biome.BiomeColorCalculator;
import xaero.map.biome.BlockTintProvider;
import xaero.map.region.MapBlock;
import xaero.map.region.MapRegion;
import xaero.map.region.OverlayBuilder;
import xaero.map.region.OverlayManager;
import xaero.map.world.MapWorld;
import xaeroplus.feature.extensions.CustomMapProcessor;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.util.ChunkUtils;

Expand Down Expand Up @@ -254,4 +258,58 @@ public void netherCaveFixInject(final Level world, final Registry<Block> blockRe
fullCaveRef.set(shouldForceFullInNether || fullCave);
}
}

@WrapOperation(method = "onRender", at = @At(
value = "INVOKE",
target = "Lxaero/map/world/MapWorld;getCurrentDimensionId()Lnet/minecraft/resources/ResourceKey;"),
remap = true) // $REMAP
public ResourceKey<Level> removeCustomDimSwitchWriterPrevention(final MapWorld mapWorld, final Operation<ResourceKey<Level>> original) {
var world = mapProcessor.getWorld();
return XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() && world != null
? world.dimension() // makes if condition in injected code always true
: original.call(mapWorld);
}

@WrapOperation(method = "writeChunk", at = @At(
value = "INVOKE",
target = "Lxaero/map/MapProcessor;getLeafMapRegion(IIIZ)Lxaero/map/region/MapRegion;"
))
public MapRegion getActualMapRegionInWriteChunk(final MapProcessor mapProcessor, int caveLayer, int regX, int regZ, boolean create, final Operation<MapRegion> original) {
if (XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue()) {
((CustomMapProcessor) mapProcessor).xaeroPlus$getLeafRegionActualDimSignal().set(true);
}
return original.call(
mapProcessor,
caveLayer,
regX,
regZ,
create);
}

@WrapOperation(method = "writeChunk", at = @At(
value = "INVOKE",
target = "Lxaero/map/MapProcessor;getCurrentDimension()Ljava/lang/String;"
))
public String getActualDimensionInWriteChunk(final MapProcessor mapProcessor, final Operation<String> original) {
var world = mapProcessor.getWorld();
return XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() && world != null
? mapProcessor.getDimensionName(world.dimension())
: original.call(mapProcessor);
}

@WrapOperation(method = "onRender", at = @At(
value = "INVOKE",
target = "Lxaero/map/MapProcessor;getLeafMapRegion(IIIZ)Lxaero/map/region/MapRegion;"
))
public MapRegion getActualMapRegionInOnRender(final MapProcessor mapProcessor, int caveLayer, int regX, int regZ, boolean create, final Operation<MapRegion> original) {
if (XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue()) {
((CustomMapProcessor) mapProcessor).xaeroPlus$getLeafRegionActualDimSignal().set(true);
}
return original.call(
mapProcessor,
caveLayer,
regX,
regZ,
create);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ public final class XaeroPlusSettingRegistry {
if (!b) Globals.zipFastByteBuffer = new ByteArrayOutputStream(); // release any existing sized buffer to gc
},
true,
SettingLocation.WORLD_MAP_MAIN
);
SettingLocation.WORLD_MAP_MAIN);
public static final XaeroPlusBooleanSetting writesWhileDimSwitched = XaeroPlusBooleanSetting.create(
"Region Writes While Dim Switched",
"setting.world_map.region_write_while_dimension_switched",
"setting.world_map.region_write_while_dimension_switched.tooltip",
false,
SettingLocation.WORLD_MAP_MAIN);
public static final XaeroPlusBooleanSetting baritoneWaypointSyncSetting = XaeroPlusBooleanSetting.create(
"Baritone Goal Waypoint",
"setting.world_map.baritone_waypoint",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"setting.world_map.fast_mapping_rate_limit.tooltip": "Fast Mapping must be enabled. \n Limits how many chunks can be written in a single cycle. Lower values improve FPS at high render distances.",
"setting.world_map.fast_zip_writes": "Fast Zip Writes",
"setting.world_map.fast_zip_writes.tooltip": "Writes Map tile zip files faster but uses more RAM. Disable this if you have low RAM available.",
"setting.world_map.region_write_while_dimension_switched": "Region Writes While Dim Switched",
"setting.world_map.region_write_while_dimension_switched.tooltip": "Fixes Xaero's WorldMap not writing/loading chunks you load while viewing another dimension.",
"setting.world_map.baritone_waypoint": "Baritone Goal Waypoint",
"setting.world_map.baritone_waypoint.tooltip": "Syncs Baritone goals as temporary waypoints.",
"setting.world_map.disable_waypoint_sharing": "Disable Waypoint Sharing",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/es_ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"setting.world_map.fast_mapping_rate_limit.tooltip": "El Mapeo Rápido debe estar habilitado. \n Limita cuántos chunks pueden escribirse en un solo ciclo. Valores más bajos mejoran los FPS a distancias de renderizado altas.",
"setting.world_map.fast_zip_writes": "Escritura Rápida ZIP",
"setting.world_map.fast_zip_writes.tooltip": "Escribe archivos ZIP de los mapas más rápido pero utiliza más RAM. Deshabilitalo si tenes pocc RAM disponible.",
"setting.world_map.region_write_while_dimension_switched": "Escrituras de Región Mientras Se Cambia de Dimensión",
"setting.world_map.region_write_while_dimension_switched.tooltip": "Corrige el WorldMap para que escriba/cargue los fragmentos que cargas mientras ves otra dimensión.",
"setting.world_map.baritone_waypoint": "Punto Destino Baritone",
"setting.world_map.baritone_waypoint.tooltip": "Sincroniza los waypoint (puntos de recorrido) de Baritone como waypoints temporarios.",
"setting.world_map.disable_waypoint_sharing": "Desactivar Compartir waypoint",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/fr_ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"setting.world_map.fast_mapping_rate_limit.tooltip": "L'option Cartographie Rapide doit être activée. \n Limite le nombre de chunks pouvant être écrits à chaque tick.",
"setting.world_map.fast_zip_writes": "Écritures Zip rapides",
"setting.world_map.fast_zip_writes.tooltip": "Écrit les fichiers zip des tuiles de carte plus rapidement mais utilise plus de RAM. Désactivez ceci si vous avez peu de RAM disponible.",
"setting.world_map.region_write_while_dimension_switched": "Écriture de Région Pendant le Changement de Dimension",
"setting.world_map.region_write_while_dimension_switched.tooltip": "Corrige WorldMap pour qu'il écrive/charge les morceaux que vous chargez en regardant une autre dimension.",
"setting.world_map.baritone_waypoint": "Baryton Objectif Waypoint",
"setting.world_map.baritone_waypoint.tooltip": "Synchronise les objectifs de Baritone en tant que waypoints temporaires.",
"setting.world_map.disable_waypoint_sharing": "Désactiver le partage de points de cheminement",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"setting.world_map.fast_mapping_rate_limit.tooltip": "L'option Cartographie Rapide doit être activée. \n Limite le nombre de chunks pouvant être écrits à chaque tick.",
"setting.world_map.fast_zip_writes": "Écritures Zip rapides",
"setting.world_map.fast_zip_writes.tooltip": "Écrit les fichiers zip des tuiles de carte plus rapidement mais utilise plus de RAM. Désactivez ceci si vous avez peu de RAM disponible.",
"setting.world_map.region_write_while_dimension_switched": "Écriture de Région Pendant le Changement de Dimension",
"setting.world_map.region_write_while_dimension_switched.tooltip": "Corrige WorldMap pour qu'il écrive/charge les morceaux que vous chargez en regardant une autre dimension.",
"setting.world_map.baritone_waypoint": "Baryton Objectif Waypoint",
"setting.world_map.baritone_waypoint.tooltip": "Synchronise les objectifs de Baritone en tant que waypoints temporaires.",
"setting.world_map.disable_waypoint_sharing": "Désactiver le partage de points de cheminement",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/ja_jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"setting.world_map.fast_mapping_rate_limit.tooltip": "Fast Mappingを有効にする必要があります。\n1サイクルで書き込めるチャンクの数を制限します。値を低くすると、高いレンダリング距離で FPS が向上します。",
"setting.world_map.fast_zip_writes": "Fast Zip Writes",
"setting.world_map.fast_zip_writes.tooltip": "Map タイルの zip ファイルをより速く書き込みますが、RAM をより多く使用します。使用可能なRAMが少ない場合は無効にしてください。",
"setting.world_map.region_write_while_dimension_switched": "次元切り替え中のリージョン書き込み",
"setting.world_map.region_write_while_dimension_switched.tooltip": "他の次元を表示中に読み込んだチャンクを書き込み/読み込みしないWorldMapの修正。",
"setting.world_map.baritone_waypoint": "Baritone Goal Waypoint",
"setting.world_map.baritone_waypoint.tooltip": "バリトンのゴールを一時的なウェイポイントとして表示させる。",
"setting.world_map.disable_waypoint_sharing": "Disable Waypoint Sharing",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/pl_pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"setting.world_map.fast_mapping_rate_limit.tooltip": "Szybkie Mapowanie musi być włączone. \n Ogranicza liczbę chunktów, które mogą być zapisane co jeden Tick.",
"setting.world_map.fast_zip_writes": "Szybkie Zip pisze",
"setting.world_map.fast_zip_writes.tooltip": "Szybciej zapisuje pliki zip kafelków mapy, ale zużywa więcej pamięci RAM. Wyłącz tę opcję, jeśli masz mało dostępnej pamięci RAM",
"setting.world_map.region_write_while_dimension_switched": "Zapisywanie Regionu Podczas Zmiany Wymiaru",
"setting.world_map.region_write_while_dimension_switched.tooltip": "Naprawia WorldMap, aby zapisywał/ładował kawałki, które ładujesz, oglądając inny wymiar.",
"setting.world_map.baritone_waypoint": "Punkt nawigacyjny Celu Baritone",
"setting.world_map.baritone_waypoint.tooltip": "Synchronizuje cele Baritone jako tymczasowe punkty orientacyjne.",
"setting.world_map.disable_waypoint_sharing": "Wyłącz udostępnianie punktów trasy",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/pt_pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"setting.world_map.fast_mapping_rate_limit.tooltip": "O Mapeamento Rápido tem de estar ativo. \n Limita quantas partes do mapa são gravadas num ciclo. Valores mais baixos aumentam os FPS com alcances visuais maiores.",
"setting.world_map.fast_zip_writes": "Gravação Rápida de Zips",
"setting.world_map.fast_zip_writes.tooltip": "Grava ficheiros zip com dados do mapa mais rápido mas usa mais RAM. Desativa esta opção se tiveres pouca RAM disponível.",
"setting.world_map.region_write_while_dimension_switched": "Escritas de Região Durante a Mudança de Dimensão",
"setting.world_map.region_write_while_dimension_switched.tooltip": "Corrige o WorldMap para escrever/carregar os pedaços que você carrega enquanto visualiza outra dimensão.",
"setting.world_map.baritone_waypoint": "Loc. de Destino do Baritone",
"setting.world_map.baritone_waypoint.tooltip": "Sincroniza os destinos do Baritone como localizações temporárias.",
"setting.world_map.disable_waypoint_sharing": "Desativar Partilha de Localizações",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"setting.world_map.fast_mapping_rate_limit.tooltip": "Быстрое картографирование должно быть включено. \n Ограничивает количество фрагментов, которые могут быть записаны за один цикл. Более низкие значения улучшают FPS на больших расстояниях рендеринга.",
"setting.world_map.fast_zip_writes": "Быстрая запись в почтовый индекс",
"setting.world_map.fast_zip_writes.tooltip": "Записывает ZIP-файлы фрагментов карты быстрее, но использует больше оперативной памяти. Отключите это, если у вас мало оперативной памяти.",
"setting.world_map.region_write_while_dimension_switched": "Запись Региона При Смене Измерения",
"setting.world_map.region_write_while_dimension_switched.tooltip": "Исправляет WorldMap, чтобы записывать/загружать чанки, которые вы загружаете, просматривая другое измерение.",
"setting.world_map.baritone_waypoint": "Точка Цели Baritone",
"setting.world_map.baritone_waypoint.tooltip": "Синхронизирует цели Baritone в качестве временных путевых точек.",
"setting.world_map.disable_waypoint_sharing": "Отключить обмен маршрутными точками",
Expand Down
Loading

0 comments on commit 8e4d64d

Please sign in to comment.