2019-07-23 12:54:53 +02:00
|
|
|
package com.simibubi.create;
|
2019-07-19 17:50:23 +02:00
|
|
|
|
2019-08-08 19:31:46 +02:00
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
import java.util.function.Function;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2020-01-19 19:29:39 +01:00
|
|
|
import com.simibubi.create.foundation.behaviour.filtering.FilteringCountUpdatePacket;
|
2019-07-23 12:54:53 +02:00
|
|
|
import com.simibubi.create.foundation.packet.NbtPacket;
|
2019-08-08 19:31:46 +02:00
|
|
|
import com.simibubi.create.foundation.packet.SimplePacketBase;
|
2019-12-12 11:58:29 +01:00
|
|
|
import com.simibubi.create.modules.contraptions.components.contraptions.chassis.ConfigureChassisPacket;
|
2019-12-12 10:56:34 +01:00
|
|
|
import com.simibubi.create.modules.contraptions.components.mixer.ConfigureMixerPacket;
|
|
|
|
import com.simibubi.create.modules.contraptions.components.motor.ConfigureMotorPacket;
|
2020-01-26 23:58:55 +01:00
|
|
|
import com.simibubi.create.modules.curiosities.blockzapper.BlockzapperBeamPacket;
|
2019-09-14 18:21:30 +02:00
|
|
|
import com.simibubi.create.modules.curiosities.symmetry.SymmetryEffectPacket;
|
2019-09-13 18:36:18 +02:00
|
|
|
import com.simibubi.create.modules.logistics.block.diodes.ConfigureFlexpeaterPacket;
|
2020-01-19 19:29:39 +01:00
|
|
|
import com.simibubi.create.modules.logistics.item.filter.FilterScreenPacket;
|
2019-08-27 17:35:34 +02:00
|
|
|
import com.simibubi.create.modules.logistics.packet.ConfigureFlexcratePacket;
|
|
|
|
import com.simibubi.create.modules.logistics.packet.ConfigureStockswitchPacket;
|
2019-07-23 12:54:53 +02:00
|
|
|
import com.simibubi.create.modules.schematics.packet.ConfigureSchematicannonPacket;
|
|
|
|
import com.simibubi.create.modules.schematics.packet.SchematicPlacePacket;
|
|
|
|
import com.simibubi.create.modules.schematics.packet.SchematicUploadPacket;
|
2019-07-19 17:50:23 +02:00
|
|
|
|
2019-08-08 19:31:46 +02:00
|
|
|
import net.minecraft.network.PacketBuffer;
|
2019-07-19 17:50:23 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2019-08-08 19:31:46 +02:00
|
|
|
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
2019-07-19 17:50:23 +02:00
|
|
|
import net.minecraftforge.fml.network.NetworkRegistry;
|
|
|
|
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
|
|
|
|
2019-08-08 19:31:46 +02:00
|
|
|
public enum AllPackets {
|
|
|
|
|
|
|
|
// Client to Server
|
|
|
|
NBT(NbtPacket.class, NbtPacket::new),
|
|
|
|
CONFIGURE_SCHEMATICANNON(ConfigureSchematicannonPacket.class, ConfigureSchematicannonPacket::new),
|
2019-08-27 17:35:34 +02:00
|
|
|
CONFIGURE_FLEXCRATE(ConfigureFlexcratePacket.class, ConfigureFlexcratePacket::new),
|
|
|
|
CONFIGURE_STOCKSWITCH(ConfigureStockswitchPacket.class, ConfigureStockswitchPacket::new),
|
2019-09-07 13:12:12 +02:00
|
|
|
CONFIGURE_CHASSIS(ConfigureChassisPacket.class, ConfigureChassisPacket::new),
|
|
|
|
CONFIGURE_MOTOR(ConfigureMotorPacket.class, ConfigureMotorPacket::new),
|
2019-09-13 18:36:18 +02:00
|
|
|
CONFIGURE_FLEXPEATER(ConfigureFlexpeaterPacket.class, ConfigureFlexpeaterPacket::new),
|
2019-10-29 19:02:20 +01:00
|
|
|
CONFIGURE_MIXER(ConfigureMixerPacket.class, ConfigureMixerPacket::new),
|
2019-08-08 19:31:46 +02:00
|
|
|
PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new),
|
|
|
|
UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new),
|
2020-01-19 19:29:39 +01:00
|
|
|
CONFIGURE_FILTER(FilterScreenPacket.class, FilterScreenPacket::new),
|
|
|
|
CONFIGURE_FILTERING_AMOUNT(FilteringCountUpdatePacket.class, FilteringCountUpdatePacket::new),
|
2019-10-05 19:00:43 +02:00
|
|
|
|
2019-08-08 19:31:46 +02:00
|
|
|
// Server to Client
|
|
|
|
SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new),
|
2020-01-26 23:58:55 +01:00
|
|
|
BEAM_EFFECT(BlockzapperBeamPacket.class, BlockzapperBeamPacket::new),
|
2019-08-08 19:31:46 +02:00
|
|
|
|
|
|
|
;
|
2019-07-19 17:50:23 +02:00
|
|
|
|
2019-07-28 10:08:49 +02:00
|
|
|
public static final ResourceLocation CHANNEL_NAME = new ResourceLocation(Create.ID, "network");
|
|
|
|
public static final String NETWORK_VERSION = new ResourceLocation(Create.ID, "1").toString();
|
2019-07-19 17:50:23 +02:00
|
|
|
public static SimpleChannel channel;
|
|
|
|
|
2019-08-08 19:31:46 +02:00
|
|
|
private LoadedPacket<?> packet;
|
|
|
|
|
|
|
|
private <T extends SimplePacketBase> AllPackets(Class<T> type, Function<PacketBuffer, T> factory) {
|
|
|
|
packet = new LoadedPacket<>(type, factory);
|
|
|
|
}
|
2019-07-19 17:50:23 +02:00
|
|
|
|
2019-08-08 19:31:46 +02:00
|
|
|
public static void registerPackets() {
|
2019-07-28 10:08:49 +02:00
|
|
|
channel = NetworkRegistry.ChannelBuilder.named(CHANNEL_NAME).serverAcceptedVersions(s -> true)
|
|
|
|
.clientAcceptedVersions(s -> true).networkProtocolVersion(() -> NETWORK_VERSION).simpleChannel();
|
2019-08-08 19:31:46 +02:00
|
|
|
for (AllPackets packet : values())
|
|
|
|
packet.packet.register();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class LoadedPacket<T extends SimplePacketBase> {
|
|
|
|
private static int index = 0;
|
|
|
|
BiConsumer<T, PacketBuffer> encoder;
|
|
|
|
Function<PacketBuffer, T> decoder;
|
|
|
|
BiConsumer<T, Supplier<Context>> handler;
|
|
|
|
Class<T> type;
|
2019-07-28 10:08:49 +02:00
|
|
|
|
2019-08-08 19:31:46 +02:00
|
|
|
private LoadedPacket(Class<T> type, Function<PacketBuffer, T> factory) {
|
|
|
|
encoder = T::write;
|
|
|
|
decoder = factory;
|
|
|
|
handler = T::handle;
|
|
|
|
this.type = type;
|
|
|
|
}
|
2019-07-28 10:08:49 +02:00
|
|
|
|
2019-08-08 19:31:46 +02:00
|
|
|
private void register() {
|
|
|
|
channel.messageBuilder(type, index++).encoder(encoder).decoder(decoder).consumer(handler).add();
|
|
|
|
}
|
2019-07-19 17:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|