[NO-ORBIT] Unified Porting Branch
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
--- a/NeoForge/src/main/java/com/hypherionmc/craterlib/CraterLib.java
|
||||
+++ b/NeoForge/src/main/java/com/hypherionmc/craterlib/CraterLib.java
|
||||
@@ -1,12 +1,8 @@
|
||||
package com.hypherionmc.craterlib;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.client.LateInitEvent;
|
||||
-import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||
import com.hypherionmc.craterlib.common.NeoForgeServerEvents;
|
||||
import com.hypherionmc.craterlib.compat.Vanish;
|
||||
-import com.hypherionmc.craterlib.core.config.ConfigController;
|
||||
-import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||
-import com.hypherionmc.craterlib.core.config.annotations.NoConfigScreen;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||
import com.hypherionmc.craterlib.core.networking.PacketRegistry;
|
||||
@@ -17,16 +13,12 @@
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedOptions;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
-import net.neoforged.fml.ModList;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.neoforged.fml.loading.FMLEnvironment;
|
||||
import net.neoforged.fml.loading.FMLLoader;
|
||||
-import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
|
||||
-import java.util.Optional;
|
||||
-
|
||||
@Mod(CraterConstants.MOD_ID)
|
||||
public class CraterLib {
|
||||
|
||||
@@ -47,13 +39,6 @@
|
||||
if (FMLEnvironment.dist.isClient()) {
|
||||
LateInitEvent event = new LateInitEvent(new BridgedMinecraft(), BridgedOptions.of(Minecraft.getInstance().options));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
-
|
||||
- ConfigController.getMonitoredConfigs().forEach((conf, watcher) -> {
|
||||
- if (!conf.getClass().isAnnotationPresent(NoConfigScreen.class)) {
|
||||
- ModuleConfig config = (ModuleConfig) conf;
|
||||
- ModList.get().getModContainerById(config.getModId()).ifPresent(c -> c.registerExtensionPoint(IConfigScreenFactory.class, ((minecraft, screen) -> new CraterConfigScreen(config, screen))));
|
||||
- }
|
||||
- });
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
--- a/NeoForge/src/main/java/com/hypherionmc/craterlib/client/NeoForgeClientEvents.java
|
||||
+++ b/NeoForge/src/main/java/com/hypherionmc/craterlib/client/NeoForgeClientEvents.java
|
||||
@@ -7,14 +7,14 @@
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
-import net.neoforged.fml.common.EventBusSubscriber;
|
||||
-import net.neoforged.neoforge.event.tick.LevelTickEvent;
|
||||
+import net.neoforged.fml.common.Mod;
|
||||
+import net.neoforged.neoforge.event.TickEvent;
|
||||
|
||||
-@EventBusSubscriber(modid = CraterConstants.MOD_ID, value = Dist.CLIENT)
|
||||
+@Mod.EventBusSubscriber(modid = CraterConstants.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
|
||||
public class NeoForgeClientEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
- public static void clientTick(LevelTickEvent.Pre event) {
|
||||
+ public static void clientTick(TickEvent.LevelTickEvent event) {
|
||||
if (Minecraft.getInstance().level == null)
|
||||
return;
|
||||
|
@@ -0,0 +1,46 @@
|
||||
--- /dev/null
|
||||
+++ b/NeoForge/src/main/java/com/hypherionmc/craterlib/mixin/ConfigScreenHandlerMixin.java
|
||||
@@ -1,0 +1,43 @@
|
||||
+package com.hypherionmc.craterlib.mixin;
|
||||
+
|
||||
+import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||
+import com.hypherionmc.craterlib.core.config.ConfigController;
|
||||
+import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||
+import com.hypherionmc.craterlib.core.config.annotations.NoConfigScreen;
|
||||
+import net.minecraft.client.Minecraft;
|
||||
+import net.minecraft.client.gui.screens.Screen;
|
||||
+import net.neoforged.neoforge.client.ConfigScreenHandler;
|
||||
+import net.neoforged.neoforgespi.language.IModInfo;
|
||||
+import org.spongepowered.asm.mixin.Mixin;
|
||||
+import org.spongepowered.asm.mixin.injection.At;
|
||||
+import org.spongepowered.asm.mixin.injection.Inject;
|
||||
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
+
|
||||
+import java.util.Optional;
|
||||
+import java.util.function.BiFunction;
|
||||
+
|
||||
+/**
|
||||
+ * @author HypherionSA
|
||||
+ */
|
||||
+@Mixin(ConfigScreenHandler.class)
|
||||
+public class ConfigScreenHandlerMixin {
|
||||
+
|
||||
+ /**
|
||||
+ * Inject Auto Generated config Screens into forge
|
||||
+ *
|
||||
+ */
|
||||
+ @Inject(at = @At("RETURN"), method = "getScreenFactoryFor", cancellable = true, remap = false)
|
||||
+ private static void injectConfigScreen(IModInfo selectedMod, CallbackInfoReturnable<Optional<BiFunction<Minecraft, Screen, Screen>>> cir) {
|
||||
+ ConfigController.getMonitoredConfigs().forEach((conf, watcher) -> {
|
||||
+ if (!conf.getClass().isAnnotationPresent(NoConfigScreen.class)) {
|
||||
+ ModuleConfig config = (ModuleConfig) conf;
|
||||
+ if (config.getModId().equals(selectedMod.getModId())) {
|
||||
+ cir.setReturnValue(
|
||||
+ Optional.of((minecraft, screen) -> new CraterConfigScreen(config, screen))
|
||||
+ );
|
||||
+ }
|
||||
+ }
|
||||
+ });
|
||||
+ }
|
||||
+
|
||||
+}
|
@@ -0,0 +1,11 @@
|
||||
--- a/NeoForge/src/main/java/com/hypherionmc/craterlib/mixin/ServerGamePacketListenerImplMixin.java
|
||||
+++ b/NeoForge/src/main/java/com/hypherionmc/craterlib/mixin/ServerGamePacketListenerImplMixin.java
|
||||
@@ -22,7 +22,7 @@
|
||||
public ServerPlayer player;
|
||||
|
||||
@Inject(
|
||||
- method = "lambda$handleChat$5",
|
||||
+ method = "lambda$handleChat$6",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
@@ -0,0 +1,146 @@
|
||||
--- a/NeoForge/src/main/java/com/hypherionmc/craterlib/network/CraterNeoForgeNetworkHandler.java
|
||||
+++ b/NeoForge/src/main/java/com/hypherionmc/craterlib/network/CraterNeoForgeNetworkHandler.java
|
||||
@@ -1,40 +1,71 @@
|
||||
package com.hypherionmc.craterlib.network;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
-import com.hypherionmc.craterlib.api.networking.CommonPacketWrapper;
|
||||
import com.hypherionmc.craterlib.core.networking.PacketRegistry;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
+import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
+import net.minecraft.network.FriendlyByteBuf;
|
||||
+import net.minecraft.server.level.ServerPlayer;
|
||||
+import net.minecraft.world.entity.player.Player;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.LogicalSide;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
-import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
+import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
||||
+import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
|
||||
|
||||
+import java.util.HashMap;
|
||||
+import java.util.Map;
|
||||
+import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
+import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public class CraterNeoForgeNetworkHandler extends PacketRegistry {
|
||||
|
||||
+ private final Map<Class<?>, NeoForgePacketContainer> PACKETS = new HashMap<>();
|
||||
+
|
||||
public CraterNeoForgeNetworkHandler(PacketSide side) {
|
||||
super(side);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
- public void register(final RegisterPayloadHandlersEvent event) {
|
||||
- if (!PACKET_MAP.isEmpty()) {
|
||||
- PACKET_MAP.forEach((type, container) -> event.registrar(container.getType().id().getNamespace())
|
||||
- .optional().commonBidirectional(container.getType(), container.getCodec(), buildHandler(container.handler())));
|
||||
+ public void register(final RegisterPayloadHandlerEvent event) {
|
||||
+ if (!PACKETS.isEmpty()) {
|
||||
+ PACKETS.forEach((type, container) -> {
|
||||
+ final IPayloadRegistrar registrar = event.registrar(container.packetId().getNamespace());
|
||||
+ registrar.common(
|
||||
+ container.packetId(),
|
||||
+ container.decoder(),
|
||||
+ container.handler());
|
||||
+ });
|
||||
}
|
||||
}
|
||||
|
||||
- @Override
|
||||
protected <T> void registerPacket(PacketHolder<T> container) {
|
||||
-
|
||||
+ if (PACKETS.get(container.messageType()) == null) {
|
||||
+ var packetContainer = new NeoForgePacketContainer<>(
|
||||
+ container.messageType(),
|
||||
+ container.type().toMojang(),
|
||||
+ this.mojangEncoder(container.encoder()),
|
||||
+ decoder(this.mojangDecoder(container.decoder())),
|
||||
+ buildHandler(container.handler())
|
||||
+ );
|
||||
+
|
||||
+ PACKETS.put(container.messageType(), packetContainer);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private <T> FriendlyByteBuf.Reader<NeoForgePacket<T>> decoder(Function<FriendlyByteBuf, T> decoder) {
|
||||
+ return (buf -> {
|
||||
+ T packet = decoder.apply(buf);
|
||||
+ return new NeoForgePacket<T>(PACKETS.get(packet.getClass()), packet);
|
||||
+ });
|
||||
}
|
||||
|
||||
public <T> void sendToServer(T packet) {
|
||||
@@ -42,36 +73,45 @@
|
||||
}
|
||||
|
||||
public <T> void sendToServer(T packet, boolean ignoreCheck) {
|
||||
- PacketHolder<T> container = (PacketHolder<T>) PACKET_MAP.get(packet.getClass());
|
||||
- if (container != null) {
|
||||
- PacketDistributor.sendToServer(new CommonPacketWrapper<>(container, packet));
|
||||
+ NeoForgePacketContainer<T> container = PACKETS.get(packet.getClass());
|
||||
+ try {
|
||||
+ PacketDistributor.SERVER.noArg().send(new NeoForgePacket<>(container, packet));
|
||||
+ } catch (Throwable t) {
|
||||
+ CraterConstants.LOG.error("{} packet not registered on the client, this is needed.", packet.getClass(), t);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToClient(T packet, BridgedPlayer player) {
|
||||
- PacketHolder<T> container = (PacketHolder<T>) PACKET_MAP.get(packet.getClass());
|
||||
- if (container != null) {
|
||||
- if (player.getConnection().hasChannel(container.type())) {
|
||||
- PacketDistributor.sendToPlayer(player.toMojangServerPlayer(), new CommonPacketWrapper<>(container, packet));
|
||||
+ NeoForgePacketContainer<T> container = PACKETS.get(packet.getClass());
|
||||
+ try {
|
||||
+ if (player.getConnection() == null)
|
||||
+ return;
|
||||
+
|
||||
+ if (player.getConnection().isConnected(container.packetId())) {
|
||||
+ PacketDistributor.PLAYER.with(player.toMojangServerPlayer()).send(new NeoForgePacket<>(container, packet));
|
||||
}
|
||||
+ } catch (Throwable t) {
|
||||
+ CraterConstants.LOG.error("{} packet not registered on the server, this is needed.", packet.getClass(), t);
|
||||
}
|
||||
}
|
||||
|
||||
- private <T, K extends CommonPacketWrapper<T>> IPayloadHandler<K> buildHandler(Consumer<PacketContext<T>> handler) {
|
||||
+ private <T, K extends NeoForgePacket<T>> IPayloadHandler<K> buildHandler(Consumer<PacketContext<T>> handler) {
|
||||
return (payload, ctx) -> {
|
||||
- try
|
||||
- {
|
||||
+ try {
|
||||
PacketSide side = ctx.flow().getReceptionSide().equals(LogicalSide.SERVER) ? PacketSide.SERVER : PacketSide.CLIENT;
|
||||
- if (PacketSide.SERVER.equals(side)) {
|
||||
- handler.accept(new PacketContext<>(BridgedPlayer.of(ctx.player()), payload.packet(), side));
|
||||
- } else {
|
||||
- handler.accept(new PacketContext<>(payload.packet(), side));
|
||||
- }
|
||||
-
|
||||
- }
|
||||
- catch (Throwable t) {
|
||||
+ Player player = ctx.player().orElse(null);
|
||||
+ handler.accept(new PacketContext<>(BridgedPlayer.of(player), payload.packet(), side));
|
||||
+ } catch (Throwable t) {
|
||||
CraterConstants.LOG.error("Error handling packet: {} -> ", payload.packet().getClass(), t);
|
||||
}
|
||||
};
|
||||
+ }
|
||||
+
|
||||
+ private <T> Function<FriendlyByteBuf, T> mojangDecoder(Function<BridgedFriendlyByteBuf, T> handler) {
|
||||
+ return (byteBuf) -> handler.apply(BridgedFriendlyByteBuf.of(byteBuf));
|
||||
+ }
|
||||
+
|
||||
+ private <T> BiConsumer<T, FriendlyByteBuf> mojangEncoder(BiConsumer<T, BridgedFriendlyByteBuf> handler) {
|
||||
+ return (t, byteBuf) -> handler.accept(t, BridgedFriendlyByteBuf.of(byteBuf));
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
--- /dev/null
|
||||
+++ b/NeoForge/src/main/java/com/hypherionmc/craterlib/network/NeoForgePacket.java
|
||||
@@ -1,0 +1,21 @@
|
||||
+package com.hypherionmc.craterlib.network;
|
||||
+
|
||||
+import net.minecraft.network.FriendlyByteBuf;
|
||||
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
+import net.minecraft.resources.ResourceLocation;
|
||||
+
|
||||
+/**
|
||||
+ * Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
+ */
|
||||
+public record NeoForgePacket<T>(NeoForgePacketContainer<T> container, T packet) implements CustomPacketPayload {
|
||||
+
|
||||
+ @Override
|
||||
+ public void write(FriendlyByteBuf buff) {
|
||||
+ container().encoder().accept(packet(), buff);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public ResourceLocation id() {
|
||||
+ return container().packetId();
|
||||
+ }
|
||||
+}
|
@@ -0,0 +1,19 @@
|
||||
--- /dev/null
|
||||
+++ b/NeoForge/src/main/java/com/hypherionmc/craterlib/network/NeoForgePacketContainer.java
|
||||
@@ -1,0 +1,16 @@
|
||||
+package com.hypherionmc.craterlib.network;
|
||||
+
|
||||
+import net.minecraft.network.FriendlyByteBuf;
|
||||
+import net.minecraft.resources.ResourceLocation;
|
||||
+import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
||||
+
|
||||
+import java.util.function.BiConsumer;
|
||||
+
|
||||
+/**
|
||||
+ * Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
+ */
|
||||
+public record NeoForgePacketContainer<T>(Class<T> messageType,
|
||||
+ ResourceLocation packetId,
|
||||
+ BiConsumer<T, FriendlyByteBuf> encoder,
|
||||
+ FriendlyByteBuf.Reader<NeoForgePacket<T>> decoder,
|
||||
+ IPayloadHandler<NeoForgePacket<T>> handler) { }
|
@@ -0,0 +1,36 @@
|
||||
--- /dev/null
|
||||
+++ b/NeoForge/src/main/resources/META-INF/mods.toml
|
||||
@@ -1,0 +1,33 @@
|
||||
+modLoader = "javafml"
|
||||
+loaderVersion = "[1,)"
|
||||
+license = "MIT"
|
||||
+issueTrackerURL = "https://github.com/firstdarkdev/craterLib/issues"
|
||||
+
|
||||
+[[mods]]
|
||||
+ modId = "${mod_id}"
|
||||
+ version = "${version}"
|
||||
+ displayName = "${mod_name}"
|
||||
+ displayURL = "https://modrinth.com/mod/craterlib"
|
||||
+ logoFile = "craterlib_logo.png"
|
||||
+ #credits="Thanks for this example mod goes to Java"
|
||||
+ authors = "${mod_author}, Zenith"
|
||||
+ description = '''
|
||||
+ A library mod used by First Dark Development and HypherionSA Mods
|
||||
+ '''
|
||||
+ displayTest = "NONE"
|
||||
+
|
||||
+[[dependencies.${ mod_id }]]
|
||||
+ modId = "neoforge"
|
||||
+ type="required"
|
||||
+ required=true
|
||||
+ versionRange = "[20.4,)"
|
||||
+ ordering = "NONE"
|
||||
+ side = "BOTH"
|
||||
+
|
||||
+[[dependencies.${ mod_id }]]
|
||||
+ modId = "minecraft"
|
||||
+ type="required"
|
||||
+ required=true
|
||||
+ versionRange = "[1.20.4,1.20.5)"
|
||||
+ ordering = "NONE"
|
||||
+ side = "BOTH"
|
@@ -0,0 +1,34 @@
|
||||
--- a/NeoForge/src/main/resources/META-INF/neoforge.mods.toml
|
||||
+++ /dev/null
|
||||
@@ -1,31 +1,0 @@
|
||||
-modLoader = "javafml"
|
||||
-loaderVersion = "[1,)"
|
||||
-license = "MIT"
|
||||
-issueTrackerURL = "https://github.com/firstdarkdev/craterLib/issues"
|
||||
-
|
||||
-[[mods]]
|
||||
- modId = "${mod_id}"
|
||||
- version = "${version}"
|
||||
- displayName = "${mod_name}"
|
||||
- displayURL = "https://modrinth.com/mod/craterlib"
|
||||
- logoFile = "craterlib_logo.png"
|
||||
- #credits="Thanks for this example mod goes to Java"
|
||||
- authors = "${mod_author}, Zenith"
|
||||
- description = '''
|
||||
- A library mod used by First Dark Development and HypherionSA Mods
|
||||
- '''
|
||||
- displayTest = "NONE"
|
||||
-
|
||||
-[[dependencies.${ mod_id }]]
|
||||
- modId = "neoforge"
|
||||
- type="required"
|
||||
- versionRange = "[20.6,)"
|
||||
- ordering = "NONE"
|
||||
- side = "BOTH"
|
||||
-
|
||||
-[[dependencies.${ mod_id }]]
|
||||
- modId = "minecraft"
|
||||
- type="required"
|
||||
- versionRange = "[1.20.6,1.21)"
|
||||
- ordering = "NONE"
|
||||
- side = "BOTH"
|
@@ -0,0 +1,13 @@
|
||||
--- a/NeoForge/src/main/resources/craterlib.neoforge.mixins.json
|
||||
+++ b/NeoForge/src/main/resources/craterlib.neoforge.mixins.json
|
||||
@@ -5,7 +5,9 @@
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
- "client": [],
|
||||
+ "client": [
|
||||
+ "ConfigScreenHandlerMixin"
|
||||
+ ],
|
||||
"server": [
|
||||
"ServerGamePacketListenerImplMixin"
|
||||
],
|
Reference in New Issue
Block a user