From cc360e8cba9cb4760e6b3479d67f27a5ea50de15 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Sat, 26 Oct 2024 12:50:11 +0200 Subject: [PATCH 1/6] Fix CCA block provider sync --- build.gradle | 2 ++ .../java/qouteall/imm_ptl/core/IPModMain.java | 5 +++- .../chunk_loading/PlayerChunkLoading.java | 3 +++ .../compat/IPCardinalCompBlockCompat.java | 27 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/main/java/qouteall/imm_ptl/core/compat/IPCardinalCompBlockCompat.java diff --git a/build.gradle b/build.gradle index 2345afe48..fbf447484 100644 --- a/build.gradle +++ b/build.gradle @@ -98,6 +98,8 @@ dependencies { transitive(false) } + modCompileOnly "org.ladysnake.cardinal-components-api:cardinal-components-block:6.1.1" + modApi("com.github.iPortalTeam:DimLib:${dimlib_version}") { exclude(group: "net.fabricmc.fabric-api") } diff --git a/src/main/java/qouteall/imm_ptl/core/IPModMain.java b/src/main/java/qouteall/imm_ptl/core/IPModMain.java index 17e0d4c86..813e66afa 100644 --- a/src/main/java/qouteall/imm_ptl/core/IPModMain.java +++ b/src/main/java/qouteall/imm_ptl/core/IPModMain.java @@ -19,6 +19,7 @@ import qouteall.imm_ptl.core.commands.PortalCommand; import qouteall.imm_ptl.core.commands.SubCommandArgumentType; import qouteall.imm_ptl.core.commands.TimingFunctionArgumentType; +import qouteall.imm_ptl.core.compat.IPCardinalCompBlockCompat; import qouteall.imm_ptl.core.compat.IPPortingLibCompat; import qouteall.imm_ptl.core.debug.DebugUtil; import qouteall.imm_ptl.core.mc_utils.ServerTaskList; @@ -95,7 +96,9 @@ public static void init() { ServerPerformanceMonitor.init(); ImmPtlChunkTickets.init(); - + + IPCardinalCompBlockCompat.init(); + IPPortingLibCompat.init(); BlockManipulationServer.init(); diff --git a/src/main/java/qouteall/imm_ptl/core/chunk_loading/PlayerChunkLoading.java b/src/main/java/qouteall/imm_ptl/core/chunk_loading/PlayerChunkLoading.java index 69f7d8695..5811b8b6b 100644 --- a/src/main/java/qouteall/imm_ptl/core/chunk_loading/PlayerChunkLoading.java +++ b/src/main/java/qouteall/imm_ptl/core/chunk_loading/PlayerChunkLoading.java @@ -20,6 +20,7 @@ import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.mutable.MutableInt; import org.slf4j.Logger; +import qouteall.imm_ptl.core.compat.IPCardinalCompBlockCompat; import qouteall.imm_ptl.core.ducks.IEChunkMap; import qouteall.imm_ptl.core.miscellaneous.IPVanillaCopy; import qouteall.imm_ptl.core.network.PacketRedirection; @@ -166,6 +167,8 @@ public void doChunkSending(ServerPlayer serverPlayer) { sendChunkPacket( connection, world, tickingChunk ); + + IPCardinalCompBlockCompat.syncBlockEntities(serverPlayer, tickingChunk); if (sentNum.getValue() >= maxSendNum) { shouldStop.setValue(true); diff --git a/src/main/java/qouteall/imm_ptl/core/compat/IPCardinalCompBlockCompat.java b/src/main/java/qouteall/imm_ptl/core/compat/IPCardinalCompBlockCompat.java new file mode 100644 index 000000000..f79ce296b --- /dev/null +++ b/src/main/java/qouteall/imm_ptl/core/compat/IPCardinalCompBlockCompat.java @@ -0,0 +1,27 @@ +package qouteall.imm_ptl.core.compat; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.chunk.LevelChunk; +import org.ladysnake.cca.api.v3.block.BlockEntitySyncCallback; +import qouteall.q_misc_util.Helper; + +public class IPCardinalCompBlockCompat { + public static boolean isCardinalCompBlockPresent = false; + + public static void init() { + if (FabricLoader.getInstance().isModLoaded("cardinal-components-block")) { + Helper.log("Cardinal Components Block is present"); + isCardinalCompBlockPresent = true; + } + } + + public static void syncBlockEntities(ServerPlayer player, LevelChunk chunk) { + if (isCardinalCompBlockPresent) { + for (BlockEntity be : chunk.getBlockEntities().values()) { + BlockEntitySyncCallback.EVENT.invoker().onBlockEntitySync(player, be); + } + } + } +} From 61684bf46427c2a6088fef7b1691fa8eeba9d891 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Tue, 29 Oct 2024 23:13:36 +0100 Subject: [PATCH 2/6] Fix PlayerLookup incompatibility --- .../imm_ptl/core/ducks/IEServerPlayerEntity.java | 5 +++++ .../mixin/common/chunk_sync/MixinChunkMap_C.java | 13 ++++++++++++- .../common/entity_sync/MixinServerPlayer.java | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java b/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java index 569646c37..8bde2817b 100644 --- a/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java +++ b/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java @@ -1,5 +1,6 @@ package qouteall.imm_ptl.core.ducks; +import net.minecraft.server.level.ChunkTrackingView; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.phys.Vec3; @@ -11,4 +12,8 @@ public interface IEServerPlayerEntity { void ip_startRidingWithoutTeleportRequest(Entity newVehicle); void portal_worldChanged(ServerLevel fromWorld, Vec3 fromPos); + + void ip_setChunkTrackingView(ChunkTrackingView view); + + ChunkTrackingView ip_getChunkTrackingView(); } diff --git a/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java b/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java index 0c4884595..dae408449 100644 --- a/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java +++ b/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java @@ -17,6 +17,7 @@ import qouteall.imm_ptl.core.chunk_loading.ImmPtlChunkTracking; import qouteall.imm_ptl.core.chunk_loading.PlayerChunkLoading; import qouteall.imm_ptl.core.ducks.IEChunkMap; +import qouteall.imm_ptl.core.ducks.IEServerPlayerEntity; @Mixin(value = ChunkMap.class, priority = 1100) public abstract class MixinChunkMap_C implements IEChunkMap { @@ -54,7 +55,16 @@ public ThreadedLevelLightEngine ip_getLightingProvider() { public ChunkHolder ip_getChunkHolder(long chunkPosLong) { return getVisibleChunkIfPresent(chunkPosLong); } - + + /** + * @author daimond113 + * @reason Maintain compatibility with APIs such as Fabric's PlayerLookup + */ + @Overwrite + public boolean isChunkTracked(ServerPlayer player, int x, int z) { + return ((IEServerPlayerEntity) player).ip_getChunkTrackingView().contains(x, z); + } + /** * packets will be sent on {@link PlayerChunkLoading} */ @@ -66,6 +76,7 @@ public ChunkHolder ip_getChunkHolder(long chunkPosLong) { private void onUpdateChunkTracking( ServerPlayer serverPlayer, ChunkTrackingView chunkTrackingView, CallbackInfo ci ) { + ((IEServerPlayerEntity) serverPlayer).ip_setChunkTrackingView(chunkTrackingView); ci.cancel(); } diff --git a/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java b/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java index fe9342067..a7db40feb 100644 --- a/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java +++ b/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java @@ -2,6 +2,7 @@ import com.mojang.authlib.GameProfile; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ChunkTrackingView; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; @@ -11,6 +12,7 @@ import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import qouteall.imm_ptl.core.ducks.IEServerPlayerEntity; @Mixin(ServerPlayer.class) @@ -22,6 +24,9 @@ public abstract class MixinServerPlayer extends Player implements IEServerPlayer @Shadow private boolean isChangingDimension; + + @Unique + private ChunkTrackingView ip_chunkTrackingView; public MixinServerPlayer(Level level, BlockPos blockPos, float f, GameProfile gameProfile) { super(level, blockPos, f, gameProfile); @@ -49,4 +54,14 @@ public void portal_worldChanged(ServerLevel fromWorld, Vec3 fromPos) { } triggerDimensionChangeTriggers(fromWorld); } + + @Override + public void ip_setChunkTrackingView(ChunkTrackingView view) { + ip_chunkTrackingView = view; + } + + @Override + public ChunkTrackingView ip_getChunkTrackingView() { + return ip_chunkTrackingView; + } } From f7dfdc974f5f518384ff1efbb74e314f32c45d40 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:27:36 +0100 Subject: [PATCH 3/6] Use IP chunk tracking for isChunkTracked --- .../imm_ptl/core/ducks/IEServerPlayerEntity.java | 4 ---- .../core/mixin/common/chunk_sync/MixinChunkMap_C.java | 8 ++++++-- .../mixin/common/entity_sync/MixinServerPlayer.java | 10 ---------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java b/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java index 8bde2817b..bcba80819 100644 --- a/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java +++ b/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java @@ -12,8 +12,4 @@ public interface IEServerPlayerEntity { void ip_startRidingWithoutTeleportRequest(Entity newVehicle); void portal_worldChanged(ServerLevel fromWorld, Vec3 fromPos); - - void ip_setChunkTrackingView(ChunkTrackingView view); - - ChunkTrackingView ip_getChunkTrackingView(); } diff --git a/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java b/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java index dae408449..5cc050480 100644 --- a/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java +++ b/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java @@ -62,7 +62,12 @@ public ChunkHolder ip_getChunkHolder(long chunkPosLong) { */ @Overwrite public boolean isChunkTracked(ServerPlayer player, int x, int z) { - return ((IEServerPlayerEntity) player).ip_getChunkTrackingView().contains(x, z); + return ImmPtlChunkTracking.isPlayerWatchingChunk( + player, + level.dimension(), + x, + z + ); } /** @@ -76,7 +81,6 @@ public boolean isChunkTracked(ServerPlayer player, int x, int z) { private void onUpdateChunkTracking( ServerPlayer serverPlayer, ChunkTrackingView chunkTrackingView, CallbackInfo ci ) { - ((IEServerPlayerEntity) serverPlayer).ip_setChunkTrackingView(chunkTrackingView); ci.cancel(); } diff --git a/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java b/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java index a7db40feb..00eb8f121 100644 --- a/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java +++ b/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java @@ -54,14 +54,4 @@ public void portal_worldChanged(ServerLevel fromWorld, Vec3 fromPos) { } triggerDimensionChangeTriggers(fromWorld); } - - @Override - public void ip_setChunkTrackingView(ChunkTrackingView view) { - ip_chunkTrackingView = view; - } - - @Override - public ChunkTrackingView ip_getChunkTrackingView() { - return ip_chunkTrackingView; - } } From efc1aaa37d918684904ddbec0ff97b588f386e87 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:38:23 +0100 Subject: [PATCH 4/6] Remove unused artifacts --- .../qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java | 1 - .../core/mixin/common/chunk_sync/MixinChunkMap_C.java | 1 - .../core/mixin/common/entity_sync/MixinServerPlayer.java | 5 ----- 3 files changed, 7 deletions(-) diff --git a/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java b/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java index bcba80819..569646c37 100644 --- a/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java +++ b/src/main/java/qouteall/imm_ptl/core/ducks/IEServerPlayerEntity.java @@ -1,6 +1,5 @@ package qouteall.imm_ptl.core.ducks; -import net.minecraft.server.level.ChunkTrackingView; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.phys.Vec3; diff --git a/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java b/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java index 5cc050480..f1fc727a1 100644 --- a/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java +++ b/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java @@ -17,7 +17,6 @@ import qouteall.imm_ptl.core.chunk_loading.ImmPtlChunkTracking; import qouteall.imm_ptl.core.chunk_loading.PlayerChunkLoading; import qouteall.imm_ptl.core.ducks.IEChunkMap; -import qouteall.imm_ptl.core.ducks.IEServerPlayerEntity; @Mixin(value = ChunkMap.class, priority = 1100) public abstract class MixinChunkMap_C implements IEChunkMap { diff --git a/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java b/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java index 00eb8f121..320ad0962 100644 --- a/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java +++ b/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java @@ -2,7 +2,6 @@ import com.mojang.authlib.GameProfile; import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ChunkTrackingView; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; @@ -12,7 +11,6 @@ import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import qouteall.imm_ptl.core.ducks.IEServerPlayerEntity; @Mixin(ServerPlayer.class) @@ -25,9 +23,6 @@ public abstract class MixinServerPlayer extends Player implements IEServerPlayer @Shadow private boolean isChangingDimension; - @Unique - private ChunkTrackingView ip_chunkTrackingView; - public MixinServerPlayer(Level level, BlockPos blockPos, float f, GameProfile gameProfile) { super(level, blockPos, f, gameProfile); } From 42a5c5bbcb7fec6f82c7dbc7f08277abbfaf2bd9 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:40:05 +0100 Subject: [PATCH 5/6] Reformat file --- .../core/mixin/common/entity_sync/MixinServerPlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java b/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java index 320ad0962..fe9342067 100644 --- a/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java +++ b/src/main/java/qouteall/imm_ptl/core/mixin/common/entity_sync/MixinServerPlayer.java @@ -22,7 +22,7 @@ public abstract class MixinServerPlayer extends Player implements IEServerPlayer @Shadow private boolean isChangingDimension; - + public MixinServerPlayer(Level level, BlockPos blockPos, float f, GameProfile gameProfile) { super(level, blockPos, f, gameProfile); } From cb4293b75bdb50178a734efdd6b414b6ef4cb8ed Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:24:29 +0100 Subject: [PATCH 6/6] Redirect getPlayers methods --- .../common/chunk_sync/MixinChunkMap_C.java | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java b/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java index f1fc727a1..f471bb717 100644 --- a/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java +++ b/src/main/java/qouteall/imm_ptl/core/mixin/common/chunk_sync/MixinChunkMap_C.java @@ -1,23 +1,20 @@ package qouteall.imm_ptl.core.mixin.common.chunk_sync; -import net.minecraft.server.level.ChunkHolder; -import net.minecraft.server.level.ChunkMap; -import net.minecraft.server.level.ChunkTrackingView; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.level.ThreadedLevelLightEngine; +import net.minecraft.server.level.*; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.LevelChunk; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.*; 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.callback.CallbackInfo; import qouteall.imm_ptl.core.chunk_loading.ImmPtlChunkTracking; import qouteall.imm_ptl.core.chunk_loading.PlayerChunkLoading; import qouteall.imm_ptl.core.ducks.IEChunkMap; +import java.util.HashSet; +import java.util.Set; + @Mixin(value = ChunkMap.class, priority = 1100) public abstract class MixinChunkMap_C implements IEChunkMap { @@ -69,6 +66,37 @@ public boolean isChunkTracked(ServerPlayer player, int x, int z) { ); } + @Unique + private Set ip_getPlayersInChunk(ChunkPos pos, boolean boundaryOnly) { + return new HashSet<>(ImmPtlChunkTracking.getPlayersViewingChunk( + level.dimension(), + pos.x, pos.z, + boundaryOnly + )); + } + + @Redirect( + method = "getPlayersCloseForSpawning", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/level/PlayerMap;getAllPlayers()Ljava/util/Set;" + ) + ) + private Set redirectGetPlayersCloseForSpawning(PlayerMap instance, ChunkPos pos) { + return ip_getPlayersInChunk(pos, false); + } + + @Redirect( + method = "getPlayers", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/level/PlayerMap;getAllPlayers()Ljava/util/Set;" + ) + ) + private Set redirectGetPlayers(PlayerMap instance, ChunkPos pos, boolean boundaryOnly) { + return ip_getPlayersInChunk(pos, boundaryOnly); + } + /** * packets will be sent on {@link PlayerChunkLoading} */