mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-06-10 06:40:25 +02:00
36 lines
1.6 KiB
Java
36 lines
1.6 KiB
Java
package de.ellpeck.prettypipes.packets;
|
|
|
|
import de.ellpeck.prettypipes.PrettyPipes;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.IWorld;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.fml.network.NetworkRegistry;
|
|
import net.minecraftforge.fml.network.PacketDistributor;
|
|
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
|
|
|
public final class PacketHandler {
|
|
|
|
private static final String VERSION = "1";
|
|
private static SimpleChannel network;
|
|
|
|
public static void setup() {
|
|
network = NetworkRegistry.newSimpleChannel(new ResourceLocation(PrettyPipes.ID, "network"), () -> VERSION, VERSION::equals, VERSION::equals);
|
|
network.registerMessage(0, PacketItemEnterPipe.class, PacketItemEnterPipe::toBytes, PacketItemEnterPipe::fromBytes, PacketItemEnterPipe::onMessage);
|
|
}
|
|
|
|
public static void sendToAllLoaded(World world, BlockPos pos, Object message) {
|
|
network.send(PacketDistributor.TRACKING_CHUNK.with(() -> world.getChunkAt(pos)), message);
|
|
}
|
|
|
|
public static void sendToAllAround(IWorld world, BlockPos pos, int range, Object message) {
|
|
network.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(pos.getX(), pos.getY(), pos.getZ(), range, world.getDimension().getType())), message);
|
|
}
|
|
|
|
public static void sendTo(PlayerEntity player, Object message) {
|
|
network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), message);
|
|
}
|
|
}
|