diff --git a/dependencies.properties b/dependencies.properties index c9f5f92..6a5f30e 100644 --- a/dependencies.properties +++ b/dependencies.properties @@ -1 +1 @@ -neoforge=21.1.63 \ No newline at end of file +neoforge=21.1.65 \ No newline at end of file diff --git a/src/main/java/org/violetmoon/zeta/Zeta.java b/src/main/java/org/violetmoon/zeta/Zeta.java index 9006e6f..967c8fb 100644 --- a/src/main/java/org/violetmoon/zeta/Zeta.java +++ b/src/main/java/org/violetmoon/zeta/Zeta.java @@ -14,23 +14,12 @@ import org.violetmoon.zeta.config.ConfigManager; import org.violetmoon.zeta.config.IZetaConfigInternals; import org.violetmoon.zeta.config.SectionDefinition; -import org.violetmoon.zeta.event.bus.IZetaLoadEvent; -import org.violetmoon.zeta.event.bus.IZetaPlayEvent; -import org.violetmoon.zeta.event.bus.LoadEvent; -import org.violetmoon.zeta.event.bus.PlayEvent; -import org.violetmoon.zeta.event.bus.ZetaEventBus; +import org.violetmoon.zeta.event.bus.*; import org.violetmoon.zeta.item.ext.ItemExtensionFactory; import org.violetmoon.zeta.module.ModuleFinder; import org.violetmoon.zeta.module.ZetaCategory; import org.violetmoon.zeta.module.ZetaModuleManager; -import org.violetmoon.zeta.network.ZetaNetworkHandler; -import org.violetmoon.zeta.registry.BrewingRegistry; -import org.violetmoon.zeta.registry.CraftingExtensionsRegistry; -import org.violetmoon.zeta.registry.DyeablesRegistry; -import org.violetmoon.zeta.registry.PottedPlantRegistry; -import org.violetmoon.zeta.registry.RenderLayerRegistry; -import org.violetmoon.zeta.registry.VariantRegistry; -import org.violetmoon.zeta.registry.ZetaRegistry; +import org.violetmoon.zeta.registry.*; import org.violetmoon.zeta.util.NameChanger; import org.violetmoon.zeta.util.RaytracingUtil; import org.violetmoon.zeta.util.RegistryUtil; @@ -123,9 +112,6 @@ public Zeta(String modid, Logger log, ZetaSide side) { //config (which isn't set in the constructor b/c module loading has to happen first) public ConfigManager configManager; public IZetaConfigInternals configInternals; - - //network (which isn't set in the constructor b/c it has a user-specified protocol version TODO this isnt good api design, imo) - public ZetaNetworkHandler network; // worldgen public EntitySpawnHandler entitySpawn; @@ -198,8 +184,6 @@ public EntitySpawnHandler createEntitySpawnHandler() { return new EntitySpawnHandler(this); } - public abstract ZetaNetworkHandler createNetworkHandler(int protocolVersion); - // event bus public abstract T fireExternalEvent(T impl); diff --git a/src/main/java/org/violetmoon/zeta/client/ZetaClient.java b/src/main/java/org/violetmoon/zeta/client/ZetaClient.java index 6138610..5a12f0a 100644 --- a/src/main/java/org/violetmoon/zeta/client/ZetaClient.java +++ b/src/main/java/org/violetmoon/zeta/client/ZetaClient.java @@ -1,16 +1,5 @@ package org.violetmoon.zeta.client; -import org.jetbrains.annotations.Nullable; -import org.violetmoon.zeta.Zeta; -import org.violetmoon.zeta.client.config.ClientConfigManager; -import org.violetmoon.zeta.event.bus.IZetaLoadEvent; -import org.violetmoon.zeta.event.bus.IZetaPlayEvent; -import org.violetmoon.zeta.event.bus.ZetaEventBus; -import org.violetmoon.zeta.network.IZetaMessage; -import org.violetmoon.zeta.util.zetalist.IZeta; -import org.violetmoon.zeta.util.zetalist.ZetaClientList; - -import net.minecraft.client.Minecraft; import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.item.ItemColor; @@ -21,6 +10,14 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; +import org.jetbrains.annotations.Nullable; +import org.violetmoon.zeta.Zeta; +import org.violetmoon.zeta.client.config.ClientConfigManager; +import org.violetmoon.zeta.event.bus.IZetaLoadEvent; +import org.violetmoon.zeta.event.bus.IZetaPlayEvent; +import org.violetmoon.zeta.event.bus.ZetaEventBus; +import org.violetmoon.zeta.util.zetalist.IZeta; +import org.violetmoon.zeta.util.zetalist.ZetaClientList; public abstract class ZetaClient implements IZeta { public ZetaClient(Zeta zeta) { @@ -65,14 +62,6 @@ public TopLayerTooltipHandler createTopLayerTooltipHandler() { return new TopLayerTooltipHandler(); } - //ummm ?? - public void sendToServer(IZetaMessage msg) { - if(Minecraft.getInstance().getConnection() == null) - return; - - zeta.network.sendToServer(msg); - } - //kinda a grab bag of stuff that needs to happen client-only; hmm, not the best design public abstract ClientRegistryExtension createClientRegistryExtension(); diff --git a/src/main/java/org/violetmoon/zeta/client/config/ClientConfigManager.java b/src/main/java/org/violetmoon/zeta/client/config/ClientConfigManager.java index fc410c0..cf7a396 100644 --- a/src/main/java/org/violetmoon/zeta/client/config/ClientConfigManager.java +++ b/src/main/java/org/violetmoon/zeta/client/config/ClientConfigManager.java @@ -1,25 +1,13 @@ package org.violetmoon.zeta.client.config; -import java.util.List; - import org.jetbrains.annotations.NotNull; import org.violetmoon.zeta.client.ZetaClient; -import org.violetmoon.zeta.client.config.definition.BooleanClientDefinition; -import org.violetmoon.zeta.client.config.definition.ClientDefinitionExt; -import org.violetmoon.zeta.client.config.definition.DoubleClientDefinition; -import org.violetmoon.zeta.client.config.definition.IConfigDefinitionProvider; -import org.violetmoon.zeta.client.config.definition.IntegerClientDefinition; -import org.violetmoon.zeta.client.config.definition.SectionClientDefinition; -import org.violetmoon.zeta.client.config.definition.StringClientDefinition; -import org.violetmoon.zeta.client.config.definition.StringListClientDefinition; +import org.violetmoon.zeta.client.config.definition.*; import org.violetmoon.zeta.config.Definition; import org.violetmoon.zeta.config.SectionDefinition; import org.violetmoon.zeta.config.ValueDefinition; -import org.violetmoon.zeta.event.bus.LoadEvent; -import org.violetmoon.zeta.event.load.ZConfigChanged; -import org.violetmoon.zeta.network.message.C2SUpdateFlag; -import net.minecraft.client.Minecraft; +import java.util.List; public class ClientConfigManager { @@ -56,11 +44,4 @@ else if(val.defaultValue instanceof List) //This cast is unsound, but Default never actually uses its argument, so it's fineeeeee, right throw new IllegalArgumentException(def + " is not a legal config value"); } - - @LoadEvent - public void configChanged(ZConfigChanged event) { - if(Minecraft.getInstance().getConnection() != null) - zc.sendToServer(C2SUpdateFlag.createPacket()); - } - -} +} \ No newline at end of file diff --git a/src/main/java/org/violetmoon/zeta/config/SyncedFlagHandler.java b/src/main/java/org/violetmoon/zeta/config/SyncedFlagHandler.java index 28c6cd1..368750d 100644 --- a/src/main/java/org/violetmoon/zeta/config/SyncedFlagHandler.java +++ b/src/main/java/org/violetmoon/zeta/config/SyncedFlagHandler.java @@ -5,10 +5,6 @@ import net.minecraft.server.level.ServerPlayer; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; -import org.violetmoon.zeta.event.bus.LoadEvent; -import org.violetmoon.zeta.event.load.ZConfigChanged; -import org.violetmoon.zeta.mod.ZetaMod; -import org.violetmoon.zeta.network.message.S2CUpdateFlag; import java.util.*; import java.util.stream.Collectors; @@ -61,11 +57,6 @@ public static void receiveFlagInfoFromPlayer(ServerPlayer player, BitSet bitSet) public static void receiveFlagInfoFromServer(BitSet bitSet) { flagsFromServer.put(Minecraft.getInstance().getConnection(), decodeFlags(bitSet)); } - - @LoadEvent - public static void sendFlagInfoToPlayers(ZConfigChanged event) { - ZetaMod.ZETA.network.sendToPlayers(S2CUpdateFlag.createPacket(), flagsFromPlayers.keySet()); - } private static final WeakHashMap> flagsFromServer = new WeakHashMap<>(); private static final WeakHashMap> flagsFromPlayers = new WeakHashMap<>(); diff --git a/src/main/java/org/violetmoon/zeta/mod/ZetaMod.java b/src/main/java/org/violetmoon/zeta/mod/ZetaMod.java index 1291ed3..7d11de4 100644 --- a/src/main/java/org/violetmoon/zeta/mod/ZetaMod.java +++ b/src/main/java/org/violetmoon/zeta/mod/ZetaMod.java @@ -3,9 +3,6 @@ import net.neoforged.bus.api.IEventBus; import org.violetmoon.zeta.Zeta; import org.violetmoon.zeta.config.ZetaGeneralConfig; -import org.violetmoon.zeta.event.bus.LoadEvent; -import org.violetmoon.zeta.event.load.ZCommonSetup; -import org.violetmoon.zeta.network.ZetaModInternalNetwork; public class ZetaMod { @@ -18,9 +15,7 @@ public static void start(Zeta zeta, ZetaModProxy proxy, IEventBus bus) { ZETA.start(bus); ZETA.loadModules(null, null, ZetaGeneralConfig.INSTANCE); - - ZetaModInternalNetwork.init(); + proxy.registerEvents(zeta); } - -} +} \ No newline at end of file diff --git a/src/main/java/org/violetmoon/zeta/network/IZetaMessage.java b/src/main/java/org/violetmoon/zeta/network/IZetaMessage.java deleted file mode 100644 index 46d186c..0000000 --- a/src/main/java/org/violetmoon/zeta/network/IZetaMessage.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.violetmoon.zeta.network; - -public interface IZetaMessage { - boolean receive(IZetaNetworkEventContext context); -} diff --git a/src/main/java/org/violetmoon/zeta/network/IZetaNetworkEventContext.java b/src/main/java/org/violetmoon/zeta/network/IZetaNetworkEventContext.java deleted file mode 100644 index 1d58ef2..0000000 --- a/src/main/java/org/violetmoon/zeta/network/IZetaNetworkEventContext.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.violetmoon.zeta.network; - -import java.util.concurrent.CompletableFuture; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.server.level.ServerPlayer; - -public interface IZetaNetworkEventContext { - CompletableFuture enqueueWork(Runnable runnable); - @Nullable ServerPlayer getSender(); - void reply(ZetaHandshakeMessage msg); -} diff --git a/src/main/java/org/violetmoon/zeta/network/ZetaHandshakeMessage.java b/src/main/java/org/violetmoon/zeta/network/ZetaHandshakeMessage.java deleted file mode 100644 index a1737c0..0000000 --- a/src/main/java/org/violetmoon/zeta/network/ZetaHandshakeMessage.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.violetmoon.zeta.network; - -import java.util.function.IntSupplier; - -public abstract class ZetaHandshakeMessage implements IntSupplier, IZetaMessage { - - private transient int loginIndex; - - public void setLoginIndex(final int loginIndex) { - this.loginIndex = loginIndex; - } - - public int getLoginIndex() { - return loginIndex; - } - - @Override - public int getAsInt() { - return loginIndex; - } - -} diff --git a/src/main/java/org/violetmoon/zeta/network/ZetaMessageSerializer.java b/src/main/java/org/violetmoon/zeta/network/ZetaMessageSerializer.java deleted file mode 100644 index 86f1fa4..0000000 --- a/src/main/java/org/violetmoon/zeta/network/ZetaMessageSerializer.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.violetmoon.zeta.network; - -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.UUID; -import java.util.function.BiConsumer; -import java.util.function.Function; - -import org.apache.commons.lang3.tuple.Pair; - -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.phys.BlockHitResult; - -@SuppressWarnings({ "unchecked", "rawtypes", "unused" }) -public final class ZetaMessageSerializer { - - private final HashMap, Pair> handlers = new HashMap<>(); - private final HashMap, Field[]> fieldCache = new HashMap<>(); - - { - this.mapFunctions(byte.class, FriendlyByteBuf::readByte, FriendlyByteBuf::writeByte); - this.mapFunctions(short.class, FriendlyByteBuf::readShort, FriendlyByteBuf::writeShort); - mapFunctions(int.class, FriendlyByteBuf::readInt, FriendlyByteBuf::writeInt); - mapFunctions(long.class, FriendlyByteBuf::readLong, FriendlyByteBuf::writeLong); - mapFunctions(float.class, FriendlyByteBuf::readFloat, FriendlyByteBuf::writeFloat); - mapFunctions(double.class, FriendlyByteBuf::readDouble, FriendlyByteBuf::writeDouble); - mapFunctions(boolean.class, FriendlyByteBuf::readBoolean, FriendlyByteBuf::writeBoolean); - this.mapFunctions(char.class, FriendlyByteBuf::readChar, FriendlyByteBuf::writeChar); - - mapFunctions(BlockPos.class, FriendlyByteBuf::readBlockPos, FriendlyByteBuf::writeBlockPos); - //mapFunctions(Component.class, FriendlyByteBuf::readComponent, FriendlyByteBuf::writeComponent); - mapFunctions(UUID.class, FriendlyByteBuf::readUUID, FriendlyByteBuf::writeUUID); - mapFunctions(CompoundTag.class, FriendlyByteBuf::readNbt, FriendlyByteBuf::writeNbt); - //mapFunctions(ItemStack.class, FriendlyByteBuf::readItem, ZetaMessageSerializer::writeItemStack); - mapFunctions(String.class, ZetaMessageSerializer::readString, ZetaMessageSerializer::writeString); - mapFunctions(ResourceLocation.class, FriendlyByteBuf::readResourceLocation, FriendlyByteBuf::writeResourceLocation); - mapFunctions(Date.class, FriendlyByteBuf::readDate, FriendlyByteBuf::writeDate); - mapFunctions(BlockHitResult.class, FriendlyByteBuf::readBlockHitResult, FriendlyByteBuf::writeBlockHitResult); - } - - public T instantiateAndReadObject(Class clazz, FriendlyByteBuf buf) { - try { - T msg = clazz.getDeclaredConstructor().newInstance(); - readObject(msg, buf); - return msg; - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - // ! NO relation to java Serializable ! - public void readObject(Object obj, FriendlyByteBuf buf) { - try { - Class clazz = obj.getClass(); - Field[] clFields = getClassFields(clazz); - for(Field f : clFields) { - Class type = f.getType(); - if(acceptField(f, type)) - readField(obj, f, type, buf); - } - } catch(Exception e) { - throw new RuntimeException("Error at reading message " + obj, e); - } - } - - public void writeObject(Object obj, FriendlyByteBuf buf) { - try { - Class clazz = obj.getClass(); - Field[] clFields = getClassFields(clazz); - for(Field f : clFields) { - Class type = f.getType(); - if(acceptField(f, type)) - writeField(obj, f, type, buf); - } - } catch(Exception e) { - throw new RuntimeException("Error at writing message " + obj, e); - } - } - - private Field[] getClassFields(Class clazz) { - if(fieldCache.containsKey(clazz)) - return fieldCache.get(clazz); - else { - Field[] fields = clazz.getFields(); - Arrays.sort(fields, Comparator.comparing(Field::getName)); - fieldCache.put(clazz, fields); - return fields; - } - } - - private void writeField(Object obj, Field f, Class clazz, FriendlyByteBuf buf) throws IllegalArgumentException, IllegalAccessException { - Pair handler = getHandler(clazz); - handler.getRight().write(buf, f, f.get(obj)); - } - - private void readField(Object obj, Field f, Class clazz, FriendlyByteBuf buf) throws IllegalArgumentException, IllegalAccessException { - Pair handler = getHandler(clazz); - f.set(obj, handler.getLeft().read(buf, f)); - } - - private Pair getHandler(Class clazz) { - Pair pair = handlers.get(clazz); - if(pair == null) - throw new RuntimeException("No R/W handler for " + clazz); - return pair; - } - - private boolean acceptField(Field f, Class type) { - int mods = f.getModifiers(); - if(Modifier.isFinal(mods) || Modifier.isStatic(mods) || Modifier.isTransient(mods)) - return false; - - return handlers.containsKey(type); - } - - private void mapFunctions(Class type, Function readerLower, BiConsumer writerLower) { - Reader reader = (buf, field) -> readerLower.apply(buf); - Writer writer = (buf, field, t) -> writerLower.accept(buf, t); - mapHandlers(type, reader, writer); - } - - private void mapWriterFunction(Class type, Reader reader, BiConsumer writerLower) { - Writer writer = (buf, field, t) -> writerLower.accept(buf, t); - mapHandlers(type, reader, writer); - } - - private void mapReaderFunction(Class type, Function readerLower, Writer writer) { - Reader reader = (buf, field) -> readerLower.apply(buf); - mapHandlers(type, reader, writer); - } - - public void mapHandlers(Class type, Reader reader, Writer writer) { - Class arrayType = (Class) Array.newInstance(type, 0).getClass(); - - Reader arrayReader = (buf, field) -> { - int count = buf.readInt(); - T[] arr = (T[]) Array.newInstance(type, count); - - for(int i = 0; i < count; i++) - arr[i] = reader.read(buf, field); - - return arr; - }; - - Writer arrayWriter = (buf, field, t) -> { - int count = t.length; - buf.writeInt(count); - - for(int i = 0; i < count; i++) - writer.write(buf, field, t[i]); - }; - - handlers.put(type, Pair.of(reader, writer)); - handlers.put(arrayType, Pair.of(arrayReader, arrayWriter)); - } - - // ================================================================ - // Auxiliary I/O - // ================================================================ - - // Needed because the methods are overloaded - - /*private static void writeItemStack(FriendlyByteBuf buf, ItemStack stack) { - buf.writeItem(stack); - }*/ - - private static String readString(FriendlyByteBuf buf) { - return buf.readUtf(32767); - } - - private static void writeString(FriendlyByteBuf buf, String string) { - buf.writeUtf(string); - } - - // ================================================================ - // Functional interfaces - // ================================================================ - - public interface Reader { - T read(FriendlyByteBuf buf, Field field); - } - - public interface Writer { - void write(FriendlyByteBuf buf, Field field, T t); - } -} diff --git a/src/main/java/org/violetmoon/zeta/network/ZetaModInternalNetwork.java b/src/main/java/org/violetmoon/zeta/network/ZetaModInternalNetwork.java deleted file mode 100644 index b6a2145..0000000 --- a/src/main/java/org/violetmoon/zeta/network/ZetaModInternalNetwork.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.violetmoon.zeta.network; - -import java.util.BitSet; - -import org.violetmoon.zeta.mod.ZetaMod; -import org.violetmoon.zeta.network.message.C2SLoginFlag; -import org.violetmoon.zeta.network.message.C2SUpdateFlag; -import org.violetmoon.zeta.network.message.S2CLoginFlag; -import org.violetmoon.zeta.network.message.S2CUpdateFlag; - -public class ZetaModInternalNetwork { - - public static final int PROTOCOL_VERSION = 1; - - public static void init() { - ZetaNetworkHandler network = ZetaMod.ZETA.createNetworkHandler(PROTOCOL_VERSION); - ZetaMod.ZETA.network = network; - - network.getSerializer().mapHandlers(BitSet.class, (buf, field) -> BitSet.valueOf(buf.readLongArray()), (buf, field, bitSet) -> buf.writeLongArray(bitSet.toLongArray())); - - // Flag Syncing - network.register(S2CUpdateFlag.class, ZetaNetworkDirection.PLAY_TO_CLIENT); - network.register(C2SUpdateFlag.class, ZetaNetworkDirection.PLAY_TO_SERVER); - - // Login - network.registerLogin(S2CLoginFlag.class, ZetaNetworkDirection.LOGIN_TO_CLIENT, 98, true, S2CLoginFlag::generateRegistryPackets); - network.registerLogin(C2SLoginFlag.class, ZetaNetworkDirection.LOGIN_TO_SERVER, 99, false, null); - } - -} diff --git a/src/main/java/org/violetmoon/zeta/network/ZetaNetworkDirection.java b/src/main/java/org/violetmoon/zeta/network/ZetaNetworkDirection.java deleted file mode 100644 index 04f59bb..0000000 --- a/src/main/java/org/violetmoon/zeta/network/ZetaNetworkDirection.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.violetmoon.zeta.network; - -public enum ZetaNetworkDirection { - PLAY_TO_SERVER, - PLAY_TO_CLIENT, - LOGIN_TO_SERVER, - LOGIN_TO_CLIENT; - - public boolean isLogin() { - return this == LOGIN_TO_SERVER || this == LOGIN_TO_CLIENT; - } -} diff --git a/src/main/java/org/violetmoon/zeta/network/ZetaNetworkHandler.java b/src/main/java/org/violetmoon/zeta/network/ZetaNetworkHandler.java deleted file mode 100644 index b8540b3..0000000 --- a/src/main/java/org/violetmoon/zeta/network/ZetaNetworkHandler.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.violetmoon.zeta.network; - -import java.util.List; -import java.util.function.Function; - -import org.apache.commons.lang3.tuple.Pair; -import org.jetbrains.annotations.Nullable; -import org.violetmoon.zeta.Zeta; - -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; - -public abstract class ZetaNetworkHandler { - public ZetaMessageSerializer serializer = new ZetaMessageSerializer(); - - protected final Zeta zeta; - protected final int protocolVersion; - - public ZetaNetworkHandler(Zeta zeta, int protocolVersion) { - this.zeta = zeta; - this.protocolVersion = protocolVersion; - } - - public ZetaMessageSerializer getSerializer() { - return serializer; - } - - public void sendToPlayers(IZetaMessage msg, Iterable players) { - for(ServerPlayer player : players) sendToPlayer(msg, player); - } - - public void sendToAllPlayers(IZetaMessage msg, MinecraftServer server) { - sendToPlayers(msg, server.getPlayerList().getPlayers()); - } - - public abstract void register(Class clazz, ZetaNetworkDirection dir); - //TODO: BAD GARBAGE api - public abstract void registerLogin(Class clazz, ZetaNetworkDirection dir, int id, boolean hasResponse, @Nullable Function>> loginPacketGenerators); - - public abstract void sendToPlayer(IZetaMessage msg, ServerPlayer player); - public abstract void sendToServer(IZetaMessage msg); - - public abstract Packet wrapInVanilla(IZetaMessage msg, ZetaNetworkDirection dir); -} diff --git a/src/main/java/org/violetmoon/zeta/network/message/C2SLoginFlag.java b/src/main/java/org/violetmoon/zeta/network/message/C2SLoginFlag.java deleted file mode 100644 index 1880115..0000000 --- a/src/main/java/org/violetmoon/zeta/network/message/C2SLoginFlag.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.violetmoon.zeta.network.message; - -import java.util.BitSet; - -import org.violetmoon.zeta.config.SyncedFlagHandler; -import org.violetmoon.zeta.network.IZetaNetworkEventContext; -import org.violetmoon.zeta.network.ZetaHandshakeMessage; - -public class C2SLoginFlag extends ZetaHandshakeMessage { - - public BitSet flags; - public int expectedLength; - public int expectedHash; - - public C2SLoginFlag() { - flags = SyncedFlagHandler.compileFlagInfo(); - expectedLength = SyncedFlagHandler.expectedLength(); - expectedHash = SyncedFlagHandler.expectedHash(); - } - - @Override - public boolean receive(IZetaNetworkEventContext context) { - if(expectedLength == SyncedFlagHandler.expectedLength() && expectedHash == SyncedFlagHandler.expectedHash()) - SyncedFlagHandler.receiveFlagInfoFromPlayer(context.getSender(), flags); - return true; - } - -} diff --git a/src/main/java/org/violetmoon/zeta/network/message/C2SUpdateFlag.java b/src/main/java/org/violetmoon/zeta/network/message/C2SUpdateFlag.java deleted file mode 100644 index 1177a10..0000000 --- a/src/main/java/org/violetmoon/zeta/network/message/C2SUpdateFlag.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.violetmoon.zeta.network.message; - -import java.io.Serial; -import java.util.BitSet; - -import org.violetmoon.zeta.config.SyncedFlagHandler; -import org.violetmoon.zeta.network.IZetaMessage; -import org.violetmoon.zeta.network.IZetaNetworkEventContext; - -public class C2SUpdateFlag implements IZetaMessage { - - @Serial - private static final long serialVersionUID = 5243197411999379903L; - - public BitSet flags; - public int expectedLength; - public int expectedHash; - - @Override - public boolean receive(IZetaNetworkEventContext context) { - if(expectedLength == SyncedFlagHandler.expectedLength() && expectedHash == SyncedFlagHandler.expectedHash()) - SyncedFlagHandler.receiveFlagInfoFromPlayer(context.getSender(), flags); - return true; - } - - public C2SUpdateFlag() { - // NO-OP - } - - private C2SUpdateFlag(BitSet flags, int expectedLength, int expectedHash) { - this.flags = flags; - this.expectedLength = expectedLength; - this.expectedHash = expectedHash; - } - - public static C2SUpdateFlag createPacket() { - return new C2SUpdateFlag(SyncedFlagHandler.compileFlagInfo(), SyncedFlagHandler.expectedLength(), SyncedFlagHandler.expectedHash()); - } -} diff --git a/src/main/java/org/violetmoon/zeta/network/message/S2CLoginFlag.java b/src/main/java/org/violetmoon/zeta/network/message/S2CLoginFlag.java deleted file mode 100644 index 16871c7..0000000 --- a/src/main/java/org/violetmoon/zeta/network/message/S2CLoginFlag.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.violetmoon.zeta.network.message; - -import java.util.BitSet; -import java.util.Collections; -import java.util.List; - -import org.apache.commons.lang3.tuple.Pair; -import org.violetmoon.zeta.config.SyncedFlagHandler; -import org.violetmoon.zeta.network.IZetaNetworkEventContext; -import org.violetmoon.zeta.network.ZetaHandshakeMessage; - -public class S2CLoginFlag extends ZetaHandshakeMessage { - - public BitSet flags; - public int expectedLength; - public int expectedHash; - - public S2CLoginFlag() { - flags = SyncedFlagHandler.compileFlagInfo(); - expectedLength = SyncedFlagHandler.expectedLength(); - expectedHash = SyncedFlagHandler.expectedHash(); - } - - //what The fuck is forge doing - public static List> generateRegistryPackets(boolean isLocal) { - return !isLocal ? Collections.singletonList(Pair.of(S2CLoginFlag.class.getName(), new S2CLoginFlag())) : Collections.emptyList(); - } - - @Override - public boolean receive(IZetaNetworkEventContext context) { - if(expectedLength == SyncedFlagHandler.expectedLength() && expectedHash == SyncedFlagHandler.expectedHash()) - SyncedFlagHandler.receiveFlagInfoFromServer(flags); - context.reply(new C2SLoginFlag()); - return true; - } -} diff --git a/src/main/java/org/violetmoon/zeta/network/message/S2CUpdateFlag.java b/src/main/java/org/violetmoon/zeta/network/message/S2CUpdateFlag.java deleted file mode 100644 index 6c13bee..0000000 --- a/src/main/java/org/violetmoon/zeta/network/message/S2CUpdateFlag.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.violetmoon.zeta.network.message; - -import java.io.Serial; -import java.util.BitSet; - -import org.violetmoon.zeta.config.SyncedFlagHandler; -import org.violetmoon.zeta.network.IZetaMessage; -import org.violetmoon.zeta.network.IZetaNetworkEventContext; - -public class S2CUpdateFlag implements IZetaMessage { - - @Serial - private static final long serialVersionUID = 5889504104199410797L; - - public BitSet flags; - public int expectedLength; - public int expectedHash; - - @Override - public boolean receive(IZetaNetworkEventContext context) { - if(expectedLength == SyncedFlagHandler.expectedLength() && expectedHash == SyncedFlagHandler.expectedHash()) - SyncedFlagHandler.receiveFlagInfoFromServer(flags); - return true; - } - - public S2CUpdateFlag() { - // NO-OP - } - - private S2CUpdateFlag(BitSet flags, int expectedLength, int expectedHash) { - this.flags = flags; - this.expectedLength = expectedLength; - this.expectedHash = expectedHash; - } - - public static S2CUpdateFlag createPacket() { - return new S2CUpdateFlag(SyncedFlagHandler.compileFlagInfo(), SyncedFlagHandler.expectedLength(), SyncedFlagHandler.expectedHash()); - } -} diff --git a/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java b/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java index e4102e6..1c4e678 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java +++ b/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java @@ -18,19 +18,8 @@ import net.neoforged.neoforge.event.AnvilUpdateEvent; import net.neoforged.neoforge.event.LootTableLoadEvent; import net.neoforged.neoforge.event.TagsUpdatedEvent; -import net.neoforged.neoforge.event.entity.EntityAttributeCreationEvent; -import net.neoforged.neoforge.event.entity.EntityEvent; -import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent; -import net.neoforged.neoforge.event.entity.EntityMobGriefingEvent; -import net.neoforged.neoforge.event.entity.EntityTeleportEvent; -import net.neoforged.neoforge.event.entity.living.AnimalTameEvent; -import net.neoforged.neoforge.event.entity.living.BabyEntitySpawnEvent; -import net.neoforged.neoforge.event.entity.living.LivingChangeTargetEvent; -import net.neoforged.neoforge.event.entity.living.LivingConversionEvent; -import net.neoforged.neoforge.event.entity.living.LivingDeathEvent; -import net.neoforged.neoforge.event.entity.living.LivingDropsEvent; -import net.neoforged.neoforge.event.entity.living.LivingFallEvent; -import net.neoforged.neoforge.event.entity.living.MobSpawnEvent; +import net.neoforged.neoforge.event.entity.*; +import net.neoforged.neoforge.event.entity.living.*; import net.neoforged.neoforge.event.entity.player.*; import net.neoforged.neoforge.event.furnace.FurnaceFuelBurnTimeEvent; import net.neoforged.neoforge.event.level.BlockEvent; @@ -47,46 +36,16 @@ import org.violetmoon.zeta.block.ext.BlockExtensionFactory; import org.violetmoon.zeta.config.IZetaConfigInternals; import org.violetmoon.zeta.config.SectionDefinition; -import org.violetmoon.zeta.event.bus.ZResult; -import org.violetmoon.zeta.event.load.ZAddReloadListener; -import org.violetmoon.zeta.event.load.ZCommonSetup; -import org.violetmoon.zeta.event.load.ZEntityAttributeCreation; -import org.violetmoon.zeta.event.load.ZGatherAdvancementModifiers; -import org.violetmoon.zeta.event.load.ZLoadComplete; -import org.violetmoon.zeta.event.load.ZRegister; -import org.violetmoon.zeta.event.load.ZTagsUpdated; -import org.violetmoon.zeta.event.play.ZAnvilRepair; -import org.violetmoon.zeta.event.play.ZAnvilUpdate; -import org.violetmoon.zeta.event.play.ZBlock; -import org.violetmoon.zeta.event.play.ZBonemeal; -import org.violetmoon.zeta.event.play.ZFurnaceFuelBurnTime; -import org.violetmoon.zeta.event.play.ZItemTooltip; -import org.violetmoon.zeta.event.play.ZLevelTick; -import org.violetmoon.zeta.event.play.ZPlayNoteBlock; -import org.violetmoon.zeta.event.play.ZServerTick; -import org.violetmoon.zeta.event.play.entity.ZEntityConstruct; -import org.violetmoon.zeta.event.play.entity.ZEntityInteract; -import org.violetmoon.zeta.event.play.entity.ZItemEntityPickup; -import org.violetmoon.zeta.event.play.entity.ZEntityJoinLevel; -import org.violetmoon.zeta.event.play.entity.ZEntityMobGriefing; -import org.violetmoon.zeta.event.play.entity.ZEntityTeleport; +import org.violetmoon.zeta.event.load.*; +import org.violetmoon.zeta.event.play.*; +import org.violetmoon.zeta.event.play.entity.*; import org.violetmoon.zeta.event.play.entity.living.*; -import org.violetmoon.zeta.event.play.entity.player.ZPlayer; -import org.violetmoon.zeta.event.play.entity.player.ZPlayerDestroyItem; -import org.violetmoon.zeta.event.play.entity.player.ZPlayerInteract; -import org.violetmoon.zeta.event.play.entity.player.ZPlayerTick; -import org.violetmoon.zeta.event.play.entity.player.ZRightClickBlock; -import org.violetmoon.zeta.event.play.entity.player.ZRightClickItem; +import org.violetmoon.zeta.event.play.entity.player.*; import org.violetmoon.zeta.event.play.loading.ZLootTableLoad; import org.violetmoon.zeta.event.play.loading.ZVillagerTrades; import org.violetmoon.zeta.event.play.loading.ZWandererTrades; import org.violetmoon.zeta.item.ext.ItemExtensionFactory; -import org.violetmoon.zeta.network.ZetaNetworkHandler; -import org.violetmoon.zeta.registry.BrewingRegistry; -import org.violetmoon.zeta.registry.CraftingExtensionsRegistry; -import org.violetmoon.zeta.registry.CreativeTabManager; -import org.violetmoon.zeta.registry.PottedPlantRegistry; -import org.violetmoon.zeta.registry.ZetaRegistry; +import org.violetmoon.zeta.registry.*; import org.violetmoon.zeta.util.RaytracingUtil; import org.violetmoon.zeta.util.ZetaSide; import org.violetmoon.zetaimplforge.api.GatherAdvancementModifiersEvent; @@ -98,41 +57,14 @@ import org.violetmoon.zetaimplforge.event.load.ForgeZCommonSetup; import org.violetmoon.zetaimplforge.event.load.ForgeZEntityAttributeCreation; import org.violetmoon.zetaimplforge.event.load.ForgeZLoadComplete; -import org.violetmoon.zetaimplforge.event.play.ForgeZAnvilRepair; -import org.violetmoon.zetaimplforge.event.play.ForgeZAnvilUpdate; -import org.violetmoon.zetaimplforge.event.play.ForgeZBlock; -import org.violetmoon.zetaimplforge.event.play.ForgeZBonemeal; -import org.violetmoon.zetaimplforge.event.play.ForgeZFurnaceFuelBurnTime; -import org.violetmoon.zetaimplforge.event.play.ForgeZItemTooltip; -import org.violetmoon.zetaimplforge.event.play.ForgeZLevelTick; -import org.violetmoon.zetaimplforge.event.play.ForgeZPlayNoteBlock; -import org.violetmoon.zetaimplforge.event.play.ForgeZServerTick; -import org.violetmoon.zetaimplforge.event.play.entity.ForgeZEntityConstruct; -import org.violetmoon.zetaimplforge.event.play.entity.ForgeZEntityInteract; -import org.violetmoon.zetaimplforge.event.play.entity.ForgeZEntityItemPickup; -import org.violetmoon.zetaimplforge.event.play.entity.ForgeZEntityJoinLevel; -import org.violetmoon.zetaimplforge.event.play.entity.ForgeZEntityMobGriefing; -import org.violetmoon.zetaimplforge.event.play.entity.ForgeZEntityTeleport; -import org.violetmoon.zetaimplforge.event.play.entity.living.ForgeZAnimalTame; -import org.violetmoon.zetaimplforge.event.play.entity.living.ForgeZBabyEntitySpawn; -import org.violetmoon.zetaimplforge.event.play.entity.living.ForgeZLivingChangeTarget; -import org.violetmoon.zetaimplforge.event.play.entity.living.ForgeZLivingConversion; -import org.violetmoon.zetaimplforge.event.play.entity.living.ForgeZLivingDeath; -import org.violetmoon.zetaimplforge.event.play.entity.living.ForgeZLivingDrops; -import org.violetmoon.zetaimplforge.event.play.entity.living.ForgeZLivingFall; -import org.violetmoon.zetaimplforge.event.play.entity.living.ForgeZLivingTick; -import org.violetmoon.zetaimplforge.event.play.entity.living.ForgeZMobSpawnEvent; -import org.violetmoon.zetaimplforge.event.play.entity.player.ForgeZPlayer; -import org.violetmoon.zetaimplforge.event.play.entity.player.ForgeZPlayerDestroyItem; -import org.violetmoon.zetaimplforge.event.play.entity.player.ForgeZPlayerInteract; -import org.violetmoon.zetaimplforge.event.play.entity.player.ForgeZPlayerTick; -import org.violetmoon.zetaimplforge.event.play.entity.player.ForgeZRightClickBlock; -import org.violetmoon.zetaimplforge.event.play.entity.player.ForgeZRightClickItem; +import org.violetmoon.zetaimplforge.event.play.*; +import org.violetmoon.zetaimplforge.event.play.entity.*; +import org.violetmoon.zetaimplforge.event.play.entity.living.*; +import org.violetmoon.zetaimplforge.event.play.entity.player.*; import org.violetmoon.zetaimplforge.event.play.loading.ForgeZLootTableLoad; import org.violetmoon.zetaimplforge.event.play.loading.ForgeZVillagerTrades; import org.violetmoon.zetaimplforge.event.play.loading.ForgeZWandererTrades; import org.violetmoon.zetaimplforge.item.IForgeItemItemExtensions; -import org.violetmoon.zetaimplforge.network.ForgeZetaNetworkHandler; import org.violetmoon.zetaimplforge.registry.ForgeBrewingRegistry; import org.violetmoon.zetaimplforge.registry.ForgeCraftingExtensionsRegistry; import org.violetmoon.zetaimplforge.registry.ForgeZetaRegistry; @@ -209,11 +141,6 @@ public RaytracingUtil createRaytracingUtil() { return new ForgeRaytracingUtil(); } - @Override - public ZetaNetworkHandler createNetworkHandler(int protocolVersion) { - return new ForgeZetaNetworkHandler(this, protocolVersion); - } - @Override public PlayerInteractEvent.RightClickBlock fireRightClickBlock(Player player, InteractionHand hand, BlockPos pos, BlockHitResult bhr) { return NeoForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickBlock(player, hand, pos, bhr)); diff --git a/src/main/java/org/violetmoon/zetaimplforge/network/ForgeNetworkEventContextImpl.java b/src/main/java/org/violetmoon/zetaimplforge/network/ForgeNetworkEventContextImpl.java deleted file mode 100644 index bbfd059..0000000 --- a/src/main/java/org/violetmoon/zetaimplforge/network/ForgeNetworkEventContextImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.violetmoon.zetaimplforge.network; - -import java.util.concurrent.CompletableFuture; - -import org.jetbrains.annotations.Nullable; -import org.violetmoon.zeta.network.IZetaNetworkEventContext; -import org.violetmoon.zeta.network.ZetaHandshakeMessage; - -import net.minecraft.server.level.ServerPlayer; - -public class ForgeNetworkEventContextImpl implements IZetaNetworkEventContext { - private final NetworkEvent.Context ctx; - private final SimpleChannel channel; - - public ForgeNetworkEventContextImpl(NetworkEvent.Context ctx, SimpleChannel channel) { - this.ctx = ctx; - this.channel = channel; - } - - @Override - public CompletableFuture enqueueWork(Runnable runnable) { - return ctx.enqueueWork(runnable); - } - - @Override - public @Nullable ServerPlayer getSender() { - return ctx.getSender(); - } - - @Override - public void reply(ZetaHandshakeMessage msg) { - channel.reply(msg, ctx); - } -} diff --git a/src/main/java/org/violetmoon/zetaimplforge/network/ForgeZetaNetworkHandler.java b/src/main/java/org/violetmoon/zetaimplforge/network/ForgeZetaNetworkHandler.java deleted file mode 100644 index 2984eda..0000000 --- a/src/main/java/org/violetmoon/zetaimplforge/network/ForgeZetaNetworkHandler.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.violetmoon.zetaimplforge.network; - -import java.util.List; -import java.util.function.BiConsumer; -import java.util.function.Function; -import java.util.function.Supplier; - -import org.apache.commons.lang3.tuple.Pair; -import org.jetbrains.annotations.Nullable; -import org.violetmoon.zeta.network.IZetaMessage; -import org.violetmoon.zeta.network.ZetaHandshakeMessage; -import org.violetmoon.zeta.network.ZetaNetworkDirection; -import org.violetmoon.zeta.network.ZetaNetworkHandler; -import org.violetmoon.zetaimplforge.ForgeZeta; - -import net.minecraft.network.protocol.Packet; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; - -public class ForgeZetaNetworkHandler extends ZetaNetworkHandler { - protected final SimpleChannel channel; - protected int i = 0; - - public ForgeZetaNetworkHandler(ForgeZeta zeta, int protocolVersion) { - super(zeta, protocolVersion); - - String protocolStr = Integer.toString(protocolVersion); - - channel = NetworkRegistry.ChannelBuilder - .named(ResourceLocation.fromNamespaceAndPath(zeta.modid, "main")) - .networkProtocolVersion(() -> protocolStr) - .clientAcceptedVersions(protocolStr::equals) - .serverAcceptedVersions(protocolStr::equals) - .simpleChannel(); - } - - protected SimpleChannel.MessageBuilder builder(Class clazz, NetworkDirection dir) { - return builder(clazz, i++, dir); - } - - protected SimpleChannel.MessageBuilder builder(Class clazz, int id, NetworkDirection dir) { - return channel.messageBuilder(clazz, id, dir) - .encoder(serializer::writeObject) - .decoder(buf -> serializer.instantiateAndReadObject(clazz, buf)); - } - - @Override - public void register(Class clazz, ZetaNetworkDirection dir) { - NetworkDirection forgeDir = toForge(dir); - - builder(clazz, forgeDir) - .consumerNetworkThread((BiConsumer>) (msg, ctxS) -> handlePacket(msg, ctxS, forgeDir)) //Yes you need the cast - .add(); - } - - //God this api suuuucks - @Override - public void registerLogin(Class clazz, ZetaNetworkDirection dir, int id, boolean hasResponse, @Nullable Function>> loginPacketGenerators) { - NetworkDirection forgeDir = toForge(dir); - - SimpleChannel.MessageBuilder builder = builder(clazz, id, forgeDir) - .loginIndex(T::getLoginIndex, T::setLoginIndex); - - if(loginPacketGenerators != null) - builder.buildLoginPacketList(loginPacketGenerators); - - if(dir == ZetaNetworkDirection.LOGIN_TO_SERVER) - builder = builder.consumerNetworkThread(HandshakeHandler.indexFirst((handshakeCrap, msg, ctxS) -> handlePacket(msg, ctxS, forgeDir))); - else - builder = builder.consumerNetworkThread((BiConsumer>) (msg, ctxS) -> handlePacket(msg, ctxS, forgeDir)); //Yes you need the cast - - if(!hasResponse) - builder = builder.noResponse(); - - builder.add(); - } - - private void handlePacket(T msg, Supplier contextSupplier, NetworkDirection forgeDir) { - NetworkEvent.Context context = contextSupplier.get(); - if(context.getDirection() != forgeDir) - return; - - context.setPacketHandled(msg.receive(new ForgeNetworkEventContextImpl(context, channel))); - } - - @Override - public void sendToPlayer(IZetaMessage msg, ServerPlayer player) { - channel.sendTo(msg, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT); - } - - @Override - public void sendToServer(IZetaMessage msg) { - channel.sendToServer(msg); - } - - @Override - public Packet wrapInVanilla(IZetaMessage msg, ZetaNetworkDirection dir) { - return channel.toVanillaPacket(msg, toForge(dir)); - } - - /// - - public static ZetaNetworkDirection fromForge(NetworkDirection dir) { - return switch(dir) { - case PLAY_TO_SERVER -> ZetaNetworkDirection.PLAY_TO_SERVER; - case PLAY_TO_CLIENT -> ZetaNetworkDirection.PLAY_TO_CLIENT; - case LOGIN_TO_SERVER -> ZetaNetworkDirection.LOGIN_TO_SERVER; - case LOGIN_TO_CLIENT -> ZetaNetworkDirection.LOGIN_TO_CLIENT; - }; - } - - public static NetworkDirection toForge(ZetaNetworkDirection dir) { - return switch(dir) { - case PLAY_TO_SERVER -> NetworkDirection.PLAY_TO_SERVER; - case PLAY_TO_CLIENT -> NetworkDirection.PLAY_TO_CLIENT; - case LOGIN_TO_SERVER -> NetworkDirection.LOGIN_TO_SERVER; - case LOGIN_TO_CLIENT -> NetworkDirection.LOGIN_TO_CLIENT; - }; - } -}