From a49316000bc50a1b5949d7ccc8213daf59bb66e1 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 13 Mar 2023 18:58:06 +0700 Subject: [PATCH] Functional essence capsule drops! --- .../mc/otm/datagen/lang/English.kt | 2 +- .../mc/otm/datagen/lang/Russian.kt | 2 +- .../mc/otm/mixin/MixinLivingEntity.java | 59 +++++++++++++++++++ .../dbotthepony/mc/otm/config/ServerConfig.kt | 21 +++++++ .../mc/otm/item/EssenceCapsuleItem.kt | 4 +- 5 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt index e558c82c3..9391e8d34 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt @@ -447,7 +447,7 @@ private fun items(provider: MatteryLanguageProvider) { add(MItems.ExopackUpgrades.INVENTORY_UPGRADE_PROCEDURAL, "description", "They normally generate in dungeons with appropriate NBT tag attached") add(MItems.ESSENCE_CAPSULE, "Essence Capsule") - add(MItems.ESSENCE_DRIVE, "Essence Memory Drive") + add(MItems.ESSENCE_DRIVE, "Essence Memory Holotape") add(MItems.ESSENCE_SERVO, "Essence Servo") add(MItems.ESSENCE_SERVO, "desc", "Allows to 'pump' essence involving fleshy humanoids") add(MItems.ESSENCE_SERVO, "desc2", "Can be used standalone, or as tool inside Essence Servo") diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt index 08e3317bf..e385cdf2e 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt @@ -452,7 +452,7 @@ private fun items(provider: MatteryLanguageProvider) { add(MItems.ExopackUpgrades.INVENTORY_UPGRADE_PROCEDURAL, "description", "В нормальных условиях, они появляются в сундуках") add(MItems.ESSENCE_CAPSULE, "Капсула эссенции") - add(MItems.ESSENCE_DRIVE, "Диск эссенции") + add(MItems.ESSENCE_DRIVE, "Голодиск воспоминаний андроида") add(MItems.ESSENCE_SERVO, "Помпа эссенции") add(MItems.ESSENCE_SERVO, "desc", "Позволяет 'перекачивать' эссенцию гуманоидов из плоти") add(MItems.ESSENCE_SERVO, "desc2", "Может быть использовано напрямую, или как инструмент внутри хранилища эссенции") diff --git a/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinLivingEntity.java b/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinLivingEntity.java index 8f4aae057..338337d93 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinLivingEntity.java +++ b/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinLivingEntity.java @@ -2,12 +2,22 @@ package ru.dbotthepony.mc.otm.mixin; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraftforge.event.ForgeEventFactory; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import ru.dbotthepony.mc.otm.capability.MatteryCapability; +import ru.dbotthepony.mc.otm.config.ServerConfig; +import ru.dbotthepony.mc.otm.core.util.ExperienceUtilsKt; import ru.dbotthepony.mc.otm.registry.MItems; +import java.util.Random; + +@SuppressWarnings("ConstantConditions") @Mixin(LivingEntity.class) public class MixinLivingEntity { @Inject( @@ -27,4 +37,53 @@ public class MixinLivingEntity { hook.setReturnValue(false); } } + + @Shadow Player lastHurtByPlayer; + + @Inject( + method = "dropExperience()V", + at = @At("HEAD"), + cancellable = true) + public void dropExperience(CallbackInfo hook) { + if (((Object) this) instanceof Player player && ServerConfig.INSTANCE.getDROP_EXPERIENCE_CAPSULES()) { + player.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresent(it -> { + hook.cancel(); + + long totalExperience = ExperienceUtilsKt.getTotalXpRequiredForLevel(player.experienceLevel); + totalExperience += (long) (player.experienceProgress * player.getXpNeededForNextLevel()); + + double min = ServerConfig.INSTANCE.getMIN_EXPERIENCE_DROPPED(); + double max = ServerConfig.INSTANCE.getMAX_EXPERIENCE_DROPPED(); + + if (min == max) { + totalExperience *= min; + } else { + if (min > max) { + min = 0.4; + max = 0.8; + } + + totalExperience *= new Random().nextDouble(min, max); + } + + if (totalExperience >= Integer.MAX_VALUE) { + int hooked = ForgeEventFactory.getExperienceDrop(player, lastHurtByPlayer, Integer.MAX_VALUE); + + if (hooked != Integer.MAX_VALUE) { + totalExperience = hooked; + } + } else { + totalExperience = ForgeEventFactory.getExperienceDrop(player, lastHurtByPlayer, (int) totalExperience); + } + + if (totalExperience > 0L) { + if (it.isAndroid()) { + player.drop(MItems.INSTANCE.getESSENCE_DRIVE().make(totalExperience), true, false); + } else { + player.drop(MItems.INSTANCE.getESSENCE_CAPSULE().make(totalExperience), true, false); + } + } + }); + } + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/config/ServerConfig.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/config/ServerConfig.kt index c1f3e2783..686a85282 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/ServerConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/ServerConfig.kt @@ -19,4 +19,25 @@ import ru.dbotthepony.mc.otm.registry.MNames object ServerConfig : AbstractConfig("misc") { val LABORATORY_LAMP_LIGHT_LENGTH: Int by builder.comment("In blocks").defineInRange("LABORATORY_LAMP_LIGHT_LENGTH", 6, 1, 128) val INFINITE_EXOSUIT_UPGRADES: Boolean by builder.comment("Allows to apply the same upgrade over and over again.", "Obviously completely breaks balance.").define("INFINITE_EXOSUIT_UPGRADES", false) + + init { + builder.push("EXPERIENCE_CAPSULES") + } + + val DROP_EXPERIENCE_CAPSULES: Boolean by builder + .comment("Whenever to replace regular player experience drops with experience capsules") + .comment("These capsules can be collected by gravestone mods, and are not limited in experience they can contain") + .define("ENABLED", true) + + val MIN_EXPERIENCE_DROPPED: Double by builder + .comment("Minimal percent of experience dropped on death into capsules") + .defineInRange("MINIMAL_PERCENT", 0.4, 0.0, 1.0) + + val MAX_EXPERIENCE_DROPPED: Double by builder + .comment("Maximal percent of experience dropped on death into capsules") + .defineInRange("MAXIMAL_PERCENT", 0.8, 0.0, 1.0) + + init { + builder.pop() + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/EssenceCapsuleItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/EssenceCapsuleItem.kt index 922a37662..8ba7a3c00 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/EssenceCapsuleItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/EssenceCapsuleItem.kt @@ -18,8 +18,8 @@ import ru.dbotthepony.mc.otm.runIfClient class EssenceCapsuleItem : Item(Properties().stacksTo(1).rarity(Rarity.UNCOMMON)) { override fun appendHoverText(pStack: ItemStack, pLevel: Level?, pTooltipComponents: MutableList, pIsAdvanced: TooltipFlag) { super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced) - pTooltipComponents.add(TranslatableComponent("otm.gui.essence_capsule").withStyle(ChatFormatting.GRAY)) - pTooltipComponents.add(TranslatableComponent("otm.gui.essence_capsule2").withStyle(ChatFormatting.GRAY)) + pTooltipComponents.add(TranslatableComponent("otm.gui.essence_capsule").withStyle(ChatFormatting.DARK_GRAY)) + pTooltipComponents.add(TranslatableComponent("otm.gui.essence_capsule2").withStyle(ChatFormatting.DARK_GRAY)) if (runIfClient(false) { minecraft.window.isShiftDown }) { pTooltipComponents.add(TranslatableComponent("otm.gui.experience", experienceStored(pStack)).withStyle(ChatFormatting.GRAY))