mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
packets
This commit is contained in:
1 parent
a219aad6ee
commit
22a0c2026f
5 files changed
+128
-139
No files matched your search
@@ -3,30 +3,36 @@ package vazkii.botania.common.network;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.network.NetworkDirection;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
public final class PacketHandler {
|
||||
|
||||
private static final SimpleNetworkWrapper HANDLER = new SimpleNetworkWrapper(LibMisc.NETWORK_CHANNEL);
|
||||
private static final String PROTOCOL = "1";
|
||||
private static final SimpleChannel HANDLER = NetworkRegistry.newSimpleChannel(
|
||||
new ResourceLocation(LibMisc.MOD_ID, "chan"),
|
||||
() -> PROTOCOL,
|
||||
PROTOCOL::equals,
|
||||
PROTOCOL::equals
|
||||
);
|
||||
|
||||
public static void init() {
|
||||
int id = 0;
|
||||
HANDLER.registerMessage(PacketBotaniaEffect.Handler.class, PacketBotaniaEffect.class, id++, Side.CLIENT);
|
||||
HANDLER.registerMessage(PacketLeftClick.Handler.class, PacketLeftClick.class, id++, Side.SERVER);
|
||||
HANDLER.registerMessage(PacketDodge.Handler.class, PacketDodge.class, id++, Side.SERVER);
|
||||
HANDLER.registerMessage(PacketJump.Handler.class, PacketJump.class, id++, Side.SERVER);
|
||||
HANDLER.registerMessage(id++, PacketBotaniaEffect.class, PacketBotaniaEffect::encode, PacketBotaniaEffect::decode, PacketBotaniaEffect.Handler::handle);
|
||||
HANDLER.registerMessage(id++, PacketLeftClick.class, PacketLeftClick::encode, PacketLeftClick::decode, PacketLeftClick::handle);
|
||||
HANDLER.registerMessage(id++, PacketDodge.class, PacketDodge::encode, PacketDodge::decode, PacketDodge::handle);
|
||||
HANDLER.registerMessage(id++, PacketJump.class, PacketJump::encode, PacketJump::decode, PacketJump::handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message to all within 64 blocks that have this chunk loaded
|
||||
*/
|
||||
public static void sendToNearby(World world, BlockPos pos, IMessage toSend) {
|
||||
public static void sendToNearby(World world, BlockPos pos, Object toSend) {
|
||||
if(world instanceof WorldServer) {
|
||||
WorldServer ws = (WorldServer) world;
|
||||
|
||||
@@ -35,22 +41,22 @@ public final class PacketHandler {
|
||||
|
||||
if (playerMP.getDistanceSq(pos) < 64 * 64
|
||||
&& ws.getPlayerChunkMap().isPlayerWatchingChunk(playerMP, pos.getX() >> 4, pos.getZ() >> 4)) {
|
||||
HANDLER.sendTo(toSend, playerMP);
|
||||
HANDLER.sendTo(toSend, playerMP.connection.getNetworkManager(), NetworkDirection.PLAY_TO_CLIENT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendToNearby(World world, Entity e, IMessage toSend) {
|
||||
public static void sendToNearby(World world, Entity e, Object toSend) {
|
||||
sendToNearby(world, new BlockPos(e), toSend);
|
||||
}
|
||||
|
||||
public static void sendTo(EntityPlayerMP playerMP, IMessage toSend) {
|
||||
HANDLER.sendTo(toSend, playerMP);
|
||||
public static void sendTo(EntityPlayerMP playerMP, Object toSend) {
|
||||
HANDLER.sendTo(toSend, playerMP.connection.getNetworkManager(), NetworkDirection.PLAY_TO_CLIENT);
|
||||
}
|
||||
|
||||
public static void sendToServer(IMessage msg) {
|
||||
public static void sendToServer(Object msg) {
|
||||
HANDLER.sendToServer(msg);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user