Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CCA Block syncing and PlayerLookup API #1645

Open
wants to merge 6 commits into
base: 1.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/qouteall/imm_ptl/core/IPModMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,7 +96,9 @@ public static void init() {
ServerPerformanceMonitor.init();

ImmPtlChunkTickets.init();


IPCardinalCompBlockCompat.init();

IPPortingLibCompat.init();

BlockManipulationServer.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -166,6 +167,8 @@ public void doChunkSending(ServerPlayer serverPlayer) {
sendChunkPacket(
connection, world, tickingChunk
);

IPCardinalCompBlockCompat.syncBlockEntities(serverPlayer, tickingChunk);

if (sentNum.getValue() >= maxSendNum) {
shouldStop.setValue(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -54,7 +51,52 @@ 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 ImmPtlChunkTracking.isPlayerWatchingChunk(
player,
level.dimension(),
x,
z
);
}

@Unique
private Set<ServerPlayer> 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<ServerPlayer> 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<ServerPlayer> redirectGetPlayers(PlayerMap instance, ChunkPos pos, boolean boundaryOnly) {
return ip_getPlayersInChunk(pos, boundaryOnly);
}

/**
* packets will be sent on {@link PlayerChunkLoading}
*/
Expand Down