diff --git a/patches/rtm.patch b/patches/rtm.patch index 69db0886..c51a3b21 100644 --- a/patches/rtm.patch +++ b/patches/rtm.patch @@ -87,6 +87,257 @@ index 5ca3be3..92dcff4 100644 .method public onBogieUpdate ()V .limit stack 2 +diff --git a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/train/EntityTrainBase.jasm b/src/main/rtm/jp/ngt/rtm/entity/train/EntityTrainBase.jasm +index 50ba737..796060f 100644 +--- a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/train/EntityTrainBase.jasm ++++ b/src/main/rtm/jp/ngt/rtm/entity/train/EntityTrainBase.jasm +@@ -66,20 +66,23 @@ + .field private final loadedChunks Ljava/util/Set; + .signature "Ljava/util/Set;" + .end field + + .field private prevChunkCoordX I + .end field + + .field private prevChunkCoordZ I + .end field + ++.field private prevChunkLoaderRadius I ++.end field ++ + .method public (Lnet/minecraft/world/World;)V + .limit stack 3 + .limit local 2 + L_0000: + .line 89 + .var 0 is this Ljp/ngt/rtm/entity/train/EntityTrainBase; from L_0000 to L_0030 + .var 1 is world Lnet/minecraft/world/World; from L_0000 to L_0030 + aload 0 + aload 1 + invokespecial jp/ngt/rtm/entity/vehicle/EntityVehicleBase/ (Lnet/minecraft/world/World;)V +@@ -101,23 +104,23 @@ L_0011: + iconst_1 + putfield jp/ngt/rtm/entity/train/EntityTrainBase/onRail Z + L_0016: + .line 81 + aload 0 + sipush 2880 + putfield jp/ngt/rtm/entity/train/EntityTrainBase/brakeAirCount I + L_001b: + .line 1180 + aload 0 +- new java/util/HashSet ++ new java/util/LinkedHashSet + dup +- invokespecial java/util/HashSet/ ()V ++ invokespecial java/util/LinkedHashSet/ ()V + putfield jp/ngt/rtm/entity/train/EntityTrainBase/loadedChunks Ljava/util/Set; + L_0022: + .line 90 + aload 0 + ldc 2.75f + ldc 1.1875f + invokevirtual jp/ngt/rtm/entity/train/EntityTrainBase/setSize (FF)V + L_0028: + .line 91 + aload 0 +@@ -4649,21 +4652,21 @@ L_0000: + .line 1174 + .var 0 is this Ljp/ngt/rtm/entity/train/EntityTrainBase; from L_0000 to L_0005 + .var 1 is target Lnet/minecraft/util/math/RayTraceResult; from L_0000 to L_0005 + aload 0 + invokestatic jp/ngt/rtm/item/ItemTrain/convertFormationAsItem (Ljp/ngt/rtm/entity/train/EntityTrainBase;)Lnet/minecraft/item/ItemStack; + areturn + L_0005: + .end method + + .method private updateChunks ()V +- .limit stack 2 ++ .limit stack 3 + .limit local 1 + L_0000: + .line 1187 + .var 0 is this Ljp/ngt/rtm/entity/train/EntityTrainBase; from L_0000 to L_001f + aload 0 + invokevirtual jp/ngt/rtm/entity/train/EntityTrainBase/isChunkLoaderEnable ()Z + ifeq L_000a + L_0005: + .line 1189 + aload 0 +@@ -4683,20 +4686,28 @@ L_000f: + aload 0 + aload 0 + getfield jp/ngt/rtm/entity/train/EntityTrainBase/chunkCoordX I + putfield jp/ngt/rtm/entity/train/EntityTrainBase/prevChunkCoordX I + L_0016: + .line 1197 + aload 0 + aload 0 + getfield jp/ngt/rtm/entity/train/EntityTrainBase/chunkCoordZ I + putfield jp/ngt/rtm/entity/train/EntityTrainBase/prevChunkCoordZ I ++ ++ .line 11197 ++ aload 0 ++ aload 0 ++ getstatic jp/ngt/rtm/entity/train/util/TrainState$TrainStateType/ChunkLoader Ljp/ngt/rtm/entity/train/util/TrainState$TrainStateType; ++ invokevirtual jp/ngt/rtm/entity/train/EntityTrainBase/getVehicleState (Ljp/ngt/rtm/entity/train/util/TrainState$TrainStateType;)B ++ putfield jp/ngt/rtm/entity/train/EntityTrainBase/prevChunkLoaderRadius I ++ + L_001c: + .line 1198 + return + L_001f: + .end method + + .method public isChunkLoaderEnable ()Z + .limit stack 2 + .limit local 1 + L_0000: +@@ -4776,25 +4787,20 @@ L_000c: + aload 0 + getstatic jp/ngt/rtm/entity/train/util/TrainState$TrainStateType/ChunkLoader Ljp/ngt/rtm/entity/train/util/TrainState$TrainStateType; + invokevirtual jp/ngt/rtm/entity/train/EntityTrainBase/getVehicleState (Ljp/ngt/rtm/entity/train/util/TrainState$TrainStateType;)B + istore 2 + L_0012: + .line 1222 + .var 2 is depth I from L_0012 to L_002a + aload 1 + invokevirtual net/minecraftforge/common/ForgeChunkManager$Ticket/getModData ()Lnet/minecraft/nbt/NBTTagCompound; + pop +-L_0017: +- .line 1223 +- aload 1 +- iload 2 +- invokevirtual net/minecraftforge/common/ForgeChunkManager$Ticket/setChunkListDepth (I)V + L_001c: + .line 1224 + aload 1 + aload 0 + invokevirtual net/minecraftforge/common/ForgeChunkManager$Ticket/bindEntity (Lnet/minecraft/entity/Entity;)V + L_0021: + .line 1225 + aload 0 + aload 1 + invokevirtual jp/ngt/rtm/entity/train/EntityTrainBase/setChunkTicket (Lnet/minecraftforge/common/ForgeChunkManager$Ticket;)V +@@ -4890,36 +4896,62 @@ L_0007: + getfield jp/ngt/rtm/entity/train/EntityTrainBase/ticket Lnet/minecraftforge/common/ForgeChunkManager$Ticket; + ifnonnull L_0011 + aload 0 + invokespecial jp/ngt/rtm/entity/train/EntityTrainBase/requestTicket ()Z + ifne L_0011 + return + L_0011: + .line 1259 + .stack use locals + .end stack ++ ++ aload 0 ++ getstatic jp/ngt/rtm/entity/train/util/TrainState$TrainStateType/ChunkLoader Ljp/ngt/rtm/entity/train/util/TrainState$TrainStateType; ++ invokevirtual jp/ngt/rtm/entity/train/EntityTrainBase/getVehicleState (Ljp/ngt/rtm/entity/train/util/TrainState$TrainStateType;)B ++ aload 0 ++ getfield jp/ngt/rtm/entity/train/EntityTrainBase/prevChunkLoaderRadius I ++ if_icmpne L_should_setupChunks ++ + iload 1 + aload 0 + getfield jp/ngt/rtm/entity/train/EntityTrainBase/prevChunkCoordX I + if_icmpne L_001c + iload 2 + aload 0 + getfield jp/ngt/rtm/entity/train/EntityTrainBase/prevChunkCoordZ I + if_icmpeq L_0023 ++L_should_setupChunks: + L_001c: + .line 1261 + .stack use locals + .end stack + aload 0 + iload 1 + iload 2 + invokespecial jp/ngt/rtm/entity/train/EntityTrainBase/setupChunks (II)V ++ ++ aload 0 ++ getfield jp/ngt/rtm/entity/train/EntityTrainBase/ticket Lnet/minecraftforge/common/ForgeChunkManager$Ticket; ++ aload 0 ++ getstatic jp/ngt/rtm/entity/train/util/TrainState$TrainStateType/ChunkLoader Ljp/ngt/rtm/entity/train/util/TrainState$TrainStateType; ++ invokevirtual jp/ngt/rtm/entity/train/EntityTrainBase/getVehicleState (Ljp/ngt/rtm/entity/train/util/TrainState$TrainStateType;)B ++ iconst_2 ++ imul ++ iconst_1 ++ iadd ++ dup ++ imul ++ ldc "rtm" ++ invokestatic net/minecraftforge/common/ForgeChunkManager/getMaxChunkDepthFor (Ljava/lang/String;)I ++ invokestatic java/lang/Math/min (II)I ++ invokevirtual net/minecraftforge/common/ForgeChunkManager$Ticket/setChunkListDepth (I)V ++ + L_0023: + .line 1264 + .stack use locals + .end stack + aload 0 + getfield jp/ngt/rtm/entity/train/EntityTrainBase/loadedChunks Ljava/util/Set; + invokeinterface java/util/Set/iterator ()Ljava/util/Iterator; + astore 3 + L_002a: + .stack +@@ -4935,20 +4967,27 @@ L_002a: + invokeinterface java/util/Iterator/next ()Ljava/lang/Object; + checkcast net/minecraft/util/math/ChunkPos + astore 4 + L_0033: + .line 1266 + .var 4 is chunk Lnet/minecraft/util/math/ChunkPos; from L_0033 to L_0039 + aload 0 + getfield jp/ngt/rtm/entity/train/EntityTrainBase/ticket Lnet/minecraftforge/common/ForgeChunkManager$Ticket; + aload 4 + invokestatic net/minecraftforge/common/ForgeChunkManager/forceChunk (Lnet/minecraftforge/common/ForgeChunkManager$Ticket;Lnet/minecraft/util/math/ChunkPos;)V ++ ++ .line 11266 ++ aload 0 ++ getfield jp/ngt/rtm/entity/train/EntityTrainBase/ticket Lnet/minecraftforge/common/ForgeChunkManager$Ticket; ++ aload 4 ++ invokestatic net/minecraftforge/common/ForgeChunkManager/reorderChunk (Lnet/minecraftforge/common/ForgeChunkManager$Ticket;Lnet/minecraft/util/math/ChunkPos;)V ++ + L_0039: + .line 1268 + goto L_002a + L_003c: + .line 1269 + .stack + locals Object jp/ngt/rtm/entity/train/EntityTrainBase + locals Integer + locals Integer + .end stack +@@ -4958,20 +4997,27 @@ L_003c: + iload 2 + invokespecial net/minecraft/util/math/ChunkPos/ (II)V + astore 3 + L_0045: + .line 1270 + .var 3 is myChunk Lnet/minecraft/util/math/ChunkPos; from L_0045 to L_004b + aload 0 + getfield jp/ngt/rtm/entity/train/EntityTrainBase/ticket Lnet/minecraftforge/common/ForgeChunkManager$Ticket; + aload 3 + invokestatic net/minecraftforge/common/ForgeChunkManager/forceChunk (Lnet/minecraftforge/common/ForgeChunkManager$Ticket;Lnet/minecraft/util/math/ChunkPos;)V ++ ++ .line 11270 ++ aload 0 ++ getfield jp/ngt/rtm/entity/train/EntityTrainBase/ticket Lnet/minecraftforge/common/ForgeChunkManager$Ticket; ++ aload 3 ++ invokestatic net/minecraftforge/common/ForgeChunkManager/reorderChunk (Lnet/minecraftforge/common/ForgeChunkManager$Ticket;Lnet/minecraft/util/math/ChunkPos;)V ++ + L_004b: + .line 1272 + .stack use locals + .end stack + return + L_004f: + .end method + + .method private setupChunks (II)V + .limit stack 5 diff --git a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/train/util/Formation.jasm b/src/main/rtm/jp/ngt/rtm/entity/train/util/Formation.jasm index 08fdfe9..a7f5e63 100644 --- a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/train/util/Formation.jasm @@ -1471,3 +1722,118 @@ index 34f470e..019c243 100644 locals Object java/lang/String locals Object java/util/Map locals Object java/util/Iterator +diff --git a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/world/RTMChunkManager.jasm b/src/main/rtm/jp/ngt/rtm/world/RTMChunkManager.jasm +index 478c0e0..02bf660 100644 +--- a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/world/RTMChunkManager.jasm ++++ b/src/main/rtm/jp/ngt/rtm/world/RTMChunkManager.jasm +@@ -66,108 +66,33 @@ L_0019: + locals Object jp/ngt/rtm/world/RTMChunkManager + locals Object net/minecraftforge/event/entity/EntityEvent$EnteringChunk + .end stack + return + L_001d: + .end method + + .method public getChunksAround (Ljava/util/Set;III)V + .signature "(Ljava/util/Set;III)V" + .limit stack 5 +- .limit local 7 ++ .limit local 5 + L_0000: + .line 50 + .var 0 is this Ljp/ngt/rtm/world/RTMChunkManager; from L_0000 to L_0035 + .var 1 is set Ljava/util/Set; signature "Ljava/util/Set;" from L_0000 to L_0035 + .var 2 is xChunk I from L_0000 to L_0035 + .var 3 is zChunk I from L_0000 to L_0035 + .var 4 is radius I from L_0000 to L_0035 + aload 1 +- invokeinterface java/util/Set/clear ()V +-L_0004: +- .line 51 +- iload 2 +- iload 4 +- isub +- istore 5 +-L_000a: +- .var 5 is xx I from L_000a to L_0031 +- .stack +- locals Object jp/ngt/rtm/world/RTMChunkManager +- locals Object java/util/Set +- locals Integer +- locals Integer +- locals Integer +- locals Integer +- .end stack +- iload 5 + iload 2 +- iload 4 +- iadd +- if_icmpgt L_0031 +-L_0011: +- .line 53 +- iload 3 +- iload 4 +- isub +- istore 6 +-L_0017: +- .var 6 is zz I from L_0017 to L_002c +- .stack +- locals Object jp/ngt/rtm/world/RTMChunkManager +- locals Object java/util/Set +- locals Integer +- locals Integer +- locals Integer +- locals Integer +- locals Integer +- .end stack +- iload 6 + iload 3 + iload 4 +- iadd +- if_icmpgt L_002c +-L_001e: +- .line 55 +- aload 1 +- new net/minecraft/util/math/ChunkPos +- dup +- iload 5 +- iload 6 +- invokespecial net/minecraft/util/math/ChunkPos/ (II)V +- invokeinterface java/util/Set/add (Ljava/lang/Object;)Z +- pop +-L_0028: +- .line 53 +- iinc 6 1 +- goto L_0017 +-L_002c: +- .line 51 +- .stack +- locals Object jp/ngt/rtm/world/RTMChunkManager +- locals Object java/util/Set +- locals Integer +- locals Integer +- locals Integer +- locals Integer +- .end stack +- iinc 5 1 +- goto L_000a +-L_0031: +- .line 58 +- .stack +- locals Object jp/ngt/rtm/world/RTMChunkManager +- locals Object java/util/Set +- locals Integer +- locals Integer +- locals Integer +- .end stack ++ invokestatic com/anatawa12/fixRtm/rtm/world/RTMChunkManagerKt/getChunksAround (Ljava/util/Set;III)V + return + L_0035: + .end method + + .method public getNewTicket (Lnet/minecraft/world/World;Lnet/minecraftforge/common/ForgeChunkManager$Type;)Lnet/minecraftforge/common/ForgeChunkManager$Ticket; + .limit stack 3 + .limit local 3 + L_0000: + .line 62 + .var 0 is this Ljp/ngt/rtm/world/RTMChunkManager; from L_0000 to L_0007 diff --git a/src/main/java/com/anatawa12/fixRtm/rtm/world/RTMChunkManager.kt b/src/main/java/com/anatawa12/fixRtm/rtm/world/RTMChunkManager.kt new file mode 100644 index 00000000..7a131982 --- /dev/null +++ b/src/main/java/com/anatawa12/fixRtm/rtm/world/RTMChunkManager.kt @@ -0,0 +1,24 @@ +@file:JvmName("RTMChunkManagerKt") + +package com.anatawa12.fixRtm.rtm.world + +import net.minecraft.util.math.ChunkPos +import kotlin.math.abs +import kotlin.math.max + + +fun getChunksAround(set: MutableSet, xChunk: Int, zChunk: Int, radius: Int) { + set.clear() + val list = mutableListOf() + + for (xx in xChunk - radius..xChunk + radius) { + for (zz in zChunk - radius..zChunk + radius) { + list.add(ChunkPos(xx, zz)) + } + } + + list.sortByDescending { max(abs(it.x - xChunk), abs(it.z - zChunk)) } + + set.addAll(list) + +}