From c995cc74c73f520835e38c70f81714efedc3658a Mon Sep 17 00:00:00 2001 From: C4 <29991504+TheIllusiveC4@users.noreply.github.com> Date: Wed, 2 Oct 2024 22:37:32 -0700 Subject: [PATCH] Fix Deeper Darker compatibility, closes #132 --- fabric/build.gradle | 12 +++- .../elytraslot/ElytraSlotFabricClientMod.java | 6 +- .../elytraslot/ElytraSlotFabricMod.java | 5 ++ .../DeeperDarkerClientPlugin.java | 32 ++++++++++ .../deeperdarker/DeeperDarkerPlugin.java | 47 +++++++++++++++ .../deeperdarker/SoulElytraBoostPayload.java | 29 +++++++++ forge/build.gradle | 1 + .../elytraslot/ElytraSlotForgeClientMod.java | 7 +++ .../elytraslot/ElytraSlotForgeMod.java | 7 +++ .../elytraslot/common/CurioElytra.java | 6 ++ .../DeeperDarkerClientPlugin.java | 22 +++++++ .../deeperdarker/DeeperDarkerPlugin.java | 59 +++++++++++++++++++ .../deeperdarker/SoulElytraBoostPayload.java | 56 ++++++++++++++++++ quilt/build.gradle | 10 ++++ .../elytraslot/ElytraSlotQuiltClientMod.java | 6 +- .../elytraslot/ElytraSlotQuiltMod.java | 5 ++ .../DeeperDarkerClientPlugin.java | 36 +++++++++++ .../deeperdarker/DeeperDarkerPlugin.java | 50 ++++++++++++++++ .../deeperdarker/SoulElytraBoostPayload.java | 28 +++++++++ 19 files changed, 419 insertions(+), 5 deletions(-) create mode 100644 fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java create mode 100644 fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java create mode 100644 fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java create mode 100644 forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java create mode 100644 forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java create mode 100644 forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java create mode 100644 quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java create mode 100644 quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java create mode 100644 quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java diff --git a/fabric/build.gradle b/fabric/build.gradle index 4a6b6fa..d7fd592 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' + id 'fabric-loom' version '1.7-SNAPSHOT' id 'maven-publish' id 'idea' id 'net.darkhax.curseforgegradle' version '1.+' @@ -8,6 +8,15 @@ plugins { archivesBaseName = "${mod_id}-fabric" +repositories { + maven { + url "https://cursemaven.com" + content { + includeGroup "curse.maven" + } + } +} + dependencies { minecraft "com.mojang:minecraft:${minecraft_version}" mappings(loom.layered { @@ -18,6 +27,7 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" modImplementation "dev.emi:trinkets:${trinkets_version}" modCompileOnly "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${cca_version}" + modCompileOnly "curse.maven:deeperdarker-659011:5725442" modRuntimeOnly("com.terraformersmc:modmenu:${mod_menu_version}") { transitive = false diff --git a/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricClientMod.java b/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricClientMod.java index 7f67517..93e0e20 100644 --- a/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricClientMod.java +++ b/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricClientMod.java @@ -19,6 +19,8 @@ import com.illusivesoulworks.elytraslot.client.ElytraSlotLayer; import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerClientModule; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerClientPlugin; +import com.illusivesoulworks.elytraslot.platform.Services; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.fabricmc.fabric.api.client.rendering.v1.LivingEntityFeatureRenderEvents; @@ -35,8 +37,8 @@ public void onInitializeClient() { (entityType, entityRenderer, registrationHelper, context) -> registrationHelper.register( new ElytraSlotLayer<>(entityRenderer, context.getModelSet()))); - if (FabricLoader.getInstance().isModLoaded("deeperdarker")) { - HudRenderCallback.EVENT.register(DeeperDarkerClientModule::registerHudCallback); + if (Services.PLATFORM.isModLoaded("deeperdarker")) { + DeeperDarkerClientPlugin.setup(); } } } diff --git a/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricMod.java b/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricMod.java index b032fe4..f87e6c0 100644 --- a/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricMod.java +++ b/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricMod.java @@ -17,6 +17,7 @@ package com.illusivesoulworks.elytraslot; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerPlugin; import com.illusivesoulworks.elytraslot.platform.Services; import dev.emi.trinkets.api.SlotReference; import dev.emi.trinkets.api.Trinket; @@ -68,5 +69,9 @@ public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity return ElytraSlotCommonMod.canEquip(entity); } }); + + if (Services.PLATFORM.isModLoaded("deeperdarker")) { + DeeperDarkerPlugin.setup(); + } } } diff --git a/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java b/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java new file mode 100644 index 0000000..787a391 --- /dev/null +++ b/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java @@ -0,0 +1,32 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.platform.Services; +import com.kyanite.deeperdarker.client.Keybinds; +import com.kyanite.deeperdarker.content.DDItems; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.minecraft.client.Minecraft; +import net.minecraft.world.item.ItemStack; + +public class DeeperDarkerClientPlugin { + + public static void setup() { + ClientTickEvents.START_WORLD_TICK.register(world -> { + Minecraft client = Minecraft.getInstance(); + + if (client.player == null) { + return; + } + ItemStack itemStack = Services.ELYTRA.getEquipped(client.player); + + if (itemStack.is(DDItems.SOUL_ELYTRA) && client.player.getCooldowns() + .getCooldownPercent(DDItems.SOUL_ELYTRA, Minecraft.getInstance().getFrameTime()) == 0 && + client.player.isFallFlying() && Keybinds.BOOST.isDown()) { + ClientPlayNetworking.send(new SoulElytraBoostPayload(PacketByteBufs.empty())); + } + }); + HudRenderCallback.EVENT.register(DeeperDarkerClientModule::registerHudCallback); + } +} diff --git a/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java b/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java new file mode 100644 index 0000000..113e68e --- /dev/null +++ b/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java @@ -0,0 +1,47 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.kyanite.deeperdarker.DeeperDarker; +import com.kyanite.deeperdarker.content.DDItems; +import dev.emi.trinkets.api.TrinketsApi; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; +import net.minecraft.world.entity.projectile.FireworkRocketEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; + +public class DeeperDarkerPlugin { + + public static void setup() { + registerPayloads(); + } + + public static void registerPayloads() { + ServerPlayNetworking.registerGlobalReceiver(SoulElytraBoostPayload.TYPE, + (payload, player, sender) -> { + Level level = player.level(); + + if (DeeperDarker.CONFIG.server.soulElytraCooldown() == -1) { + player.displayClientMessage( + Component.translatable(DDItems.SOUL_ELYTRA.getDescriptionId() + ".boost_disabled") + .setStyle( + Style.EMPTY.withColor(ChatFormatting.RED)), true); + return; + } + + if (player.isFallFlying() && TrinketsApi.getTrinketComponent(player) + .map(inv -> inv.isEquipped(DDItems.SOUL_ELYTRA)).orElse(false) && + !player.getCooldowns().isOnCooldown(DDItems.SOUL_ELYTRA) && + DeeperDarker.CONFIG.server.soulElytraCooldown() != -1) { + FireworkRocketEntity + rocket = + new FireworkRocketEntity(level, new ItemStack(Items.FIREWORK_ROCKET), player); + level.addFreshEntity(rocket); + player.getCooldowns() + .addCooldown(DDItems.SOUL_ELYTRA, DeeperDarker.CONFIG.server.soulElytraCooldown()); + } + }); + } +} diff --git a/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java b/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java new file mode 100644 index 0000000..3ab9097 --- /dev/null +++ b/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java @@ -0,0 +1,29 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.ElytraSlotConstants; +import com.kyanite.deeperdarker.DeeperDarker; +import io.netty.buffer.ByteBuf; +import net.fabricmc.fabric.api.networking.v1.FabricPacket; +import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; + +public class SoulElytraBoostPayload implements FabricPacket { + + public static final PacketType TYPE = + PacketType.create(new ResourceLocation(ElytraSlotConstants.MOD_ID, "soul_elytra_boost"), + SoulElytraBoostPayload::new); + + public SoulElytraBoostPayload(ByteBuf buf) { + } + + @Override + public void write(FriendlyByteBuf buf) { + + } + + @Override + public PacketType getType() { + return TYPE; + } +} diff --git a/forge/build.gradle b/forge/build.gradle index fe76892..0b9f1aa 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -103,6 +103,7 @@ dependencies { compileOnly fg.deobf("curse.maven:zeta-968868:5418213") compileOnly fg.deobf("curse.maven:quark-243121:5418252") + compileOnly fg.deobf("curse.maven:deeperdarker-659011:5698212") implementation(jarJar("com.github.bawnorton.mixinsquared:mixinsquared-forge:0.1.2-beta.6")) { jarJar.ranged(it, "[0.1.2-beta.6,)") diff --git a/forge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotForgeClientMod.java b/forge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotForgeClientMod.java index 579a9c3..663a9b6 100644 --- a/forge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotForgeClientMod.java +++ b/forge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotForgeClientMod.java @@ -18,6 +18,9 @@ package com.illusivesoulworks.elytraslot; import com.illusivesoulworks.elytraslot.client.ElytraSlotLayer; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerClientPlugin; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerPlugin; +import com.illusivesoulworks.elytraslot.platform.Services; import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.LivingEntityRenderer; @@ -36,6 +39,10 @@ public static void setup() { IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); eventBus.addListener(ElytraSlotForgeClientMod::addLayers); MinecraftForge.EVENT_BUS.addListener(ElytraSlotForgeClientMod::renderCape); + + if (Services.PLATFORM.isModLoaded("deeperdarker")) { + DeeperDarkerClientPlugin.setup(); + } } private static void addLayers(final EntityRenderersEvent.AddLayers evt) { diff --git a/forge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotForgeMod.java b/forge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotForgeMod.java index b5d1cef..c7a2069 100644 --- a/forge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotForgeMod.java +++ b/forge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotForgeMod.java @@ -18,6 +18,9 @@ package com.illusivesoulworks.elytraslot; import com.illusivesoulworks.elytraslot.common.CurioElytra; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerClientPlugin; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerPlugin; +import com.illusivesoulworks.elytraslot.platform.Services; import javax.annotation.Nonnull; import javax.annotation.Nullable; import net.minecraft.core.Direction; @@ -56,6 +59,10 @@ public ElytraSlotForgeMod() { private void setup(final FMLCommonSetupEvent evt) { MinecraftForge.EVENT_BUS.addGenericListener(ItemStack.class, this::attachCapabilities); MinecraftForge.EVENT_BUS.addListener(this::playerTick); + + if (Services.PLATFORM.isModLoaded("deeperdarker")) { + DeeperDarkerPlugin.setup(); + } } private void clientSetup(final FMLClientSetupEvent evt) { diff --git a/forge/src/main/java/com/illusivesoulworks/elytraslot/common/CurioElytra.java b/forge/src/main/java/com/illusivesoulworks/elytraslot/common/CurioElytra.java index 0200939..4934502 100644 --- a/forge/src/main/java/com/illusivesoulworks/elytraslot/common/CurioElytra.java +++ b/forge/src/main/java/com/illusivesoulworks/elytraslot/common/CurioElytra.java @@ -18,6 +18,8 @@ package com.illusivesoulworks.elytraslot.common; import com.illusivesoulworks.elytraslot.ElytraSlotCommonMod; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerPlugin; +import com.illusivesoulworks.elytraslot.platform.Services; import java.util.UUID; import javax.annotation.Nonnull; import net.minecraft.sounds.SoundEvents; @@ -51,6 +53,10 @@ public void curioTick(SlotContext slotContext) { if (ticks > 0 && livingEntity.isFallFlying()) { this.stack.elytraFlightTick(livingEntity, ticks); } + + if (Services.PLATFORM.isModLoaded("deeperdarker")) { + DeeperDarkerPlugin.tick(livingEntity.level(), livingEntity); + } } @Override diff --git a/forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java b/forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java new file mode 100644 index 0000000..a6eb79f --- /dev/null +++ b/forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java @@ -0,0 +1,22 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.kyanite.deeperdarker.client.Keybinds; +import net.minecraft.client.Minecraft; +import net.minecraftforge.client.event.InputEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.EventPriority; + +public class DeeperDarkerClientPlugin { + + public static void setup() { + MinecraftForge.EVENT_BUS.addListener(EventPriority.LOW, DeeperDarkerClientPlugin::keyInput); + } + private static void keyInput(final InputEvent.Key evt) { + Minecraft mc = Minecraft.getInstance(); + + if (mc.player != null && mc.getConnection() != null && + evt.getKey() == Keybinds.BOOST.getKey().getValue()) { + DeeperDarkerPlugin.NETWORK.sendToServer(new SoulElytraBoostPayload()); + } + } +} diff --git a/forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java b/forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java new file mode 100644 index 0000000..62ca42c --- /dev/null +++ b/forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java @@ -0,0 +1,59 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.ElytraSlotConstants; +import com.kyanite.deeperdarker.DeeperDarker; +import com.kyanite.deeperdarker.DeeperDarkerConfig; +import com.kyanite.deeperdarker.content.DDItems; +import com.kyanite.deeperdarker.network.Messages; +import com.kyanite.deeperdarker.network.SoulElytraBoostPacket; +import com.kyanite.deeperdarker.network.SoulElytraClientPacket; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.PacketDistributor; +import net.minecraftforge.network.simple.SimpleChannel; +import top.theillusivec4.curios.api.event.CurioChangeEvent; + +public class DeeperDarkerPlugin { + + public static SimpleChannel NETWORK; + private static int ID; + + public static void setup() { + MinecraftForge.EVENT_BUS.addListener(DeeperDarkerPlugin::onCurioChange); + NETWORK = + NetworkRegistry.newSimpleChannel(new ResourceLocation(ElytraSlotConstants.MOD_ID, "main"), + () -> "1", (s) -> s.equals("1"), (s) -> s.equals("1")); + NETWORK.registerMessage(ID++, SoulElytraBoostPayload.class, SoulElytraBoostPayload::toBytes, + SoulElytraBoostPayload::new, SoulElytraBoostPayload::handle); + } + + private static void onCurioChange(final CurioChangeEvent evt) { + + if (!evt.getTo().is(DDItems.SOUL_ELYTRA.get()) || evt.getFrom().is(DDItems.SOUL_ELYTRA.get())) { + return; + } + if (evt.getEntity() instanceof ServerPlayer player) { + Messages.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), + new SoulElytraClientPacket()); + } + } + + public static void tick(Level level, Entity entity) { + + if (level.isClientSide() && entity instanceof Player player) { + + if (player.getCooldowns().isOnCooldown(DDItems.SOUL_ELYTRA.get())) { + float percent = player.getCooldowns().getCooldownPercent(DDItems.SOUL_ELYTRA.get(), 0); + player.displayClientMessage( + Component.translatable("item." + DeeperDarker.MOD_ID + ".soul_elytra.cooldown", + (int) Math.ceil(percent * DeeperDarkerConfig.soulElytraCooldown / 20)), true); + } + } + } +} diff --git a/forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java b/forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java new file mode 100644 index 0000000..2eed6e3 --- /dev/null +++ b/forge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java @@ -0,0 +1,56 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.platform.Services; +import com.kyanite.deeperdarker.DeeperDarker; +import com.kyanite.deeperdarker.DeeperDarkerConfig; +import com.kyanite.deeperdarker.content.DDItems; +import io.netty.buffer.ByteBuf; +import java.util.function.Supplier; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.projectile.FireworkRocketEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import net.minecraftforge.network.NetworkEvent; + +public class SoulElytraBoostPayload { + + public SoulElytraBoostPayload() { + } + + public SoulElytraBoostPayload(ByteBuf buf) { + } + + public void toBytes(ByteBuf buf) { + } + + public void handle(Supplier context) { + context.get().enqueueWork(() -> { + ServerPlayer player = context.get().getSender(); + + if (player == null) { + return; + } + Level level = player.level(); + + if (DeeperDarkerConfig.soulElytraCooldown == -1) { + player.displayClientMessage( + Component.translatable("item." + DeeperDarker.MOD_ID + ".soul_elytra.no_cooldown"), + true); + return; + } + Item item = DDItems.SOUL_ELYTRA.get(); + + if (player.isFallFlying() && Services.ELYTRA.getEquipped(player).is(item) && + !player.getCooldowns().isOnCooldown(item)) { + FireworkRocketEntity rocket = + new FireworkRocketEntity(level, new ItemStack(Items.FIREWORK_ROCKET), player); + level.addFreshEntity(rocket); + player.getCooldowns().addCooldown(item, DeeperDarkerConfig.soulElytraCooldown); + } + }); + context.get().setPacketHandled(true); + } +} diff --git a/quilt/build.gradle b/quilt/build.gradle index 30f4adf..e3643ce 100644 --- a/quilt/build.gradle +++ b/quilt/build.gradle @@ -8,6 +8,15 @@ plugins { archivesBaseName = "${mod_id}-quilt" +repositories { + maven { + url "https://cursemaven.com" + content { + includeGroup "curse.maven" + } + } +} + dependencies { minecraft "com.mojang:minecraft:${minecraft_version}" mappings(loom.layered { @@ -21,6 +30,7 @@ dependencies { modImplementation "org.quiltmc.quilted-fabric-api:quilted-fabric-api:${quilted_fabric_api_version}" modImplementation "dev.emi:trinkets:${trinkets_version}" modCompileOnly "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${cca_version}" + modCompileOnly "curse.maven:deeperdarker-659011:5725442" modRuntimeOnly("com.terraformersmc:modmenu:${mod_menu_version}") { transitive = false diff --git a/quilt/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotQuiltClientMod.java b/quilt/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotQuiltClientMod.java index 1953043..c97eae9 100644 --- a/quilt/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotQuiltClientMod.java +++ b/quilt/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotQuiltClientMod.java @@ -19,6 +19,8 @@ import com.illusivesoulworks.elytraslot.client.ElytraSlotLayer; import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerClientModule; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerClientPlugin; +import com.illusivesoulworks.elytraslot.platform.Services; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.fabricmc.fabric.api.client.rendering.v1.LivingEntityFeatureRenderEvents; import net.fabricmc.fabric.api.client.rendering.v1.LivingEntityFeatureRendererRegistrationCallback; @@ -36,8 +38,8 @@ public void onInitializeClient(ModContainer modContainer) { (entityType, entityRenderer, registrationHelper, context) -> registrationHelper.register( new ElytraSlotLayer<>(entityRenderer, context.getModelSet()))); - if (FabricLoader.getInstance().isModLoaded("deeperdarker")) { - HudRenderCallback.EVENT.register(DeeperDarkerClientModule::registerHudCallback); + if (Services.PLATFORM.isModLoaded("deeperdarker")) { + DeeperDarkerClientPlugin.setup(); } } } diff --git a/quilt/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotQuiltMod.java b/quilt/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotQuiltMod.java index 5c19866..eb0ae46 100644 --- a/quilt/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotQuiltMod.java +++ b/quilt/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotQuiltMod.java @@ -17,6 +17,7 @@ package com.illusivesoulworks.elytraslot; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerPlugin; import com.illusivesoulworks.elytraslot.platform.Services; import dev.emi.trinkets.api.SlotReference; import dev.emi.trinkets.api.Trinket; @@ -69,5 +70,9 @@ public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity return ElytraSlotCommonMod.canEquip(entity); } }); + + if (Services.PLATFORM.isModLoaded("deeperdarker")) { + DeeperDarkerPlugin.setup(); + } } } diff --git a/quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java b/quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java new file mode 100644 index 0000000..4399fae --- /dev/null +++ b/quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java @@ -0,0 +1,36 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.ElytraSlotConstants; +import com.illusivesoulworks.elytraslot.platform.Services; +import com.kyanite.deeperdarker.client.Keybinds; +import com.kyanite.deeperdarker.content.DDItems; +import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; +import net.minecraft.client.Minecraft; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import org.quiltmc.qsl.lifecycle.api.client.event.ClientTickEvents; +import org.quiltmc.qsl.networking.api.PacketByteBufs; +import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking; + +public class DeeperDarkerClientPlugin { + + public static void setup() { + ClientTickEvents.START.register(world -> { + Minecraft client = Minecraft.getInstance(); + + if (client.player == null) { + return; + } + ItemStack itemStack = Services.ELYTRA.getEquipped(client.player); + + if (itemStack.is(DDItems.SOUL_ELYTRA) && client.player.getCooldowns() + .getCooldownPercent(DDItems.SOUL_ELYTRA, Minecraft.getInstance().getFrameTime()) == 0 && + client.player.isFallFlying() && Keybinds.BOOST.isDown()) { + ClientPlayNetworking.send( + new ResourceLocation(ElytraSlotConstants.MOD_ID, "soul_elytra_boost"), + PacketByteBufs.empty()); + } + }); + HudRenderCallback.EVENT.register(DeeperDarkerClientModule::registerHudCallback); + } +} diff --git a/quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java b/quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java new file mode 100644 index 0000000..0a2b88a --- /dev/null +++ b/quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java @@ -0,0 +1,50 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.ElytraSlotConstants; +import com.kyanite.deeperdarker.DeeperDarker; +import com.kyanite.deeperdarker.content.DDItems; +import dev.emi.trinkets.api.TrinketsApi; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.projectile.FireworkRocketEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import org.quiltmc.qsl.networking.api.ServerPlayNetworking; + +public class DeeperDarkerPlugin { + + public static void setup() { + registerPayloads(); + } + + public static void registerPayloads() { + ServerPlayNetworking.registerGlobalReceiver( + new ResourceLocation(ElytraSlotConstants.MOD_ID, "soul_elytra_boost"), + (server, player, handler, buf, responseSender) -> { + Level level = player.level(); + + if (DeeperDarker.CONFIG.server.soulElytraCooldown() == -1) { + player.displayClientMessage( + Component.translatable(DDItems.SOUL_ELYTRA.getDescriptionId() + ".boost_disabled") + .setStyle( + Style.EMPTY.withColor(ChatFormatting.RED)), true); + return; + } + + if (player.isFallFlying() && TrinketsApi.getTrinketComponent(player) + .map(inv -> inv.isEquipped(DDItems.SOUL_ELYTRA)).orElse(false) && + !player.getCooldowns().isOnCooldown(DDItems.SOUL_ELYTRA) && + DeeperDarker.CONFIG.server.soulElytraCooldown() != -1) { + FireworkRocketEntity + rocket = + new FireworkRocketEntity(level, new ItemStack(Items.FIREWORK_ROCKET), player); + level.addFreshEntity(rocket); + player.getCooldowns() + .addCooldown(DDItems.SOUL_ELYTRA, DeeperDarker.CONFIG.server.soulElytraCooldown()); + } + }); + } +} diff --git a/quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java b/quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java new file mode 100644 index 0000000..6547e1d --- /dev/null +++ b/quilt/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java @@ -0,0 +1,28 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.ElytraSlotConstants; +import io.netty.buffer.ByteBuf; +import net.fabricmc.fabric.api.networking.v1.FabricPacket; +import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; + +public class SoulElytraBoostPayload implements FabricPacket { + + public static final PacketType TYPE = + PacketType.create(new ResourceLocation(ElytraSlotConstants.MOD_ID, "soul_elytra_boost"), + SoulElytraBoostPayload::new); + + public SoulElytraBoostPayload(ByteBuf buf) { + } + + @Override + public void write(FriendlyByteBuf buf) { + + } + + @Override + public PacketType getType() { + return TYPE; + } +}