[FEAT] More Nojang abstractions and compat layers (SDLink)

This commit is contained in:
2024-05-01 18:28:52 +02:00
parent 5166886924
commit 9ffd14d9c1
23 changed files with 292 additions and 10 deletions

View File

@@ -1,6 +1,8 @@
archivesBaseName = "${mod_name.replace(" ", "")}-NeoForge-${minecraft_version}"
dependencies {
// Compat
modImplementation("maven.modrinth:vanishmod:puxrKAMr")
// Do not edit or remove
implementation project(":Common")
@@ -11,8 +13,11 @@ shadowJar {
configurations = [project.configurations.shade]
dependencies {
exclude(dependency('com.google.code.gson:.*'))
relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig'
relocate 'me.hypherionmc.mcdiscordformatter', 'shadow.hypherionmc.mcdiscordformatter'
relocate 'net.kyori', 'shadow.kyori'
}
setArchiveClassifier('dev-shadow')
@@ -62,9 +67,7 @@ tasks.withType(JavaCompile).configureEach {
publishing {
publications {
mavenJava(MavenPublication) {
groupId project.group
artifactId project.archivesBaseName
version project.version
from components.java
artifact(remapJar) {

View File

@@ -2,10 +2,12 @@ package com.hypherionmc.craterlib;
import com.hypherionmc.craterlib.api.events.client.LateInitEvent;
import com.hypherionmc.craterlib.common.NeoForgeServerEvents;
import com.hypherionmc.craterlib.compat.Vanish;
import com.hypherionmc.craterlib.core.event.CraterEventBus;
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
import com.hypherionmc.craterlib.core.networking.PacketRegistry;
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
import com.hypherionmc.craterlib.network.CraterNeoForgeNetworkHandler;
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
import com.hypherionmc.craterlib.nojang.client.BridgedOptions;
@@ -26,6 +28,10 @@ public class CraterLib {
NeoForge.EVENT_BUS.register(new NeoForgeServerEvents());
eventBus.addListener(this::commonSetup);
handler = new CraterNeoForgeNetworkHandler(FMLLoader.getDist().isClient() ? PacketSide.CLIENT : PacketSide.SERVER);
if (ModloaderEnvironment.INSTANCE.isModLoaded("vmod")) {
eventBus.register(new Vanish());
}
}
public void commonSetup(FMLCommonSetupEvent evt) {

View File

@@ -0,0 +1,22 @@
package com.hypherionmc.craterlib.common;
import com.hypherionmc.craterlib.core.platform.CompatUtils;
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import redstonedubstep.mods.vanishmod.VanishUtil;
public class NeoForgeCompatHelper implements CompatUtils {
@Override
public boolean isPlayerActive(BridgedPlayer player) {
if (!ModloaderEnvironment.INSTANCE.isModLoaded("vmod"))
return true;
return VanishUtil.isVanished(player.toMojangServerPlayer());
}
@Override
public String getSkinUUID(BridgedPlayer player) {
return player.getStringUUID();
}
}

View File

@@ -0,0 +1,24 @@
package com.hypherionmc.craterlib.compat;
import com.hypherionmc.craterlib.api.events.server.CraterPlayerEvent;
import com.hypherionmc.craterlib.core.event.CraterEventBus;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import net.neoforged.bus.api.SubscribeEvent;
import redstonedubstep.mods.vanishmod.api.PlayerVanishEvent;
public class Vanish {
public Vanish() {
}
@SubscribeEvent
public void vanishevent(PlayerVanishEvent event) {
if (event.isVanished()) {
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity())));
} else {
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity())));
}
}
}

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.NeoForgeCompatHelper