-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Deeper Darker compatibility, closes #132
- Loading branch information
1 parent
e18f08a
commit c995cc7
Showing
19 changed files
with
419 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...llusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
}); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...llusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerClientPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../com/illusivesoulworks/elytraslot/common/integration/deeperdarker/DeeperDarkerPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
.../illusivesoulworks/elytraslot/common/integration/deeperdarker/SoulElytraBoostPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.