Skip to content

Commit

Permalink
neoforge platform
Browse files Browse the repository at this point in the history
enable forge platform
  • Loading branch information
deirn committed Nov 3, 2023
1 parent f0ee620 commit 24b07b9
Show file tree
Hide file tree
Showing 19 changed files with 220 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
build/
eclipse/
run/
runs/
out/
asm/
bin/
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ allprojects {
version = rootProject.version

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ majorVersion = 0

fabricLoader = 0.14.22
fabricApi = 0.90.0+1.20.2
forge = 48.0.1
forge = 48.0.34
neo = 20.2.25-beta

cf.projectId = 615134
mr.projectId = ftdbN0KK
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase = GRADLE_USER_HOME
distributionPath = wrapper/dists
zipStoreBase = GRADLE_USER_HOME
zipStorePath = wrapper/dists
distributionUrl = https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl = https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
2 changes: 1 addition & 1 deletion platform/forge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import net.minecraftforge.gradle.common.util.RunConfig

plugins {
id("net.neoforged.gradle") version "[6.0, 6.2)"
id("net.minecraftforge.gradle") version "[6.0, 6.2)"
id("org.spongepowered.mixin") version "0.7.+"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@
import lol.bai.badpackets.impl.Constants;
import lol.bai.badpackets.impl.platform.PlatformProxy;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.DiscardedPayload;

public class ForgeProxy extends PlatformProxy {

@Override
public CustomPacketPayload createVanillaRegisterPayload(FriendlyByteBuf buf) {
return new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf);
public Packet<?> createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) {
return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf));
}

@Override
public Packet<?> createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) {
return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf));
}

@Override
public Packet<?> createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) {
return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf));
}

@Override
public Packet<?> createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) {
return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf));
}

}
45 changes: 45 additions & 0 deletions platform/neo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import net.neoforged.gradle.dsl.common.runs.run.Run

plugins {
idea
id("net.neoforged.gradle.userdev") version "7.0.+"
}

setupPlatform()

dependencies {
implementation("net.neoforged:neoforge:${rootProp["neo"]}")
}

runs {
val runConfig = Action<Run> {
modSource(sourceSets["main"])
modSource(sourceSets["testmod"])
}

create("client", runConfig)
create("server", runConfig)
}

tasks.processResources {
inputs.property("version", project.version)

filesMatching("META-INF/mods.toml") {
expand("version" to project.version)
}
}

tasks.named<JavaCompile>("compileTestmodJava") {
source(rootProject.sourceSets["testmod"].allSource)
}

afterEvaluate {
val jar = tasks.jar.get()
val sourcesJar = tasks.sourcesJar.get()

upload {
curseforge(jar)
modrinth(jar)
maven(jar, sourcesJar)
}
}
11 changes: 11 additions & 0 deletions platform/neo/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# CurseForge
cf.endpoint = minecraft.curseforge.com
cf.prefix = [NeoForge]
cf.releaseType = beta
cf.loader = NeoForge
cf.gameVersion = 1.20.2

# Modrinth
mr.releaseType = release
mr.loader = neoforge
mr.gameVersion = 1.20.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package lol.bai.badpackets.impl.neo;

import lol.bai.badpackets.impl.Constants;
import net.neoforged.fml.common.Mod;

@Mod(Constants.MOD_ID)
public class NeoBadPackets {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package lol.bai.badpackets.impl.neo;

import lol.bai.badpackets.impl.Constants;
import lol.bai.badpackets.impl.platform.PlatformProxy;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.neoforged.neoforge.network.custom.payload.SimplePayload;

public class NeoProxy extends PlatformProxy {

@Override
public Packet<?> createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) {
return new ClientboundCustomPayloadPacket(SimplePayload.outbound(buf, 0, Constants.MC_REGISTER_CHANNEL));
}

@Override
public Packet<?> createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) {
return new ServerboundCustomPayloadPacket(SimplePayload.outbound(buf, 0, Constants.MC_REGISTER_CHANNEL));
}

@Override
public Packet<?> createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) {
return new ClientboundCustomPayloadPacket(SimplePayload.outbound(buf, 0, Constants.MC_REGISTER_CHANNEL));
}

@Override
public Packet<?> createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) {
return new ServerboundCustomPayloadPacket(SimplePayload.outbound(buf, 0, Constants.MC_REGISTER_CHANNEL));
}

}
23 changes: 23 additions & 0 deletions platform/neo/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
modLoader = "javafml"
loaderVersion = "[1,)"

license = "Apache-2.0"
issueTrackerURL = "https://github.com/badasintended/badpackets/issues"

[[mods]]
modId = "badpackets"
version = "${version}"
displayName = "Bad Packets"
description = "Allow packet messaging between multiple modding platform."
authors = "deirn"
logoFile = "badpackets.png"

