Functional essence capsule drops!

This commit is contained in:
DBotThePony 2023-03-13 18:58:06 +07:00
parent 398bff70b8
commit a49316000b
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 84 additions and 4 deletions

View File

@ -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.ExopackUpgrades.INVENTORY_UPGRADE_PROCEDURAL, "description", "They normally generate in dungeons with appropriate NBT tag attached")
add(MItems.ESSENCE_CAPSULE, "Essence Capsule") 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, "Essence Servo")
add(MItems.ESSENCE_SERVO, "desc", "Allows to 'pump' essence involving fleshy humanoids") 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") add(MItems.ESSENCE_SERVO, "desc2", "Can be used standalone, or as tool inside Essence Servo")

View File

@ -452,7 +452,7 @@ private fun items(provider: MatteryLanguageProvider) {
add(MItems.ExopackUpgrades.INVENTORY_UPGRADE_PROCEDURAL, "description", "В нормальных условиях, они появляются в сундуках") add(MItems.ExopackUpgrades.INVENTORY_UPGRADE_PROCEDURAL, "description", "В нормальных условиях, они появляются в сундуках")
add(MItems.ESSENCE_CAPSULE, "Капсула эссенции") add(MItems.ESSENCE_CAPSULE, "Капсула эссенции")
add(MItems.ESSENCE_DRIVE, "Диск эссенции") add(MItems.ESSENCE_DRIVE, "Голодиск воспоминаний андроида")
add(MItems.ESSENCE_SERVO, "Помпа эссенции") add(MItems.ESSENCE_SERVO, "Помпа эссенции")
add(MItems.ESSENCE_SERVO, "desc", "Позволяет 'перекачивать' эссенцию гуманоидов из плоти") add(MItems.ESSENCE_SERVO, "desc", "Позволяет 'перекачивать' эссенцию гуманоидов из плоти")
add(MItems.ESSENCE_SERVO, "desc2", "Может быть использовано напрямую, или как инструмент внутри хранилища эссенции") add(MItems.ESSENCE_SERVO, "desc2", "Может быть использовано напрямую, или как инструмент внутри хранилища эссенции")

View File

@ -2,12 +2,22 @@ package ru.dbotthepony.mc.otm.mixin;
import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity; 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.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 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 ru.dbotthepony.mc.otm.registry.MItems;
import java.util.Random;
@SuppressWarnings("ConstantConditions")
@Mixin(LivingEntity.class) @Mixin(LivingEntity.class)
public class MixinLivingEntity { public class MixinLivingEntity {
@Inject( @Inject(
@ -27,4 +37,53 @@ public class MixinLivingEntity {
hook.setReturnValue(false); 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);
}
}
});
}
}
} }

View File

@ -19,4 +19,25 @@ import ru.dbotthepony.mc.otm.registry.MNames
object ServerConfig : AbstractConfig("misc") { object ServerConfig : AbstractConfig("misc") {
val LABORATORY_LAMP_LIGHT_LENGTH: Int by builder.comment("In blocks").defineInRange("LABORATORY_LAMP_LIGHT_LENGTH", 6, 1, 128) 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) 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()
}
} }

View File

@ -18,8 +18,8 @@ import ru.dbotthepony.mc.otm.runIfClient
class EssenceCapsuleItem : Item(Properties().stacksTo(1).rarity(Rarity.UNCOMMON)) { class EssenceCapsuleItem : Item(Properties().stacksTo(1).rarity(Rarity.UNCOMMON)) {
override fun appendHoverText(pStack: ItemStack, pLevel: Level?, pTooltipComponents: MutableList<Component>, pIsAdvanced: TooltipFlag) { override fun appendHoverText(pStack: ItemStack, pLevel: Level?, pTooltipComponents: MutableList<Component>, pIsAdvanced: TooltipFlag) {
super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced) super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced)
pTooltipComponents.add(TranslatableComponent("otm.gui.essence_capsule").withStyle(ChatFormatting.GRAY)) pTooltipComponents.add(TranslatableComponent("otm.gui.essence_capsule").withStyle(ChatFormatting.DARK_GRAY))
pTooltipComponents.add(TranslatableComponent("otm.gui.essence_capsule2").withStyle(ChatFormatting.GRAY)) pTooltipComponents.add(TranslatableComponent("otm.gui.essence_capsule2").withStyle(ChatFormatting.DARK_GRAY))
if (runIfClient(false) { minecraft.window.isShiftDown }) { if (runIfClient(false) { minecraft.window.isShiftDown }) {
pTooltipComponents.add(TranslatableComponent("otm.gui.experience", experienceStored(pStack)).withStyle(ChatFormatting.GRAY)) pTooltipComponents.add(TranslatableComponent("otm.gui.experience", experienceStored(pStack)).withStyle(ChatFormatting.GRAY))