From 95c2b3f7f5daeebcb9fa35b26c703e2cf25a6fa9 Mon Sep 17 00:00:00 2001 From: enjarai Date: Mon, 1 Apr 2024 11:53:42 +0200 Subject: [PATCH] Progress? im not sure... --- .../enjarai/doabarrelroll/util/ToastUtil.java | 2 +- fabric/build.gradle | 2 +- .../compat/controlify/ControlifyCompat.java | 47 +++++++++++-------- .../doabarrelroll/DoABarrelRollForge.java | 10 ++-- .../enjarai/doabarrelroll/ModPermissions.java | 10 ++-- .../enjarai/doabarrelroll/SillyPayload.java | 12 +++++ ...rePublicTransportationInThisModLoader.java | 37 ++++++++++++--- ...icTransportationInThisModLoaderClient.java | 10 ++-- ...ransportationInThisModLoaderClientMod.java | 8 ++-- .../platform/ForgeClientNetworkUtils.java | 8 +++- .../platform/ForgePlatformHelper.java | 29 +----------- .../platform/ForgeServerNetworkUtils.java | 12 +++-- .../src/main/resources/META-INF/mods.toml | 4 +- 13 files changed, 108 insertions(+), 83 deletions(-) create mode 100644 neoforge/src/main/java/nl/enjarai/doabarrelroll/SillyPayload.java diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/util/ToastUtil.java b/common/src/main/java/nl/enjarai/doabarrelroll/util/ToastUtil.java index ed2374c5..5702e6ea 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/util/ToastUtil.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/util/ToastUtil.java @@ -8,7 +8,7 @@ public class ToastUtil { public static void toasty(String key) { MinecraftClient.getInstance().getToastManager().add(SystemToast.create( MinecraftClient.getInstance(), - SystemToast.Type.TUTORIAL_HINT, + SystemToast.Type.PERIODIC_NOTIFICATION, Text.translatable("toast.do_a_barrel_roll"), Text.translatable("toast.do_a_barrel_roll." + key) )); diff --git a/fabric/build.gradle b/fabric/build.gradle index 921e5c6d..96271de4 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -17,7 +17,7 @@ dependencies { exclude group: "net.fabricmc" } - modCompileOnly("dev.isxander:controlify:${project.controlify_version}") { + modImplementation("dev.isxander:controlify:${project.controlify_version}") { exclude group: "net.fabricmc" exclude group: "maven.modrinth" exclude group: "com.github.CaffeineMC" diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/compat/controlify/ControlifyCompat.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/compat/controlify/ControlifyCompat.java index 766a2e38..9e59181c 100644 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/compat/controlify/ControlifyCompat.java +++ b/fabric/src/main/java/nl/enjarai/doabarrelroll/compat/controlify/ControlifyCompat.java @@ -4,7 +4,7 @@ import dev.isxander.controlify.api.bind.BindingSupplier; import dev.isxander.controlify.api.bind.ControlifyBindingsApi; import dev.isxander.controlify.api.entrypoint.ControlifyEntrypoint; -import dev.isxander.controlify.bindings.GamepadBinds; +import dev.isxander.controlify.controller.input.GamepadInputs; import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; import nl.enjarai.doabarrelroll.DoABarrelRoll; @@ -15,6 +15,8 @@ import nl.enjarai.doabarrelroll.api.rotation.RotationInstant; import nl.enjarai.doabarrelroll.config.ModConfig; +import static dev.isxander.controlify.controller.input.GamepadInputs.*; + public class ControlifyCompat implements ControlifyEntrypoint { public static BindingSupplier PITCH_UP; public static BindingSupplier PITCH_DOWN; @@ -26,22 +28,27 @@ public class ControlifyCompat implements ControlifyEntrypoint { public static BindingSupplier THRUST_BACKWARD; private RotationInstant applyToRotation(RotationInstant rotationDelta, RollContext context) { - var controller = ControlifyApi.get().currentController(); - var sensitivity = ModConfig.INSTANCE.getControllerSensitivity(); + var perhapsController = ControlifyApi.get().getCurrentController(); + if (perhapsController.isPresent()) { + var controller = perhapsController.get(); + var sensitivity = ModConfig.INSTANCE.getControllerSensitivity(); + + if (PITCH_UP.onController(controller) == null) return rotationDelta; - if (PITCH_UP.onController(controller) == null) return rotationDelta; + double multiplier = context.getRenderDelta() * 1200; - double multiplier = context.getRenderDelta() * 1200; + double pitchAxis = PITCH_DOWN.onController(controller).state() - PITCH_UP.onController(controller).state(); + double yawAxis = YAW_RIGHT.onController(controller).state() - YAW_LEFT.onController(controller).state(); + double rollAxis = ROLL_RIGHT.onController(controller).state() - ROLL_LEFT.onController(controller).state(); - float pitchAxis = PITCH_DOWN.onController(controller).state() - PITCH_UP.onController(controller).state(); - float yawAxis = YAW_RIGHT.onController(controller).state() - YAW_LEFT.onController(controller).state(); - float rollAxis = ROLL_RIGHT.onController(controller).state() - ROLL_LEFT.onController(controller).state(); + pitchAxis *= multiplier * sensitivity.pitch; + yawAxis *= multiplier * sensitivity.yaw; + rollAxis *= multiplier * sensitivity.roll; - pitchAxis *= multiplier * sensitivity.pitch; - yawAxis *= multiplier * sensitivity.yaw; - rollAxis *= multiplier * sensitivity.roll; + return rotationDelta.add(pitchAxis, yawAxis, rollAxis); + } - return rotationDelta.add(pitchAxis, yawAxis, rollAxis); + return rotationDelta; } public static double getThrustModifier() { @@ -68,42 +75,42 @@ public static RotationInstant manageThrottle(RotationInstant rotationInstant, Ro public void onControlifyPreInit(ControlifyApi controlifyApi) { var bindings = ControlifyBindingsApi.get(); PITCH_UP = bindings.registerBind(DoABarrelRoll.id("pitch_up"), builder -> builder - .defaultBind(GamepadBinds.RIGHT_STICK_FORWARD) + .defaultBind(getBind(RIGHT_STICK_AXIS_UP)) .category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll")) .name(Text.translatable("controlify.bind.do_a_barrel_roll.pitch_up")) ); PITCH_DOWN = bindings.registerBind(DoABarrelRoll.id("pitch_down"), builder -> builder - .defaultBind(GamepadBinds.RIGHT_STICK_BACKWARD) + .defaultBind(getBind(RIGHT_STICK_AXIS_DOWN)) .category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll")) .name(Text.translatable("controlify.bind.do_a_barrel_roll.pitch_down")) ); ROLL_LEFT = bindings.registerBind(DoABarrelRoll.id("roll_left"), builder -> builder - .defaultBind(GamepadBinds.RIGHT_STICK_LEFT) + .defaultBind(getBind(RIGHT_STICK_AXIS_LEFT)) .category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll")) .name(Text.translatable("controlify.bind.do_a_barrel_roll.roll_left")) ); ROLL_RIGHT = bindings.registerBind(DoABarrelRoll.id("roll_right"), builder -> builder - .defaultBind(GamepadBinds.RIGHT_STICK_RIGHT) + .defaultBind(getBind(RIGHT_STICK_AXIS_RIGHT)) .category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll")) .name(Text.translatable("controlify.bind.do_a_barrel_roll.roll_right")) ); YAW_LEFT = bindings.registerBind(DoABarrelRoll.id("yaw_left"), builder -> builder - .defaultBind(GamepadBinds.LEFT_STICK_LEFT) + .defaultBind(getBind(LEFT_STICK_AXIS_LEFT)) .category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll")) .name(Text.translatable("controlify.bind.do_a_barrel_roll.yaw_left")) ); YAW_RIGHT = bindings.registerBind(DoABarrelRoll.id("yaw_right"), builder -> builder - .defaultBind(GamepadBinds.LEFT_STICK_RIGHT) + .defaultBind(getBind(LEFT_STICK_AXIS_RIGHT)) .category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll")) .name(Text.translatable("controlify.bind.do_a_barrel_roll.yaw_right")) ); THRUST_FORWARD = bindings.registerBind(DoABarrelRoll.id("thrust_forward"), builder -> builder - .defaultBind(GamepadBinds.LEFT_STICK_FORWARD) + .defaultBind(getBind(LEFT_STICK_AXIS_UP)) .category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll")) .name(Text.translatable("controlify.bind.do_a_barrel_roll.thrust_forward")) ); THRUST_BACKWARD = bindings.registerBind(DoABarrelRoll.id("thrust_backward"), builder -> builder - .defaultBind(GamepadBinds.LEFT_STICK_BACKWARD) + .defaultBind(getBind(LEFT_STICK_AXIS_DOWN)) .category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll")) .name(Text.translatable("controlify.bind.do_a_barrel_roll.thrust_backward")) ); diff --git a/neoforge/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollForge.java b/neoforge/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollForge.java index 0855934e..f31500bb 100644 --- a/neoforge/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollForge.java +++ b/neoforge/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollForge.java @@ -1,11 +1,10 @@ package nl.enjarai.doabarrelroll; import net.minecraft.util.Identifier; -import net.minecraftforge.client.ConfigScreenHandler; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.loading.FMLLoader; -import net.minecraftforge.network.simple.SimpleChannel; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.loading.FMLLoader; +import net.neoforged.neoforge.client.ConfigScreenHandler; import nl.enjarai.doabarrelroll.config.ModConfigScreen; import nl.enjarai.doabarrelroll.platform.services.ClientNetworkUtils; import nl.enjarai.doabarrelroll.platform.services.ServerNetworkUtils; @@ -15,7 +14,6 @@ @Mod(DoABarrelRoll.MODID) public class DoABarrelRollForge { - public static final HashMap NETWORK_CHANNELS = new HashMap<>(); public static final HashMap> CLIENT_LISTENERS = new HashMap<>(); public static final HashMap> SERVER_LISTENERS = new HashMap<>(); diff --git a/neoforge/src/main/java/nl/enjarai/doabarrelroll/ModPermissions.java b/neoforge/src/main/java/nl/enjarai/doabarrelroll/ModPermissions.java index 0ccf99b0..c60cb87b 100644 --- a/neoforge/src/main/java/nl/enjarai/doabarrelroll/ModPermissions.java +++ b/neoforge/src/main/java/nl/enjarai/doabarrelroll/ModPermissions.java @@ -1,11 +1,11 @@ package nl.enjarai.doabarrelroll; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraftforge.server.permission.PermissionAPI; -import net.minecraftforge.server.permission.nodes.PermissionDynamicContext; -import net.minecraftforge.server.permission.nodes.PermissionDynamicContextKey; -import net.minecraftforge.server.permission.nodes.PermissionNode; -import net.minecraftforge.server.permission.nodes.PermissionTypes; +import net.neoforged.neoforge.server.permission.PermissionAPI; +import net.neoforged.neoforge.server.permission.nodes.PermissionDynamicContext; +import net.neoforged.neoforge.server.permission.nodes.PermissionDynamicContextKey; +import net.neoforged.neoforge.server.permission.nodes.PermissionNode; +import net.neoforged.neoforge.server.permission.nodes.PermissionTypes; import org.jetbrains.annotations.Nullable; import java.util.List; diff --git a/neoforge/src/main/java/nl/enjarai/doabarrelroll/SillyPayload.java b/neoforge/src/main/java/nl/enjarai/doabarrelroll/SillyPayload.java new file mode 100644 index 00000000..48eb8ee9 --- /dev/null +++ b/neoforge/src/main/java/nl/enjarai/doabarrelroll/SillyPayload.java @@ -0,0 +1,12 @@ +package nl.enjarai.doabarrelroll; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.util.Identifier; + +public record SillyPayload(PacketByteBuf buf, Identifier id) implements CustomPayload { + @Override + public void write(PacketByteBuf buf) { + buf.writeBytes(buf); + } +} diff --git a/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoader.java b/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoader.java index 628bde47..ce6f4f60 100644 --- a/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoader.java +++ b/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoader.java @@ -1,12 +1,17 @@ package nl.enjarai.doabarrelroll; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.server.permission.events.PermissionGatherEvent; -import net.minecraftforge.server.permission.nodes.PermissionNode; +import net.minecraft.util.Identifier; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.event.TickEvent; +import net.neoforged.neoforge.event.entity.player.PlayerEvent; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; +import net.neoforged.neoforge.network.registration.IPayloadRegistrar; +import net.neoforged.neoforge.server.permission.events.PermissionGatherEvent; +import net.neoforged.neoforge.server.permission.nodes.PermissionNode; + +import java.util.Objects; @Mod.EventBusSubscriber public class WhyIsTherePublicTransportationInThisModLoader { @@ -28,4 +33,24 @@ public static void serverTick(TickEvent.ServerTickEvent event) { EventCallbacks.serverTick(event.getServer()); } } + + @SubscribeEvent + public static void register(final RegisterPayloadHandlerEvent event) { + final IPayloadRegistrar registrar = event.registrar(DoABarrelRoll.MODID); + registerChannel(registrar, DoABarrelRoll.HANDSHAKE_CHANNEL); + registerChannel(registrar, DoABarrelRoll.ROLL_CHANNEL); + } + + private static void registerChannel(IPayloadRegistrar registrar, Identifier id) { + registrar.play(id, buf -> new SillyPayload(buf, id), (payload, ctx) -> { + if (ctx.flow().getReceptionSide().isServer()) { + DoABarrelRollForge.SERVER_LISTENERS.get(id).forEach( + listener -> listener.accept(((ServerPlayerEntity) ctx.player().orElseThrow()).networkHandler, payload.buf(), + replyBuf -> ctx.replyHandler().send(new SillyPayload(replyBuf, id)))); + } else { + DoABarrelRollForge.CLIENT_LISTENERS.get(id).forEach( + listener -> listener.accept(payload.buf(), replyBuf -> ctx.replyHandler().send(new SillyPayload(replyBuf, id)))); + } + }); + } } diff --git a/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoaderClient.java b/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoaderClient.java index 589f1647..d715779f 100644 --- a/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoaderClient.java +++ b/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoaderClient.java @@ -1,11 +1,11 @@ package nl.enjarai.doabarrelroll; import net.minecraft.client.MinecraftClient; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.ClientPlayerNetworkEvent; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent; +import net.neoforged.neoforge.event.TickEvent; @Mod.EventBusSubscriber(Dist.CLIENT) public class WhyIsTherePublicTransportationInThisModLoaderClient { diff --git a/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoaderClientMod.java b/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoaderClientMod.java index d7a05ba7..8fa33208 100644 --- a/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoaderClientMod.java +++ b/neoforge/src/main/java/nl/enjarai/doabarrelroll/WhyIsTherePublicTransportationInThisModLoaderClientMod.java @@ -1,9 +1,9 @@ package nl.enjarai.doabarrelroll; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.RegisterKeyMappingsEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; @Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public class WhyIsTherePublicTransportationInThisModLoaderClientMod { diff --git a/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgeClientNetworkUtils.java b/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgeClientNetworkUtils.java index 4679c844..bdc6c549 100644 --- a/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgeClientNetworkUtils.java +++ b/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgeClientNetworkUtils.java @@ -1,9 +1,10 @@ package nl.enjarai.doabarrelroll.platform; +import net.minecraft.client.MinecraftClient; import net.minecraft.network.PacketByteBuf; import net.minecraft.util.Identifier; -import net.minecraftforge.network.PacketDistributor; import nl.enjarai.doabarrelroll.DoABarrelRollForge; +import nl.enjarai.doabarrelroll.SillyPayload; import nl.enjarai.doabarrelroll.platform.services.ClientNetworkUtils; import java.util.ArrayList; @@ -11,7 +12,10 @@ public class ForgeClientNetworkUtils implements ClientNetworkUtils { @Override public void sendPacket(Identifier channel, PacketByteBuf buf) { - DoABarrelRollForge.NETWORK_CHANNELS.get(channel).send(PacketDistributor.SERVER.noArg(), buf); + var handler = MinecraftClient.getInstance().getNetworkHandler(); + if (handler != null) { + handler.send(new SillyPayload(buf, channel)); + } } @Override diff --git a/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgePlatformHelper.java b/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgePlatformHelper.java index 35de5ab0..f1efe9c0 100644 --- a/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgePlatformHelper.java +++ b/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgePlatformHelper.java @@ -1,20 +1,15 @@ package nl.enjarai.doabarrelroll.platform; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.network.PacketByteBuf; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.util.Identifier; -import net.minecraftforge.fml.loading.LoadingModList; -import net.minecraftforge.network.NetworkRegistry; +import net.neoforged.fml.loading.LoadingModList; import nl.enjarai.doabarrelroll.DoABarrelRoll; -import nl.enjarai.doabarrelroll.DoABarrelRollForge; import nl.enjarai.doabarrelroll.ModPermissions; import nl.enjarai.doabarrelroll.platform.services.PlatformHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Objects; - public class ForgePlatformHelper implements PlatformHelper { @Override public String getPlatformName() { @@ -33,27 +28,7 @@ public boolean checkPermission(ServerPlayNetworkHandler source, String permissio @Override public void registerNetworkChannels(Identifier... channels) { - for (var channel : channels) { - var frogeChannel = NetworkRegistry.newSimpleChannel(channel, () -> "", s -> true, s -> true); - DoABarrelRollForge.NETWORK_CHANNELS.put(channel, frogeChannel); - frogeChannel.registerMessage(0, PacketByteBuf.class, (bufSource, bufDest) -> bufDest.writeBytes(bufSource), buf -> { - buf.retain(); - return buf; - }, (buf, contextSupplier) -> { - var ctx = contextSupplier.get(); - ctx.enqueueWork(() -> { - if (ctx.getDirection().getReceptionSide().isServer()) { - DoABarrelRollForge.SERVER_LISTENERS.get(channel).forEach( - listener -> listener.accept(Objects.requireNonNull(ctx.getSender()).networkHandler, buf, - replyBuf -> frogeChannel.sendTo(replyBuf, ctx.getSender().networkHandler.connection, ctx.getDirection().reply()))); - } else { - DoABarrelRollForge.CLIENT_LISTENERS.get(channel).forEach( - listener -> listener.accept(buf, frogeChannel::sendToServer)); - } - }); - ctx.setPacketHandled(true); - }); - } + // Network channels on NeoForge are registered in an event, so we'll have to do it manually there... } @Override diff --git a/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgeServerNetworkUtils.java b/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgeServerNetworkUtils.java index 1e00bbca..5b126367 100644 --- a/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgeServerNetworkUtils.java +++ b/neoforge/src/main/java/nl/enjarai/doabarrelroll/platform/ForgeServerNetworkUtils.java @@ -5,8 +5,8 @@ import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; -import net.minecraftforge.network.PacketDistributor; import nl.enjarai.doabarrelroll.DoABarrelRollForge; +import nl.enjarai.doabarrelroll.SillyPayload; import nl.enjarai.doabarrelroll.platform.services.ServerNetworkUtils; import java.util.ArrayList; @@ -15,13 +15,17 @@ public class ForgeServerNetworkUtils implements ServerNetworkUtils { @Override public void sendPacket(ServerPlayNetworkHandler handler, Identifier channel, PacketByteBuf buf) { - DoABarrelRollForge.NETWORK_CHANNELS.get(channel).send(PacketDistributor.PLAYER.with(handler::getPlayer), buf); + handler.send(new SillyPayload(buf, channel)); } @Override public void sendPacketsToTracking(Entity entity, Predicate predicate, Identifier channel, PacketByteBuf buf) { - // Cant do predicates here apparently? Well fuck me. - DoABarrelRollForge.NETWORK_CHANNELS.get(channel).send(PacketDistributor.TRACKING_ENTITY.with(() -> entity), buf); + entity.getWorld().getPlayers().stream() + .filter(player -> player != entity) + // Temporary solution until I can figure out how to find tracked players on NeoForge. + .filter(player -> entity.getEyePos().squaredDistanceTo(player.getPos()) <= 16 * 10) + .filter(player -> predicate.test((ServerPlayerEntity) player)) + .forEach(player -> ((ServerPlayerEntity) player).networkHandler.send(new SillyPayload(buf, channel))); } @Override diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/mods.toml index c487e890..b6d60a1f 100644 --- a/neoforge/src/main/resources/META-INF/mods.toml +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -51,7 +51,7 @@ description='''${mod_description}''' # the modid of the dependency modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified - mandatory = true #mandatory + type = "required" #mandatory # The version range of the dependency versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory @@ -62,7 +62,7 @@ description='''${mod_description}''' side = "BOTH" # Side this dependency is applied on - 'BOTH', 'CLIENT' or 'SERVER' [[dependencies.'${mod_id}']] modId = "minecraft" - mandatory = true + type = "required" # This version range declares a minimum of the current minecraft version up to but not including the next major version versionRange = "${forge_minecraft_version_range}" ordering = "NONE"