[PORT] 1.20.6 port
This commit is contained in:
@@ -50,7 +50,7 @@ processResources {
|
||||
from project(":Common").sourceSets.main.resources
|
||||
def buildProps = project.properties.clone()
|
||||
|
||||
filesMatching("META-INF/mods.toml") {
|
||||
filesMatching("META-INF/neoforge.mods.toml") {
|
||||
expand buildProps
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,12 @@
|
||||
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;
|
||||
@@ -13,12 +17,16 @@ import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||
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 {
|
||||
|
||||
@@ -39,6 +47,13 @@ public class CraterLib {
|
||||
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))));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,15 +7,15 @@ import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.event.TickEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.event.tick.LevelTickEvent;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = CraterConstants.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
|
||||
@EventBusSubscriber(modid = CraterConstants.MOD_ID, value = Dist.CLIENT)
|
||||
public class NeoForgeClientEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void clientTick(TickEvent.LevelTickEvent event) {
|
||||
if (event.level == null)
|
||||
public static void clientTick(LevelTickEvent.Pre event) {
|
||||
if (Minecraft.getInstance().level == null)
|
||||
return;
|
||||
|
||||
CraterClientTickEvent craterClientTickEvent = new CraterClientTickEvent(BridgedClientLevel.of(Minecraft.getInstance().level));
|
||||
|
@@ -1,43 +0,0 @@
|
||||
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))
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -22,7 +22,7 @@ public class ServerGamePacketListenerImplMixin {
|
||||
public ServerPlayer player;
|
||||
|
||||
@Inject(
|
||||
method = "lambda$handleChat$6",
|
||||
method = "lambda$handleChat$5",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
|
@@ -1,70 +1,40 @@
|
||||
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.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.RegisterPayloadHandlerEvent;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
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 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());
|
||||
});
|
||||
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())));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> void registerPacket(PacketHolder<T> container) {
|
||||
if (PACKETS.get(container.messageType()) == null) {
|
||||
var packetContainer = new NeoForgePacketContainer<>(
|
||||
container.messageType(),
|
||||
container.packetId().toMojang(),
|
||||
mojangEncoder(container.encoder()),
|
||||
decoder(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) {
|
||||
@@ -72,45 +42,36 @@ public class CraterNeoForgeNetworkHandler extends PacketRegistry {
|
||||
}
|
||||
|
||||
public <T> void sendToServer(T packet, boolean ignoreCheck) {
|
||||
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);
|
||||
PacketHolder<T> container = (PacketHolder<T>) PACKET_MAP.get(packet.getClass());
|
||||
if (container != null) {
|
||||
PacketDistributor.sendToServer(new CommonPacketWrapper<>(container, packet));
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToClient(T packet, BridgedPlayer player) {
|
||||
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));
|
||||
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));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
CraterConstants.LOG.error("{} packet not registered on the server, this is needed.", packet.getClass(), t);
|
||||
}
|
||||
}
|
||||
|
||||
private <T, K extends NeoForgePacket<T>> IPayloadHandler<K> buildHandler(Consumer<PacketContext<T>> handler) {
|
||||
private <T, K extends CommonPacketWrapper<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;
|
||||
Player player = ctx.player().orElse(null);
|
||||
handler.accept(new PacketContext<>(BridgedPlayer.of(player), payload.packet(), side));
|
||||
} catch (Throwable t) {
|
||||
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) {
|
||||
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)));
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package com.hypherionmc.craterlib.network;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 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(@NotNull FriendlyByteBuf buff)
|
||||
{
|
||||
container().encoder().accept(packet(), buff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResourceLocation id()
|
||||
{
|
||||
return container().packetId();
|
||||
}
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
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) { }
|
@@ -1,31 +0,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 = "MATCH_VERSION"
|
||||
|
||||
[[dependencies.${ mod_id }]]
|
||||
modId = "neoforge"
|
||||
mandatory = true
|
||||
versionRange = "[20.4,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.${ mod_id }]]
|
||||
modId = "minecraft"
|
||||
mandatory = true
|
||||
versionRange = "[1.20.4,1.21)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
31
NeoForge/src/main/resources/META-INF/neoforge.mods.toml
Normal file
31
NeoForge/src/main/resources/META-INF/neoforge.mods.toml
Normal file
@@ -0,0 +1,31 @@
|
||||
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"
|
@@ -5,9 +5,7 @@
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"ConfigScreenHandlerMixin"
|
||||
],
|
||||
"client": [],
|
||||
"server": [
|
||||
"ServerGamePacketListenerImplMixin"
|
||||
],
|
||||
|
Reference in New Issue
Block a user