|
|
|
|
@@ -3,7 +3,11 @@ package com.ejclaw.videoplayer.block;
|
|
|
|
|
import com.ejclaw.videoplayer.registry.VideoPlayerBlockEntities;
|
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
|
import net.minecraft.core.Direction;
|
|
|
|
|
import net.minecraft.core.HolderLookup;
|
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
|
import net.minecraft.network.protocol.Packet;
|
|
|
|
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
|
|
|
|
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
|
import net.minecraft.world.level.storage.ValueInput;
|
|
|
|
|
@@ -123,6 +127,35 @@ public class VideoAnchorBlockEntity extends BlockEntity {
|
|
|
|
|
out.putBoolean("autoplay", autoplay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Vanilla chunk-load BE sync. The base implementation returns an empty tag, which means
|
|
|
|
|
* when a client first sees this BE (chunk loads or player walks into range) it gets default
|
|
|
|
|
* values — url="" in particular makes the renderer no-op and the panel appears invisible.
|
|
|
|
|
*
|
|
|
|
|
* <p>Returning {@link #toNbt()} here carries the custom fields in the vanilla packet, so
|
|
|
|
|
* we don't depend on the {@code SyncAnchorPayload} arriving before the chunk's block-update
|
|
|
|
|
* packet (there's a race: {@code level.setBlock} queues a deferred chunk broadcast while
|
|
|
|
|
* {@code ServerPlayNetworking.send} writes immediately; if the payload wins, the client
|
|
|
|
|
* drops it because the BE doesn't exist yet, then the chunk packet creates the BE with
|
|
|
|
|
* defaults). It also fixes "player walks far away and comes back" — that path has no
|
|
|
|
|
* SyncAnchorPayload at all, just vanilla chunk re-sync.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public CompoundTag getUpdateTag(HolderLookup.Provider provider) {
|
|
|
|
|
return toNbt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Triggers a {@link ClientboundBlockEntityDataPacket} whenever the chunk tracker decides
|
|
|
|
|
* this BE needs to push an update. Default implementation returns {@code null} (no packet
|
|
|
|
|
* sent on BE change). Combined with {@link #getUpdateTag} above, every BE-state change a
|
|
|
|
|
* client sees carries the full config.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Packet<ClientGamePacketListener> getUpdatePacket() {
|
|
|
|
|
return ClientboundBlockEntityDataPacket.create(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void loadAdditional(ValueInput in) {
|
|
|
|
|
super.loadAdditional(in);
|
|
|
|
|
|