[[mixins]]
config = "badpackets.mixins.json"

[[dependencies.badpackets]]
modId = "minecraft"
mandatory = true
versionRange = "[1.20.2,)"
ordering = "NONE"
side = "BOTH"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lol.bai.badpackets.impl.neo.NeoProxy
6 changes: 6 additions & 0 deletions platform/neo/src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"description": "badpackets",
"pack_format": 8
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package lol.badpackets.test.neo;

import lol.bai.badpackets.impl.Constants;
import lol.bai.badpackets.test.BadPacketTest;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod.EventBusSubscriber;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;

import static net.neoforged.fml.common.Mod.EventBusSubscriber.Bus;

@EventBusSubscriber(modid = Constants.MOD_ID, bus = Bus.MOD, value = Dist.CLIENT)
public class ForgeBadPacketTestClient {

@SubscribeEvent
static void setup(FMLClientSetupEvent event) {
BadPacketTest.client();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package lol.badpackets.test.neo;

import lol.bai.badpackets.impl.Constants;
import lol.bai.badpackets.test.BadPacketTest;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod.EventBusSubscriber;
import net.neoforged.fml.common.Mod.EventBusSubscriber.Bus;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;

@EventBusSubscriber(modid = Constants.MOD_ID, bus = Bus.MOD)
public class NeoBadPacketTest {

@SubscribeEvent
static void setup(FMLCommonSetupEvent event) {
BadPacketTest.server();
}

}
6 changes: 4 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fun platform(name: String) {
project(":${name}").projectDir = file("platform/${name}")
}

platform("fabric")
//platform("forge")
platform("mojmap")

platform("fabric")
platform("forge")
platform("neo")
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ClientboundPingPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -22,6 +23,11 @@ private void badpackets_handlePing(ClientboundPingPacket packet, CallbackInfo ci
if (badpackets_handlePing(packet.getId())) ci.cancel();
}

@Inject(method = "handleCustomPayload(Lnet/minecraft/network/protocol/common/ClientboundCustomPayloadPacket;)V", at = @At("HEAD"), cancellable = true)
private void badpackets_handleCustomPayload(ClientboundCustomPayloadPacket packet, CallbackInfo ci) {
if (badpackets_handleCustomPayload(packet)) ci.cancel();
}

@Unique
protected void badpackets_removeClientPacketHandler(Component reason) {
}
Expand All @@ -31,4 +37,9 @@ protected boolean badpackets_handlePing(int id) {
return false;
}

@Unique
protected boolean badpackets_handleCustomPayload(ClientboundCustomPayloadPacket packet) {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.client.multiplayer.CommonListenerCookie;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.configuration.ClientboundFinishConfigurationPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -26,11 +26,6 @@ private void badpackets_createPacketHandler(Minecraft minecraft, Connection conn
badpackets_packetHandler = new ClientConfigPacketHandler(minecraft, (ClientConfigurationPacketListenerImpl) (Object) this, connection);
}

@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
private void badpackets_receiveS2CPacket(CustomPacketPayload payload, CallbackInfo ci) {
if (badpackets_packetHandler.receive(payload)) ci.cancel();
}

@Inject(method = "handleConfigurationFinished", at = @At("RETURN"))
private void badpacekts_removePacketHandler(ClientboundFinishConfigurationPacket $$0, CallbackInfo ci) {
badpackets_packetHandler.remove();
Expand All @@ -46,4 +41,9 @@ protected boolean badpackets_handlePing(int id) {
return id == Constants.PING_PONG;
}

@Override
protected boolean badpackets_handleCustomPayload(ClientboundCustomPayloadPacket packet) {
return badpackets_packetHandler.receive(packet.payload());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.client.multiplayer.CommonListenerCookie;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.game.ClientboundStartConfigurationPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -30,11 +30,6 @@ protected void badpackets_removeClientPacketHandler(Component reason) {
badpacket_packetHandler.remove();
}

@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
private void badpackets_receiveS2CPacket(CustomPacketPayload payload, CallbackInfo ci) {
if (badpacket_packetHandler.receive(payload)) ci.cancel();
}

@Inject(method = "handleConfigurationStart", at = @At("RETURN"))
private void badpackets_removeHandler(ClientboundStartConfigurationPacket $$0, CallbackInfo ci) {
badpacket_packetHandler.remove();
Expand All @@ -45,4 +40,9 @@ public ClientPlayPacketHandler badpackets_getHandler() {
return badpacket_packetHandler;
}

@Override
protected boolean badpackets_handleCustomPayload(ClientboundCustomPayloadPacket packet) {
return badpacket_packetHandler.receive(packet.payload());
}

}

0 comments on commit 24b07b9

Please sign in to comment.