diff --git a/gradle.properties b/gradle.properties index 05ba2d56..36aeb5d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ modGroup=com.anatawa12.fixRtm -modVersion=2.0.3 +modVersion=SNAPSHOT-2020-05-12-16-32-30 modBaseName=fixRtm forgeVersion=1.12.2-14.23.5.2847 mcpVersion=stable_39 diff --git a/patches/rtm.patch b/patches/rtm.patch index 1e536a22..499649c3 100644 --- a/patches/rtm.patch +++ b/patches/rtm.patch @@ -26,10 +26,33 @@ index 2297030..17edb7e 100644 .line 156 getstatic jp/ngt/rtm/RTMItem/itemMotorman Lnet/minecraft/item/Item; diff --git a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/train/EntityBogie.jasm b/src/main/rtm/jp/ngt/rtm/entity/train/EntityBogie.jasm -index 5ca3be3..aa70ce9 100644 +index 5ca3be3..92dcff4 100644 --- a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/train/EntityBogie.jasm +++ b/src/main/rtm/jp/ngt/rtm/entity/train/EntityBogie.jasm -@@ -1547,24 +1547,34 @@ L_0012: +@@ -128,20 +128,22 @@ L_0020: + iconst_1 + putfield jp/ngt/rtm/entity/train/EntityBogie/preventEntitySpawning Z + L_0025: + .line 81 + aload 0 + ldc 2.75f + ldc 1.1875f + invokevirtual jp/ngt/rtm/entity/train/EntityBogie/setBogieSize (FF)V + L_002b: + .line 82 ++ aload 0 ++ invokestatic com/anatawa12/fixRtm/rtm/entity/train/EntityBogieKt/constructor (Ljp/ngt/rtm/entity/train/EntityBogie;)V + return + L_002e: + .end method + + .method public (Lnet/minecraft/world/World;BLjp/ngt/rtm/entity/train/EntityTrainBase;)V + .limit stack 2 + .limit local 4 + L_0000: + .line 86 + .var 0 is this Ljp/ngt/rtm/entity/train/EntityBogie; from L_0000 to L_0012 +@@ -1547,24 +1549,34 @@ L_0012: .end stack iconst_0 istore 1 @@ -64,11 +87,100 @@ index 5ca3be3..aa70ce9 100644 .method public onBogieUpdate ()V .limit stack 2 +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 ++++ b/src/main/rtm/jp/ngt/rtm/entity/train/util/Formation.jasm +@@ -1843,46 +1843,57 @@ L_0000: + .line 397 + .var 0 is this Ljp/ngt/rtm/entity/train/util/Formation; from L_0000 to L_001f + .var 1 is train Ljp/ngt/rtm/entity/train/EntityTrainBase; from L_0000 to L_001f + aload 0 + getfield jp/ngt/rtm/entity/train/util/Formation/direction B + ifne L_000b + aload 0 + getfield jp/ngt/rtm/entity/train/util/Formation/entries "[Ljp/ngt/rtm/entity/train/util/FormationEntry;" + iconst_0 + aaload +- getfield jp/ngt/rtm/entity/train/util/FormationEntry/train Ljp/ngt/rtm/entity/train/EntityTrainBase; + goto L_0016 + L_000b: + .stack + locals Object jp/ngt/rtm/entity/train/util/Formation + locals Object jp/ngt/rtm/entity/train/EntityTrainBase + .end stack + aload 0 + getfield jp/ngt/rtm/entity/train/util/Formation/entries "[Ljp/ngt/rtm/entity/train/util/FormationEntry;" + aload 0 + getfield jp/ngt/rtm/entity/train/util/Formation/entries "[Ljp/ngt/rtm/entity/train/util/FormationEntry;" + arraylength + iconst_1 + isub + aaload +- getfield jp/ngt/rtm/entity/train/util/FormationEntry/train Ljp/ngt/rtm/entity/train/EntityTrainBase; + L_0016: + .stack use locals +- stacks Object jp/ngt/rtm/entity/train/EntityTrainBase ++ stacks Object jp/ngt/rtm/entity/train/util/FormationEntry + .end stack + astore 2 + L_0019: + .line 398 +- .var 2 is front Ljp/ngt/rtm/entity/train/EntityTrainBase; from L_0019 to L_001f ++ .var 2 is front Ljp/ngt/rtm/entity/train/util/FormationEntry; from L_0019 to L_001f ++ ++ aload 2 ++ ifnonnull L_nonnull ++ iconst_0 ++ ireturn ++L_nonnull: ++ .stack ++ locals Object jp/ngt/rtm/entity/train/util/Formation ++ locals Object jp/ngt/rtm/entity/train/EntityTrainBase ++ locals Object jp/ngt/rtm/entity/train/util/FormationEntry ++ .end stack ++ + aload 1 + aload 2 ++ getfield jp/ngt/rtm/entity/train/util/FormationEntry/train Ljp/ngt/rtm/entity/train/EntityTrainBase; + invokevirtual jp/ngt/rtm/entity/train/EntityTrainBase/equals (Ljava/lang/Object;)Z + ireturn + L_001f: + .end method + + .method public updateTrainMovement ()V + .limit stack 5 + .limit local 6 + L_0000: + .line 404 diff --git a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/vehicle/EntityVehicleBase.jasm b/src/main/rtm/jp/ngt/rtm/entity/vehicle/EntityVehicleBase.jasm -index b252a06..0c0db45 100644 +index b252a06..595c970 100644 --- a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/vehicle/EntityVehicleBase.jasm +++ b/src/main/rtm/jp/ngt/rtm/entity/vehicle/EntityVehicleBase.jasm -@@ -1068,48 +1068,50 @@ L_0004: +@@ -271,20 +271,22 @@ L_0061: + L_0068: + .line 96 + iinc 4 1 + goto L_0058 + L_006c: + .line 100 + .stack + locals Object jp/ngt/rtm/entity/vehicle/EntityVehicleBase + locals Object net/minecraft/world/World + .end stack ++ aload 0 ++ invokestatic com/anatawa12/fixRtm/rtm/entity/vehicle/EntityVehicleBaseKt/constructor (Ljp/ngt/rtm/entity/vehicle/EntityVehicleBase;)V + return + L_0070: + .end method + + .method protected entityInit ()V + .limit stack 0 + .limit local 1 + L_0000: + .line 105 + .var 0 is this Ljp/ngt/rtm/entity/vehicle/EntityVehicleBase; signature "Ljp/ngt/rtm/entity/vehicle/EntityVehicleBase;" from L_0000 to L_0003 +@@ -1068,48 +1070,50 @@ L_0004: astore 4 L_000b: .line 365 @@ -126,7 +238,7 @@ index b252a06..0c0db45 100644 getfield jp/ngt/rtm/entity/vehicle/EntityVehicleBase/posX D dsub aload 2 -@@ -1228,21 +1230,21 @@ L_0092: +@@ -1228,21 +1232,21 @@ L_0092: .line 387 .var 12 is z D from L_0092 to L_00b1 aload 0 @@ -178,11 +290,124 @@ index 5298b6c..b941866 100644 .line 76 .stack locals Object jp/ngt/rtm/entity/vehicle/RenderVehicleBase +diff --git a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry.jasm b/src/main/rtm/jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry.jasm +index 137db20..730442e 100644 +--- a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry.jasm ++++ b/src/main/rtm/jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry.jasm +@@ -616,20 +616,30 @@ L_0051: + new net/minecraft/network/play/server/SPacketEntityAttach + dup + aload 0 + getfield jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry/trackedEntity Lnet/minecraft/entity/Entity; + aload 0 + getfield jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry/trackedEntity Lnet/minecraft/entity/Entity; + invokevirtual net/minecraft/entity/Entity/getRidingEntity ()Lnet/minecraft/entity/Entity; + invokespecial net/minecraft/network/play/server/SPacketEntityAttach/ (Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/Entity;)V + invokevirtual net/minecraft/network/NetHandlerPlayServer/sendPacket (Lnet/minecraft/network/Packet;)V + L_005e: ++ ++ .stack use locals ++ .end stack ++ ++ .line 1195 ++ aload 1 ++ aload 0 ++ getfield jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry/trackedEntity Lnet/minecraft/entity/Entity; ++ invokevirtual net/minecraft/entity/player/EntityPlayerMP/addEntity (Lnet/minecraft/entity/Entity;)V ++ + .line 195 + .stack use locals + .end stack + aload 0 + getfield jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry/trackedEntity Lnet/minecraft/entity/Entity; + aload 1 + invokestatic net/minecraftforge/event/ForgeEventFactory/onStartEntityTracking (Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/player/EntityPlayer;)V + L_0065: + .line 196 + goto L_0083 +@@ -665,26 +675,51 @@ L_007d: + invokestatic net/minecraftforge/event/ForgeEventFactory/onStopEntityTracking (Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/player/EntityPlayer;)V + L_0083: + .line 205 + .stack use locals + .end stack + return + L_0087: + .end method + + .method public isVisibleTo (Lnet/minecraft/entity/player/EntityPlayerMP;)Z +- .limit stack 1 ++ .limit stack 4 + .limit local 2 + L_0000: + .line 210 + .var 0 is this Ljp/ngt/rtm/entity/vehicle/VehicleTrackerEntry; from L_0000 to L_0004 + .var 1 is playerMP Lnet/minecraft/entity/player/EntityPlayerMP; from L_0000 to L_0004 ++ aload 1 ++ aload 0 ++ getfield jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry/trackedEntity Lnet/minecraft/entity/Entity; ++ getfield net/minecraft/entity/Entity/posX D ++ aload 0 ++ getfield jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry/trackedEntity Lnet/minecraft/entity/Entity; ++ getfield net/minecraft/entity/Entity/posY D ++ aload 0 ++ getfield jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry/trackedEntity Lnet/minecraft/entity/Entity; ++ getfield net/minecraft/entity/Entity/posZ D ++ invokevirtual net/minecraft/entity/Entity/getDistanceSq (DDD)D ++ ldc 16.0 ++ ldc 32.0 ++ dmul ++ dup2 ++ dmul ++ dcmpl ++ iflt JMP ++ iconst_0 ++ ireturn ++JMP: ++ .stack ++ locals Object jp/ngt/rtm/entity/vehicle/VehicleTrackerEntry ++ locals Object net/minecraft/entity/player/EntityPlayerMP ++ .end stack + iconst_1 + ireturn + L_0004: + .end method + + .method private isPlayerWatchingThisChunk (Lnet/minecraft/entity/player/EntityPlayerMP;)Z + .limit stack 4 + .limit local 2 + L_0000: + .line 215 diff --git a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/vehicle/WeatherEffectDummy.jasm b/src/main/rtm/jp/ngt/rtm/entity/vehicle/WeatherEffectDummy.jasm -index d0e484a..ab9a52f 100644 +index d0e484a..b7325e4 100644 --- a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/entity/vehicle/WeatherEffectDummy.jasm +++ b/src/main/rtm/jp/ngt/rtm/entity/vehicle/WeatherEffectDummy.jasm -@@ -226,10 +226,21 @@ L_0003: +@@ -110,22 +110,23 @@ L_002b: + L_0032: + .line 36 + aload 0 + aload 0 + getfield jp/ngt/rtm/entity/vehicle/WeatherEffectDummy/parent Ljp/ngt/rtm/entity/vehicle/EntityVehicleBase; + getfield jp/ngt/rtm/entity/vehicle/EntityVehicleBase/rotationPitch F + putfield jp/ngt/rtm/entity/vehicle/WeatherEffectDummy/rotationPitch F + L_0039: + .line 38 + aload 0 ++ aload 0 + getfield jp/ngt/rtm/entity/vehicle/WeatherEffectDummy/parent Ljp/ngt/rtm/entity/vehicle/EntityVehicleBase; +- getfield jp/ngt/rtm/entity/vehicle/EntityVehicleBase/isDead Z ++ invokestatic com/anatawa12/fixRtm/rtm/entity/vehicle/WeatherEffectDummyKt/shouldDead (Ljp/ngt/rtm/entity/vehicle/WeatherEffectDummy;Ljp/ngt/rtm/entity/vehicle/EntityVehicleBase;)Z + ifeq L_0050 + L_003f: + .line 40 + aload 0 + invokevirtual jp/ngt/rtm/entity/vehicle/WeatherEffectDummy/setDead ()V + L_0043: + .line 41 + ldc "[WED] Remove %d" + iconst_1 + anewarray java/lang/Object +@@ -226,10 +227,21 @@ L_0003: .limit stack 0 .limit local 2 L_0000: @@ -575,6 +800,35 @@ index 2945cc2..a90bdee 100644 L_001a: .line 120 aload 0 +diff --git a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/network/PacketVehicleMovement.jasm b/src/main/rtm/jp/ngt/rtm/network/PacketVehicleMovement.jasm +index 6e5c39c..e670ca1 100644 +--- a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/network/PacketVehicleMovement.jasm ++++ b/src/main/rtm/jp/ngt/rtm/network/PacketVehicleMovement.jasm +@@ -357,20 +357,24 @@ L_001b: + L_0023: + .line 97 + .var 4 is entity Lnet/minecraft/entity/Entity; from L_0023 to L_008e + aload 4 + ifnull L_007c + aload 4 + getfield net/minecraft/entity/Entity/isDead Z + ifne L_007c + L_002a: + .line 99 ++ ++ aload 4 ++ invokestatic com/anatawa12/fixRtm/rtm/network/PacketVehicleMovementKt/addEntityIfNotExits (Lnet/minecraft/entity/Entity;)V ++ + aload 1 + getfield jp/ngt/rtm/network/PacketVehicleMovement/vehicleX I + i2d + ldc 0.03125 + dmul + dstore 5 + L_0032: + .line 100 + .var 5 is x D from L_0032 to L_0078 + aload 1 diff --git a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/rail/BlockMarker.jasm b/src/main/rtm/jp/ngt/rtm/rail/BlockMarker.jasm index d2c0e4b..6ffb4cc 100644 --- a/mods/rtm.deobf.jar.src.processed/jp/ngt/rtm/rail/BlockMarker.jasm diff --git a/src/main/java/com/anatawa12/fixRtm/FixRtm.kt b/src/main/java/com/anatawa12/fixRtm/FixRtm.kt index 546277d4..0a4a768a 100644 --- a/src/main/java/com/anatawa12/fixRtm/FixRtm.kt +++ b/src/main/java/com/anatawa12/fixRtm/FixRtm.kt @@ -19,10 +19,12 @@ import net.minecraftforge.event.RegistryEvent import net.minecraftforge.fml.client.registry.ClientRegistry import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.ModMetadata +import net.minecraftforge.fml.common.SidedProxy import net.minecraftforge.fml.common.event.FMLConstructionEvent import net.minecraftforge.fml.common.event.FMLInitializationEvent import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent import net.minecraftforge.fml.common.network.NetworkCheckHandler import net.minecraftforge.fml.relauncher.Side import java.awt.Color @@ -144,7 +146,14 @@ object FixRtm { } } + @SubscribeEvent + fun tick(e: TickEvent.ClientTickEvent) { + if (e.phase == TickEvent.Phase.END) + proxy.tick() + } + @field:SidedProxy(clientSide = "com.anatawa12.fixRtm.ClientProxy", serverSide = "com.anatawa12.fixRtm.ServerProxy") + lateinit var proxy: CommonProxy @Mod.InstanceFactory @JvmStatic diff --git a/src/main/java/com/anatawa12/fixRtm/Proxy.kt b/src/main/java/com/anatawa12/fixRtm/Proxy.kt new file mode 100644 index 00000000..377cdffd --- /dev/null +++ b/src/main/java/com/anatawa12/fixRtm/Proxy.kt @@ -0,0 +1,18 @@ +package com.anatawa12.fixRtm + +import net.minecraft.client.Minecraft + +abstract class CommonProxy { + open fun tick() {} + + +} + +class ServerProxy : CommonProxy() + +class ClientProxy : CommonProxy() { + override fun tick() { + if (Minecraft.getMinecraft().world != null) + VehicleTrackerEntryFix.tick() + } +} diff --git a/src/main/java/com/anatawa12/fixRtm/VehicleTrackerEntryFix.kt b/src/main/java/com/anatawa12/fixRtm/VehicleTrackerEntryFix.kt new file mode 100644 index 00000000..8d8e4231 --- /dev/null +++ b/src/main/java/com/anatawa12/fixRtm/VehicleTrackerEntryFix.kt @@ -0,0 +1,33 @@ +package com.anatawa12.fixRtm + +import net.minecraft.client.Minecraft +import net.minecraft.entity.Entity +import java.util.* + +object VehicleTrackerEntryFix { + private val instances = Collections.newSetFromMap(WeakHashMap()) + + fun addInstance(instance: Entity) { + instances.add(instance) + } + + fun tick() { + val mc = Minecraft.getMinecraft() + val iter = instances.iterator() + while (iter.hasNext()) { + val instance = iter.next() ?: continue + if (instance.world != mc.world) { + iter.remove() + continue + } + if (instance.isDead) continue + if ((!instance.isAddedToWorld || !instance.addedToChunk) + && mc.world.isBlockLoaded(instance.position, false)) { + logger.trace("the entity: $instance is not added") + mc.world.spawnEntity(instance) + } + } + } + + private val logger = Loggers.getLogger("VehicleTrackerEntryFix") +} diff --git a/src/main/java/com/anatawa12/fixRtm/ngtlib/renderer/model/CachedPolygonModel.kt b/src/main/java/com/anatawa12/fixRtm/ngtlib/renderer/model/CachedPolygonModel.kt index bfa97c08..83cbb618 100644 --- a/src/main/java/com/anatawa12/fixRtm/ngtlib/renderer/model/CachedPolygonModel.kt +++ b/src/main/java/com/anatawa12/fixRtm/ngtlib/renderer/model/CachedPolygonModel.kt @@ -5,6 +5,7 @@ import com.anatawa12.fixRtm.io.FIXFileLoader import com.anatawa12.fixRtm.io.FIXModelPack import jp.ngt.ngtlib.io.FileType import jp.ngt.ngtlib.renderer.model.* +import net.minecraft.client.Minecraft import net.minecraft.util.ResourceLocation import org.apache.commons.codec.digest.DigestUtils import java.io.* @@ -32,7 +33,7 @@ object CachedPolygonModel { for (modelPack in FIXFileLoader.allModelPacks) { val cache = FileCache( baseDir.resolve(modelPack.file.name), - DigestUtils.sha1Hex(modelPack.file.inputStream().buffered()), + modelPack.sha1Hash, executor, { out, v -> CachedModelWriter.writeCachedModel(DataOutputStream(out), v) }, ::CachedModel, diff --git a/src/main/java/com/anatawa12/fixRtm/rtm/entity/train/EntityBogie.kt b/src/main/java/com/anatawa12/fixRtm/rtm/entity/train/EntityBogie.kt new file mode 100644 index 00000000..73fb73b2 --- /dev/null +++ b/src/main/java/com/anatawa12/fixRtm/rtm/entity/train/EntityBogie.kt @@ -0,0 +1,10 @@ +@file:JvmName("EntityBogieKt") + +package com.anatawa12.fixRtm.rtm.entity.train + +import com.anatawa12.fixRtm.VehicleTrackerEntryFix +import jp.ngt.rtm.entity.train.EntityBogie + +fun EntityBogie.constructor() { + VehicleTrackerEntryFix.addInstance(this) +} diff --git a/src/main/java/com/anatawa12/fixRtm/rtm/entity/vehicle/EntityVehicleBase.kt b/src/main/java/com/anatawa12/fixRtm/rtm/entity/vehicle/EntityVehicleBase.kt new file mode 100644 index 00000000..2f8bacba --- /dev/null +++ b/src/main/java/com/anatawa12/fixRtm/rtm/entity/vehicle/EntityVehicleBase.kt @@ -0,0 +1,10 @@ +@file:JvmName("EntityVehicleBaseKt") + +package com.anatawa12.fixRtm.rtm.entity.vehicle + +import com.anatawa12.fixRtm.VehicleTrackerEntryFix +import jp.ngt.rtm.entity.vehicle.EntityVehicleBase + +fun EntityVehicleBase<*>.constructor() { + VehicleTrackerEntryFix.addInstance(this) +} diff --git a/src/main/java/com/anatawa12/fixRtm/rtm/entity/vehicle/WeatherEffectDummy.kt b/src/main/java/com/anatawa12/fixRtm/rtm/entity/vehicle/WeatherEffectDummy.kt new file mode 100644 index 00000000..9c6228c0 --- /dev/null +++ b/src/main/java/com/anatawa12/fixRtm/rtm/entity/vehicle/WeatherEffectDummy.kt @@ -0,0 +1,15 @@ +@file:JvmName("WeatherEffectDummyKt") + +package com.anatawa12.fixRtm.rtm.entity.vehicle + +import jp.ngt.rtm.entity.vehicle.EntityVehicleBase +import jp.ngt.rtm.entity.vehicle.WeatherEffectDummy + +fun WeatherEffectDummy.shouldDead(parent: EntityVehicleBase<*>): Boolean { + if (this.parent.isDead) return true + if (world.getEntityByID(parent.entityId) == null) { + println("WeatherEffectDummy.shouldDead return true with world.getEntityByID(parent.entityId) == null") + return true + } + return false +} diff --git a/src/main/java/com/anatawa12/fixRtm/rtm/network/PacketVehicleMovement.kt b/src/main/java/com/anatawa12/fixRtm/rtm/network/PacketVehicleMovement.kt new file mode 100644 index 00000000..be73c533 --- /dev/null +++ b/src/main/java/com/anatawa12/fixRtm/rtm/network/PacketVehicleMovement.kt @@ -0,0 +1,20 @@ +@file:JvmName("PacketVehicleMovementKt") + +package com.anatawa12.fixRtm.rtm.network + +import com.anatawa12.fixRtm.Loggers +import net.minecraft.client.Minecraft +import net.minecraft.entity.Entity + +fun addEntityIfNotExits(entity: Entity) { + val world = Minecraft.getMinecraft().world + if ((!entity.addedToChunk || !entity.isAddedToWorld) + && world.isBlockLoaded(entity.position, false)) { + Minecraft.getMinecraft().addScheduledTask { + logger.trace("the entity: $entity is not added") + world.spawnEntity(entity) + } + } +} + +private val logger = Loggers.getLogger("PacketVehicleMovementKt")