Skip to content

Commit 4171b16

Browse files
authored
Merge pull request #187 from daimond113/1.21
Add Immersive Portals compatibility for the block provider
2 parents a04ac01 + 4ba1964 commit 4171b16

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ allprojects {
4949
name = "JitPack"
5050
url = URI("https://jitpack.io")
5151
}
52+
maven {
53+
name = "Modrinth"
54+
url = URI("https://api.modrinth.com/maven")
55+
}
56+
maven {
57+
name = "Shedaniel"
58+
url = URI("https://maven.shedaniel.me")
59+
}
5260
}
5361

5462
dependencies {

cardinal-components-block/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ dependencies {
44
annotationProcessor api(project(path: ":cardinal-components-base", configuration: "namedElements"))
55
modApi fabricApi.module("fabric-api-lookup-api-v1", rootProject.fabric_api_version)
66
testmodImplementation project(":cardinal-components-base").sourceSets.testmod.output
7+
modCompileOnly "com.github.iPortalTeam:ImmersivePortalsMod:${rootProject.immersive_portals_version}"
78
}

cardinal-components-block/src/main/java/org/ladysnake/cca/internal/BlockEntityAddress.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@
2727
import net.minecraft.network.codec.PacketCodec;
2828
import net.minecraft.network.codec.PacketCodecs;
2929
import net.minecraft.registry.Registries;
30+
import net.minecraft.registry.RegistryKey;
31+
import net.minecraft.registry.RegistryKeys;
3032
import net.minecraft.util.math.BlockPos;
33+
import net.minecraft.world.World;
3134

3235
public record BlockEntityAddress(
3336
BlockEntityType<?> beType,
34-
BlockPos bePos
37+
BlockPos bePos,
38+
RegistryKey<World> worldKey
3539
) {
3640

3741
public static final PacketCodec<RegistryByteBuf, BlockEntityAddress> CODEC = PacketCodec.tuple(
3842
PacketCodecs.entryOf(Registries.BLOCK_ENTITY_TYPE), BlockEntityAddress::beType,
3943
BlockPos.PACKET_CODEC, BlockEntityAddress::bePos,
44+
RegistryKey.createPacketCodec(RegistryKeys.WORLD), BlockEntityAddress::worldKey,
4045
BlockEntityAddress::new
4146
);
4247
}

cardinal-components-block/src/main/java/org/ladysnake/cca/internal/CcaBlockClient.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,37 @@
2424

2525
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientBlockEntityEvents;
2626
import net.fabricmc.loader.api.FabricLoader;
27+
import net.minecraft.world.World;
2728
import org.ladysnake.cca.api.v3.component.ComponentProvider;
2829
import org.ladysnake.cca.internal.base.CcaClientInternals;
30+
import qouteall.imm_ptl.core.ClientWorldLoader;
31+
32+
import java.util.Optional;
2933

3034
public class CcaBlockClient {
35+
private static boolean hasImmersivePortals = false;
36+
3137
public static void initClient() {
38+
hasImmersivePortals = FabricLoader.getInstance().isModLoaded("immersive_portals");
39+
3240
if (FabricLoader.getInstance().isModLoaded("fabric-networking-api-v1")) {
3341
CcaClientInternals.registerComponentSync(CardinalComponentsBlock.PACKET_ID,
34-
(payload, ctx) -> payload.componentKey().flatMap(key -> key.maybeGet(payload.targetData().beType().get(
35-
ctx.client().world,
36-
payload.targetData().bePos()
37-
))
42+
(payload, ctx) -> payload.componentKey().flatMap(key -> {
43+
World world;
44+
if (hasImmersivePortals) {
45+
world = ClientWorldLoader.getOptionalWorld(payload.targetData().worldKey());
46+
if (world == null) {
47+
return Optional.empty();
48+
}
49+
} else {
50+
world = ctx.client().world;
51+
}
52+
53+
return key.maybeGet(payload.targetData().beType().get(
54+
world,
55+
payload.targetData().bePos()
56+
));
57+
}
3858
));
3959
}
4060
if (FabricLoader.getInstance().isModLoaded("fabric-lifecycle-events-v1")) {

cardinal-components-block/src/main/java/org/ladysnake/cca/mixin/block/common/MixinBlockEntity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,14 @@ public Iterable<ServerPlayerEntity> getRecipientsForComponentSync() {
102102

103103
@Override
104104
public <C extends AutoSyncedComponent> ComponentUpdatePayload<?> toComponentPacket(ComponentKey<? super C> key, boolean required, RegistryByteBuf data) {
105+
World world = this.getWorld();
106+
if (world == null) {
107+
return null;
108+
}
109+
105110
return new ComponentUpdatePayload<>(
106111
CardinalComponentsBlock.PACKET_ID,
107-
new BlockEntityAddress(this.getType(), this.getPos()),
112+
new BlockEntityAddress(this.getType(), this.getPos(), world.getRegistryKey()),
108113
required,
109114
key.getId(),
110115
data

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ fabric_api_version=0.110.5+1.21.4
1212

1313
elmendorf_version=0.13.0
1414

15+
immersive_portals_version=v6.0.3-mc1.21.1
16+
1517
#Publishing
1618
mod_version = 6.2.1
1719
curseforge_id = 318449

0 commit comments

Comments
 (0)