Skip to content

Commit

Permalink
Merge pull request #187 from daimond113/1.21
Browse files Browse the repository at this point in the history
Add Immersive Portals compatibility for the block provider
  • Loading branch information
Pyrofab authored Dec 27, 2024
2 parents a04ac01 + 4ba1964 commit 4171b16
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cardinal-components-block/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<World> worldKey
) {

public static final PacketCodec<RegistryByteBuf, BlockEntityAddress> CODEC = PacketCodec.tuple(
PacketCodecs.entryOf(Registries.BLOCK_ENTITY_TYPE), BlockEntityAddress::beType,
BlockPos.PACKET_CODEC, BlockEntityAddress::bePos,
RegistryKey.createPacketCodec(RegistryKeys.WORLD), BlockEntityAddress::worldKey,
BlockEntityAddress::new
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,14 @@ public Iterable<ServerPlayerEntity> getRecipientsForComponentSync() {

@Override
public <C extends AutoSyncedComponent> ComponentUpdatePayload<?> toComponentPacket(ComponentKey<? super C> 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
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4171b16

Please sign in to comment.