mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-16 06:23:42 +01:00
Add network direction designation
This commit is contained in:
parent
b20359808a
commit
b1aeba61c0
1 changed files with 38 additions and 32 deletions
|
@ -25,8 +25,8 @@ import com.simibubi.create.content.logistics.packet.ConfigureStockswitchPacket;
|
||||||
import com.simibubi.create.content.schematics.packet.ConfigureSchematicannonPacket;
|
import com.simibubi.create.content.schematics.packet.ConfigureSchematicannonPacket;
|
||||||
import com.simibubi.create.content.schematics.packet.InstantSchematicPacket;
|
import com.simibubi.create.content.schematics.packet.InstantSchematicPacket;
|
||||||
import com.simibubi.create.content.schematics.packet.SchematicPlacePacket;
|
import com.simibubi.create.content.schematics.packet.SchematicPlacePacket;
|
||||||
import com.simibubi.create.content.schematics.packet.SchematicUploadPacket;
|
|
||||||
import com.simibubi.create.content.schematics.packet.SchematicSyncPacket;
|
import com.simibubi.create.content.schematics.packet.SchematicSyncPacket;
|
||||||
|
import com.simibubi.create.content.schematics.packet.SchematicUploadPacket;
|
||||||
import com.simibubi.create.foundation.command.ConfigureConfigPacket;
|
import com.simibubi.create.foundation.command.ConfigureConfigPacket;
|
||||||
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringCountUpdatePacket;
|
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringCountUpdatePacket;
|
||||||
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueUpdatePacket;
|
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueUpdatePacket;
|
||||||
|
@ -36,44 +36,48 @@ import net.minecraft.network.PacketBuffer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.network.NetworkDirection;
|
||||||
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
||||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||||
import net.minecraftforge.fml.network.PacketDistributor;
|
import net.minecraftforge.fml.network.PacketDistributor;
|
||||||
import net.minecraftforge.fml.network.PacketDistributor.TargetPoint;
|
import net.minecraftforge.fml.network.PacketDistributor.TargetPoint;
|
||||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||||
|
|
||||||
|
import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_SERVER;
|
||||||
|
import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_CLIENT;
|
||||||
|
|
||||||
public enum AllPackets {
|
public enum AllPackets {
|
||||||
|
|
||||||
// Client to Server
|
// Client to Server
|
||||||
NBT(NbtPacket.class, NbtPacket::new),
|
NBT(NbtPacket.class, NbtPacket::new, PLAY_TO_SERVER),
|
||||||
CONFIGURE_SCHEMATICANNON(ConfigureSchematicannonPacket.class, ConfigureSchematicannonPacket::new),
|
CONFIGURE_SCHEMATICANNON(ConfigureSchematicannonPacket.class, ConfigureSchematicannonPacket::new, PLAY_TO_SERVER),
|
||||||
CONFIGURE_FLEXCRATE(ConfigureFlexcratePacket.class, ConfigureFlexcratePacket::new),
|
CONFIGURE_FLEXCRATE(ConfigureFlexcratePacket.class, ConfigureFlexcratePacket::new, PLAY_TO_SERVER),
|
||||||
CONFIGURE_STOCKSWITCH(ConfigureStockswitchPacket.class, ConfigureStockswitchPacket::new),
|
CONFIGURE_STOCKSWITCH(ConfigureStockswitchPacket.class, ConfigureStockswitchPacket::new, PLAY_TO_SERVER),
|
||||||
CONFIGURE_SEQUENCER(ConfigureSequencedGearshiftPacket.class, ConfigureSequencedGearshiftPacket::new),
|
CONFIGURE_SEQUENCER(ConfigureSequencedGearshiftPacket.class, ConfigureSequencedGearshiftPacket::new, PLAY_TO_SERVER),
|
||||||
PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new),
|
PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new, PLAY_TO_SERVER),
|
||||||
UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new),
|
UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new, PLAY_TO_SERVER),
|
||||||
CONFIGURE_FILTER(FilterScreenPacket.class, FilterScreenPacket::new),
|
CONFIGURE_FILTER(FilterScreenPacket.class, FilterScreenPacket::new, PLAY_TO_SERVER),
|
||||||
CONFIGURE_FILTERING_AMOUNT(FilteringCountUpdatePacket.class, FilteringCountUpdatePacket::new),
|
CONFIGURE_FILTERING_AMOUNT(FilteringCountUpdatePacket.class, FilteringCountUpdatePacket::new, PLAY_TO_SERVER),
|
||||||
CONFIGURE_SCROLLABLE(ScrollValueUpdatePacket.class, ScrollValueUpdatePacket::new),
|
CONFIGURE_SCROLLABLE(ScrollValueUpdatePacket.class, ScrollValueUpdatePacket::new, PLAY_TO_SERVER),
|
||||||
EXTENDO_INTERACT(ExtendoGripInteractionPacket.class, ExtendoGripInteractionPacket::new),
|
EXTENDO_INTERACT(ExtendoGripInteractionPacket.class, ExtendoGripInteractionPacket::new, PLAY_TO_SERVER),
|
||||||
CONTRAPTION_INTERACT(ContraptionInteractionPacket.class, ContraptionInteractionPacket::new),
|
CONTRAPTION_INTERACT(ContraptionInteractionPacket.class, ContraptionInteractionPacket::new, PLAY_TO_SERVER),
|
||||||
CLIENT_MOTION(ClientMotionPacket.class, ClientMotionPacket::new),
|
CLIENT_MOTION(ClientMotionPacket.class, ClientMotionPacket::new, PLAY_TO_SERVER),
|
||||||
PLACE_ARM(ArmPlacementPacket.class, ArmPlacementPacket::new),
|
PLACE_ARM(ArmPlacementPacket.class, ArmPlacementPacket::new, PLAY_TO_SERVER),
|
||||||
MINECART_COUPLING_CREATION(CouplingCreationPacket.class, CouplingCreationPacket::new),
|
MINECART_COUPLING_CREATION(CouplingCreationPacket.class, CouplingCreationPacket::new, PLAY_TO_SERVER),
|
||||||
INSTANT_SCHEMATIC(InstantSchematicPacket.class, InstantSchematicPacket::new),
|
INSTANT_SCHEMATIC(InstantSchematicPacket.class, InstantSchematicPacket::new, PLAY_TO_SERVER),
|
||||||
SYNC_SCHEMATIC(SchematicSyncPacket.class, SchematicSyncPacket::new),
|
SYNC_SCHEMATIC(SchematicSyncPacket.class, SchematicSyncPacket::new, PLAY_TO_SERVER),
|
||||||
|
|
||||||
// Server to Client
|
// Server to Client
|
||||||
SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new),
|
SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new, PLAY_TO_CLIENT),
|
||||||
SERVER_SPEED(ServerSpeedProvider.Packet.class, ServerSpeedProvider.Packet::new),
|
SERVER_SPEED(ServerSpeedProvider.Packet.class, ServerSpeedProvider.Packet::new, PLAY_TO_CLIENT),
|
||||||
BEAM_EFFECT(ZapperBeamPacket.class, ZapperBeamPacket::new),
|
BEAM_EFFECT(ZapperBeamPacket.class, ZapperBeamPacket::new, PLAY_TO_CLIENT),
|
||||||
CONFIGURE_CONFIG(ConfigureConfigPacket.class, ConfigureConfigPacket::new),
|
CONFIGURE_CONFIG(ConfigureConfigPacket.class, ConfigureConfigPacket::new, PLAY_TO_CLIENT),
|
||||||
CONTRAPTION_STALL(ContraptionStallPacket.class, ContraptionStallPacket::new),
|
CONTRAPTION_STALL(ContraptionStallPacket.class, ContraptionStallPacket::new, PLAY_TO_CLIENT),
|
||||||
GLUE_EFFECT(GlueEffectPacket.class, GlueEffectPacket::new),
|
GLUE_EFFECT(GlueEffectPacket.class, GlueEffectPacket::new, PLAY_TO_CLIENT),
|
||||||
CONTRAPTION_SEAT_MAPPING(ContraptionSeatMappingPacket.class, ContraptionSeatMappingPacket::new),
|
CONTRAPTION_SEAT_MAPPING(ContraptionSeatMappingPacket.class, ContraptionSeatMappingPacket::new, PLAY_TO_CLIENT),
|
||||||
LIMBSWING_UPDATE(LimbSwingUpdatePacket.class, LimbSwingUpdatePacket::new),
|
LIMBSWING_UPDATE(LimbSwingUpdatePacket.class, LimbSwingUpdatePacket::new, PLAY_TO_CLIENT),
|
||||||
MINECART_CONTROLLER(MinecartControllerUpdatePacket.class, MinecartControllerUpdatePacket::new),
|
MINECART_CONTROLLER(MinecartControllerUpdatePacket.class, MinecartControllerUpdatePacket::new, PLAY_TO_CLIENT),
|
||||||
FLUID_SPLASH(FluidSplashPacket.class, FluidSplashPacket::new),
|
FLUID_SPLASH(FluidSplashPacket.class, FluidSplashPacket::new, PLAY_TO_CLIENT),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -83,8 +87,8 @@ public enum AllPackets {
|
||||||
|
|
||||||
private LoadedPacket<?> packet;
|
private LoadedPacket<?> packet;
|
||||||
|
|
||||||
private <T extends SimplePacketBase> AllPackets(Class<T> type, Function<PacketBuffer, T> factory) {
|
private <T extends SimplePacketBase> AllPackets(Class<T> type, Function<PacketBuffer, T> factory, NetworkDirection direction) {
|
||||||
packet = new LoadedPacket<>(type, factory);
|
packet = new LoadedPacket<>(type, factory, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerPackets() {
|
public static void registerPackets() {
|
||||||
|
@ -110,16 +114,18 @@ public enum AllPackets {
|
||||||
Function<PacketBuffer, T> decoder;
|
Function<PacketBuffer, T> decoder;
|
||||||
BiConsumer<T, Supplier<Context>> handler;
|
BiConsumer<T, Supplier<Context>> handler;
|
||||||
Class<T> type;
|
Class<T> type;
|
||||||
|
NetworkDirection direction;
|
||||||
|
|
||||||
private LoadedPacket(Class<T> type, Function<PacketBuffer, T> factory) {
|
private LoadedPacket(Class<T> type, Function<PacketBuffer, T> factory, NetworkDirection direction) {
|
||||||
encoder = T::write;
|
encoder = T::write;
|
||||||
decoder = factory;
|
decoder = factory;
|
||||||
handler = T::handle;
|
handler = T::handle;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register() {
|
private void register() {
|
||||||
channel.messageBuilder(type, index++)
|
channel.messageBuilder(type, index++, direction)
|
||||||
.encoder(encoder)
|
.encoder(encoder)
|
||||||
.decoder(decoder)
|
.decoder(decoder)
|
||||||
.consumer(handler)
|
.consumer(handler)
|
||||||
|
|
Loading…
Reference in a new issue