2020-04-14 17:14:24 +02:00
|
|
|
package de.ellpeck.prettypipes.packets;
|
|
|
|
|
|
|
|
import de.ellpeck.prettypipes.Utility;
|
2020-04-16 04:42:42 +02:00
|
|
|
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
2020-04-14 17:14:24 +02:00
|
|
|
import de.ellpeck.prettypipes.network.PipeItem;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
|
|
|
import net.minecraft.network.PacketBuffer;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraftforge.fml.network.NetworkEvent;
|
|
|
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
public class PacketItemEnterPipe {
|
|
|
|
|
|
|
|
private BlockPos tilePos;
|
|
|
|
private CompoundNBT item;
|
|
|
|
|
|
|
|
public PacketItemEnterPipe(BlockPos tilePos, PipeItem item) {
|
|
|
|
this.tilePos = tilePos;
|
|
|
|
this.item = item.serializeNBT();
|
|
|
|
}
|
|
|
|
|
|
|
|
private PacketItemEnterPipe() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static PacketItemEnterPipe fromBytes(PacketBuffer buf) {
|
|
|
|
PacketItemEnterPipe client = new PacketItemEnterPipe();
|
|
|
|
client.tilePos = buf.readBlockPos();
|
|
|
|
client.item = buf.readCompoundTag();
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toBytes(PacketItemEnterPipe packet, PacketBuffer buf) {
|
|
|
|
buf.writeBlockPos(packet.tilePos);
|
|
|
|
buf.writeCompoundTag(packet.item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("Convert2Lambda")
|
|
|
|
public static void onMessage(PacketItemEnterPipe message, Supplier<NetworkEvent.Context> ctx) {
|
|
|
|
ctx.get().enqueueWork(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Minecraft mc = Minecraft.getInstance();
|
|
|
|
if (mc.world == null)
|
|
|
|
return;
|
2020-10-16 22:36:44 +02:00
|
|
|
PipeItem item = PipeItem.load(message.item);
|
2020-04-14 17:14:24 +02:00
|
|
|
PipeTileEntity pipe = Utility.getTileEntity(PipeTileEntity.class, mc.world, message.tilePos);
|
|
|
|
if (pipe != null)
|
2020-04-17 21:32:01 +02:00
|
|
|
pipe.getItems().add(item);
|
2020-04-14 17:14:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
ctx.get().setPacketHandled(true);
|
|
|
|
}
|
|
|
|
}
|