-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
19 deletions.
There are no files selected for viewing
44 changes: 25 additions & 19 deletions
44
src/main/java/com/wenxin2/warp_pipes/network/PacketHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,50 @@ | ||
package com.wenxin2.warp_pipes.network; | ||
|
||
import com.wenxin2.warp_pipes.network.server_bound.ClosePipeButtonPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.PipeBubblesButtonPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.PipeBubblesSliderPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.RenamePipePayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.WaterSpoutButtonPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.WaterSpoutSliderPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.data.ClosePipeButtonPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.data.PipeBubblesButtonPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.data.PipeBubblesSliderPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.data.RenamePipePayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.data.WaterSpoutButtonPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.data.WaterSpoutSliderPayload; | ||
import com.wenxin2.warp_pipes.network.server_bound.handler.ClosePipeButtonPacket; | ||
import com.wenxin2.warp_pipes.network.server_bound.handler.PipeBubblesButtonPacket; | ||
import com.wenxin2.warp_pipes.network.server_bound.handler.PipeBubblesSliderPacket; | ||
import com.wenxin2.warp_pipes.network.server_bound.handler.RenamePipePacket; | ||
import com.wenxin2.warp_pipes.network.server_bound.handler.WaterSpoutButtonPacket; | ||
import com.wenxin2.warp_pipes.network.server_bound.handler.WaterSpoutSliderPacket; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.EventBusSubscriber; | ||
import net.neoforged.neoforge.network.PacketDistributor; | ||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; | ||
import net.neoforged.neoforge.network.registration.IPayloadRegistrar; | ||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; | ||
import net.neoforged.neoforge.network.registration.PayloadRegistrar; | ||
|
||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD) | ||
public class PacketHandler { | ||
|
||
@SubscribeEvent | ||
public static void registerPackets(final RegisterPayloadHandlerEvent event) { | ||
final IPayloadRegistrar registrar = event.registrar("warp_pipes").versioned("1.0.0"); | ||
public static void registerPackets(final RegisterPayloadHandlersEvent event) { | ||
final PayloadRegistrar registrar = event.registrar("warp_pipes").versioned("1.0.0"); | ||
|
||
// Sends to server | ||
registrar.play(ClosePipeButtonPayload.CLOSE_STATE_PAYLOAD, ClosePipeButtonPayload::new, ClosePipeButtonPayload::handle); | ||
registrar.play(PipeBubblesSliderPayload.BUBBLES_DISTANCE_PAYLOAD, PipeBubblesSliderPayload::new, PipeBubblesSliderPayload::handle); | ||
registrar.play(PipeBubblesButtonPayload.BUBBLES_STATE_PAYLOAD, PipeBubblesButtonPayload::new, PipeBubblesButtonPayload::handle); | ||
registrar.play(RenamePipePayload.RENAME_PIPE_PAYLOAD, RenamePipePayload::new, RenamePipePayload::handle); | ||
registrar.play(WaterSpoutSliderPayload.SPOUT_HEIGHT_PAYLOAD, WaterSpoutSliderPayload::new, WaterSpoutSliderPayload::handle); | ||
registrar.play(WaterSpoutButtonPayload.SPOUT_STATE_PAYLOAD, WaterSpoutButtonPayload::new, WaterSpoutButtonPayload::handle); | ||
registrar.playToServer(ClosePipeButtonPayload.CLOSE_STATE_PAYLOAD, ClosePipeButtonPayload.STREAM_CODEC, ClosePipeButtonPacket.get()::handle); | ||
registrar.playToServer(PipeBubblesSliderPayload.BUBBLES_DISTANCE_PAYLOAD, PipeBubblesSliderPayload.STREAM_CODEC, PipeBubblesSliderPacket.get()::handle); | ||
registrar.playToServer(PipeBubblesButtonPayload.BUBBLES_STATE_PAYLOAD, PipeBubblesButtonPayload.STREAM_CODEC, PipeBubblesButtonPacket.get()::handle); | ||
registrar.playToServer(RenamePipePayload.RENAME_PIPE_PAYLOAD, RenamePipePayload.STREAM_CODEC, RenamePipePacket.get()::handle); | ||
registrar.playToServer(WaterSpoutSliderPayload.SPOUT_HEIGHT_PAYLOAD, WaterSpoutSliderPayload.STREAM_CODEC, WaterSpoutSliderPacket.get()::handle); | ||
registrar.playToServer(WaterSpoutButtonPayload.SPOUT_STATE_PAYLOAD, WaterSpoutButtonPayload.STREAM_CODEC, WaterSpoutButtonPacket.get()::handle); | ||
} | ||
|
||
public static <MSG extends CustomPacketPayload> void sendToServer(MSG message) { | ||
PacketDistributor.SERVER.noArg().send(message); | ||
PacketDistributor.sendToServer(message); | ||
} | ||
|
||
public static <MSG extends CustomPacketPayload> void sentToAllClients(MSG message) { | ||
PacketDistributor.ALL.noArg().send(message); | ||
PacketDistributor.sendToAllPlayers(message); | ||
} | ||
|
||
public static <MSG extends CustomPacketPayload> void sendToPlayer(MSG message, ServerPlayer player) { | ||
PacketDistributor.PLAYER.with(player).send(message); | ||
PacketDistributor.sendToPlayer(player, message); | ||
} | ||
} |