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

Add Immersive Portals compatibility for the block provider #187

Open
wants to merge 1 commit 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
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.106.1+1.21.3

elmendorf_version=0.13.0

immersive_portals_version=v6.0.3-mc1.21.1

#Publishing
mod_version = 6.2.0
curseforge_id = 318449
Expand Down