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 Oct 3, 2024
1 parent e18f08a commit c995cc7
Show file tree
Hide file tree
Showing 19 changed files with 419 additions and 5 deletions.
12 changes: 11 additions & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -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.+'
Expand All @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
}
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 @@ -68,5 +69,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,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);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
});
}
}
Original file line number Diff line number Diff line change
@@ -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<SoulElytraBoostPayload> 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;
}
}
1 change: 1 addition & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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,)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<NetworkEvent.Context> 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);
}
}
Loading

0 comments on commit c995cc7

Please sign in to comment.