From baf681d166ce1975cecd341a101bb7d9ff4dd888 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Fri, 3 Dec 2021 16:52:33 +0800 Subject: [PATCH] Fix some stuff, updated api to 1.2.2 --- .../game/SWorldBorderPacketMixin.java | 6 ++++-- .../core/server/MinecraftServerMixin.java | 2 +- .../server/level/DistanceManagerMixin.java | 2 +- .../core/server/level/ServerLevelMixin.java | 20 +++++++++++++++++-- .../mixin/core/world/level/LevelMixin.java | 1 - .../chunk/storage/ChunkSerializerMixin.java | 3 +-- .../chunk/storage/RegionFileCacheMixin.java | 7 ++++--- .../world/level/portal/PortalForcerMixin.java | 2 +- ...StorageSource_LevelStorageAccessMixin.java | 9 ++++----- .../common/mod/server/BukkitRegistry.java | 6 +++--- arclight-forge/build.gradle | 2 +- .../arclight/boot/AbstractBootstrap.java | 2 +- build.gradle | 2 +- 13 files changed, 40 insertions(+), 24 deletions(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/protocol/game/SWorldBorderPacketMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/protocol/game/SWorldBorderPacketMixin.java index c7e991a9..21fa4d0b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/protocol/game/SWorldBorderPacketMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/protocol/game/SWorldBorderPacketMixin.java @@ -3,7 +3,9 @@ package io.izzel.arclight.common.mixin.core.network.protocol.game; import io.izzel.arclight.common.bridge.core.world.border.WorldBorderBridge; import net.minecraft.network.protocol.game.ClientboundSetBorderCenterPacket; import net.minecraft.world.level.border.WorldBorder; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -13,8 +15,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class SWorldBorderPacketMixin { // @formatter:off - @Shadow private double newCenterX; - @Shadow private double newCenterZ; + @Shadow @Final @Mutable private double newCenterX; + @Shadow @Final @Mutable private double newCenterZ; // @formatter:on @Inject(method = "(Lnet/minecraft/world/level/border/WorldBorder;)V", at = @At("RETURN")) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MinecraftServerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MinecraftServerMixin.java index 8c17e942..baf5b43c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MinecraftServerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MinecraftServerMixin.java @@ -325,7 +325,7 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop set) { + private void arclight$remove(SectionPos p_140829_, ServerPlayer p_140830_, CallbackInfo ci, ChunkPos pos, long l, ObjectSet set) { if (set == null) { ci.cancel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerLevelMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerLevelMixin.java index 2859a8f6..502adb8a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerLevelMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerLevelMixin.java @@ -18,6 +18,7 @@ import io.izzel.arclight.common.mod.util.ArclightCaptures; import io.izzel.arclight.common.mod.util.DelegateWorldInfo; import io.izzel.arclight.i18n.ArclightConfig; import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket; @@ -65,6 +66,7 @@ import org.bukkit.event.world.PortalCreateEvent; import org.bukkit.event.world.TimeSkipEvent; import org.bukkit.event.world.WorldSaveEvent; import org.objectweb.asm.Opcodes; +import org.spigotmc.SpigotWorldConfig; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -105,10 +107,11 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerWorld private int tickPosition; public LevelStorageSource.LevelStorageAccess convertable; public UUID uuid; + public ResourceKey typeKey; @Override public ResourceKey getTypeKey() { - return ((LevelStorageSourceBridge.LevelStorageAccessBridge) this.convertable).bridge$getTypeKey(); + return this.typeKey; } public void arclight$constructor(MinecraftServer server, Executor backgroundExecutor, LevelStorageSource.LevelStorageAccess levelSave, ServerLevelData serverWorldInfo, ResourceKey dimension, DimensionType dimensionType, ChunkProgressListener statusListener, ChunkGenerator chunkGenerator, boolean isDebug, long seed, List specialSpawners, boolean shouldBeTicking) { @@ -131,7 +134,18 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerWorld private void arclight$init(MinecraftServer minecraftServer, Executor backgroundExecutor, LevelStorageSource.LevelStorageAccess levelSave, ServerLevelData worldInfo, ResourceKey dimension, DimensionType dimensionType, ChunkProgressListener statusListener, ChunkGenerator chunkGenerator, boolean isDebug, long seed, List specialSpawners, boolean shouldBeTicking, CallbackInfo ci) { this.pvpMode = minecraftServer.isPvpAllowed(); this.convertable = levelSave; - this.uuid = WorldUUID.getUUID(levelSave.getDimensionPath(this.dimension()).toFile()); + var typeKey = ((LevelStorageSourceBridge.LevelStorageAccessBridge) levelSave).bridge$getTypeKey(); + if (typeKey != null) { + this.typeKey = typeKey; + } else { + var dimensions = shadow$getServer().getWorldData().worldGenSettings().dimensions(); + var levelStem = dimensions.get(dimension.location()); + if (levelStem != null) { + this.typeKey = ResourceKey.create(Registry.LEVEL_STEM_REGISTRY, dimension.location()); + } else { + throw new IllegalStateException("No level stem for dimension " + dimension.location()); + } + } if (worldInfo instanceof PrimaryLevelData) { this.$$worldDataServer = (PrimaryLevelData) worldInfo; } else if (worldInfo instanceof DerivedLevelData) { @@ -142,6 +156,8 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerWorld WorldSymlink.create((DerivedLevelData) worldInfo, levelSave.getDimensionPath(this.dimension()).toFile()); } } + this.spigotConfig = new SpigotWorldConfig(worldInfo.getLevelName()); + this.uuid = WorldUUID.getUUID(levelSave.getDimensionPath(this.dimension()).toFile()); ((ServerChunkProviderBridge) this.chunkSource).bridge$setViewDistance(spigotConfig.viewDistance); ((WorldInfoBridge) this.$$worldDataServer).bridge$setWorld((ServerLevel) (Object) this); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/LevelMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/LevelMixin.java index 0ee78f34..ed38d4f5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/LevelMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/LevelMixin.java @@ -110,7 +110,6 @@ public abstract class LevelMixin implements WorldBridge, LevelWriter { @Inject(method = "(Lnet/minecraft/world/level/storage/WritableLevelData;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/DimensionType;Ljava/util/function/Supplier;ZZJ)V", at = @At("RETURN")) private void arclight$init(WritableLevelData info, ResourceKey dimension, DimensionType dimType, Supplier profiler, boolean isRemote, boolean isDebug, long seed, CallbackInfo ci) { - this.spigotConfig = new SpigotWorldConfig(((ServerLevelData) info).getLevelName()); ((WorldBorderBridge) this.worldBorder).bridge$setWorld((Level) (Object) this); this.ticksPerAnimalSpawns = this.getCraftServer().getTicksPerAnimalSpawns(); this.ticksPerMonsterSpawns = this.getCraftServer().getTicksPerMonsterSpawns(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/chunk/storage/ChunkSerializerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/chunk/storage/ChunkSerializerMixin.java index e84433ff..52d04e49 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/chunk/storage/ChunkSerializerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/chunk/storage/ChunkSerializerMixin.java @@ -6,7 +6,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.ai.village.poi.PoiManager; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.ProtoChunk; import net.minecraft.world.level.chunk.storage.ChunkSerializer; import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataContainer; import org.spongepowered.asm.mixin.Mixin; @@ -19,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public class ChunkSerializerMixin { @Redirect(method = "read", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/ChunkAccess;setLightCorrect(Z)V")) - private static void arclight$loadPersistent(ChunkAccess instance, boolean correct, ServerLevel level, PoiManager poiManager, ChunkPos pos, CompoundTag tag, CallbackInfoReturnable cir) { + private static void arclight$loadPersistent(ChunkAccess instance, boolean correct, ServerLevel level, PoiManager poiManager, ChunkPos pos, CompoundTag tag) { net.minecraft.nbt.Tag persistentBase = tag.get("ChunkBukkitValues"); if (persistentBase instanceof CompoundTag) { ((CraftPersistentDataContainer) ((ChunkAccessBridge) instance).bridge$getPersistentDataContainer()).putAll((CompoundTag) persistentBase); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/chunk/storage/RegionFileCacheMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/chunk/storage/RegionFileCacheMixin.java index a4dd0d02..4291a9d5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/chunk/storage/RegionFileCacheMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/chunk/storage/RegionFileCacheMixin.java @@ -14,8 +14,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; @Mixin(RegionFileStorage.class) public abstract class RegionFileCacheMixin implements RegionFileCacheBridge { @@ -33,8 +34,8 @@ public abstract class RegionFileCacheMixin implements RegionFileCacheBridge { @Inject(method = "getRegionFile", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "NEW", target = "net/minecraft/world/level/chunk/storage/RegionFile")) - private void arclight$retIfSearch(ChunkPos pos, CallbackInfoReturnable cir, long l, RegionFile rf, File file) { - if (arclight$existOnly && !file.exists()) cir.setReturnValue(null); + private void arclight$retIfSearch(ChunkPos pos, CallbackInfoReturnable cir, long l, RegionFile rf, Path path) { + if (arclight$existOnly && !Files.exists(path)) cir.setReturnValue(null); } @Inject(method = "read", at = @At("HEAD")) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/portal/PortalForcerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/portal/PortalForcerMixin.java index 3868f9fb..b924756c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/portal/PortalForcerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/portal/PortalForcerMixin.java @@ -38,7 +38,7 @@ public abstract class PortalForcerMixin implements TeleporterBridge { @Shadow public abstract Optional findPortalAround(BlockPos p_192986_, boolean p_192987_, WorldBorder p_192988_); // @formatter:on - @ModifyVariable(method = "findPortalAround", index = 4, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/village/poi/PoiManager;ensureLoadedAndValid(Lnet/minecraft/world/level/LevelReader;Lnet/minecraft/core/BlockPos;I)V")) + @ModifyVariable(method = "findPortalAround", index = 5, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/village/poi/PoiManager;ensureLoadedAndValid(Lnet/minecraft/world/level/LevelReader;Lnet/minecraft/core/BlockPos;I)V")) private int arclight$useSearchRadius(int i) { return this.arclight$searchRadius == -1 ? i : this.arclight$searchRadius; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/LevelStorageSource_LevelStorageAccessMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/LevelStorageSource_LevelStorageAccessMixin.java index db0cf2b2..76fb6be3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/LevelStorageSource_LevelStorageAccessMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/LevelStorageSource_LevelStorageAccessMixin.java @@ -12,7 +12,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.io.File; import java.nio.file.Path; @Mixin(LevelStorageSource.LevelStorageAccess.class) @@ -42,13 +41,13 @@ public class LevelStorageSource_LevelStorageAccessMixin implements LevelStorageS } @Inject(method = "getDimensionPath", cancellable = true, at = @At("HEAD")) - private void arclight$useActualType(ResourceKey dimensionKey, CallbackInfoReturnable cir) { + private void arclight$useActualType(ResourceKey dimensionKey, CallbackInfoReturnable cir) { if (dimensionType == LevelStem.OVERWORLD) { - cir.setReturnValue(this.levelPath.toFile()); + cir.setReturnValue(this.levelPath); } else if (dimensionType == LevelStem.NETHER) { - cir.setReturnValue(new File(this.levelPath.toFile(), "DIM-1")); + cir.setReturnValue(this.levelPath.resolve("DIM-1")); } else if (dimensionType == LevelStem.END) { - cir.setReturnValue(new File(this.levelPath.toFile(), "DIM1")); + cir.setReturnValue(this.levelPath.resolve("DIM1")); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java index fccaa0f3..62908fdb 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java @@ -16,6 +16,7 @@ import io.izzel.arclight.common.mod.util.types.ArclightPotionEffect; import io.izzel.arclight.i18n.ArclightConfig; import io.izzel.arclight.i18n.conf.EntityPropertySpec; import io.izzel.arclight.i18n.conf.MaterialPropertySpec; +import net.minecraft.core.MappedRegistry; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -206,11 +207,10 @@ public class BukkitRegistry { ArclightMod.LOGGER.info("registry.villager-profession", newTypes.size()); } - public static void registerEnvironments() { + public static void registerEnvironments(MappedRegistry dimensions) { int i = World.Environment.values().length; List newTypes = new ArrayList<>(); - Registry registry = ArclightServer.getMinecraftServer().registryAccess().registryOrThrow(Registry.LEVEL_STEM_REGISTRY); - for (Map.Entry, LevelStem> entry : registry.entrySet()) { + for (Map.Entry, LevelStem> entry : dimensions.entrySet()) { ResourceKey key = entry.getKey(); World.Environment environment = DIM_MAP.get(key); if (environment == null) { diff --git a/arclight-forge/build.gradle b/arclight-forge/build.gradle index 0e76a4cf..859bb238 100644 --- a/arclight-forge/build.gradle +++ b/arclight-forge/build.gradle @@ -55,7 +55,7 @@ def embedLibs = [/*"org.spongepowered:mixin:$mixinVersion", */ 'org.yaml:snakeya 'org.apache.maven:maven-repository-metadata:3.8.1', 'org.apache.maven.resolver:maven-resolver-api:1.6.2', 'org.apache.maven.resolver:maven-resolver-spi:1.6.2', 'org.apache.maven.resolver:maven-resolver-util:1.6.2', 'org.apache.maven.resolver:maven-resolver-impl:1.6.2', 'org.apache.httpcomponents:httpclient:4.5.12', - 'org.apache.httpcomponents:httpcore:4.4.13',/* 'commons-codec:commons-codec:1.11',*/ + 'org.apache.httpcomponents:httpcore:4.4.13', 'commons-codec:commons-codec:1.15', 'org.slf4j:jcl-over-slf4j:1.7.30', /*'org.apache.logging.log4j:log4j-slf4j18-impl:2.14.1',*/ 'org.spongepowered:configurate-hocon:3.6.1', 'org.spongepowered:configurate-core:3.6.1', 'com.typesafe:config:1.3.1'] diff --git a/arclight-forge/src/main/java/io/izzel/arclight/boot/AbstractBootstrap.java b/arclight-forge/src/main/java/io/izzel/arclight/boot/AbstractBootstrap.java index bdd8352a..00228c7a 100644 --- a/arclight-forge/src/main/java/io/izzel/arclight/boot/AbstractBootstrap.java +++ b/arclight-forge/src/main/java/io/izzel/arclight/boot/AbstractBootstrap.java @@ -27,7 +27,7 @@ public class AbstractBootstrap { } protected void setupMod() throws Exception { - ArclightVersion.setVersion(ArclightVersion.v1_17_R1); + ArclightVersion.setVersion(ArclightVersion.v1_18_R1); try (InputStream stream = getClass().getModule().getResourceAsStream("/META-INF/MANIFEST.MF")) { Manifest manifest = new Manifest(stream); Attributes attributes = manifest.getMainAttributes(); diff --git a/build.gradle b/build.gradle index 13869694..1d1fa578 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ allprojects { agpVersion = '1.21' minecraftVersion = '1.18' forgeVersion = '38.0.12' - apiVersion = '1.2.+' + apiVersion = '1.2.2' toolsVersion = '1.3.+' mixinVersion = '0.8.5' gitHash = getGitHash()