com.parzivail.util.block.BlockEntityClientSerializable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pswg Show documentation
Show all versions of pswg Show documentation
Explore the galaxy with Galaxies: Parzi's Star Wars Mod!
package com.parzivail.util.block;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.class_1937;
import net.minecraft.class_2338;
import net.minecraft.class_2487;
import net.minecraft.class_2540;
import net.minecraft.class_2586;
import net.minecraft.class_2960;
import net.minecraft.class_310;
import net.minecraft.class_3218;
import net.minecraft.class_3222;
import net.minecraft.class_5321;
import net.minecraft.class_634;
import net.minecraft.class_638;
import net.minecraft.class_7924;
public interface BlockEntityClientSerializable
{
void fromClientTag(class_2487 tag);
class_2487 toClientTag(class_2487 tag);
class_2960 getSyncPacketId();
default void sync()
{
if (this instanceof class_2586 entity)
{
var level = entity.method_10997();
if (level != null && !level.field_9236)
{
var passedData = new class_2540(Unpooled.buffer());
passedData.method_10807(entity.method_11016());
passedData.method_10812(level.method_27983().method_29177());
passedData.method_10794(toClientTag(new class_2487()));
for (var trackingPlayer : PlayerLookup.tracking((class_3218)level, entity.method_11016()))
ServerPlayNetworking.send(trackingPlayer, getSyncPacketId(), passedData);
}
}
}
static void handle(class_310 minecraftClient, class_634 clientPlayNetworkHandler, class_2540 buf, PacketSender packetSender)
{
var targetPos = buf.method_10811();
var targetWorldId = buf.method_10810();
var tag = buf.method_10798();
minecraftClient.execute(() -> {
var world = minecraftClient.field_1687;
var targetWorld = class_5321.method_29179(class_7924.field_41223, targetWorldId);
if (world == null || !world.method_27983().equals(targetWorld) || !(world.method_8321(targetPos) instanceof BlockEntityClientSerializable tile))
return;
tile.fromClientTag(tag);
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy