Skip to content

Commit

Permalink
Fix Deeper Darker compatibility, closes #132
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIllusiveC4 committed Sep 30, 2024
1 parent e4689a7 commit 462205c
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 65 deletions.

This file was deleted.

2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,5 +73,9 @@ public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity
return ElytraSlotCommonMod.canEquip(entity);
}
});

if (Services.PLATFORM.isModLoaded("deeperdarker")) {
DeeperDarkerPlugin.setup();
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
});
}
}
Original file line number Diff line number Diff line change
@@ -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<SoulElytraBoostPayload> TYPE =
new CustomPacketPayload.Type<>(
ResourceLocation.fromNamespaceAndPath(ElytraSlotConstants.MOD_ID, "soul_elytra_boost"));
public static final SoulElytraBoostPayload INSTANCE = new SoulElytraBoostPayload();
public static final StreamCodec<RegistryFriendlyByteBuf, SoulElytraBoostPayload> CODEC =
StreamCodec.unit(INSTANCE);

@Override
@Nonnull
public Type<? extends CustomPacketPayload> type() {
return TYPE;
}
}
2 changes: 2 additions & 0 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
Loading

0 comments on commit 462205c

Please sign in to comment.