diff --git a/build.gradle.kts b/build.gradle.kts index ca6cfb6b..91d5c2db 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -49,6 +49,14 @@ allprojects { name = "JitPack" url = URI("https://jitpack.io") } + maven { + name = "Modrinth" + url = URI("https://api.modrinth.com/maven") + } + maven { + name = "Shedaniel" + url = URI("https://maven.shedaniel.me") + } } dependencies { diff --git a/cardinal-components-block/build.gradle b/cardinal-components-block/build.gradle index 5e8a3ae3..9c4196fd 100644 --- a/cardinal-components-block/build.gradle +++ b/cardinal-components-block/build.gradle @@ -4,4 +4,5 @@ dependencies { annotationProcessor api(project(path: ":cardinal-components-base", configuration: "namedElements")) modApi fabricApi.module("fabric-api-lookup-api-v1", rootProject.fabric_api_version) testmodImplementation project(":cardinal-components-base").sourceSets.testmod.output + modCompileOnly "com.github.iPortalTeam:ImmersivePortalsMod:${rootProject.immersive_portals_version}" } diff --git a/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/BlockEntityAddress.java b/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/BlockEntityAddress.java index 670fbf9c..d3c10ca3 100644 --- a/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/BlockEntityAddress.java +++ b/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/BlockEntityAddress.java @@ -27,16 +27,21 @@ import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; import net.minecraft.registry.Registries; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public record BlockEntityAddress( BlockEntityType beType, - BlockPos bePos + BlockPos bePos, + RegistryKey worldKey ) { public static final PacketCodec CODEC = PacketCodec.tuple( PacketCodecs.entryOf(Registries.BLOCK_ENTITY_TYPE), BlockEntityAddress::beType, BlockPos.PACKET_CODEC, BlockEntityAddress::bePos, + RegistryKey.createPacketCodec(RegistryKeys.WORLD), BlockEntityAddress::worldKey, BlockEntityAddress::new ); } diff --git a/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/CcaBlockClient.java b/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/CcaBlockClient.java index 8b4ef6b0..9a8345a5 100644 --- a/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/CcaBlockClient.java +++ b/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/CcaBlockClient.java @@ -24,17 +24,37 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientBlockEntityEvents; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.world.World; import org.ladysnake.cca.api.v3.component.ComponentProvider; import org.ladysnake.cca.internal.base.CcaClientInternals; +import qouteall.imm_ptl.core.ClientWorldLoader; + +import java.util.Optional; public class CcaBlockClient { + private static boolean hasImmersivePortals = false; + public static void initClient() { + hasImmersivePortals = FabricLoader.getInstance().isModLoaded("immersive_portals"); + if (FabricLoader.getInstance().isModLoaded("fabric-networking-api-v1")) { CcaClientInternals.registerComponentSync(CardinalComponentsBlock.PACKET_ID, - (payload, ctx) -> payload.componentKey().flatMap(key -> key.maybeGet(payload.targetData().beType().get( - ctx.client().world, - payload.targetData().bePos() - )) + (payload, ctx) -> payload.componentKey().flatMap(key -> { + World world; + if (hasImmersivePortals) { + world = ClientWorldLoader.getOptionalWorld(payload.targetData().worldKey()); + if (world == null) { + return Optional.empty(); + } + } else { + world = ctx.client().world; + } + + return key.maybeGet(payload.targetData().beType().get( + world, + payload.targetData().bePos() + )); + } )); } if (FabricLoader.getInstance().isModLoaded("fabric-lifecycle-events-v1")) { diff --git a/cardinal-components-block/src/main/java/org/ladysnake/cca/mixin/block/common/MixinBlockEntity.java b/cardinal-components-block/src/main/java/org/ladysnake/cca/mixin/block/common/MixinBlockEntity.java index e6341ceb..fa362bc9 100644 --- a/cardinal-components-block/src/main/java/org/ladysnake/cca/mixin/block/common/MixinBlockEntity.java +++ b/cardinal-components-block/src/main/java/org/ladysnake/cca/mixin/block/common/MixinBlockEntity.java @@ -102,9 +102,14 @@ public Iterable getRecipientsForComponentSync() { @Override public ComponentUpdatePayload toComponentPacket(ComponentKey key, boolean required, RegistryByteBuf data) { + World world = this.getWorld(); + if (world == null) { + return null; + } + return new ComponentUpdatePayload<>( CardinalComponentsBlock.PACKET_ID, - new BlockEntityAddress(this.getType(), this.getPos()), + new BlockEntityAddress(this.getType(), this.getPos(), world.getRegistryKey()), required, key.getId(), data diff --git a/gradle.properties b/gradle.properties index f2c88033..71f6bdbc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,6 +12,8 @@ fabric_api_version=0.110.5+1.21.4 elmendorf_version=0.13.0 +immersive_portals_version=v6.0.3-mc1.21.1 + #Publishing mod_version = 6.2.1 curseforge_id = 318449