This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
RelicCraft/src/main/java/com/thebrokenrail/reliccraft/packet/UpdateTeleportCooldownS2CPa...

31 lines
1.2 KiB
Java

package com.thebrokenrail.reliccraft.packet;
import com.thebrokenrail.reliccraft.RelicCraft;
import com.thebrokenrail.reliccraft.block.TeleportationRestrictorBlock;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
@SuppressWarnings("unused")
public class UpdateTeleportCooldownS2CPacket {
public static void send(ServerPlayerEntity player, byte cooldown) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeByte(cooldown);
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(new Identifier(RelicCraft.NAMESPACE, "update_teleport_cooldown"), buf));
}
@Environment(EnvType.CLIENT)
public static void handle(PacketContext context, PacketByteBuf buf) {
byte cooldown = buf.readByte();
if (context.getPlayer() != null) {
((TeleportationRestrictorBlock.TeleportingEntity) context.getPlayer()).setTeleportCooldown(cooldown);
}
}
}