From 462205c8737a84b5b1b5ab6e4997a35680058de2 Mon Sep 17 00:00:00 2001 From: C4 <29991504+TheIllusiveC4@users.noreply.github.com> Date: Mon, 30 Sep 2024 00:14:37 -0700 Subject: [PATCH] Fix Deeper Darker compatibility, closes #132 --- .../DeeperDarkerClientModule.java | 59 --------------- fabric/build.gradle | 2 +- .../elytraslot/ElytraSlotFabricClientMod.java | 9 +-- .../elytraslot/ElytraSlotFabricMod.java | 5 ++ .../DeeperDarkerClientPlugin.java | 73 +++++++++++++++++++ .../deeperdarker/DeeperDarkerPlugin.java | 48 ++++++++++++ .../deeperdarker/SoulElytraBoostPayload.java | 24 ++++++ neoforge/build.gradle | 2 + .../ElytraSlotNeoForgeClientMod.java | 6 ++ .../elytraslot/ElytraSlotNeoForgeMod.java | 6 ++ .../elytraslot/common/CurioElytra.java | 6 ++ .../DeeperDarkerClientPlugin.java | 21 ++++++ .../deeperdarker/DeeperDarkerPlugin.java | 54 ++++++++++++++ .../deeperdarker/SoulElytraBoostPayload.java | 62 ++++++++++++++++ 14 files changed, 312 insertions(+), 65 deletions(-) delete mode 100644 common/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientModule.java 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 neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java create mode 100644 neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java create mode 100644 neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java diff --git a/common/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientModule.java b/common/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientModule.java deleted file mode 100644 index dd6e0d3..0000000 --- a/common/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientModule.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; - -import com.illusivesoulworks.elytraslot.platform.Services; -import net.minecraft.ChatFormatting; -import net.minecraft.client.DeltaTracker; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.core.BlockPos; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; - -public class DeeperDarkerClientModule { - - private static final String MOD_ID = "deeperdarker"; - - public static void registerHudCallback(GuiGraphics drawContext, DeltaTracker deltaTracker) { - ResourceLocation texture = - ResourceLocation.fromNamespaceAndPath(MOD_ID, "textures/gui/soul_elytra_overlay_large.png"); - Minecraft client = Minecraft.getInstance(); - - if (client.player == null) { - return; - } - ItemStack itemStack = Services.ELYTRA.getEquipped(client.player); - Item item = - BuiltInRegistries.ITEM.get(ResourceLocation.fromNamespaceAndPath(MOD_ID, "soul_elytra")); - - if (item != Items.AIR && itemStack.is(item)) { - float f = client.player.getCooldowns() - .getCooldownPercent(item, Minecraft.getInstance().getFrameTimeNs()); - drawContext.blit(texture, 5, client.getWindow().getGuiScaledHeight() - 37, 0, 0, 0, 12, - Mth.floor(32 * f), 32, 32); - drawContext.blit(texture, 5, client.getWindow().getGuiScaledHeight() - 37 + Mth.floor(32 * f), - 0, 12, Mth.floor(32 * f), 12, Mth.ceil(32 * (1.0f - f)), 32, 32); - - if (f == 0.0f && client.player.isFallFlying()) { - - for (BlockPos blockPos : BlockPos.betweenClosed(client.player.getOnPos(), - client.player.getOnPos().below(5))) { - - if (client.player.level().getBlockState(blockPos).isAir()) { - continue; - } - drawContext.drawString(client.font, - Component.translatable(item.getDescriptionId() + ".boost", - client.options.keyShift.getTranslatedKeyMessage()) - .setStyle(Style.EMPTY.withColor(ChatFormatting.YELLOW)), 20, - client.getWindow().getGuiScaledHeight() - 37, 0); - } - } - } - } -} diff --git a/fabric/build.gradle b/fabric/build.gradle index 642e672..18912a9 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -22,7 +22,7 @@ dependencies { } implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' - include(implementation(annotationProcessor("com.github.bawnorton.mixinsquared:mixinsquared-fabric:0.1.2-beta.6"))) + modCompileOnly "curse.maven:deeperdarker-659011:5727329" } loom { diff --git a/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricClientMod.java b/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricClientMod.java index 7f67517..f0b01c5 100644 --- a/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricClientMod.java +++ b/fabric/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotFabricClientMod.java @@ -18,12 +18,11 @@ package com.illusivesoulworks.elytraslot; 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; import net.fabricmc.fabric.api.client.rendering.v1.LivingEntityFeatureRendererRegistrationCallback; -import net.fabricmc.loader.api.FabricLoader; public class ElytraSlotFabricClientMod implements ClientModInitializer { @@ -35,8 +34,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 ff13308..5c16147 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; @@ -72,5 +73,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..987b898 --- /dev/null +++ b/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java @@ -0,0 +1,73 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.platform.Services; +import com.kyanite.deeperdarker.DeeperDarker; +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.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +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, + (float) (Minecraft.getInstance().getFrameTimeNs() / 1000000000.0)) == 0 && + client.player.isFallFlying() && Keybinds.BOOST.isDown()) { + ClientPlayNetworking.send(SoulElytraBoostPayload.INSTANCE); + } + }); + HudRenderCallback.EVENT.register((drawContext, tickDelta) -> { + ResourceLocation texture = DeeperDarker.rl("textures/gui/soul_elytra_overlay_large.png"); + Minecraft client = Minecraft.getInstance(); + + if (client.player == null || DeeperDarker.CONFIG.server.soulElytraCooldown() == -1) { + return; + } + ItemStack itemStack = Services.ELYTRA.getEquipped(client.player); + + if (itemStack.is(DDItems.SOUL_ELYTRA)) { + float f = client.player.getCooldowns().getCooldownPercent(DDItems.SOUL_ELYTRA, + (float) (Minecraft.getInstance().getFrameTimeNs() / 1000000000.0)); + drawContext.blit(texture, 5, client.getWindow().getGuiScaledHeight() - 37, 0, 0, 0, 12, + Mth.floor(32 * f), 32, 32); + drawContext.blit(texture, 5, + client.getWindow().getGuiScaledHeight() - 37 + Mth.floor(32 * f), 0, 12, + Mth.floor(32 * f), 12, Mth.ceil(32 * (1.0f - f)), 32, 32); + + if (f == 0.0f && client.player.isFallFlying()) { + + for (BlockPos blockPos : BlockPos.betweenClosed(client.player.getOnPos(), + client.player.getOnPos().below(5))) { + + if (client.player.level().getBlockState(blockPos).isAir()) { + continue; + } + drawContext.drawString(client.font, + Component.translatable(DDItems.SOUL_ELYTRA.getDescriptionId() + ".boost", + Keybinds.BOOST.getTranslatedKeyMessage()) + .setStyle(Style.EMPTY.withColor(ChatFormatting.YELLOW)), 20, + client.getWindow().getGuiScaledHeight() - 37, 0); + } + } + } + }); + } +} 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..d942809 --- /dev/null +++ b/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java @@ -0,0 +1,48 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.platform.Services; +import com.kyanite.deeperdarker.DeeperDarker; +import com.kyanite.deeperdarker.content.DDItems; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +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.server.level.ServerPlayer; +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() { + PayloadTypeRegistry.playC2S() + .register(SoulElytraBoostPayload.TYPE, SoulElytraBoostPayload.CODEC); + ServerPlayNetworking.registerGlobalReceiver(SoulElytraBoostPayload.TYPE, (payload, ctx) -> { + ServerPlayer player = ctx.player(); + 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() && Services.ELYTRA.getEquipped(player).is(DDItems.SOUL_ELYTRA) && + !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..dc8441d --- /dev/null +++ b/fabric/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java @@ -0,0 +1,24 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.ElytraSlotConstants; +import javax.annotation.Nonnull; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; + +public record SoulElytraBoostPayload() implements CustomPacketPayload { + + public static final CustomPacketPayload.Type TYPE = + new CustomPacketPayload.Type<>( + ResourceLocation.fromNamespaceAndPath(ElytraSlotConstants.MOD_ID, "soul_elytra_boost")); + public static final SoulElytraBoostPayload INSTANCE = new SoulElytraBoostPayload(); + public static final StreamCodec CODEC = + StreamCodec.unit(INSTANCE); + + @Override + @Nonnull + public Type type() { + return TYPE; + } +} diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 1b1e946..ff2b0eb 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -50,6 +50,8 @@ dependencies { runtimeOnly "com.illusivesoulworks.caelus:caelus-neoforge:${caelus_version}" compileOnly "com.illusivesoulworks.caelus:caelus-neoforge:${caelus_version}:api" + + compileOnly "curse.maven:deeperdarker-659011:5698218" } task publishCurseForge(type: TaskPublishCurseForge) { diff --git a/neoforge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotNeoForgeClientMod.java b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotNeoForgeClientMod.java index b956526..b010b76 100644 --- a/neoforge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotNeoForgeClientMod.java +++ b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotNeoForgeClientMod.java @@ -19,6 +19,8 @@ import com.illusivesoulworks.caelus.api.RenderCapeEvent; import com.illusivesoulworks.elytraslot.client.ElytraSlotLayer; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerClientPlugin; +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; @@ -35,6 +37,10 @@ public class ElytraSlotNeoForgeClientMod { public static void setup(IEventBus eventBus) { eventBus.addListener(ElytraSlotNeoForgeClientMod::addLayers); NeoForge.EVENT_BUS.addListener(ElytraSlotNeoForgeClientMod::renderCape); + + if (Services.PLATFORM.isModLoaded("deeperdarker")) { + DeeperDarkerClientPlugin.setup(); + } } private static void addLayers(final EntityRenderersEvent.AddLayers evt) { diff --git a/neoforge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotNeoForgeMod.java b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotNeoForgeMod.java index 55c1982..19abf49 100644 --- a/neoforge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotNeoForgeMod.java +++ b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/ElytraSlotNeoForgeMod.java @@ -19,6 +19,8 @@ import com.illusivesoulworks.caelus.api.CaelusApi; import com.illusivesoulworks.elytraslot.common.CurioElytra; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerPlugin; +import com.illusivesoulworks.elytraslot.platform.Services; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.ai.attributes.AttributeInstance; import net.minecraft.world.entity.player.Player; @@ -40,6 +42,10 @@ public ElytraSlotNeoForgeMod(IEventBus eventBus) { eventBus.addListener(FMLClientSetupEvent.class, (evt) -> this.clientSetup(evt, eventBus)); eventBus.addListener(this::setup); eventBus.addListener(this::registerCapabilities); + + if (Services.PLATFORM.isModLoaded("deeperdarker")) { + DeeperDarkerPlugin.setup(eventBus); + } } private void setup(final FMLCommonSetupEvent evt) { diff --git a/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/CurioElytra.java b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/CurioElytra.java index 9c8ec59..bec7ed5 100644 --- a/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/CurioElytra.java +++ b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/CurioElytra.java @@ -19,6 +19,8 @@ import com.illusivesoulworks.elytraslot.ElytraSlotCommonMod; import com.illusivesoulworks.elytraslot.ElytraSlotConstants; +import com.illusivesoulworks.elytraslot.common.integration.deeperdarker.DeeperDarkerPlugin; +import com.illusivesoulworks.elytraslot.platform.Services; import javax.annotation.Nonnull; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; @@ -53,6 +55,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/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java new file mode 100644 index 0000000..b93f778 --- /dev/null +++ b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java @@ -0,0 +1,21 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.kyanite.deeperdarker.client.Keybinds; +import net.neoforged.bus.api.EventPriority; +import net.neoforged.neoforge.client.event.InputEvent; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.network.PacketDistributor; + +public class DeeperDarkerClientPlugin { + + public static void setup() { + NeoForge.EVENT_BUS.addListener(EventPriority.LOW, DeeperDarkerClientPlugin::keyInput); + } + + private static void keyInput(final InputEvent.Key evt) { + + if (evt.getKey() == Keybinds.BOOST.getKey().getValue()) { + PacketDistributor.sendToServer(new SoulElytraBoostPayload(true)); + } + } +} diff --git a/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java new file mode 100644 index 0000000..b76796f --- /dev/null +++ b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java @@ -0,0 +1,54 @@ +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.SoulElytraClientPacket; +import net.minecraft.network.chat.Component; +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.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.network.PacketDistributor; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import top.theillusivec4.curios.api.event.CurioChangeEvent; + +public class DeeperDarkerPlugin { + + public static void setup(IEventBus eventBus) { + eventBus.addListener(DeeperDarkerPlugin::registerPayloads); + NeoForge.EVENT_BUS.addListener(DeeperDarkerPlugin::onCurioChange); + } + + private static void registerPayloads(final RegisterPayloadHandlersEvent evt) { + evt.registrar(ElytraSlotConstants.MOD_ID) + .playToServer(SoulElytraBoostPayload.TYPE, SoulElytraBoostPayload.STREAM_CODEC, + 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) { + PacketDistributor.sendToPlayer(player, new SoulElytraClientPacket(true)); + } + } + + 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/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java new file mode 100644 index 0000000..9dcf473 --- /dev/null +++ b/neoforge/src/main/java/com/illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java @@ -0,0 +1,62 @@ +package com.illusivesoulworks.elytraslot.common.integration.deeperdarker; + +import com.illusivesoulworks.elytraslot.ElytraSlotConstants; +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 javax.annotation.Nonnull; +import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; +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 net.neoforged.neoforge.network.handling.IPayloadContext; + +public record SoulElytraBoostPayload(boolean bool) implements CustomPacketPayload { + + public static final StreamCodec STREAM_CODEC = + StreamCodec.composite( + ByteBufCodecs.BOOL, SoulElytraBoostPayload::bool, + SoulElytraBoostPayload::new + ); + + public static final ResourceLocation ID = + ResourceLocation.fromNamespaceAndPath(ElytraSlotConstants.MOD_ID, "soul_elytra_boost"); + public static final Type TYPE = new Type<>(ID); + + @Nonnull + @Override + public Type type() { + return TYPE; + } + + public void handle(IPayloadContext context) { + context.enqueueWork(() -> { + Player player = context.player(); + Level level = player.level(); + + if (DeeperDarkerConfig.soulElytraCooldown == -1) { + player.displayClientMessage( + Component.translatable("item." + DeeperDarker.MOD_ID + ".soul_elytra.no_cooldown"), + true); + return; + } + + if (player.isFallFlying() && Services.ELYTRA.getEquipped(player).is(DDItems.SOUL_ELYTRA) && + !player.getCooldowns().isOnCooldown(DDItems.SOUL_ELYTRA.get())) { + FireworkRocketEntity rocket = + new FireworkRocketEntity(level, new ItemStack(Items.FIREWORK_ROCKET), player); + level.addFreshEntity(rocket); + player.getCooldowns() + .addCooldown(DDItems.SOUL_ELYTRA.get(), DeeperDarkerConfig.soulElytraCooldown); + } + }); + } +}