Files
SoundPadMod/src/main/java/com/example/soundmod/net/packet/S2CZoneStateSyncPacket.java
T

56 lines
1.8 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* net.minecraft.client.Minecraft
* net.minecraft.nbt.CompoundNBT
* net.minecraft.network.PacketBuffer
* net.minecraft.tileentity.TileEntity
* net.minecraft.util.math.BlockPos
* net.minecraftforge.fml.network.NetworkEvent$Context
*/
package com.example.soundmod.net.packet;
import com.example.soundmod.gameplay.tile.SoundPlayerTileEntity;
import java.util.function.Supplier;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.network.NetworkEvent;
public class S2CZoneStateSyncPacket {
private final BlockPos pos;
private final CompoundNBT payload;
public S2CZoneStateSyncPacket(BlockPos pos, CompoundNBT payload) {
this.pos = pos;
this.payload = payload;
}
public static void encode(S2CZoneStateSyncPacket msg, PacketBuffer buf) {
buf.writeBlockPos(msg.pos);
buf.writeNbt(msg.payload);
}
public static S2CZoneStateSyncPacket decode(PacketBuffer buf) {
return new S2CZoneStateSyncPacket(buf.readBlockPos(), buf.readNbt());
}
public static void handle(S2CZoneStateSyncPacket msg, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
Minecraft mc = Minecraft.getInstance();
if (mc.level == null) {
return;
}
TileEntity te = mc.level.getBlockEntity(msg.pos);
if (te instanceof SoundPlayerTileEntity) {
((SoundPlayerTileEntity)te).loadZoneSyncPayload(msg.payload);
}
});
ctx.get().setPacketHandled(true);
}
}