diff --git a/src/main/java/com/sammy/malum/MalumMod.java b/src/main/java/com/sammy/malum/MalumMod.java index d5bcd0e83..4017607be 100644 --- a/src/main/java/com/sammy/malum/MalumMod.java +++ b/src/main/java/com/sammy/malum/MalumMod.java @@ -5,6 +5,7 @@ import com.sammy.malum.compability.irons_spellbooks.*; import com.sammy.malum.compability.tetra.*; import com.sammy.malum.config.*; +import com.sammy.malum.registry.common.*; import com.sammy.malum.registry.common.item.tabs.*; import net.minecraft.core.Holder; import net.minecraft.core.HolderOwner; @@ -23,6 +24,7 @@ import java.util.Map; import static com.sammy.malum.registry.client.ParticleRegistry.*; +import static com.sammy.malum.registry.common.AttachmentTypeRegistry.ATTACHMENT_TYPES; import static com.sammy.malum.registry.common.AttributeRegistry.*; import static com.sammy.malum.registry.common.ContainerRegistry.*; import static com.sammy.malum.registry.common.MobEffectRegistry.*; @@ -66,6 +68,7 @@ public MalumMod() { FEATURE_TYPES.register(modBus); STRUCTURES.register(modBus); CREATIVE_MODE_TABS.register(modBus); + ATTACHMENT_TYPES.register(modBus); TetraCompat.init(); FarmersDelightCompat.init(); diff --git a/src/main/java/com/sammy/malum/client/renderer/block/MoteOfManaRenderer.java b/src/main/java/com/sammy/malum/client/renderer/block/MoteOfManaRenderer.java index 8140933c4..2b4ce1a19 100644 --- a/src/main/java/com/sammy/malum/client/renderer/block/MoteOfManaRenderer.java +++ b/src/main/java/com/sammy/malum/client/renderer/block/MoteOfManaRenderer.java @@ -4,7 +4,6 @@ import com.sammy.malum.*; import com.sammy.malum.client.*; import com.sammy.malum.common.block.curiosities.mana_mote.*; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.systems.spirit.*; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.blockentity.*; @@ -24,7 +23,7 @@ public MoteOfManaRenderer(BlockEntityRendererProvider.Context context) { @Override public void render(MoteOfManaBlockEntity blockEntityIn, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) { poseStack.pushPose(); - MalumSpiritType spiritType = SpiritHarvestHandler.getSpiritType(blockEntityIn.getBlockState().getValue(SpiritMoteBlock.SPIRIT_TYPE)); + MalumSpiritType spiritType = MalumSpiritType.getSpiritType(blockEntityIn.getBlockState().getValue(SpiritMoteBlock.SPIRIT_TYPE)); var builder = SpiritBasedWorldVFXBuilder.create(spiritType) .setRenderType(LodestoneRenderTypes.ADDITIVE_TEXTURE.applyAndCache(MOTE_OF_MANA)); diff --git a/src/main/java/com/sammy/malum/client/renderer/item/SpiritJarItemRenderer.java b/src/main/java/com/sammy/malum/client/renderer/item/SpiritJarItemRenderer.java index 492de8fb4..ebb2febae 100644 --- a/src/main/java/com/sammy/malum/client/renderer/item/SpiritJarItemRenderer.java +++ b/src/main/java/com/sammy/malum/client/renderer/item/SpiritJarItemRenderer.java @@ -3,7 +3,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.sammy.malum.common.block.storage.jar.SpiritJarBlockEntity; import com.sammy.malum.common.item.spirit.SpiritJarItem; -import com.sammy.malum.core.handlers.*; +import com.sammy.malum.core.systems.spirit.*; import com.sammy.malum.registry.common.block.BlockRegistry; import com.sammy.malum.registry.common.item.DataComponentRegistry; import net.minecraft.client.model.geom.EntityModelSet; @@ -30,7 +30,7 @@ public void renderByItem(ItemStack pStack, ItemDisplayContext pTransformType, Po if (pStack.getItem() instanceof SpiritJarItem) { if (pStack.has(DataComponentRegistry.SPIRIT_JAR_CONTENTS)) { SpiritJarItem.Contents contents = pStack.get(DataComponentRegistry.SPIRIT_JAR_CONTENTS); - jar.type = SpiritHarvestHandler.getSpiritType(contents.spirit()); + jar.type = MalumSpiritType.getSpiritType(contents.spirit()); jar.count = contents.count(); this.blockEntityRenderDispatcher.renderItem(jar, pPoseStack, pBuffer, pPackedLight, pPackedOverlay); diff --git a/src/main/java/com/sammy/malum/common/block/curiosities/mana_mote/SpiritMoteBlockClientExtension.java b/src/main/java/com/sammy/malum/common/block/curiosities/mana_mote/SpiritMoteBlockClientExtension.java index 3e31e8d6a..ad7b2b41f 100644 --- a/src/main/java/com/sammy/malum/common/block/curiosities/mana_mote/SpiritMoteBlockClientExtension.java +++ b/src/main/java/com/sammy/malum/common/block/curiosities/mana_mote/SpiritMoteBlockClientExtension.java @@ -1,6 +1,6 @@ package com.sammy.malum.common.block.curiosities.mana_mote; -import com.sammy.malum.core.handlers.*; +import com.sammy.malum.core.systems.spirit.*; import com.sammy.malum.visual_effects.*; import net.minecraft.client.particle.*; import net.minecraft.core.*; @@ -19,7 +19,7 @@ public boolean addHitEffects(BlockState state, Level level, HitResult target, Pa @Override public boolean addDestroyEffects(BlockState state, Level level, BlockPos pos, ParticleEngine manager) { if (state.getBlock() instanceof SpiritMoteBlock) { - SpiritMoteParticleEffects.destroy(level, pos, state, SpiritHarvestHandler.getSpiritType(state.getValue(SpiritMoteBlock.SPIRIT_TYPE))); + SpiritMoteParticleEffects.destroy(level, pos, state, MalumSpiritType.getSpiritType(state.getValue(SpiritMoteBlock.SPIRIT_TYPE))); } return true; } diff --git a/src/main/java/com/sammy/malum/common/block/curiosities/totem/TotemPoleBlockEntity.java b/src/main/java/com/sammy/malum/common/block/curiosities/totem/TotemPoleBlockEntity.java index c8d02a9d8..d8df00e2d 100644 --- a/src/main/java/com/sammy/malum/common/block/curiosities/totem/TotemPoleBlockEntity.java +++ b/src/main/java/com/sammy/malum/common/block/curiosities/totem/TotemPoleBlockEntity.java @@ -1,7 +1,6 @@ package com.sammy.malum.common.block.curiosities.totem; import com.sammy.malum.common.item.curiosities.tools.*; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.systems.spirit.*; import com.sammy.malum.registry.common.*; import com.sammy.malum.registry.common.block.*; @@ -107,7 +106,7 @@ protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) @Override protected void loadAdditional(CompoundTag tag, HolderLookup.Provider pRegistries) { if (tag.contains("spirit")) { - spirit = SpiritHarvestHandler.getSpiritType(tag.getString("spirit")); + spirit = MalumSpiritType.getSpiritType(tag.getString("spirit")); } totemPoleState = tag.contains("state") ? TotemPoleState.values()[tag.getInt("state")] : TotemPoleState.INACTIVE; chargeProgress = tag.getInt("chargeProgress"); diff --git a/src/main/java/com/sammy/malum/common/block/storage/jar/SpiritJarBlockEntity.java b/src/main/java/com/sammy/malum/common/block/storage/jar/SpiritJarBlockEntity.java index ff1474814..3479667bb 100644 --- a/src/main/java/com/sammy/malum/common/block/storage/jar/SpiritJarBlockEntity.java +++ b/src/main/java/com/sammy/malum/common/block/storage/jar/SpiritJarBlockEntity.java @@ -4,7 +4,6 @@ import com.sammy.malum.common.item.spirit.SpiritJarItem; import com.sammy.malum.common.item.spirit.SpiritShardItem; import com.sammy.malum.common.packets.CodecUtil; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.systems.spirit.MalumSpiritType; import com.sammy.malum.registry.common.block.BlockEntityRegistry; import com.sammy.malum.registry.common.item.DataComponentRegistry; @@ -232,7 +231,7 @@ protected void saveAdditional(CompoundTag compound, HolderLookup.Provider pRegis @Override public void loadAdditional(@NotNull CompoundTag compound, HolderLookup.Provider pRegistries) { if (compound.contains("spirit")) { - type = SpiritHarvestHandler.getSpiritType(compound.getString("spirit")); + type = MalumSpiritType.getSpiritType(compound.getString("spirit")); } else { type = null; } diff --git a/src/main/java/com/sammy/malum/common/block/the_device/TheDevice.java b/src/main/java/com/sammy/malum/common/block/the_device/TheDevice.java index d2108b018..2cd84b3d8 100644 --- a/src/main/java/com/sammy/malum/common/block/the_device/TheDevice.java +++ b/src/main/java/com/sammy/malum/common/block/the_device/TheDevice.java @@ -1,7 +1,6 @@ package com.sammy.malum.common.block.the_device; -import com.sammy.malum.common.capability.MalumPlayerDataCapability; -import com.sammy.malum.registry.common.SoundRegistry; +import com.sammy.malum.registry.common.*; import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; @@ -29,7 +28,7 @@ protected ItemInteractionResult useItemOn(ItemStack pStack, BlockState pState, L pPlayer.swing(pHand, true); playSound(pLevel, pPos); if (pPlayer.isCreative()) { - MalumPlayerDataCapability.getCapabilityOptional(pPlayer).ifPresent(it -> it.hasBeenRejected = false); + pPlayer.getData(AttachmentTypeRegistry.PROGRESSION_DATA).hasBeenRejected = false; } return ItemInteractionResult.SUCCESS; } diff --git a/src/main/java/com/sammy/malum/common/capabilities/CachedSpiritDropsData.java b/src/main/java/com/sammy/malum/common/capabilities/CachedSpiritDropsData.java new file mode 100644 index 000000000..3a7feb474 --- /dev/null +++ b/src/main/java/com/sammy/malum/common/capabilities/CachedSpiritDropsData.java @@ -0,0 +1,36 @@ +package com.sammy.malum.common.capabilities; + +import com.mojang.serialization.*; +import com.mojang.serialization.codecs.*; +import com.sammy.malum.common.capabilities.soul_data.*; +import net.minecraft.core.*; +import net.minecraft.world.item.*; + +import java.util.*; + +public class CachedSpiritDropsData { + + public static final Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( + Codec.list(ItemStack.CODEC).optionalFieldOf("spiritDrops", Collections.emptyList()).forGetter(c -> c.spiritDrops), + UUIDUtil.CODEC.optionalFieldOf("spiritOwner", null).forGetter(c -> c.spiritOwner) + ).apply(obj, CachedSpiritDropsData::new)); + + private List spiritDrops = new ArrayList<>(); + private UUID spiritOwner; + + public CachedSpiritDropsData() { + + } + public CachedSpiritDropsData(List spiritDrops, UUID spiritOwner) { + this.spiritDrops = spiritDrops; + this.spiritOwner = spiritOwner; + } + + public List getSpiritDrops() { + return spiritDrops; + } + + public UUID getSpiritOwner() { + return spiritOwner; + } +} diff --git a/src/main/java/com/sammy/malum/common/capabilities/CurioData.java b/src/main/java/com/sammy/malum/common/capabilities/CurioData.java new file mode 100644 index 000000000..433eccae1 --- /dev/null +++ b/src/main/java/com/sammy/malum/common/capabilities/CurioData.java @@ -0,0 +1,23 @@ +package com.sammy.malum.common.capabilities; + +import com.mojang.serialization.*; +import com.mojang.serialization.codecs.*; + +public class CurioData { + + public static Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( + Codec.INT.fieldOf("watcherNecklaceCooldown").forGetter(c -> c.watcherNecklaceCooldown), + Codec.INT.fieldOf("hiddenBladeNecklaceCooldown").forGetter(c -> c.hiddenBladeNecklaceCooldown) + ).apply(obj, CurioData::new)); + + public int watcherNecklaceCooldown; + public int hiddenBladeNecklaceCooldown; + + public CurioData() { + } + + public CurioData(int watcherNecklaceCooldown, int hiddenBladeNecklaceCooldown) { + this.watcherNecklaceCooldown = hiddenBladeNecklaceCooldown; + this.hiddenBladeNecklaceCooldown = hiddenBladeNecklaceCooldown; + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/capabilities/MalignantInfluenceData.java b/src/main/java/com/sammy/malum/common/capabilities/MalignantInfluenceData.java new file mode 100644 index 000000000..981b5f82e --- /dev/null +++ b/src/main/java/com/sammy/malum/common/capabilities/MalignantInfluenceData.java @@ -0,0 +1,19 @@ +package com.sammy.malum.common.capabilities; + +import com.mojang.serialization.*; +import com.mojang.serialization.codecs.*; +import net.minecraft.core.*; +import net.minecraft.world.entity.ai.attributes.*; + +import java.util.*; + +public class MalignantInfluenceData { + + public static Codec CODEC = Codec.unit(MalignantInfluenceData::new); + + public final HashMap, Double> cachedAttributeValues = new HashMap<>(); + public boolean skipConversionLogic; + + public MalignantInfluenceData() { + } +} diff --git a/src/main/java/com/sammy/malum/common/capabilities/ProgressionData.java b/src/main/java/com/sammy/malum/common/capabilities/ProgressionData.java new file mode 100644 index 000000000..d2c9a2285 --- /dev/null +++ b/src/main/java/com/sammy/malum/common/capabilities/ProgressionData.java @@ -0,0 +1,23 @@ +package com.sammy.malum.common.capabilities; + +import com.mojang.serialization.*; +import com.mojang.serialization.codecs.*; + +public class ProgressionData { + + public static Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( + Codec.BOOL.fieldOf("obtainedEncyclopedia").forGetter(c -> c.obtainedEncyclopedia), + Codec.BOOL.fieldOf("hasBeenRejected").forGetter(c -> c.hasBeenRejected) + ).apply(obj, ProgressionData::new)); + + public boolean obtainedEncyclopedia; + public boolean hasBeenRejected; + + public ProgressionData() { + } + + public ProgressionData(boolean obtainedEncyclopedia, boolean hasBeenRejected) { + this.obtainedEncyclopedia = obtainedEncyclopedia; + this.hasBeenRejected = hasBeenRejected; + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/capabilities/SoulWardData.java b/src/main/java/com/sammy/malum/common/capabilities/SoulWardData.java new file mode 100644 index 000000000..824430083 --- /dev/null +++ b/src/main/java/com/sammy/malum/common/capabilities/SoulWardData.java @@ -0,0 +1,110 @@ +package com.sammy.malum.common.capabilities; + +import com.mojang.serialization.*; +import com.mojang.serialization.codecs.*; +import com.sammy.malum.config.*; +import com.sammy.malum.registry.common.*; +import net.minecraft.network.*; +import net.minecraft.network.codec.*; +import net.minecraft.util.*; +import net.minecraft.world.entity.*; +import net.minecraft.world.entity.ai.attributes.*; +import net.minecraft.world.entity.player.*; +import team.lodestar.lodestone.helpers.*; + +import java.util.*; + +public class SoulWardData { + + public static Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( + Codec.DOUBLE.fieldOf("soulWard").forGetter(sw -> sw.soulWard), + Codec.DOUBLE.fieldOf("soulWardProgress").forGetter(sw -> sw.soulWardCooldown) + ).apply(obj, SoulWardData::new)); + + public static StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.DOUBLE, p -> p.soulWard, + ByteBufCodecs.DOUBLE, p -> p.soulWardCooldown, + SoulWardData::new); + + private double soulWard; + private double soulWardCooldown; + + private boolean isDirty; + + public SoulWardData() { + } + + public SoulWardData(double soulWard, double soulWardCooldown) { + this.soulWard = soulWard; + this.soulWardCooldown = soulWardCooldown; + } + + public void recoverSoulWard(LivingEntity entity, double amount) { + var multiplier = Optional.ofNullable(entity.getAttribute(AttributeRegistry.SOUL_WARD_RECOVERY_MULTIPLIER)).map(AttributeInstance::getValue).orElse(1.0); + addSoulWard(amount * multiplier); + if (!(entity instanceof Player player) || !player.isCreative()) { + var capacity = entity.getAttribute(AttributeRegistry.SOUL_WARD_CAPACITY); + if (capacity != null) { + var sound = soulWard >= capacity.getValue() ? SoundRegistry.SOUL_WARD_CHARGE : SoundRegistry.SOUL_WARD_GROW; + double pitchOffset = (soulWard / capacity.getValue()) * 0.5f + (Mth.ceil(soulWard) % 3) * 0.25f; + SoundHelper.playSound(entity, sound.get(), 0.25f, (float) (1f + pitchOffset)); + } + } + addCooldown(entity, 1); + } + + public void addSoulWard(double added) { + setSoulWard(soulWard + added); + } + + public void reduceSoulWard(double removed) { + setSoulWard(soulWard - removed); + } + + public void setSoulWard(double soulWard) { + this.soulWard = Math.max(soulWard, 0); + isDirty = true; + } + + public double getSoulWard() { + return soulWard; + } + + public void addCooldown(LivingEntity living, double multiplier) { + final double newCooldown = getSoulWardCooldown(living) * multiplier; + if (soulWardCooldown < newCooldown) { + soulWardCooldown = newCooldown; + setDirty(true); + } + } + + public void tickCooldown() { + if (soulWardCooldown > 0) { + soulWardCooldown--; + } + } + + public double getCooldown() { + return soulWardCooldown; + } + + public boolean isDirty() { + return isDirty; + } + + public void setDirty(boolean dirty) { + isDirty = dirty; + } + + public boolean isDepleted() { + return soulWard <= 0; + } + + public static float getSoulWardCooldown(LivingEntity living) { + return getSoulWardCooldown(living.getAttributeValue(AttributeRegistry.SOUL_WARD_RECOVERY_RATE)); + } + + public static float getSoulWardCooldown(double recoverySpeed) { + return Mth.floor(CommonConfig.SOUL_WARD_RATE.getConfigValue() / recoverySpeed); + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/capabilities/StaffAbilityData.java b/src/main/java/com/sammy/malum/common/capabilities/StaffAbilityData.java new file mode 100644 index 000000000..4766f25ca --- /dev/null +++ b/src/main/java/com/sammy/malum/common/capabilities/StaffAbilityData.java @@ -0,0 +1,23 @@ +package com.sammy.malum.common.capabilities; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +public class StaffAbilityData { + + public static Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( + Codec.INT.fieldOf("reserveChargeCount").forGetter(c -> c.reserveChargeCount), + Codec.FLOAT.fieldOf("reserveChargeProgress").forGetter(c -> c.reserveChargeProgress) + ).apply(obj, StaffAbilityData::new)); + + public int reserveChargeCount; + public float reserveChargeProgress; + + public StaffAbilityData() { + } + + public StaffAbilityData(int reserveChargeCount, float reserveChargeProgress) { + this.reserveChargeCount = reserveChargeCount; + this.reserveChargeProgress = reserveChargeProgress; + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/capabilities/VoidInfluenceData.java b/src/main/java/com/sammy/malum/common/capabilities/VoidInfluenceData.java new file mode 100644 index 000000000..95863a305 --- /dev/null +++ b/src/main/java/com/sammy/malum/common/capabilities/VoidInfluenceData.java @@ -0,0 +1,116 @@ +package com.sammy.malum.common.capabilities; + +import com.mojang.serialization.*; +import com.mojang.serialization.codecs.*; +import com.sammy.malum.common.block.curiosities.weeping_well.*; +import net.minecraft.world.entity.*; +import net.minecraft.world.entity.player.*; +import team.lodestar.lodestone.helpers.block.*; + +import java.util.*; + +public class VoidInfluenceData { + + public static final float MAX_AFFLICTION = 100f; + public static final float MAX_REJECTION = 60; + + public static final Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( + Codec.BOOL.fieldOf("isNearWeepingWell").forGetter(h -> h.isNearWeepingWell), + Codec.INT.fieldOf("expectedAffliction").forGetter(h -> h.expectedAffliction), + Codec.INT.fieldOf("afflictionFalloffCooldown").forGetter(h -> h.afflictionFalloffCooldown), + Codec.FLOAT.fieldOf("voidAffliction").forGetter(h -> h.voidAffliction), + Codec.BOOL.fieldOf("isInRejectedState").forGetter(h -> h.isInRejectedState), + Codec.INT.fieldOf("voidRejection").forGetter(h -> h.voidRejection), + Codec.INT.fieldOf("primordialGoopTimer").forGetter(h -> h.primordialGoopTimer) + ).apply(obj, VoidInfluenceData::new)); + + public boolean isNearWeepingWell; + + public int expectedAffliction; + public int afflictionFalloffCooldown; + public float voidAffliction; + + public boolean isInRejectedState; + public int voidRejection; + + public int primordialGoopTimer; + + public VoidInfluenceData() { + } + + public VoidInfluenceData(boolean isNearWeepingWell, int expectedAffliction, int afflictionFalloffCooldown, float voidAffliction, boolean isInRejectedState, int voidRejection, int primordialGoopTimer) { + this.isNearWeepingWell = isNearWeepingWell; + this.expectedAffliction = expectedAffliction; + this.afflictionFalloffCooldown = afflictionFalloffCooldown; + this.voidAffliction = voidAffliction; + this.isInRejectedState = isInRejectedState; + this.voidRejection = voidRejection; + this.primordialGoopTimer = primordialGoopTimer; + } + + public void update(LivingEntity living) { + var level = living.level(); + if (living instanceof Player) { + if (level.getGameTime() % 20L == 0) { + isNearWeepingWell = checkForWeepingWell(living).isPresent(); + } + } + if (voidAffliction > 0) { + voidAffliction--; + if (voidAffliction == 0) { + expectedAffliction = 0; + } + } + if (voidAffliction < expectedAffliction) { + voidAffliction = Math.min(MAX_AFFLICTION, voidAffliction + 2f); + } + if (voidAffliction > expectedAffliction) { + voidAffliction = Math.max(voidAffliction - (expectedAffliction == 0 ? 1.5f : 0.75f), expectedAffliction); + } + + if (isInGoop()) { + primordialGoopTimer--; + if (voidRejection < MAX_REJECTION) { + voidRejection++; + if (voidRejection == MAX_REJECTION) { + isInRejectedState = true; + } + } + } + if (isInRejectedState) { + if (voidRejection > 0) { + voidRejection--; + if (voidRejection == 0) { + isInRejectedState = false; + } + } + } + if (!isInGoop() && !isInRejectedState) { + voidRejection = 0; + } + } + + public void setAfflictionLevel(int expectedAffliction) { + if (this.expectedAffliction > expectedAffliction) { + return; + } + this.expectedAffliction = expectedAffliction; + afflictionFalloffCooldown = 100; + } + + public void setGoopStatus() { + primordialGoopTimer = 2; + } + + public boolean isInGoop() { + return primordialGoopTimer > 0; + } + + public boolean wasJustRejected() { + return isInRejectedState && voidRejection == MAX_REJECTION; + } + + public static Optional checkForWeepingWell(LivingEntity livingEntity) { + return BlockEntityHelper.getBlockEntitiesStream(VoidConduitBlockEntity.class, livingEntity.level(), livingEntity.blockPosition(), 8).findFirst(); + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/capabilities/soul_data/LivingSoulData.java b/src/main/java/com/sammy/malum/common/capabilities/soul_data/LivingSoulData.java new file mode 100644 index 000000000..214a67488 --- /dev/null +++ b/src/main/java/com/sammy/malum/common/capabilities/soul_data/LivingSoulData.java @@ -0,0 +1,84 @@ +package com.sammy.malum.common.capabilities.soul_data; + +import com.mojang.serialization.*; +import com.mojang.serialization.codecs.*; +import net.minecraft.world.entity.*; +import net.minecraft.world.entity.ai.goal.*; +import net.neoforged.neoforge.event.entity.living.*; + +import java.util.*; + +public class LivingSoulData { + + public static final Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( + Codec.FLOAT.fieldOf("exposedSoulDuration").forGetter(sd -> sd.exposedSoulDuration), + Codec.BOOL.fieldOf("soulless").forGetter(sd -> sd.soulless), + Codec.BOOL.fieldOf("spawnerSpawned").forGetter(sd -> sd.spawnerSpawned) + ).apply(obj, LivingSoulData::new)); + + private float exposedSoulDuration; + private boolean soulless; + private boolean spawnerSpawned; + + public LivingSoulData() { + } + + private LivingSoulData(float exposedSoulDuration, boolean soulless, boolean spawnerSpawned) { + this.exposedSoulDuration = exposedSoulDuration; + this.soulless = soulless; + this.spawnerSpawned = spawnerSpawned; + } + + public void setExposed() { + exposedSoulDuration = 200; + } + + public void updateSoullessBehavior(Mob mob) { + if (isSoulless()) { + ArrayList> goalsToRemove = new ArrayList<>(List.of( + LookAtPlayerGoal.class, MeleeAttackGoal.class, SwellGoal.class, PanicGoal.class, RandomLookAroundGoal.class, AvoidEntityGoal.class + )); + mob.goalSelector.getAvailableGoals().removeIf(g -> goalsToRemove.stream().anyMatch(c -> c.isInstance(g))); + } + } + + public void updateSoullessTargeting(LivingChangeTargetEvent event) { + if (isSoulless()) { + event.setNewAboutToBeSetTarget(null); + } + } + + public void tickDuration() { + if (exposedSoulDuration > 0) { + exposedSoulDuration--; + } + } + + public boolean shouldDropSpirits() { + return !soulless && exposedSoulDuration > 0; + } + + public void setExposedSoulDuration(float exposedSoulDuration) { + this.exposedSoulDuration = exposedSoulDuration; + } + + public float getExposedSoulDuration() { + return exposedSoulDuration; + } + + public void setSoulless(boolean soulless) { + this.soulless = soulless; + } + + public boolean isSoulless() { + return soulless; + } + + public void setSpawnerSpawned(boolean spawnerSpawned) { + this.spawnerSpawned = spawnerSpawned; + } + + public boolean isSpawnerSpawned() { + return spawnerSpawned; + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/capabilities/soul_data/ProjectileSoulData.java b/src/main/java/com/sammy/malum/common/capabilities/soul_data/ProjectileSoulData.java new file mode 100644 index 000000000..d01844150 --- /dev/null +++ b/src/main/java/com/sammy/malum/common/capabilities/soul_data/ProjectileSoulData.java @@ -0,0 +1,28 @@ +package com.sammy.malum.common.capabilities.soul_data; + +import com.mojang.serialization.*; +import com.mojang.serialization.codecs.*; + +public class ProjectileSoulData { + + public static final Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( + Codec.BOOL.fieldOf("dealsSoulDamage").forGetter(sd -> sd.dealsSoulDamage) + ).apply(obj, ProjectileSoulData::new)); + + private boolean dealsSoulDamage; + + public ProjectileSoulData() { + + } + private ProjectileSoulData(boolean dealsSoulDamage) { + this.dealsSoulDamage = dealsSoulDamage; + } + + public boolean dealsSoulDamage() { + return dealsSoulDamage; + } + + public void setSoulDamage(boolean dealsSoulDamage) { + this.dealsSoulDamage = dealsSoulDamage; + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/capability/MalumItemDataCapability.java b/src/main/java/com/sammy/malum/common/capability/MalumItemDataCapability.java deleted file mode 100644 index 8f147602a..000000000 --- a/src/main/java/com/sammy/malum/common/capability/MalumItemDataCapability.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.sammy.malum.common.capability; - -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import com.sammy.malum.MalumMod; -import com.sammy.malum.common.packets.CodecUtil; -import net.minecraft.core.UUIDUtil; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.capabilities.EntityCapability; -import net.neoforged.neoforge.capabilities.ICapabilityProvider; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -public class MalumItemDataCapability { - - public static final EntityCapability CAPABILITY = EntityCapability.createVoid( - MalumMod.malumPath("item_data"), - MalumItemDataCapability.class - ); - - public static final Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( - Codec.list(ItemStack.CODEC).fieldOf("soulsToDrop").forGetter(c -> c.soulsToDrop), - UUIDUtil.CODEC.fieldOf("attackerForSouls").forGetter(c -> c.attackerForSouls) - ).apply(obj, MalumItemDataCapability::new)); - - public List soulsToDrop; - public UUID attackerForSouls; - - public MalumItemDataCapability(List soulsToDrop, UUID attackerForSouls) { - this.soulsToDrop = soulsToDrop; - this.attackerForSouls = attackerForSouls; - } - - public static void registerItemDataCapability(RegisterCapabilitiesEvent event) { - event.registerEntity(CAPABILITY, EntityType.ITEM, (item, ctx) -> { - CompoundTag tag = item.getPersistentData(); - return CodecUtil.decodeNBT(MalumItemDataCapability.CODEC, tag); - }); - } - - public static Optional getCapabilityOptional(ItemEntity entity) { - return Optional.ofNullable(entity.getCapability(CAPABILITY)); - } - - public void pullFromNBT(CompoundTag tag) { - MalumItemDataCapability capability = CodecUtil.decodeNBT(CODEC, tag); - this.soulsToDrop = capability.soulsToDrop; - this.attackerForSouls = capability.attackerForSouls; - } -} diff --git a/src/main/java/com/sammy/malum/common/capability/MalumLivingEntityDataCapability.java b/src/main/java/com/sammy/malum/common/capability/MalumLivingEntityDataCapability.java deleted file mode 100644 index fd4f58fef..000000000 --- a/src/main/java/com/sammy/malum/common/capability/MalumLivingEntityDataCapability.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.sammy.malum.common.capability; - -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import com.sammy.malum.MalumMod; -import com.sammy.malum.common.packets.CodecUtil; -import com.sammy.malum.common.packets.SyncLivingCapabilityDataPacket; -import com.sammy.malum.core.handlers.*; -import net.minecraft.core.UUIDUtil; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.capabilities.EntityCapability; -import net.neoforged.neoforge.capabilities.ICapabilityProvider; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; -import net.neoforged.neoforge.event.entity.player.PlayerEvent; -import net.neoforged.neoforge.network.PacketDistributor; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -public class MalumLivingEntityDataCapability { - - public static final EntityCapability CAPABILITY = EntityCapability.createVoid( - MalumMod.malumPath("living_data"), - MalumLivingEntityDataCapability.class - ); - - public static final Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( - SoulDataHandler.CODEC.fieldOf("soulData").forGetter(c -> c.soulData), - TouchOfDarknessHandler.CODEC.fieldOf("darknessAfflictionData").forGetter(c -> c.touchOfDarknessHandler), - Codec.INT.fieldOf("watcherNecklaceCooldown").forGetter(c -> c.watcherNecklaceCooldown), - Codec.INT.fieldOf("hiddenBladeNecklaceCooldown").forGetter(c -> c.hiddenBladeNecklaceCooldown), - Codec.list(ItemStack.CODEC).optionalFieldOf("soulsToApplyToDrops", null).forGetter(c -> c.soulsToApplyToDrops), - UUIDUtil.CODEC.optionalFieldOf("killerUUID", null).forGetter(c -> c.killerUUID) - ).apply(obj, MalumLivingEntityDataCapability::new)); - - public SoulDataHandler soulData = new SoulDataHandler(); - public MalignantConversionHandler malignantConversionHandler = new MalignantConversionHandler(); - public TouchOfDarknessHandler touchOfDarknessHandler = new TouchOfDarknessHandler(); - - public int watcherNecklaceCooldown; - public int hiddenBladeNecklaceCooldown; - - public List soulsToApplyToDrops; - public UUID killerUUID; - - public MalumLivingEntityDataCapability() {} - - public MalumLivingEntityDataCapability(SoulDataHandler soulData, TouchOfDarknessHandler touchOfDarknessHandler, int watcherNecklaceCooldown, int hiddenBladeNecklaceCooldown, List soulsToApplyToDrops, UUID killerUUID) { - this.soulData = soulData; - this.touchOfDarknessHandler = touchOfDarknessHandler; - this.watcherNecklaceCooldown = watcherNecklaceCooldown; - this.hiddenBladeNecklaceCooldown = hiddenBladeNecklaceCooldown; - this.soulsToApplyToDrops = soulsToApplyToDrops; - this.killerUUID = killerUUID; - } - - public static void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerEntity(CAPABILITY, EntityType.PLAYER, GET_CAPABILITY); - } - - public static ICapabilityProvider GET_CAPABILITY = (livingEntity, ctx) -> { - CompoundTag tag = livingEntity.getPersistentData(); - return CodecUtil.decodeNBT(CODEC, tag); - }; - - public static void syncEntityCapability(PlayerEvent.StartTracking event) { - if (event.getTarget() instanceof LivingEntity livingEntity) { - if (livingEntity.level() instanceof ServerLevel) { - MalumLivingEntityDataCapability.sync(livingEntity); - } - } - } - - public static void sync(LivingEntity entity) { - getCapabilityOptional(entity).ifPresent(c -> PacketDistributor.sendToPlayersTrackingEntity(entity, new SyncLivingCapabilityDataPacket(entity.getId(), (CompoundTag)CodecUtil.encodeNBT(CODEC, c)))); - } - - public static Optional getCapabilityOptional(LivingEntity entity) { - return Optional.ofNullable(entity.getCapability(CAPABILITY)); - } - - public static MalumLivingEntityDataCapability getCapability(LivingEntity entity) { - return getCapabilityOptional(entity).orElse(new MalumLivingEntityDataCapability()); - } - - public void pullFromNBT(CompoundTag tag) { - MalumLivingEntityDataCapability decoded = CodecUtil.decodeNBT(CODEC, tag); - this.soulData = decoded.soulData; - this.touchOfDarknessHandler = decoded.touchOfDarknessHandler; - this.watcherNecklaceCooldown = decoded.watcherNecklaceCooldown; - this.soulsToApplyToDrops = decoded.soulsToApplyToDrops; - this.killerUUID = decoded.killerUUID; - } -} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/capability/MalumPlayerDataCapability.java b/src/main/java/com/sammy/malum/common/capability/MalumPlayerDataCapability.java deleted file mode 100644 index 7194e37ab..000000000 --- a/src/main/java/com/sammy/malum/common/capability/MalumPlayerDataCapability.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.sammy.malum.common.capability; - -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import com.sammy.malum.MalumMod; -import com.sammy.malum.common.packets.CodecUtil; -import com.sammy.malum.common.packets.SyncMalumPlayerCapabilityDataPacket; -import com.sammy.malum.core.handlers.*; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.player.Player; -import net.neoforged.neoforge.capabilities.EntityCapability; -import net.neoforged.neoforge.capabilities.ICapabilityProvider; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; -import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent; -import net.neoforged.neoforge.event.entity.player.PlayerEvent; -import net.neoforged.neoforge.network.PacketDistributor; - -import java.util.Optional; -import java.util.function.Consumer; - -public class MalumPlayerDataCapability { - - public static final EntityCapability CAPABILITY = EntityCapability.createVoid( - MalumMod.malumPath("player_data"), - MalumPlayerDataCapability.class - ); - - public static final Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( - SoulWardHandler.CODEC.fieldOf("soulWardData").forGetter(c -> c.soulWardHandler), - ReserveStaffChargeHandler.CODEC.fieldOf("staffChargeData").forGetter(c -> c.reserveStaffChargeHandler), - Codec.BOOL.fieldOf("obtainedEncyclopedia").forGetter(c -> c.obtainedEncyclopedia), - Codec.BOOL.fieldOf("hasBeenRejected").forGetter(c -> c.hasBeenRejected) - ).apply(obj, MalumPlayerDataCapability::new)); - - public SoulWardHandler soulWardHandler = new SoulWardHandler(); - public ReserveStaffChargeHandler reserveStaffChargeHandler = new ReserveStaffChargeHandler(); - - public boolean obtainedEncyclopedia; - public boolean hasBeenRejected; - - public MalumPlayerDataCapability() {} - - public MalumPlayerDataCapability(SoulWardHandler soulWardHandler, ReserveStaffChargeHandler reserveStaffChargeHandler, boolean obtainedEncyclopedia, boolean hasBeenRejected) { - this.soulWardHandler = soulWardHandler; - this.reserveStaffChargeHandler = reserveStaffChargeHandler; - this.obtainedEncyclopedia = obtainedEncyclopedia; - this.hasBeenRejected = hasBeenRejected; - } - - public static void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerEntity(CAPABILITY, EntityType.PLAYER, GET_CAPABILITY); - } - - public static ICapabilityProvider GET_CAPABILITY = (player, ctx) -> { - CompoundTag tag = player.getPersistentData(); - return CodecUtil.decodeNBT(CODEC, tag); - }; - - public static void playerJoin(EntityJoinLevelEvent event) { - if (event.getEntity() instanceof Player player) { - if (player instanceof ServerPlayer serverPlayer) { - syncSelf(serverPlayer); - } - } - } - - public static void syncPlayerCapability(PlayerEvent.StartTracking event) { - if (event.getTarget() instanceof Player player) { - if (player.level() instanceof ServerLevel) { - syncTracking(player); - } - } - } - - public static void playerClone(PlayerEvent.Clone event) { - MalumPlayerDataCapability originalCapability = MalumPlayerDataCapability.getCapability(event.getOriginal()); - MalumPlayerDataCapability capability = MalumPlayerDataCapability.getCapability(event.getEntity()); - capability.hasBeenRejected = originalCapability.hasBeenRejected; - capability.obtainedEncyclopedia = originalCapability.obtainedEncyclopedia; - capability.reserveStaffChargeHandler = originalCapability.reserveStaffChargeHandler; - capability.soulWardHandler = originalCapability.soulWardHandler; - } - - public static void syncSelf(ServerPlayer player) { - sync(player, c -> PacketDistributor.sendToPlayer(player, - new SyncMalumPlayerCapabilityDataPacket(player.getUUID(), (CompoundTag)CodecUtil.encodeNBT(CODEC, c))) - ); - } - - public static void syncTrackingAndSelf(Player player) { - sync(player, c -> PacketDistributor.sendToPlayersTrackingEntityAndSelf(player, - new SyncMalumPlayerCapabilityDataPacket(player.getUUID(), (CompoundTag)CodecUtil.encodeNBT(CODEC, c))) - ); - } - - public static void syncTracking(Player player) { - sync(player, c -> PacketDistributor.sendToPlayersTrackingEntity(player, - new SyncMalumPlayerCapabilityDataPacket(player.getUUID(), (CompoundTag)CodecUtil.encodeNBT(CODEC, c))) - ); - } - - public static void sync(Player player, Consumer syncFunc) { - getCapabilityOptional(player).ifPresent(syncFunc); - } - - public static Optional getCapabilityOptional(Player player) { - return Optional.ofNullable(player.getCapability(CAPABILITY)); - } - - public static MalumPlayerDataCapability getCapability(Player player) { - return getCapabilityOptional(player).orElse(new MalumPlayerDataCapability()); - } - - public void pullFromNBT(CompoundTag tag) { - MalumPlayerDataCapability decoded = CodecUtil.decodeNBT(CODEC, tag); - this.soulWardHandler = decoded.soulWardHandler; - this.reserveStaffChargeHandler = decoded.reserveStaffChargeHandler; - this.obtainedEncyclopedia = decoded.obtainedEncyclopedia; - this.hasBeenRejected = decoded.hasBeenRejected; - } -} diff --git a/src/main/java/com/sammy/malum/common/effect/RejectedEffect.java b/src/main/java/com/sammy/malum/common/effect/RejectedEffect.java index 5dd61302a..60be74178 100644 --- a/src/main/java/com/sammy/malum/common/effect/RejectedEffect.java +++ b/src/main/java/com/sammy/malum/common/effect/RejectedEffect.java @@ -1,9 +1,7 @@ package com.sammy.malum.common.effect; import com.sammy.malum.*; -import com.sammy.malum.common.capability.MalumLivingEntityDataCapability; -import com.sammy.malum.core.handlers.TouchOfDarknessHandler; -import com.sammy.malum.registry.common.DamageTypeRegistry; +import com.sammy.malum.registry.common.*; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectCategory; import net.minecraft.world.entity.LivingEntity; @@ -20,8 +18,7 @@ public RejectedEffect() { @Override public boolean applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) { - TouchOfDarknessHandler handler = MalumLivingEntityDataCapability.getCapability(pLivingEntity).touchOfDarknessHandler; - handler.afflict(40); + pLivingEntity.getData(AttachmentTypeRegistry.VOID_INFLUENCE).setAfflictionLevel(40); if (pLivingEntity.level().getGameTime() % 60L == 0) { if (pLivingEntity instanceof Player player && player.isCreative()) { return false; diff --git a/src/main/java/com/sammy/malum/common/effect/SilencedEffect.java b/src/main/java/com/sammy/malum/common/effect/SilencedEffect.java index e28ec0c45..ee9936275 100644 --- a/src/main/java/com/sammy/malum/common/effect/SilencedEffect.java +++ b/src/main/java/com/sammy/malum/common/effect/SilencedEffect.java @@ -1,9 +1,7 @@ package com.sammy.malum.common.effect; import com.sammy.malum.*; -import com.sammy.malum.common.capability.*; import com.sammy.malum.compability.irons_spellbooks.*; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.registry.common.*; import net.minecraft.world.effect.*; import net.minecraft.world.entity.*; @@ -27,8 +25,7 @@ public SilencedEffect() { @Override public boolean applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) { - TouchOfDarknessHandler handler = MalumLivingEntityDataCapability.getCapability(pLivingEntity).touchOfDarknessHandler; - handler.afflict((int) (20 + pAmplifier * 2.5)); + pLivingEntity.getData(AttachmentTypeRegistry.VOID_INFLUENCE).setAfflictionLevel(20 + (pAmplifier+1) * 3); return true; } } \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/entity/activator/SpiritCollectionActivatorEntity.java b/src/main/java/com/sammy/malum/common/entity/activator/SpiritCollectionActivatorEntity.java index 8b4728ce4..d6709af62 100644 --- a/src/main/java/com/sammy/malum/common/entity/activator/SpiritCollectionActivatorEntity.java +++ b/src/main/java/com/sammy/malum/common/entity/activator/SpiritCollectionActivatorEntity.java @@ -36,7 +36,7 @@ public SoundSource getSoundSource() { @Override public void collect() { - SpiritHarvestHandler.triggerSpiritCollection(owner); + SoulHarvestHandler.triggerSpiritCollection(owner); SoundHelper.playSound(this, SoundRegistry.SPIRIT_PICKUP.get(), 0.3f, Mth.nextFloat(random, 1.2f, 1.5f)); } diff --git a/src/main/java/com/sammy/malum/common/entity/spirit/SpiritItemEntity.java b/src/main/java/com/sammy/malum/common/entity/spirit/SpiritItemEntity.java index a0202b49c..c9c7601fe 100644 --- a/src/main/java/com/sammy/malum/common/entity/spirit/SpiritItemEntity.java +++ b/src/main/java/com/sammy/malum/common/entity/spirit/SpiritItemEntity.java @@ -45,7 +45,7 @@ public SoundSource getSoundSource() { public void collect() { ItemStack stack = getItem(); if (stack.getItem() instanceof SpiritShardItem) { - SpiritHarvestHandler.pickupSpirit(owner, stack); + SoulHarvestHandler.pickupSpirit(owner, stack); } else { ItemHelper.giveItemToEntity(owner, stack); } diff --git a/src/main/java/com/sammy/malum/common/item/IMalumEventResponderItem.java b/src/main/java/com/sammy/malum/common/item/IMalumEventResponderItem.java index 398afa207..3926cbf6f 100644 --- a/src/main/java/com/sammy/malum/common/item/IMalumEventResponderItem.java +++ b/src/main/java/com/sammy/malum/common/item/IMalumEventResponderItem.java @@ -2,7 +2,6 @@ import com.sammy.malum.core.systems.events.*; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import team.lodestar.lodestone.handlers.*; @@ -11,9 +10,9 @@ default void spiritCollectionEvent(CollectSpiritEvent event, LivingEntity collec } - default void modifySoulWardPropertiesEvent(ModifySoulWardPropertiesEvent event, Player wardedEntity, ItemStack stack) { + default void modifySoulWardPropertiesEvent(ModifySoulWardPropertiesEvent event, LivingEntity wardedEntity, ItemStack stack) { } - default void soulWardDamageEvent(SoulWardDamageEvent event, Player wardedEntity, ItemStack stack) { + default void soulWardDamageEvent(SoulWardDamageEvent event, LivingEntity wardedEntity, ItemStack stack) { } } \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/alchemical/CurioManaweavingRing.java b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/alchemical/CurioManaweavingRing.java index b2b93b32d..0cfd2b2c9 100644 --- a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/alchemical/CurioManaweavingRing.java +++ b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/alchemical/CurioManaweavingRing.java @@ -1,10 +1,10 @@ package com.sammy.malum.common.item.curiosities.curios.sets.alchemical; -import com.sammy.malum.common.capability.*; import com.sammy.malum.common.item.*; import com.sammy.malum.common.item.curiosities.curios.*; import com.sammy.malum.compability.irons_spellbooks.*; import com.sammy.malum.core.systems.events.*; +import com.sammy.malum.registry.common.*; import net.minecraft.network.chat.*; import net.minecraft.server.level.*; import net.minecraft.world.entity.*; @@ -27,8 +27,8 @@ public void addExtraTooltipLines(Consumer consumer) { @Override public void spiritCollectionEvent(CollectSpiritEvent event, LivingEntity collector, double arcaneResonance) { if (collector instanceof ServerPlayer player) { - var handler = MalumPlayerDataCapability.getCapability(player).soulWardHandler; - handler.recoverSoulWard(player, arcaneResonance); + var data = player.getData(AttachmentTypeRegistry.SOUL_WARD); + data.recoverSoulWard(player, arcaneResonance); IronsSpellsCompat.generateMana(player, 10 * arcaneResonance); } } diff --git a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/misc/CurioHarmonyNecklace.java b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/misc/CurioHarmonyNecklace.java index 58693074f..4be993683 100644 --- a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/misc/CurioHarmonyNecklace.java +++ b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/misc/CurioHarmonyNecklace.java @@ -1,7 +1,7 @@ package com.sammy.malum.common.item.curiosities.curios.sets.misc; import com.sammy.malum.common.item.curiosities.curios.*; -import com.sammy.malum.core.handlers.*; +import com.sammy.malum.core.systems.spirit.*; import com.sammy.malum.registry.common.*; import com.sammy.malum.registry.common.item.*; import net.minecraft.network.chat.*; @@ -26,7 +26,7 @@ public static void preventDetection(LivingVisibilityEvent event) { if (event.getLookingEntity() instanceof LivingEntity watcher) { LivingEntity target = event.getEntity(); if (CurioHelper.hasCurioEquipped(target, ItemRegistry.NECKLACE_OF_BLISSFUL_HARMONY.get())) { - float visibilityModifier = SpiritHarvestHandler.getSpiritData(watcher).map(data -> 0.5f / (1 + data.dataEntries.stream().map(s -> s.equals(SpiritTypeRegistry.WICKED_SPIRIT) ? 1 : 0).count())).orElse(0.5f); + float visibilityModifier = EntitySpiritDropData.getSpiritData(watcher).map(data -> 0.5f / (1 + data.dataEntries.stream().map(s -> s.equals(SpiritTypeRegistry.WICKED_SPIRIT) ? 1 : 0).count())).orElse(0.5f); if (target.hasEffect(MobEffects.INVISIBILITY)) { visibilityModifier *= 0.5f; } diff --git a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/soulward/CurioMagebaneBelt.java b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/soulward/CurioMagebaneBelt.java index 50bf11770..4b5634a45 100644 --- a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/soulward/CurioMagebaneBelt.java +++ b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/soulward/CurioMagebaneBelt.java @@ -8,9 +8,9 @@ import com.sammy.malum.registry.common.AttributeRegistry; import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.*; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import team.lodestar.lodestone.registry.common.tag.LodestoneDamageTypeTags; import top.theillusivec4.curios.api.SlotContext; @@ -30,14 +30,14 @@ public void addExtraTooltipLines(Consumer consumer) { } @Override - public void modifySoulWardPropertiesEvent(ModifySoulWardPropertiesEvent event, Player wardedEntity, ItemStack stack) { + public void modifySoulWardPropertiesEvent(ModifySoulWardPropertiesEvent event, LivingEntity wardedEntity, ItemStack stack) { if (event.getSource().is(LodestoneDamageTypeTags.IS_MAGIC)) { event.setNewIntegrity(event.getOriginalIntegrity()*1.5f); } } @Override - public void soulWardDamageEvent(SoulWardDamageEvent event, Player wardedEntity, ItemStack stack) { + public void soulWardDamageEvent(SoulWardDamageEvent event, LivingEntity wardedEntity, ItemStack stack) { var handler = event.getSoulWardHandler(); if (handler.isDepleted()) { diff --git a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioHiddenBladeNecklace.java b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioHiddenBladeNecklace.java index 99d5c2aca..f0317d6c4 100644 --- a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioHiddenBladeNecklace.java +++ b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioHiddenBladeNecklace.java @@ -1,36 +1,24 @@ package com.sammy.malum.common.item.curiosities.curios.sets.weeping; -import com.mojang.blaze3d.systems.*; -import com.sammy.malum.*; -import com.sammy.malum.common.capability.*; import com.sammy.malum.common.entity.hidden_blade.*; import com.sammy.malum.common.item.*; -import com.sammy.malum.common.item.curiosities.curios.MalumCurioItem; +import com.sammy.malum.common.item.curiosities.curios.*; import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.helpers.*; import com.sammy.malum.registry.common.*; import com.sammy.malum.registry.common.item.*; -import net.minecraft.client.*; -import net.minecraft.client.gui.*; -import net.minecraft.client.player.*; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.*; +import net.minecraft.network.chat.*; import net.minecraft.util.*; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.effect.*; +import net.minecraft.world.entity.*; import net.minecraft.world.entity.ai.attributes.*; -import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.client.event.*; +import net.minecraft.world.item.*; import net.neoforged.neoforge.event.entity.living.*; import net.neoforged.neoforge.event.tick.*; -import org.lwjgl.opengl.*; import team.lodestar.lodestone.helpers.*; -import team.lodestar.lodestone.registry.client.*; import team.lodestar.lodestone.registry.common.*; -import team.lodestar.lodestone.systems.rendering.*; -import team.lodestar.lodestone.systems.rendering.shader.*; -import java.util.function.Consumer; +import java.util.function.*; public class CurioHiddenBladeNecklace extends MalumCurioItem implements IMalumEventResponderItem, IVoidItem { @@ -54,14 +42,12 @@ public void incomingDamageEvent(LivingDamageEvent.Pre event, LivingEntity attack if (attacked.level().isClientSide()) { return; } - MalumLivingEntityDataCapability.getCapabilityOptional(attacked).ifPresent(c -> { - if (c.hiddenBladeNecklaceCooldown == 0) { - float damage = event.getOriginalDamage(); - int amplifier = Math.min(1 + Mth.floor(damage / 6), 10); - attacked.addEffect(new MobEffectInstance(MobEffectRegistry.WICKED_INTENT, 80, amplifier)); - SoundHelper.playSound(attacked, SoundRegistry.HIDDEN_BLADE_PRIMED.get(), 1f, RandomHelper.randomBetween(attacked.level().getRandom(), 1.4f, 1.6f)); - } - }); + if (attacked.getData(AttachmentTypeRegistry.CURIO_DATA).hiddenBladeNecklaceCooldown == 0) { + float damage = event.getOriginalDamage(); + int amplifier = Math.min(1 + Mth.floor(damage / 6), 10); + attacked.addEffect(new MobEffectInstance(MobEffectRegistry.WICKED_INTENT, 80, amplifier)); + SoundHelper.playSound(attacked, SoundRegistry.HIDDEN_BLADE_PRIMED.get(), 1f, RandomHelper.randomBetween(attacked.level().getRandom(), 1.4f, 1.6f)); + } } @Override @@ -75,155 +61,66 @@ public void outgoingDamageEvent(LivingDamageEvent.Pre event, LivingEntity attack return; } if (CurioHelper.hasCurioEquipped(attacker, ItemRegistry.NECKLACE_OF_THE_HIDDEN_BLADE.get())) { - MalumLivingEntityDataCapability.getCapabilityOptional(attacker).ifPresent(c -> { - var random = level.getRandom(); - if (c.hiddenBladeNecklaceCooldown != 0) { - if (c.hiddenBladeNecklaceCooldown <= COOLDOWN_DURATION) { - SoundHelper.playSound(attacker, SoundRegistry.HIDDEN_BLADE_DISRUPTED.get(), 1f, RandomHelper.randomBetween(random, 0.7f, 0.8f)); - } - c.hiddenBladeNecklaceCooldown = (int) (COOLDOWN_DURATION * 1.5); - MalumLivingEntityDataCapability.sync(attacker); - return; - } - var effect = attacker.getEffect(MobEffectRegistry.WICKED_INTENT); - if (effect == null) { - return; - } - var scytheWeapon = SoulDataHandler.getScytheWeapon(source, attacker); - final boolean isRanged = source.getDirectEntity() != null; - var damageDealer = isRanged ? source.getDirectEntity() : attacker; - var direction = isRanged ? damageDealer.getDeltaMovement().normalize() : attacker.getLookAngle(); - var damageCenter = damageDealer.position().add(direction); - var attributes = attacker.getAttributes(); - float multiplier = (float) Mth.clamp(attributes.getValue(Attributes.ATTACK_SPEED), 0, 2) * ((effect.amplifier*2) + 1); - int duration = 25; - - float physicalDamage = (float) (attributes.getValue(Attributes.ATTACK_DAMAGE) / duration) * multiplier; - float magicDamage = (float) (attributes.getValue(LodestoneAttributes.MAGIC_DAMAGE) / duration) * multiplier; - - var entity = new HiddenBladeDelayedImpactEntity(level, damageCenter.x, damageCenter.y - 3f + attacker.getBbHeight() / 2f, damageCenter.z); - entity.setData(attacker, physicalDamage, magicDamage, duration); - entity.setItem(scytheWeapon); - level.addFreshEntity(entity); - c.hiddenBladeNecklaceCooldown = 200; - if (!effect.isInfiniteDuration()) { - attacker.removeEffect(effect.getEffect()); - } - for (int i = 0; i < 3; i++) { - SoundHelper.playSound(attacker, SoundRegistry.HIDDEN_BLADE_UNLEASHED.get(), 3f, RandomHelper.randomBetween(random, 0.75f, 1.25f)); - } - var particle = ParticleHelper.createSlashingEffect(ParticleEffectTypeRegistry.HIDDEN_BLADE_COUNTER_FLURRY); - if (scytheWeapon.getItem() instanceof ISpiritAffiliatedItem spiritAffiliatedItem) { - particle.setSpiritType(spiritAffiliatedItem); + var data = target.getData(AttachmentTypeRegistry.CURIO_DATA); + var random = level.getRandom(); + if (data.hiddenBladeNecklaceCooldown != 0) { + if (data.hiddenBladeNecklaceCooldown <= COOLDOWN_DURATION) { + SoundHelper.playSound(attacker, SoundRegistry.HIDDEN_BLADE_DISRUPTED.get(), 1f, RandomHelper.randomBetween(random, 0.7f, 0.8f)); } - particle.setRandomSlashAngle(random) - .mirrorRandomly(random) - .spawnForwardSlashingParticle(attacker, direction); - MalumLivingEntityDataCapability.sync(attacker); - }); + data.hiddenBladeNecklaceCooldown = (int) (COOLDOWN_DURATION * 1.5); +// MalumLivingEntityDataCapability.sync(attacker); + return; + } + var effect = attacker.getEffect(MobEffectRegistry.WICKED_INTENT); + if (effect == null) { + return; + } + var scytheWeapon = SoulDataHandler.getScytheWeapon(source, attacker); + final boolean isRanged = source.getDirectEntity() != null; + var damageDealer = isRanged ? source.getDirectEntity() : attacker; + var direction = isRanged ? damageDealer.getDeltaMovement().normalize() : attacker.getLookAngle(); + var damageCenter = damageDealer.position().add(direction); + var attributes = attacker.getAttributes(); + float multiplier = (float) Mth.clamp(attributes.getValue(Attributes.ATTACK_SPEED), 0, 2) * ((effect.amplifier * 2) + 1); + int duration = 25; + + float physicalDamage = (float) (attributes.getValue(Attributes.ATTACK_DAMAGE) / duration) * multiplier; + float magicDamage = (float) (attributes.getValue(LodestoneAttributes.MAGIC_DAMAGE) / duration) * multiplier; + + var entity = new HiddenBladeDelayedImpactEntity(level, damageCenter.x, damageCenter.y - 3f + attacker.getBbHeight() / 2f, damageCenter.z); + entity.setData(attacker, physicalDamage, magicDamage, duration); + entity.setItem(scytheWeapon); + level.addFreshEntity(entity); + data.hiddenBladeNecklaceCooldown = 200; + if (!effect.isInfiniteDuration()) { + attacker.removeEffect(effect.getEffect()); + } + for (int i = 0; i < 3; i++) { + SoundHelper.playSound(attacker, SoundRegistry.HIDDEN_BLADE_UNLEASHED.get(), 3f, RandomHelper.randomBetween(random, 0.75f, 1.25f)); + } + var particle = ParticleHelper.createSlashingEffect(ParticleEffectTypeRegistry.HIDDEN_BLADE_COUNTER_FLURRY); + if (scytheWeapon.getItem() instanceof ISpiritAffiliatedItem spiritAffiliatedItem) { + particle.setSpiritType(spiritAffiliatedItem); + } + particle.setRandomSlashAngle(random) + .mirrorRandomly(random) + .spawnForwardSlashingParticle(attacker, direction); +// MalumLivingEntityDataCapability.sync(attacker); } } public static void entityTick(EntityTickEvent.Pre event) { if (event.getEntity() instanceof LivingEntity entity) { var level = entity.level(); - MalumLivingEntityDataCapability.getCapabilityOptional(entity).ifPresent(c -> { - if (c.hiddenBladeNecklaceCooldown > 0) { - c.hiddenBladeNecklaceCooldown--; - if (!level.isClientSide()) { - if (c.hiddenBladeNecklaceCooldown == 0) { - SoundHelper.playSound(entity, SoundRegistry.HIDDEN_BLADE_CHARGED.get(), 1f, RandomHelper.randomBetween(level.getRandom(), 1.0f, 1.2f)); - } + var data = entity.getData(AttachmentTypeRegistry.CURIO_DATA); + if (data.hiddenBladeNecklaceCooldown > 0) { + data.hiddenBladeNecklaceCooldown--; + if (!level.isClientSide()) { + if (data.hiddenBladeNecklaceCooldown == 0) { + SoundHelper.playSound(entity, SoundRegistry.HIDDEN_BLADE_CHARGED.get(), 1f, RandomHelper.randomBetween(level.getRandom(), 1.0f, 1.2f)); } } - }); - } - } - - public static class ClientOnly { - - public static int fadeOut; - - public static void tick(ClientTickEvent event) { - final LocalPlayer player = Minecraft.getInstance().player; - if (player != null) { - var cooldown = MalumLivingEntityDataCapability.getCapability(player).hiddenBladeNecklaceCooldown; - if (cooldown == 0) { - if (player.hasEffect(MobEffectRegistry.WICKED_INTENT)) { - if (fadeOut > 30) { - fadeOut = 30; - } - fadeOut -= 2; - return; - } - else if (fadeOut < 0) { - fadeOut = 20; - } - if (fadeOut < 80) { - fadeOut++; - } - } else { - fadeOut = 0; - } } } - - public static void renderHiddenBladeCooldown(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { - var minecraft = Minecraft.getInstance(); - var poseStack = guiGraphics.pose(); - if (!minecraft.options.hideGui) { - var player = minecraft.player; - if (!player.isCreative() && !player.isSpectator()) { - var cooldown = MalumLivingEntityDataCapability.getCapability(player).hiddenBladeNecklaceCooldown; - if (cooldown > 0 || fadeOut <= 80) { - int left = guiGraphics.guiWidth() / 2 - 8; - int top = guiGraphics.guiHeight() - 52; - poseStack.pushPose(); -// gui.setupOverlayRenderState(true, false); - RenderSystem.setShaderTexture(0, getTexture()); - RenderSystem.depthMask(true); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - ExtendedShaderInstance shaderInstance = (ExtendedShaderInstance) LodestoneShaders.DISTORTED_TEXTURE.getInstance().get(); - shaderInstance.safeGetUniform("YFrequency").set(15f); - shaderInstance.safeGetUniform("XFrequency").set(15f); - shaderInstance.safeGetUniform("Speed").set(550f); - shaderInstance.safeGetUniform("Intensity").set(120f); - var builder = VFXBuilders.createScreen() - .setPosColorTexLightmapDefaultFormat() - .setShader(() -> shaderInstance); - - float size = 16; - double delta = Mth.clamp((COOLDOWN_DURATION-cooldown) / (float)COOLDOWN_DURATION, 0, 1); - delta -= 0.125f; - final boolean secondRow = delta >= 0.5f; - int xOffset = 16*(Mth.floor(delta*8)) - (secondRow ? 64 : 0); - int yOffset = secondRow ? 16 : 0; - - if (fadeOut > 20) { - final boolean hasEffect = player.hasEffect(MobEffectRegistry.WICKED_INTENT); - builder.setAlpha((80 - fadeOut) / (hasEffect ? 10f : 60f)); - } - builder.setPosColorTexLightmapDefaultFormat() - .setPositionWithWidth(left, top, size, size) - .setUVWithWidth(xOffset, yOffset, 16, 16, 64) - .draw(poseStack); - if (fadeOut > 0 && fadeOut < 20) { - float glow = (10 - Math.abs(10 - fadeOut)) / 10f; - RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); - - builder.setAlpha(glow).draw(poseStack); - } - - shaderInstance.setUniformDefaults(); - RenderSystem.disableBlend(); - poseStack.popPose(); - } - } - } - } - - public static ResourceLocation getTexture() { - return MalumMod.malumPath("textures/gui/hud/hidden_blade.png"); - } } + } diff --git a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioLimitlessBelt.java b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioLimitlessBelt.java index b6d9265bf..509e8dc72 100644 --- a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioLimitlessBelt.java +++ b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioLimitlessBelt.java @@ -10,9 +10,9 @@ import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.util.*; +import net.minecraft.world.entity.*; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; -import net.minecraft.world.entity.player.*; import net.minecraft.world.item.ItemStack; import top.theillusivec4.curios.api.SlotContext; @@ -38,7 +38,7 @@ public void addAttributeModifiers(Multimap, AttributeModifier> } @Override - public void modifySoulWardPropertiesEvent(ModifySoulWardPropertiesEvent event, Player wardedEntity, ItemStack stack) { + public void modifySoulWardPropertiesEvent(ModifySoulWardPropertiesEvent event, LivingEntity wardedEntity, ItemStack stack) { var handler = event.getSoulWardHandler(); double capacity = wardedEntity.getAttributeValue(AttributeRegistry.SOUL_WARD_CAPACITY); diff --git a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioWatcherNecklace.java b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioWatcherNecklace.java index f6bbc4546..6668978b1 100644 --- a/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioWatcherNecklace.java +++ b/src/main/java/com/sammy/malum/common/item/curiosities/curios/sets/weeping/CurioWatcherNecklace.java @@ -1,17 +1,17 @@ package com.sammy.malum.common.item.curiosities.curios.sets.weeping; -import com.sammy.malum.common.capability.*; import com.sammy.malum.common.entity.activator.*; import com.sammy.malum.common.item.*; import com.sammy.malum.common.item.curiosities.curios.*; +import com.sammy.malum.registry.common.*; import net.minecraft.network.chat.*; import net.minecraft.world.entity.*; import net.minecraft.world.entity.player.*; import net.minecraft.world.item.*; import net.minecraft.world.level.*; import net.minecraft.world.phys.*; -import net.neoforged.neoforge.event.entity.living.LivingDamageEvent; -import net.neoforged.neoforge.event.tick.EntityTickEvent; +import net.neoforged.neoforge.event.entity.living.*; +import net.neoforged.neoforge.event.tick.*; import team.lodestar.lodestone.helpers.*; import java.util.function.*; @@ -29,36 +29,34 @@ public void addExtraTooltipLines(Consumer consumer) { @Override public void outgoingDamageEvent(LivingDamageEvent.Pre event, LivingEntity attacker, LivingEntity target, ItemStack stack) { if (target.getHealth() >= target.getMaxHealth() * 0.9875f) { - MalumLivingEntityDataCapability.getCapabilityOptional(target).ifPresent(c -> { - if (c.watcherNecklaceCooldown == 0) { - float speed = 0.4f; - final Level level = attacker.level(); - var random = level.getRandom(); - Vec3 position = target.position().add(0, target.getBbHeight() / 2f, 0); - int amount = target instanceof Player ? 5 : 2; - for (int i = 0; i < amount; i++) { - SpiritCollectionActivatorEntity entity = new SpiritCollectionActivatorEntity(level, attacker.getUUID(), - position.x, - position.y, - position.z, - RandomHelper.randomBetween(random, -speed, speed), - RandomHelper.randomBetween(random, 0.05f, 0.06f), - RandomHelper.randomBetween(random, -speed, speed)); - level.addFreshEntity(entity); - } - c.watcherNecklaceCooldown = 100; + var data = target.getData(AttachmentTypeRegistry.CURIO_DATA); + if (data.watcherNecklaceCooldown == 0) { + float speed = 0.4f; + final Level level = attacker.level(); + var random = level.getRandom(); + Vec3 position = target.position().add(0, target.getBbHeight() / 2f, 0); + int amount = target instanceof Player ? 5 : 2; + for (int i = 0; i < amount; i++) { + SpiritCollectionActivatorEntity entity = new SpiritCollectionActivatorEntity(level, attacker.getUUID(), + position.x, + position.y, + position.z, + RandomHelper.randomBetween(random, -speed, speed), + RandomHelper.randomBetween(random, 0.05f, 0.06f), + RandomHelper.randomBetween(random, -speed, speed)); + level.addFreshEntity(entity); } - }); + data.watcherNecklaceCooldown = 100; + } } } public static void entityTick(EntityTickEvent.Pre event) { if (event.getEntity() instanceof LivingEntity entity) { - MalumLivingEntityDataCapability.getCapabilityOptional(entity).ifPresent(c -> { - if (c.watcherNecklaceCooldown > 0) { - c.watcherNecklaceCooldown--; - } - }); + var data = entity.getData(AttachmentTypeRegistry.CURIO_DATA); + if (data.watcherNecklaceCooldown > 0) { + data.watcherNecklaceCooldown--; + } } } } \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/item/curiosities/weapons/TyrvingItem.java b/src/main/java/com/sammy/malum/common/item/curiosities/weapons/TyrvingItem.java index 95f4c08c8..d4e358c42 100644 --- a/src/main/java/com/sammy/malum/common/item/curiosities/weapons/TyrvingItem.java +++ b/src/main/java/com/sammy/malum/common/item/curiosities/weapons/TyrvingItem.java @@ -1,8 +1,8 @@ package com.sammy.malum.common.item.curiosities.weapons; import com.sammy.malum.common.item.*; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.helpers.*; +import com.sammy.malum.core.systems.spirit.*; import com.sammy.malum.registry.common.*; import net.minecraft.world.entity.*; import net.minecraft.world.entity.player.*; @@ -29,7 +29,7 @@ public void outgoingDamageEvent(LivingDamageEvent.Pre event, LivingEntity attack if (!event.getSource().is(LodestoneDamageTypeTags.CAN_TRIGGER_MAGIC)) { return; } - float damage = SpiritHarvestHandler.getSpiritData(target).map(d -> d.totalSpirits).orElse(0) * 2f; + float damage = EntitySpiritDropData.getSpiritData(target).map(d -> d.totalSpirits).orElse(0) * 2f; if (target instanceof Player) { damage = 4 * Math.max(1, (1 + target.getArmorValue() / 12f) * (1 + (1 - 1 / (float) target.getArmorValue())) / 12f); } diff --git a/src/main/java/com/sammy/malum/common/item/curiosities/weapons/scythe/MalumScytheItem.java b/src/main/java/com/sammy/malum/common/item/curiosities/weapons/scythe/MalumScytheItem.java index 573229f61..4f9e5ef53 100644 --- a/src/main/java/com/sammy/malum/common/item/curiosities/weapons/scythe/MalumScytheItem.java +++ b/src/main/java/com/sammy/malum/common/item/curiosities/weapons/scythe/MalumScytheItem.java @@ -61,7 +61,7 @@ public void outgoingDamageEvent(LivingDamageEvent.Pre event, LivingEntity attack SoundHelper.playSound(attacker, getScytheSound(true), 1, 1); particle.mirrorRandomly(attacker.getRandom()).spawnForwardSlashingParticle(attacker); - int sweeping = stack.getEnchantmentLevel(level.holderLookup(Registries.ENCHANTMENT).getOrThrow(Enchantments.SWEEPING_EDGE)); + int sweeping = EnchantmentRegistry.getEnchantmentLevel(level, Enchantments.SWEEPING_EDGE, stack); float damage = event.getOriginalDamage() * (0.66f + sweeping * 0.33f); float radius = 1 + sweeping * 0.25f; level.getEntities(attacker, target.getBoundingBox().inflate(radius)).forEach(e -> { diff --git a/src/main/java/com/sammy/malum/common/item/curiosities/weapons/staff/AbstractStaffItem.java b/src/main/java/com/sammy/malum/common/item/curiosities/weapons/staff/AbstractStaffItem.java index ba8320dae..15d5b403a 100644 --- a/src/main/java/com/sammy/malum/common/item/curiosities/weapons/staff/AbstractStaffItem.java +++ b/src/main/java/com/sammy/malum/common/item/curiosities/weapons/staff/AbstractStaffItem.java @@ -1,7 +1,6 @@ package com.sammy.malum.common.item.curiosities.weapons.staff; import com.google.common.collect.*; -import com.sammy.malum.common.capability.*; import com.sammy.malum.common.item.*; import com.sammy.malum.core.handlers.enchantment.*; import com.sammy.malum.registry.client.*; @@ -91,9 +90,9 @@ public void releaseUsing(ItemStack pStack, Level pLevel, LivingEntity pLivingEnt player.awardStat(Stats.ITEM_USED.get(this)); if (!player.getAbilities().instabuild) { pStack.hurtAndBreak(2, player, EquipmentSlot.MAINHAND); - final MalumPlayerDataCapability capability = MalumPlayerDataCapability.getCapability(player); - if (capability.reserveStaffChargeHandler.chargeCount > 0) { - capability.reserveStaffChargeHandler.chargeCount--; + var data = player.getData(AttachmentTypeRegistry.RESERVE_STAFF_CHARGES); + if (data.reserveChargeCount > 0) { + data.reserveChargeCount--; } else { player.getCooldowns().addCooldown(this, getCooldownDuration(pLevel, pLivingEntity)); diff --git a/src/main/java/com/sammy/malum/common/item/spirit/SpiritJarItem.java b/src/main/java/com/sammy/malum/common/item/spirit/SpiritJarItem.java index 28c5bfb01..2163295de 100644 --- a/src/main/java/com/sammy/malum/common/item/spirit/SpiritJarItem.java +++ b/src/main/java/com/sammy/malum/common/item/spirit/SpiritJarItem.java @@ -2,7 +2,6 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.systems.spirit.MalumSpiritType; import com.sammy.malum.registry.common.item.DataComponentRegistry; import io.netty.buffer.ByteBuf; @@ -40,7 +39,7 @@ public String getDescriptionId(ItemStack pStack) { public void appendHoverText(ItemStack pStack, TooltipContext context, List pTooltip, TooltipFlag tooltipFlag) { if (pStack.has(DataComponentRegistry.SPIRIT_JAR_CONTENTS)) { Contents contents = pStack.get(DataComponentRegistry.SPIRIT_JAR_CONTENTS); - MalumSpiritType spirit = SpiritHarvestHandler.getSpiritType(contents.spirit()); + MalumSpiritType spirit = MalumSpiritType.getSpiritType(contents.spirit()); pTooltip.add(Component.translatable("malum.spirit.description.stored_spirit").withStyle(ChatFormatting.GRAY)); pTooltip.add(spirit.getSpiritJarCounterComponent(contents.count())); } diff --git a/src/main/java/com/sammy/malum/common/packets/SyncLivingCapabilityDataPacket.java b/src/main/java/com/sammy/malum/common/packets/SyncLivingCapabilityDataPacket.java deleted file mode 100644 index b58560eae..000000000 --- a/src/main/java/com/sammy/malum/common/packets/SyncLivingCapabilityDataPacket.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.sammy.malum.common.packets; - -import com.sammy.malum.common.capability.MalumLivingEntityDataCapability; -import net.minecraft.client.Minecraft; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.network.handling.IPayloadContext; -import team.lodestar.lodestone.systems.network.OneSidedPayloadData; - -public class SyncLivingCapabilityDataPacket extends OneSidedPayloadData { - private final int entityId; - private final CompoundTag capability; - - public SyncLivingCapabilityDataPacket(int entityId, CompoundTag capability) { - this.entityId = entityId; - this.capability = capability; - } - - public SyncLivingCapabilityDataPacket(FriendlyByteBuf buf) { - this.entityId = buf.readInt(); - this.capability = buf.readNbt(); - } - - @OnlyIn(Dist.CLIENT) - public void handle(IPayloadContext context) { - Entity entity = Minecraft.getInstance().level.getEntity(entityId); - if (entity instanceof LivingEntity livingEntity) { - MalumLivingEntityDataCapability.getCapabilityOptional(livingEntity).ifPresent(c -> c.pullFromNBT(capability)); - } - } - - @Override - public void serialize(FriendlyByteBuf buf) { - buf.writeInt(entityId); - buf.writeNbt(capability); - } - -} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/packets/SyncMalumPlayerCapabilityDataPacket.java b/src/main/java/com/sammy/malum/common/packets/SyncMalumPlayerCapabilityDataPacket.java deleted file mode 100644 index 32c10398c..000000000 --- a/src/main/java/com/sammy/malum/common/packets/SyncMalumPlayerCapabilityDataPacket.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.sammy.malum.common.packets; - -import com.sammy.malum.common.capability.MalumPlayerDataCapability; -import net.minecraft.client.Minecraft; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.network.handling.IPayloadContext; -import team.lodestar.lodestone.systems.network.OneSidedPayloadData; - -import java.util.UUID; - -public class SyncMalumPlayerCapabilityDataPacket extends OneSidedPayloadData { - private final UUID uuid; - private final CompoundTag capability; - - public SyncMalumPlayerCapabilityDataPacket(UUID uuid, CompoundTag capability) { - this.uuid = uuid; - this.capability = capability; - } - - public SyncMalumPlayerCapabilityDataPacket(FriendlyByteBuf buf) { - this.uuid = buf.readUUID(); - this.capability = buf.readNbt(); - } - - @OnlyIn(Dist.CLIENT) - @Override - public void handle(IPayloadContext iPayloadContext) { - Player player = Minecraft.getInstance().level.getPlayerByUUID(uuid); - MalumPlayerDataCapability.getCapabilityOptional(player).ifPresent(c -> c.pullFromNBT(capability)); - } - - @Override - public void serialize(FriendlyByteBuf friendlyByteBuf) { - friendlyByteBuf.writeUUID(uuid); - friendlyByteBuf.writeNbt(capability); - } -} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/packets/SyncSoulWardDataPayload.java b/src/main/java/com/sammy/malum/common/packets/SyncSoulWardDataPayload.java new file mode 100644 index 000000000..f3aa64beb --- /dev/null +++ b/src/main/java/com/sammy/malum/common/packets/SyncSoulWardDataPayload.java @@ -0,0 +1,36 @@ +package com.sammy.malum.common.packets; + +import com.sammy.malum.common.capabilities.*; +import com.sammy.malum.registry.common.*; +import net.minecraft.network.*; +import net.minecraft.world.entity.*; +import net.neoforged.neoforge.network.handling.*; +import team.lodestar.lodestone.systems.network.*; + +public class SyncSoulWardDataPayload extends OneSidedPayloadData { + private final int entityId; + private final SoulWardData data; + + public SyncSoulWardDataPayload(int entityId, SoulWardData data) { + this.entityId = entityId; + this.data = data; + } + + public SyncSoulWardDataPayload(FriendlyByteBuf buf) { + this.entityId = buf.readInt(); + this.data = SoulWardData.STREAM_CODEC.decode(buf); + } + + public void handle(IPayloadContext context) { + Entity entity = context.player().level().getEntity(entityId); + if (entity instanceof LivingEntity livingEntity) { + livingEntity.setData(AttachmentTypeRegistry.SOUL_WARD, data); + } + } + + @Override + public void serialize(FriendlyByteBuf buf) { + buf.writeInt(entityId); + SoulWardData.STREAM_CODEC.encode(buf, data); + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/common/packets/VoidRejectionPayload.java b/src/main/java/com/sammy/malum/common/packets/VoidRejectionPayload.java index d859f7b64..7b41fcd45 100644 --- a/src/main/java/com/sammy/malum/common/packets/VoidRejectionPayload.java +++ b/src/main/java/com/sammy/malum/common/packets/VoidRejectionPayload.java @@ -1,10 +1,10 @@ package com.sammy.malum.common.packets; -import com.sammy.malum.common.capability.MalumLivingEntityDataCapability; +import com.sammy.malum.core.handlers.*; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.*; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.neoforge.network.handling.IPayloadContext; @@ -25,8 +25,8 @@ public VoidRejectionPayload(FriendlyByteBuf byteBuf) { @Override public void handle(IPayloadContext iPayloadContext) { Entity entity = Minecraft.getInstance().level.getEntity(entityId); - if (entity instanceof LivingEntity livingEntity) { - MalumLivingEntityDataCapability.getCapabilityOptional(livingEntity).ifPresent(c -> c.touchOfDarknessHandler.reject(livingEntity)); + if (entity instanceof Player player) { + TouchOfDarknessHandler.launchPlayer(player); } } diff --git a/src/main/java/com/sammy/malum/common/packets/particle/base/spirit/SpiritBasedBlockParticleEffectPacket.java b/src/main/java/com/sammy/malum/common/packets/particle/base/spirit/SpiritBasedBlockParticleEffectPacket.java index 3451d1aa2..28dbee2f6 100644 --- a/src/main/java/com/sammy/malum/common/packets/particle/base/spirit/SpiritBasedBlockParticleEffectPacket.java +++ b/src/main/java/com/sammy/malum/common/packets/particle/base/spirit/SpiritBasedBlockParticleEffectPacket.java @@ -1,7 +1,6 @@ package com.sammy.malum.common.packets.particle.base.spirit; import com.sammy.malum.common.packets.particle.base.BlockBasedParticleEffectPacket; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.systems.spirit.MalumSpiritType; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; @@ -43,7 +42,7 @@ public void serialize(FriendlyByteBuf buf) { @Override public void handle(IPayloadContext iPayloadContext) { for (String string : spirits) { - handle(iPayloadContext, SpiritHarvestHandler.getSpiritType(string)); + handle(iPayloadContext, MalumSpiritType.getSpiritType(string)); } } diff --git a/src/main/java/com/sammy/malum/compability/irons_spellbooks/IronsSpellsCompat.java b/src/main/java/com/sammy/malum/compability/irons_spellbooks/IronsSpellsCompat.java index 9bac28047..3faf0faad 100644 --- a/src/main/java/com/sammy/malum/compability/irons_spellbooks/IronsSpellsCompat.java +++ b/src/main/java/com/sammy/malum/compability/irons_spellbooks/IronsSpellsCompat.java @@ -6,6 +6,7 @@ import com.sammy.malum.common.item.curiosities.curios.MalumCurioItem; import com.sammy.malum.config.*; import com.sammy.malum.core.handlers.*; +import com.sammy.malum.registry.common.*; import com.sammy.malum.registry.common.item.EnchantmentRegistry; import io.redspace.ironsspellbooks.api.events.*; import io.redspace.ironsspellbooks.api.magic.*; @@ -37,13 +38,6 @@ public static void init() { } } - public static boolean isStaff(ItemStack stack) { - if (LOADED) { - return LoadedOnly.isStaff(stack); - } - return false; - } - public static void generateMana(ServerPlayer collector, double amount) { generateMana(collector, (float) amount); } @@ -95,7 +89,7 @@ public static void spellDamage(SpellDamageEvent event) { CommonConfig.IRONS_SPELLBOOKS_SPIRIT_DAMAGE.getConfigValue() : CommonConfig.IRONS_SPELLBOOKS_NON_PLAYER_SPIRIT_DAMAGE.getConfigValue(); if (canShatter) { - SoulDataHandler.exposeSoul(event.getEntity()); + event.getEntity().getData(AttachmentTypeRegistry.LIVING_SOUL_INFO).setExposed(); } } @@ -111,13 +105,10 @@ public static void triggerReplenishing(LivingDamageEvent.Post event) { } } - public static boolean isStaff(ItemStack stack) { - return stack.getItem() instanceof StaffItem; - } - public static void generateMana(ServerPlayer collector, float amount) { var magicData = MagicData.getPlayerMagicData(collector); magicData.addMana(amount); + //TODO: this fucker // UpdateClient.SendManaUpdate(collector, magicData); } diff --git a/src/main/java/com/sammy/malum/compability/tetra/TetraCompat.java b/src/main/java/com/sammy/malum/compability/tetra/TetraCompat.java index f0f61b243..cac755719 100644 --- a/src/main/java/com/sammy/malum/compability/tetra/TetraCompat.java +++ b/src/main/java/com/sammy/malum/compability/tetra/TetraCompat.java @@ -1,6 +1,7 @@ package com.sammy.malum.compability.tetra; import com.sammy.malum.core.handlers.*; +import com.sammy.malum.registry.common.*; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.Arrow; import net.minecraft.world.item.ItemStack; @@ -22,7 +23,7 @@ public static boolean hasSoulStrikeModifier(ItemStack stack) { return LOADED && LoadedOnly.hasSoulStrikeModifier(stack); } - public static void onEntityJoin(EntityJoinLevelEvent event) { + public static void entityJoin(EntityJoinLevelEvent event) { if (LOADED) { LoadedOnly.fireArrow(event); } @@ -49,7 +50,7 @@ public static void fireArrow(EntityJoinLevelEvent event) { if (event.getEntity() instanceof Arrow arrow) { if (arrow.getOwner() instanceof Player player) { if (hasSoulStrikeModifier(player.getUseItem())) { - arrow.addTag(SoulDataHandler.SOUL_SHATTER_ENTITY_TAG); + arrow.getData(AttachmentTypeRegistry.PROJECTILE_SOUL_INFO).setSoulDamage(true); } } } diff --git a/src/main/java/com/sammy/malum/config/CommonConfig.java b/src/main/java/com/sammy/malum/config/CommonConfig.java index 33e176b5c..2d722ad73 100644 --- a/src/main/java/com/sammy/malum/config/CommonConfig.java +++ b/src/main/java/com/sammy/malum/config/CommonConfig.java @@ -15,6 +15,9 @@ public class CommonConfig extends LodestoneConfig { public static ConfigValueHolder NO_FANCY_SPIRITS = new ConfigValueHolder<>(MALUM, "common/spirit", (builder -> builder.comment("If set to true, any spirits dropped will simply take the form of an item.") .define("noFancySpirits", false))); + public static ConfigValueHolder NO_FANCY_SPIRITS_PLAYERLESS = new ConfigValueHolder<>(MALUM, "common/spirit", (builder -> + builder.comment("If set to true, any spirits dropped when no player is present will simply take the form of an item.") + .define("noFancySpiritsPlayerless", true))); public static ConfigValueHolder SOULLESS_SPAWNERS = new ConfigValueHolder<>(MALUM, "common/spirit/spawner", (builder -> builder.comment("If set to true, mob spawners will create soulless mobs instead.") diff --git a/src/main/java/com/sammy/malum/core/events/ClientRuntimeEvents.java b/src/main/java/com/sammy/malum/core/events/ClientRuntimeEvents.java index dd254b8bc..9ad138a2c 100644 --- a/src/main/java/com/sammy/malum/core/events/ClientRuntimeEvents.java +++ b/src/main/java/com/sammy/malum/core/events/ClientRuntimeEvents.java @@ -2,7 +2,6 @@ import com.sammy.malum.client.renderer.block.*; import com.sammy.malum.common.item.augment.*; -import com.sammy.malum.common.item.curiosities.curios.sets.weeping.*; import com.sammy.malum.core.handlers.client.*; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.EventPriority; @@ -27,7 +26,7 @@ public static void lateRenderTick(RenderFrameEvent.Post event) { @SubscribeEvent public static void clientTickEvent(ClientTickEvent.Pre event) { SpiritCrucibleRenderer.checkForTuningFork(event); - CurioHiddenBladeNecklace.ClientOnly.tick(event); + HiddenBladeRenderHandler.tick(event); SoulWardRenderHandler.tick(event); TotemBaseRenderer.checkForTotemicStaff(event); } diff --git a/src/main/java/com/sammy/malum/core/events/ClientSetupEvents.java b/src/main/java/com/sammy/malum/core/events/ClientSetupEvents.java index 9ac4fb8be..1365d490c 100644 --- a/src/main/java/com/sammy/malum/core/events/ClientSetupEvents.java +++ b/src/main/java/com/sammy/malum/core/events/ClientSetupEvents.java @@ -2,8 +2,6 @@ import com.sammy.malum.*; import com.sammy.malum.client.renderer.item.SpiritJarItemRenderer; -import com.sammy.malum.common.item.curiosities.curios.sets.weeping.*; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.handlers.client.*; import com.sammy.malum.registry.client.*; import com.sammy.malum.registry.common.item.*; @@ -44,10 +42,10 @@ public static void registerOverlays(RegisterGuiLayersEvent event) { SoulWardRenderHandler::renderSoulWard); event.registerAboveAll(MalumMod.malumPath("hidden_blade_cooldown"), - CurioHiddenBladeNecklace.ClientOnly::renderHiddenBladeCooldown); + HiddenBladeRenderHandler::renderHiddenBladeCooldown); event.registerAbove(VanillaGuiLayers.BOSS_OVERLAY, MalumMod.malumPath("touch_of_darkness"), - TouchOfDarknessHandler.ClientOnly::renderDarknessVignette); + TouchOfDarknessRenderHandler::renderDarknessVignette); } @SubscribeEvent diff --git a/src/main/java/com/sammy/malum/core/events/RuntimeEvents.java b/src/main/java/com/sammy/malum/core/events/RuntimeEvents.java index fec4fb205..2d3fa8117 100644 --- a/src/main/java/com/sammy/malum/core/events/RuntimeEvents.java +++ b/src/main/java/com/sammy/malum/core/events/RuntimeEvents.java @@ -1,7 +1,6 @@ package com.sammy.malum.core.events; import com.sammy.malum.common.block.storage.jar.*; -import com.sammy.malum.common.capability.*; import com.sammy.malum.common.effect.*; import com.sammy.malum.common.effect.aura.*; import com.sammy.malum.common.entity.nitrate.*; @@ -22,28 +21,24 @@ import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.state.*; import net.minecraft.world.phys.*; -import net.neoforged.bus.api.EventPriority; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.EventBusSubscriber; -import net.neoforged.neoforge.event.AddReloadListenerEvent; -import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent; -import net.neoforged.neoforge.event.entity.item.ItemExpireEvent; +import net.neoforged.bus.api.*; +import net.neoforged.fml.common.*; +import net.neoforged.neoforge.event.*; +import net.neoforged.neoforge.event.entity.*; +import net.neoforged.neoforge.event.entity.item.*; import net.neoforged.neoforge.event.entity.living.*; -import net.neoforged.neoforge.event.entity.player.PlayerEvent; -import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; -import net.neoforged.neoforge.event.level.ExplosionEvent; -import net.neoforged.neoforge.event.tick.EntityTickEvent; -import net.neoforged.neoforge.event.tick.PlayerTickEvent; +import net.neoforged.neoforge.event.entity.player.*; +import net.neoforged.neoforge.event.level.*; +import net.neoforged.neoforge.event.tick.*; @EventBusSubscriber public class RuntimeEvents { @SubscribeEvent public static void onEntityJoin(EntityJoinLevelEvent event) { - MalumPlayerDataCapability.playerJoin(event); CurioTokenOfGratitude.giveItem(event); - SoulDataHandler.updateAi(event); - TetraCompat.onEntityJoin(event); + SoulDataHandler.entityJoin(event); + TetraCompat.entityJoin(event); } @@ -92,24 +87,14 @@ public static void onLivingVisibility(LivingEvent.LivingVisibilityEvent event) { @SubscribeEvent public static void onLivingTick(EntityTickEvent.Pre event) { - SoulDataHandler.manageSoul(event); - MalignantConversionHandler.checkForAttributeChanges(event); + SoulDataHandler.entityTick(event); + SoulWardHandler.recoverSoulWard(event); + MalignantConversionHandler.entityTick(event); TouchOfDarknessHandler.entityTick(event); CurioWatcherNecklace.entityTick(event); CurioHiddenBladeNecklace.entityTick(event); } - @SubscribeEvent - public static void onStartTracking(PlayerEvent.StartTracking event) { - MalumLivingEntityDataCapability.syncEntityCapability(event); - MalumPlayerDataCapability.syncPlayerCapability(event); - } - - @SubscribeEvent - public static void onPlayerClone(PlayerEvent.Clone event) { - MalumPlayerDataCapability.playerClone(event); - } - @SubscribeEvent public static void onPlayerBreakSpeed(PlayerEvent.BreakSpeed event) { InfernalAura.increaseDigSpeed(event); @@ -118,8 +103,7 @@ public static void onPlayerBreakSpeed(PlayerEvent.BreakSpeed event) { @SubscribeEvent public static void onPlayerTick(PlayerTickEvent.Post event) { - ReserveStaffChargeHandler.recoverStaffCharges(event); - SoulWardHandler.recoverSoulWard(event); + StaffAbilityHandler.recoverStaffCharges(event); } @SubscribeEvent @@ -162,18 +146,17 @@ public static void onHurt(LivingDamageEvent.Pre event) { @SubscribeEvent public static void onDeath(LivingDeathEvent event) { - EsotericReapingHandler.onDeath(event); - SpiritHarvestHandler.spawnSpiritsOnDeath(event); + SoulHarvestHandler.onDeath(event); } @SubscribeEvent public static void onDrops(LivingDropsEvent event) { - SpiritHarvestHandler.primeItemForShatter(event); + EnsouledItemHarvestHandler.onDrops(event); } @SubscribeEvent public static void onItemExpire(ItemExpireEvent event) { - SpiritHarvestHandler.shatterItem(event); + EnsouledItemHarvestHandler.onItemExpire(event); } @SubscribeEvent(priority = EventPriority.HIGHEST) diff --git a/src/main/java/com/sammy/malum/core/events/SetupEvents.java b/src/main/java/com/sammy/malum/core/events/SetupEvents.java index bf09d906d..68d04c9f0 100644 --- a/src/main/java/com/sammy/malum/core/events/SetupEvents.java +++ b/src/main/java/com/sammy/malum/core/events/SetupEvents.java @@ -1,19 +1,6 @@ package com.sammy.malum.core.events; -import com.sammy.malum.common.capability.MalumItemDataCapability; -import com.sammy.malum.common.capability.MalumLivingEntityDataCapability; -import com.sammy.malum.common.capability.MalumPlayerDataCapability; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.EventBusSubscriber; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; - -@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD) +//@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD) public class SetupEvents { - @SubscribeEvent - public static void registerCapabilities(RegisterCapabilitiesEvent event) { - MalumPlayerDataCapability.registerCapabilities(event); - MalumLivingEntityDataCapability.registerCapabilities(event); - MalumItemDataCapability.registerItemDataCapability(event); - } } \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/handlers/EnsouledItemHarvestHandler.java b/src/main/java/com/sammy/malum/core/handlers/EnsouledItemHarvestHandler.java new file mode 100644 index 000000000..3aa62c260 --- /dev/null +++ b/src/main/java/com/sammy/malum/core/handlers/EnsouledItemHarvestHandler.java @@ -0,0 +1,45 @@ +package com.sammy.malum.core.handlers; + +import com.sammy.malum.core.systems.spirit.*; +import com.sammy.malum.registry.common.*; +import net.minecraft.world.entity.*; +import net.minecraft.world.entity.item.*; +import net.neoforged.neoforge.event.entity.item.ItemExpireEvent; +import net.neoforged.neoforge.event.entity.living.LivingDropsEvent; + +import static team.lodestar.lodestone.helpers.RandomHelper.randomBetween; + +public class EnsouledItemHarvestHandler { + + public static void onDrops(LivingDropsEvent event) { + if (event.isCanceled()) { + return; + } + var entity = event.getEntity(); + EntitySpiritDropData.getSpiritData(entity).map(d -> d.itemAsSoul).ifPresent(itemAsSoul -> { + for (ItemEntity item : event.getDrops()) { + if (itemAsSoul.test(item.getItem())) { + moveSpiritDropsOntoItem(item, entity); + } + } + }); + } + + public static void moveSpiritDropsOntoItem(ItemEntity item, LivingEntity entity) { + var entityData = entity.getData(AttachmentTypeRegistry.CACHED_SPIRIT_DROPS); + item.setData(AttachmentTypeRegistry.CACHED_SPIRIT_DROPS, entityData); + item.setNeverPickUp(); + item.age = item.lifespan - 20; + item.setNoGravity(true); + item.setDeltaMovement(entity.getDeltaMovement().multiply(1, 0.5, 1)); + } + + public static void onItemExpire(ItemExpireEvent event) { + var item = event.getEntity(); + var data = item.getData(AttachmentTypeRegistry.CACHED_SPIRIT_DROPS); + if (!data.getSpiritDrops().isEmpty()) { + LivingEntity spiritOwner = data.getSpiritOwner() != null ? item.level().getPlayerByUUID(data.getSpiritOwner()) : null; + SoulHarvestHandler.spawnSpirits(item.level(), spiritOwner, item.position().add(0, item.getBbHeight()/2, 0), data.getSpiritDrops()); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/handlers/EsotericReapingHandler.java b/src/main/java/com/sammy/malum/core/handlers/EsotericReapingHandler.java deleted file mode 100644 index b1358bb1d..000000000 --- a/src/main/java/com/sammy/malum/core/handlers/EsotericReapingHandler.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.sammy.malum.core.handlers; - -import com.sammy.malum.common.capability.MalumLivingEntityDataCapability; -import com.sammy.malum.common.capability.MalumPlayerDataCapability; -import com.sammy.malum.config.CommonConfig; -import com.sammy.malum.core.listeners.ReapingDataReloadListener; -import com.sammy.malum.registry.common.item.ItemRegistry; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.tags.EntityTypeTags; -import net.minecraft.util.Mth; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.Ingredient; -import net.minecraft.world.level.Level; -import net.neoforged.neoforge.event.entity.living.LivingDeathEvent; -import team.lodestar.lodestone.helpers.ItemHelper; - -import java.util.List; - -public class EsotericReapingHandler { - - public static void onDeath(LivingDeathEvent event) { - if (event.isCanceled()) { - return; - } - LivingEntity target = event.getEntity(); - LivingEntity attacker = null; - if (event.getSource().getEntity() instanceof LivingEntity directAttacker) { - attacker = directAttacker; - } - if (attacker == null) { - attacker = target.getLastHurtByMob(); - } - if (CommonConfig.AWARD_CODEX_ON_KILL.getConfigValue()) { - if (target.getType().is(EntityTypeTags.UNDEAD) && attacker instanceof Player player) { - MalumPlayerDataCapability.getCapabilityOptional(player).ifPresent(c -> { - if (!c.obtainedEncyclopedia) { - if (player.getRandom().nextFloat() < 0.1f) { - c.obtainedEncyclopedia = true; - SpiritHarvestHandler.spawnItemAsSpirit(ItemRegistry.ENCYCLOPEDIA_ARCANA.get().getDefaultInstance(), target, player); - } - } - }); - } - } - List data = ReapingDataReloadListener.REAPING_DATA.get(BuiltInRegistries.ENTITY_TYPE.getKey(target.getType())); - if (data != null) { - SoulDataHandler soulData = MalumLivingEntityDataCapability.getCapability(target).soulData; - if (soulData.exposedSoulDuration > 0) { - for (ReapingDataReloadListener.MalumReapingDropsData dropData : data) { - Level level = target.level(); - var random = level.random; - if (random.nextFloat() < dropData.chance) { - Ingredient ingredient = dropData.drop; - ItemStack stack = ItemHelper.copyWithNewCount(ingredient.getItems()[random.nextInt(ingredient.getItems().length)], Mth.nextInt(random, dropData.min, dropData.max)); - ItemEntity itemEntity = new ItemEntity(level, target.getX(), target.getY(), target.getZ(), stack); - itemEntity.setDefaultPickUpDelay(); - itemEntity.setDeltaMovement(Mth.nextFloat(random, -0.1F, 0.1F), Mth.nextFloat(random, 0.25f, 0.5f), Mth.nextFloat(random, -0.1F, 0.1F)); - level.addFreshEntity(itemEntity); - } - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/handlers/MalignantConversionHandler.java b/src/main/java/com/sammy/malum/core/handlers/MalignantConversionHandler.java index 71720f523..412b88972 100644 --- a/src/main/java/com/sammy/malum/core/handlers/MalignantConversionHandler.java +++ b/src/main/java/com/sammy/malum/core/handlers/MalignantConversionHandler.java @@ -2,7 +2,7 @@ import com.mojang.datafixers.util.*; import com.sammy.malum.*; -import com.sammy.malum.common.capability.*; +import com.sammy.malum.common.capabilities.*; import com.sammy.malum.core.listeners.*; import com.sammy.malum.registry.common.*; import net.minecraft.core.*; @@ -19,49 +19,46 @@ public class MalignantConversionHandler { public static final ResourceLocation NEGATIVE_MODIFIER_ID = MalumMod.malumPath("malignant_conversion_tally"); public static final HashMap, ResourceLocation> POSITIVE_MODIFIER_IDS = new HashMap<>(); - public final HashMap, Double> cachedAttributeValues = new HashMap<>(); - public boolean skipConversionLogic; - - public static void checkForAttributeChanges(EntityTickEvent.Pre event) { + public static void entityTick(EntityTickEvent.Pre event) { if (event.getEntity() instanceof LivingEntity livingEntity) { if (!livingEntity.level().isClientSide) { - var handler = MalumLivingEntityDataCapability.getCapability(livingEntity).malignantConversionHandler; + var data = livingEntity.getData(AttachmentTypeRegistry.MALIGNANT_INFLUENCE); var conversionAttribute = AttributeRegistry.MALIGNANT_CONVERSION; AttributeInstance conversionInstance = livingEntity.getAttribute(conversionAttribute); if (conversionInstance != null) { - if (handler.skipConversionLogic) { + if (data.skipConversionLogic) { if (conversionInstance.getValue() == 0) { return; } - handler.skipConversionLogic = false; + data.skipConversionLogic = false; } - var conversionData = MalignantConversionReloadListener.CONVERSION_DATA; - for (MalignantConversionReloadListener.MalignantConversionData data : conversionData.values()) { //check for any changed attributes, and apply malignant conversion to them if they've been updated - Holder attribute = data.sourceAttribute(); + var values = MalignantConversionReloadListener.CONVERSION_DATA.values(); + for (MalignantConversionReloadListener.MalignantConversionData conversionData : values) { //check for any changed attributes, and apply malignant conversion to them if they've been updated + Holder attribute = conversionData.sourceAttribute(); AttributeInstance instance = livingEntity.getAttribute(attribute); if (instance != null) { - if (handler.cachedAttributeValues.containsKey(attribute)) { - convertAttribute(handler, livingEntity, data.sourceAttribute(), data.consumptionRatio(), data.ignoreBaseValue(), data.targetAttributes(), false); + if (data.cachedAttributeValues.containsKey(attribute)) { + convertAttribute(data, livingEntity, conversionData.sourceAttribute(), conversionData.consumptionRatio(), conversionData.ignoreBaseValue(), conversionData.targetAttributes(), false); } } } - if (handler.cachedAttributeValues.containsKey(conversionAttribute)) { //update attributes when malignant conversion changes - if (handler.cachedAttributeValues.get(conversionAttribute) != conversionInstance.getValue()) { - for (MalignantConversionReloadListener.MalignantConversionData data : conversionData.values()) { - convertAttribute(handler, livingEntity, data.sourceAttribute(), data.consumptionRatio(), data.ignoreBaseValue(), data.targetAttributes(), true); + if (data.cachedAttributeValues.containsKey(conversionAttribute)) { //update attributes when the malignant conversion attribute itself changes + if (data.cachedAttributeValues.get(conversionAttribute) != conversionInstance.getValue()) { + for (MalignantConversionReloadListener.MalignantConversionData conversionData : values) { + convertAttribute(data, livingEntity, conversionData.sourceAttribute(), conversionData.consumptionRatio(), conversionData.ignoreBaseValue(), conversionData.targetAttributes(), true); } } } - handler.cachedAttributeValues.put(conversionAttribute, conversionInstance.getValue()); + data.cachedAttributeValues.put(conversionAttribute, conversionInstance.getValue()); if (conversionInstance.getValue() == 0) { - handler.skipConversionLogic = true; + data.skipConversionLogic = true; } } } } } - private static void convertAttribute(MalignantConversionHandler handler, LivingEntity livingEntity, Holder sourceAttribute, double consumptionRatio, boolean ignoreBaseValue, List, Double>> targetAttributes, boolean skipCacheComparison) { + private static void convertAttribute(MalignantInfluenceData data, LivingEntity livingEntity, Holder sourceAttribute, double consumptionRatio, boolean ignoreBaseValue, List, Double>> targetAttributes, boolean skipCacheComparison) { var attributes = livingEntity.getAttributes(); double malignantConversion = attributes.getValue(AttributeRegistry.MALIGNANT_CONVERSION); @@ -72,7 +69,7 @@ private static void convertAttribute(MalignantConversionHandler handler, LivingE sourceInstance.removeModifier(originalModifier); } boolean hasMalignantConversion = malignantConversion > 0; - if (skipCacheComparison || handler.cachedAttributeValues.get(sourceAttribute) != sourceInstance.getValue()) { + if (skipCacheComparison || data.cachedAttributeValues.get(sourceAttribute) != sourceInstance.getValue()) { double cachedValue = sourceInstance.getValue() - (ignoreBaseValue ? sourceInstance.getBaseValue() : 0); for (Pair, Double> target : targetAttributes) { var targetAttribute = target.getFirst(); @@ -87,7 +84,7 @@ private static void convertAttribute(MalignantConversionHandler handler, LivingE } } } - handler.cachedAttributeValues.put(sourceAttribute, sourceInstance.getValue()); + data.cachedAttributeValues.put(sourceAttribute, sourceInstance.getValue()); if (hasMalignantConversion) { final double negativeOffset = -malignantConversion * consumptionRatio; var modifier = new AttributeModifier(NEGATIVE_MODIFIER_ID, negativeOffset, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL); @@ -101,6 +98,6 @@ private static void convertAttribute(MalignantConversionHandler handler, LivingE } private static ResourceLocation createPositiveModifierId(Holder attribute) { - return MalumMod.malumPath("malignant_conversion_buff_from_" + BuiltInRegistries.ATTRIBUTE.getKey(attribute.value())); //TODO: this feels a bit wrong + return MalumMod.malumPath("malignant_conversion_buff_from_" + BuiltInRegistries.ATTRIBUTE.getKey(attribute.value())); } -} +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/handlers/MalumAttributeEventHandler.java b/src/main/java/com/sammy/malum/core/handlers/MalumAttributeEventHandler.java index 18be9af92..c2b875b9b 100644 --- a/src/main/java/com/sammy/malum/core/handlers/MalumAttributeEventHandler.java +++ b/src/main/java/com/sammy/malum/core/handlers/MalumAttributeEventHandler.java @@ -13,14 +13,7 @@ public static void processAttributes(LivingDamageEvent.Pre event) { } DamageSource source = event.getSource(); if (source.getEntity() instanceof LivingEntity attacker) { - var stack = SoulDataHandler.getScytheWeapon(source, attacker); - if (stack.isEmpty()) { - return; - } - if (source.is(DamageTypes.THORNS)) { - return; - } - if (!event.getSource().is(DamageTypeTagRegistry.IS_SCYTHE)) { + if (source.is(DamageTypeTagRegistry.IS_SCYTHE)) { var scytheProficiency = attacker.getAttribute(AttributeRegistry.SCYTHE_PROFICIENCY); if (scytheProficiency != null) { event.setNewDamage((float) (event.getNewDamage() * scytheProficiency.getValue())); diff --git a/src/main/java/com/sammy/malum/core/handlers/ReserveStaffChargeHandler.java b/src/main/java/com/sammy/malum/core/handlers/ReserveStaffChargeHandler.java deleted file mode 100644 index ed189f384..000000000 --- a/src/main/java/com/sammy/malum/core/handlers/ReserveStaffChargeHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.sammy.malum.core.handlers; - -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import com.sammy.malum.common.capability.*; -import com.sammy.malum.registry.common.*; -import net.minecraft.world.entity.ai.attributes.*; -import net.minecraft.world.entity.player.*; -import net.neoforged.neoforge.event.tick.PlayerTickEvent; - -public class ReserveStaffChargeHandler { - public int chargeCount; - public float chargeProgress; - - public static Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( - Codec.INT.fieldOf("chargeCount").forGetter(c -> c.chargeCount), - Codec.FLOAT.fieldOf("chargeProgress").forGetter(c -> c.chargeProgress) - ).apply(obj, ReserveStaffChargeHandler::new)); - - public ReserveStaffChargeHandler() {} - - public ReserveStaffChargeHandler(int chargeCount, float chargeProgress) { - this.chargeCount = chargeCount; - this.chargeProgress = chargeProgress; - } - - public static void recoverStaffCharges(PlayerTickEvent.Post event) { - Player player = event.getEntity(); - if (!player.level().isClientSide) { - AttributeInstance reserveStaffCharges = player.getAttribute(AttributeRegistry.RESERVE_STAFF_CHARGES); - if (reserveStaffCharges != null) { - ReserveStaffChargeHandler chargeHandler = MalumPlayerDataCapability.getCapability(player).reserveStaffChargeHandler; - if (chargeHandler.chargeCount < reserveStaffCharges.getValue()) { - chargeHandler.chargeProgress++; - if (chargeHandler.chargeProgress >= 600) { - chargeHandler.chargeProgress = 0; - chargeHandler.chargeCount++; - MalumPlayerDataCapability.syncTrackingAndSelf(player); - } - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/handlers/SoulDataHandler.java b/src/main/java/com/sammy/malum/core/handlers/SoulDataHandler.java index 016953663..e815f398f 100644 --- a/src/main/java/com/sammy/malum/core/handlers/SoulDataHandler.java +++ b/src/main/java/com/sammy/malum/core/handlers/SoulDataHandler.java @@ -1,8 +1,5 @@ package com.sammy.malum.core.handlers; -import com.mojang.serialization.*; -import com.mojang.serialization.codecs.*; -import com.sammy.malum.common.capability.*; import com.sammy.malum.common.entity.scythe.*; import com.sammy.malum.common.item.curiosities.weapons.scythe.*; import com.sammy.malum.common.item.curiosities.weapons.staff.*; @@ -21,60 +18,27 @@ public class SoulDataHandler { - public static final String SOUL_SHATTER_ENTITY_TAG = "malum:can_shatter_souls"; - - public float exposedSoulDuration; - public boolean soulless; - public boolean spawnerSpawned; - - public static final Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( - Codec.FLOAT.fieldOf("exposedSoulDuration").forGetter(sd -> sd.exposedSoulDuration), - Codec.BOOL.fieldOf("soulless").forGetter(sd -> sd.soulless), - Codec.BOOL.fieldOf("spawnerSpawned").forGetter(sd -> sd.spawnerSpawned) - ).apply(obj, SoulDataHandler::new)); - - public SoulDataHandler() {} - - public SoulDataHandler(boolean soulless, boolean spawnerSpawned) { - this.soulless = soulless; - this.spawnerSpawned = spawnerSpawned; - } - - public SoulDataHandler(float esd, boolean soulless, boolean spawnerSpawned) { - this(false, false); - this.exposedSoulDuration = esd; - } - public static void markAsSpawnerSpawned(MobSpawnEvent.PositionCheck event) { if (event.getSpawner() != null) { - MalumLivingEntityDataCapability.getCapabilityOptional(event.getEntity()).ifPresent(ec -> { - SoulDataHandler soulData = ec.soulData; - soulData.spawnerSpawned = true; - }); + event.getEntity().getData(AttachmentTypeRegistry.LIVING_SOUL_INFO).setSpawnerSpawned(true); } } - public static void updateAi(EntityJoinLevelEvent event) { - if (event.getEntity() instanceof LivingEntity livingEntity) { - MalumLivingEntityDataCapability.getCapabilityOptional(livingEntity).ifPresent(ec -> { - SoulDataHandler soulData = ec.soulData; - if (livingEntity instanceof Mob mob) { - if (soulData.soulless) { - removeSentience(mob); - } - } - }); + public static void entityJoin(EntityJoinLevelEvent event) { + if (event.getEntity() instanceof Mob mob) { + mob.getData(AttachmentTypeRegistry.LIVING_SOUL_INFO).updateSoullessBehavior(mob); } } public static void preventTargeting(LivingChangeTargetEvent event) { if (event.getEntity() instanceof Mob mob) { - MalumLivingEntityDataCapability.getCapabilityOptional(mob).ifPresent(ec -> { - SoulDataHandler soulData = ec.soulData; - if (soulData.soulless) { - event.setNewAboutToBeSetTarget(null); - } - }); + mob.getData(AttachmentTypeRegistry.LIVING_SOUL_INFO).updateSoullessTargeting(event); + } + } + + public static void entityTick(EntityTickEvent.Pre event) { + if (event.getEntity() instanceof LivingEntity living) { + living.getData(AttachmentTypeRegistry.LIVING_SOUL_INFO).tickDuration(); } } @@ -82,40 +46,31 @@ public static void exposeSoul(LivingDamageEvent.Post event) { if (event.getOriginalDamage() <= 0) { return; } - LivingEntity target = event.getEntity(); - DamageSource source = event.getSource(); + var target = event.getEntity(); + var source = event.getSource(); + var data = target.getData(AttachmentTypeRegistry.LIVING_SOUL_INFO); if (source.is(DamageTypeTagRegistry.SOUL_SHATTER_DAMAGE)) { - exposeSoul(target); + data.setExposed(); + return; + } + + var directEntity = source.getDirectEntity(); + if (directEntity != null) { + var projectileData = directEntity.getData(AttachmentTypeRegistry.PROJECTILE_SOUL_INFO); + if (projectileData.dealsSoulDamage()) { + data.setExposed(); + return; + } } if (source.getEntity() instanceof LivingEntity attacker) { ItemStack stack = getSoulHunterWeapon(source, attacker); if (stack.is(ItemTagRegistry.SOUL_HUNTER_WEAPON) || TetraCompat.hasSoulStrikeModifier(stack)) { - exposeSoul(target); - } - } - var directEntity = source.getDirectEntity(); - if (directEntity != null && directEntity.getTags().contains(SOUL_SHATTER_ENTITY_TAG)) { - exposeSoul(target); - } - } - public static void exposeSoul(LivingEntity entity) { - SoulDataHandler soulData = MalumLivingEntityDataCapability.getCapability(entity).soulData; - soulData.exposedSoulDuration = 200; - } - - public static void manageSoul(EntityTickEvent.Pre event) { - if (event.getEntity() instanceof LivingEntity living) { - SoulDataHandler soulData = MalumLivingEntityDataCapability.getCapability(living).soulData; - if (soulData.exposedSoulDuration > 0) { - soulData.exposedSoulDuration--; + data.setExposed(); } } } - public static void removeSentience(Mob mob) { - mob.goalSelector.getAvailableGoals().removeIf(g -> g.getGoal() instanceof LookAtPlayerGoal || g.getGoal() instanceof MeleeAttackGoal || g.getGoal() instanceof SwellGoal || g.getGoal() instanceof PanicGoal || g.getGoal() instanceof RandomLookAroundGoal || g.getGoal() instanceof AvoidEntityGoal); - } - + //TODO: move these guys public static ItemStack getStaffWeapon(DamageSource source, LivingEntity attacker) { return getSoulHunterWeapon(source, attacker, s -> s.getItem() instanceof AbstractStaffItem); } diff --git a/src/main/java/com/sammy/malum/core/handlers/SoulHarvestHandler.java b/src/main/java/com/sammy/malum/core/handlers/SoulHarvestHandler.java new file mode 100644 index 000000000..b971d8e01 --- /dev/null +++ b/src/main/java/com/sammy/malum/core/handlers/SoulHarvestHandler.java @@ -0,0 +1,217 @@ +package com.sammy.malum.core.handlers; + +import com.sammy.malum.common.capabilities.*; +import com.sammy.malum.common.entity.spirit.*; +import com.sammy.malum.common.item.*; +import com.sammy.malum.config.*; +import com.sammy.malum.core.listeners.*; +import com.sammy.malum.core.systems.events.*; +import com.sammy.malum.core.systems.spirit.*; +import com.sammy.malum.registry.common.*; +import com.sammy.malum.registry.common.item.*; +import net.minecraft.core.registries.*; +import net.minecraft.sounds.*; +import net.minecraft.tags.*; +import net.minecraft.util.*; +import net.minecraft.world.damagesource.*; +import net.minecraft.world.entity.*; +import net.minecraft.world.entity.item.*; +import net.minecraft.world.entity.player.*; +import net.minecraft.world.item.*; +import net.minecraft.world.level.*; +import net.minecraft.world.phys.*; +import net.neoforged.neoforge.common.*; +import net.neoforged.neoforge.event.entity.living.*; +import team.lodestar.lodestone.handlers.*; +import team.lodestar.lodestone.helpers.*; + +import javax.annotation.*; +import java.util.*; + +import static net.minecraft.world.entity.EquipmentSlot.*; +import static team.lodestar.lodestone.helpers.RandomHelper.*; + +public class SoulHarvestHandler { + + public static void onDeath(LivingDeathEvent event) { + if (event.isCanceled()) { + return; + } + var target = event.getEntity(); + if (target instanceof Player) { + return; + } + var data = target.getData(AttachmentTypeRegistry.LIVING_SOUL_INFO); + if (data.isSoulless() || (CommonConfig.SOULLESS_SPAWNERS.getConfigValue() && data.isSpawnerSpawned())) { + return; + } + var source = event.getSource(); + var attacker = source.getEntity() instanceof LivingEntity living ? living : target.getLastHurtByMob(); + if (data.shouldDropSpirits()) { + var itemAsSoul = EntitySpiritDropData.getSpiritData(target).map(s -> s.itemAsSoul).orElse(null); + if (itemAsSoul != null) { + spawnSpirits(target, attacker, source); + } else { + var uuid = attacker != null ? attacker.getUUID() : null; + target.setData(AttachmentTypeRegistry.CACHED_SPIRIT_DROPS, new CachedSpiritDropsData(getSpiritDrops(target, attacker, source), uuid)); + } + dropSpiritInfusedDrops(target); + dropEncyclopediaArcana(target, attacker); + data.setSoulless(true); + } + } + + public static void dropSpiritInfusedDrops(LivingEntity target) { + List data = ReapingDataReloadListener.REAPING_DATA.get(BuiltInRegistries.ENTITY_TYPE.getKey(target.getType())); + if (data != null) { + for (ReapingDataReloadListener.MalumReapingDropsData dropData : data) { + Level level = target.level(); + var random = level.random; + if (random.nextFloat() < dropData.chance) { + var possibleDrops = dropData.drop.getItems(); + var stack = ItemHelper.copyWithNewCount(possibleDrops[random.nextInt(possibleDrops.length)], Mth.nextInt(random, dropData.min, dropData.max)); + var itemEntity = new ItemEntity(level, target.getX(), target.getY(), target.getZ(), stack); + itemEntity.setDefaultPickUpDelay(); + itemEntity.setDeltaMovement(Mth.nextFloat(random, -0.1F, 0.1F), Mth.nextFloat(random, 0.25f, 0.5f), Mth.nextFloat(random, -0.1F, 0.1F)); + level.addFreshEntity(itemEntity); + } + } + } + } + + public static void dropEncyclopediaArcana(LivingEntity target, LivingEntity attacker) { + if (!CommonConfig.AWARD_CODEX_ON_KILL.getConfigValue()) { + return; + } + if (target.getType().is(EntityTypeTags.UNDEAD) && attacker instanceof Player player) { + var data = player.getData(AttachmentTypeRegistry.PROGRESSION_DATA); + if (data.obtainedEncyclopedia) { + return; + } + data.obtainedEncyclopedia = true; + SoulHarvestHandler.spawnItemsAsSpirits(target, List.of(ItemRegistry.ENCYCLOPEDIA_ARCANA.get().getDefaultInstance())); + } + } + + public static void spawnSpirits(LivingEntity target) { + spawnSpirits(target, null); + } + + public static void spawnSpirits(LivingEntity target, @Nullable LivingEntity attacker) { + spawnSpirits(target, attacker, null); + } + + public static void spawnSpirits(LivingEntity target, @Nullable LivingEntity attacker, @Nullable DamageSource source) { + spawnSpirits(target.level(), attacker, target.position().add(0, target.getBbHeight() / 2f, 0), getSpiritDrops(target, attacker, source)); + } + + public static void spawnItemsAsSpirits(LivingEntity target, Collection spirits) { + spawnItemsAsSpirits(target.level(), target.position().add(0, target.getBbHeight() / 2f, 0), spirits); + } + + public static void spawnItemsAsSpirits(Level level, Vec3 position, Collection spirits) { + spawnSpirits(level, null, position, spirits); + } + + public static void spawnSpirits(Level level, @Nullable LivingEntity attacker, Vec3 position, Collection spirits) { + boolean noFancySpirits = CommonConfig.NO_FANCY_SPIRITS.getConfigValue(); + if (attacker == null) { + noFancySpirits = CommonConfig.NO_FANCY_SPIRITS_PLAYERLESS.getConfigValue(); + attacker = level.getNearestPlayer(position.x, position.y, position.z, 8, e -> true); + } + var random = level.random; + for (ItemStack spirit : spirits) { + if (spirit.isEmpty()) { + continue; + } + for (int j = 0; j < spirit.getCount(); j++) { + var stack = ItemHelper.copyWithNewCount(spirit, 1); + if (noFancySpirits) { + var itemEntity = new ItemEntity(level, position.x, position.y, position.z, stack); + itemEntity.setDefaultPickUpDelay(); + itemEntity.setDeltaMovement(randomBetween(random, -0.1F, 0.1F), randomBetween(random, 0.25f, 0.5f), randomBetween(random, -0.1F, 0.1F)); + level.addFreshEntity(itemEntity); + continue; + } + createSpiritEntity(level, attacker, stack, position); + } + } + level.playSound(null, position.x, position.y, position.z, SoundRegistry.SOUL_SHATTER, SoundSource.PLAYERS, 1.0F, 0.7f + random.nextFloat() * 0.4f); + } + + private static SpiritItemEntity createSpiritEntity(Level level, @Nullable LivingEntity spiritOwner, ItemStack stack, Vec3 position) { + var random = level.getRandom(); + float speed = 0.3f + stack.getCount() * 0.05f; + var entity = new SpiritItemEntity(level, spiritOwner == null ? null : spiritOwner.getUUID(), stack, + position.x, position.y, position.z, + randomBetween(random, -speed, speed), randomBetween(random, 0.05f, 0.06f), randomBetween(random, -speed, speed)); + level.addFreshEntity(entity); + return entity; + } + + public static List getSpiritDrops(LivingEntity entity, LivingEntity attacker, @Nullable DamageSource source) { + if (attacker == null || source == null) { + return EntitySpiritDropData.getSpiritStacks(entity); + } + ItemStack stack = SoulDataHandler.getSoulHunterWeapon(source, attacker); + return EntitySpiritDropData.getSpiritData(entity).map(data -> applySpiritLootBonuses(EntitySpiritDropData.getSpiritStacks(data), attacker, stack)).orElse(Collections.emptyList()); + } + + public static List applySpiritLootBonuses(List spirits, LivingEntity attacker, ItemStack stack) { + if (spirits.isEmpty()) { + return spirits; + } + int extra = 0; + var spiritSpoils = AttributeRegistry.SPIRIT_SPOILS; + if (attacker.getAttribute(spiritSpoils) != null) { + extra += Mth.ceil(attacker.getAttributeValue(spiritSpoils)); + } + if (!stack.isEmpty()) { + int spiritPlunder = EnchantmentRegistry.getEnchantmentLevel(attacker.level(), EnchantmentRegistry.SPIRIT_PLUNDER, stack); + if (spiritPlunder > 0) { + stack.hurtAndBreak(spiritPlunder, attacker, MAINHAND); + } + extra += spiritPlunder; + } + for (int i = 0; i < extra; i++) { + int random = attacker.getRandom().nextInt(spirits.size()); + spirits.get(random).grow(1); + } + return spirits; + } + + + public static void pickupSpirit(LivingEntity collector, ItemStack stack) { + SoulHarvestHandler.triggerSpiritCollection(collector); +// if (collector instanceof Player player) { +// for (NonNullList playerInventory : player.getInventory().compartments) { +// //TODO: need AT for compartments +// for (ItemStack item : playerInventory) { +// if (item.getItem() instanceof SpiritPouchItem) { +// var inventory = SpiritPouchItem.getInventory(item); +// ItemStack result = inventory.addItem(stack); +// if (result.isEmpty()) { +// var random = collector.getRandom(); +// float pitch = ((random.nextFloat() - random.nextFloat()) * 0.7F + 1.0F) * 2.0F; //this kinda smells but we want it to match vanilla +// +// player.playSound(SoundEvents.ITEM_PICKUP, 0.2F, pitch); +// if (player.containerMenu instanceof SpiritPouchContainer pouchMenu) { +// pouchMenu.update(inventory); +// } +// return; +// } +// } +// } +// } +// } + ItemHelper.giveItemToEntity(collector, stack); + } + + public static void triggerSpiritCollection(LivingEntity collector) { + var collectionEvent = new CollectSpiritEvent(collector); + var attribute = collector.getAttributeValue(AttributeRegistry.ARCANE_RESONANCE); + ItemEventHandler.getEventResponders(collector).forEach(lookup -> lookup.run(IMalumEventResponderItem.class, + (eventResponderItem, stack) -> eventResponderItem.spiritCollectionEvent(collectionEvent, collector, attribute))); + NeoForge.EVENT_BUS.post(collectionEvent); + } +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/handlers/SoulWardHandler.java b/src/main/java/com/sammy/malum/core/handlers/SoulWardHandler.java index 8fb53f6f9..d4d3fcd46 100644 --- a/src/main/java/com/sammy/malum/core/handlers/SoulWardHandler.java +++ b/src/main/java/com/sammy/malum/core/handlers/SoulWardHandler.java @@ -1,165 +1,87 @@ package com.sammy.malum.core.handlers; -import com.mojang.serialization.*; -import com.mojang.serialization.codecs.*; -import com.sammy.malum.common.capability.*; -import com.sammy.malum.config.CommonConfig; -import com.sammy.malum.common.item.IMalumEventResponderItem; +import com.sammy.malum.common.item.*; +import com.sammy.malum.common.packets.*; +import com.sammy.malum.config.*; import com.sammy.malum.core.systems.events.*; import com.sammy.malum.registry.common.*; -import net.minecraft.util.Mth; -import net.minecraft.world.entity.ai.attributes.*; -import net.minecraft.world.entity.player.Player; +import net.minecraft.util.*; +import net.minecraft.world.entity.*; import net.neoforged.neoforge.common.*; import net.neoforged.neoforge.event.entity.living.*; import net.neoforged.neoforge.event.tick.*; +import net.neoforged.neoforge.network.*; import team.lodestar.lodestone.helpers.*; import team.lodestar.lodestone.registry.common.tag.*; -import java.util.*; - -import static team.lodestar.lodestone.handlers.ItemEventHandler.getEventResponders; +import static team.lodestar.lodestone.handlers.ItemEventHandler.*; public class SoulWardHandler { - public static Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( - Codec.DOUBLE.fieldOf("soulWard").forGetter(sw -> sw.soulWard), - Codec.DOUBLE.fieldOf("soulWardProgress").forGetter(sw -> sw.soulWardCooldown) - ).apply(obj, SoulWardHandler::new)); - - private double soulWard; - private double soulWardCooldown; - - private boolean isDirty; - - - public SoulWardHandler() { - } - - public SoulWardHandler(double soulWard, double soulWardCooldown) { - this.soulWard = soulWard; - this.soulWardCooldown = soulWardCooldown; - } - - public static void recoverSoulWard(PlayerTickEvent event) { - var player = event.getEntity(); - if (!player.level().isClientSide) { - var handler = MalumPlayerDataCapability.getCapability(player).soulWardHandler; - var capacity = player.getAttribute(AttributeRegistry.SOUL_WARD_CAPACITY); - if (capacity != null) { - if (handler.getSoulWard() < capacity.getValue()) { - if (handler.getCooldown() <= 0) { - handler.recoverSoulWard(player, 1); - } else { - handler.soulWardCooldown--; + public static void recoverSoulWard(EntityTickEvent.Pre event) { + if (event.getEntity() instanceof LivingEntity living) { + var level = living.level(); + if (!level.isClientSide) { + var data = living.getData(AttachmentTypeRegistry.SOUL_WARD); + var capacity = living.getAttribute(AttributeRegistry.SOUL_WARD_CAPACITY); + if (capacity != null) { + if (data.getSoulWard() < capacity.getValue()) { + data.tickCooldown(); + if (data.getCooldown() <= 0) { + data.recoverSoulWard(living, 1); + } + } + if (data.getSoulWard() > capacity.getValue()) { + data.setSoulWard(capacity.getValue()); } } - if (handler.getSoulWard() > capacity.getValue()) { - handler.setSoulWard(capacity.getValue()); + if (data.isDirty()) { + PacketDistributor.sendToPlayersTrackingEntityAndSelf(living, new SyncSoulWardDataPayload(living.getId(), data)); + data.setDirty(false); } } - if (handler.isDirty) { - MalumPlayerDataCapability.syncTrackingAndSelf(player); - handler.isDirty = false; - } } } public static void shieldPlayer(LivingDamageEvent.Pre event) { - if (event.getEntity().level().isClientSide()) { + var living = event.getEntity(); + if (living.level().isClientSide()) { return; } if (event.getOriginalDamage() <= 0) { return; } - if (event.getEntity() instanceof Player player) { - var handler = MalumPlayerDataCapability.getCapability(player).soulWardHandler; - handler.addCooldown(player, 4f); - if (!handler.isDepleted()) { - var source = event.getSource(); - float amount = event.getOriginalDamage(); - double magicDamageAbsorption = CommonConfig.SOUL_WARD_MAGIC.getConfigValue(); - double physicalDamageAbsorption = CommonConfig.SOUL_WARD_PHYSICAL.getConfigValue(); - double integrity = player.getAttributeValue(AttributeRegistry.SOUL_WARD_INTEGRITY); - var eventResponders = getEventResponders(player); - - var propertiesEvent = new ModifySoulWardPropertiesEvent(player, handler, source, magicDamageAbsorption, physicalDamageAbsorption, integrity); - eventResponders.forEach(lookup -> lookup.run(IMalumEventResponderItem.class, (eventResponderItem, stack) -> - eventResponderItem.modifySoulWardPropertiesEvent(propertiesEvent, player, stack))); - NeoForge.EVENT_BUS.post(propertiesEvent); - magicDamageAbsorption = propertiesEvent.getNewMagicDamageAbsorption(); - physicalDamageAbsorption = propertiesEvent.getNewPhysicalDamageAbsorption(); - integrity = propertiesEvent.getNewIntegrity(); - - double damageMultiplier = source.is(LodestoneDamageTypeTags.IS_MAGIC) ? magicDamageAbsorption : physicalDamageAbsorption; - double absorbedDamage = amount * damageMultiplier; - double soulWardDamage = (amount - absorbedDamage) / Math.max(integrity, 0.01f); - handler.reduceSoulWard(soulWardDamage); - - var damageEvent = new SoulWardDamageEvent(player, handler, source, absorbedDamage, soulWardDamage); - eventResponders.forEach(lookup -> lookup.run(IMalumEventResponderItem.class, (eventResponderItem, stack) -> - eventResponderItem.soulWardDamageEvent(damageEvent, player, stack))); - NeoForge.EVENT_BUS.post(damageEvent); - - var sound = handler.getSoulWard() == 0 ? SoundRegistry.SOUL_WARD_DEPLETE : SoundRegistry.SOUL_WARD_HIT; - SoundHelper.playSound(player, sound.get(), 1, Mth.nextFloat(player.getRandom(), 1f, 1.5f)); - event.setNewDamage((float) absorbedDamage); - } - } - } - - public void recoverSoulWard(Player player, double amount) { - var multiplier = Optional.ofNullable(player.getAttribute(AttributeRegistry.SOUL_WARD_RECOVERY_MULTIPLIER)).map(AttributeInstance::getValue).orElse(1.0); - addSoulWard(amount * multiplier); - if (!player.isCreative()) { - var capacity = player.getAttribute(AttributeRegistry.SOUL_WARD_CAPACITY); - if (capacity != null) { - var sound = soulWard >= capacity.getValue() ? SoundRegistry.SOUL_WARD_CHARGE : SoundRegistry.SOUL_WARD_GROW; - double pitchOffset = (soulWard / capacity.getValue()) * 0.5f + (Mth.ceil(soulWard) % 3) * 0.25f; - SoundHelper.playSound(player, sound.get(), 0.25f, (float) (1f + pitchOffset)); - } + var data = living.getData(AttachmentTypeRegistry.SOUL_WARD); + data.addCooldown(living, 4f); + if (!data.isDepleted()) { + var source = event.getSource(); + float amount = event.getOriginalDamage(); + double magicDamageAbsorption = CommonConfig.SOUL_WARD_MAGIC.getConfigValue(); + double physicalDamageAbsorption = CommonConfig.SOUL_WARD_PHYSICAL.getConfigValue(); + double integrity = living.getAttributeValue(AttributeRegistry.SOUL_WARD_INTEGRITY); + var eventResponders = getEventResponders(living); + var propertiesEvent = new ModifySoulWardPropertiesEvent(living, data, source, magicDamageAbsorption, physicalDamageAbsorption, integrity); + eventResponders.forEach(lookup -> lookup.run(IMalumEventResponderItem.class, (eventResponderItem, stack) -> + eventResponderItem.modifySoulWardPropertiesEvent(propertiesEvent, living, stack))); + NeoForge.EVENT_BUS.post(propertiesEvent); + magicDamageAbsorption = propertiesEvent.getNewMagicDamageAbsorption(); + physicalDamageAbsorption = propertiesEvent.getNewPhysicalDamageAbsorption(); + integrity = propertiesEvent.getNewIntegrity(); + + double damageMultiplier = source.is(LodestoneDamageTypeTags.IS_MAGIC) ? magicDamageAbsorption : physicalDamageAbsorption; + double absorbedDamage = amount * damageMultiplier; + double soulWardDamage = (amount - absorbedDamage) / Math.max(integrity, 0.01f); + data.reduceSoulWard(soulWardDamage); + + var damageEvent = new SoulWardDamageEvent(living, data, source, absorbedDamage, soulWardDamage); + eventResponders.forEach(lookup -> lookup.run(IMalumEventResponderItem.class, (eventResponderItem, stack) -> + eventResponderItem.soulWardDamageEvent(damageEvent, living, stack))); + NeoForge.EVENT_BUS.post(damageEvent); + + var sound = data.getSoulWard() == 0 ? SoundRegistry.SOUL_WARD_DEPLETE : SoundRegistry.SOUL_WARD_HIT; + SoundHelper.playSound(living, sound.get(), 1, Mth.nextFloat(living.getRandom(), 1f, 1.5f)); + event.setNewDamage((float) absorbedDamage); } - addCooldown(player, 1); - } - - public void addSoulWard(double added) { - setSoulWard(soulWard + added); - } - - public void reduceSoulWard(double removed) { - setSoulWard(soulWard - removed); - } - - public void setSoulWard(double soulWard) { - this.soulWard = Math.max(soulWard, 0); - isDirty = true; - } - - public void addCooldown(Player player, double multiplier) { - final double newCooldown = getSoulWardCooldown(player) * multiplier; - if (soulWardCooldown < newCooldown) { - soulWardCooldown = newCooldown; - } - } - - public boolean isDepleted() { - return soulWard == 0; - } - - public double getSoulWard() { - return soulWard; - } - - public double getCooldown() { - return soulWardCooldown; - } - - public static float getSoulWardCooldown(Player player) { - return getSoulWardCooldown(player.getAttributeValue(AttributeRegistry.SOUL_WARD_RECOVERY_RATE)); - } - - public static float getSoulWardCooldown(double recoverySpeed) { - return Mth.floor(CommonConfig.SOUL_WARD_RATE.getConfigValue() / recoverySpeed); } } \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/handlers/SpiritHarvestHandler.java b/src/main/java/com/sammy/malum/core/handlers/SpiritHarvestHandler.java deleted file mode 100644 index 4384bc179..000000000 --- a/src/main/java/com/sammy/malum/core/handlers/SpiritHarvestHandler.java +++ /dev/null @@ -1,303 +0,0 @@ -package com.sammy.malum.core.handlers; - -import com.sammy.malum.common.capability.*; -import com.sammy.malum.common.entity.spirit.*; -import com.sammy.malum.common.item.*; -import com.sammy.malum.config.*; -import com.sammy.malum.core.listeners.*; -import com.sammy.malum.core.systems.events.*; -import com.sammy.malum.core.systems.recipe.*; -import com.sammy.malum.core.systems.spirit.*; -import com.sammy.malum.mixin.AccessorEvent; -import com.sammy.malum.registry.common.*; -import com.sammy.malum.registry.common.item.*; -import net.minecraft.core.*; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.*; -import net.minecraft.server.level.*; -import net.minecraft.sounds.*; -import net.minecraft.util.*; -import net.minecraft.world.entity.*; -import net.minecraft.world.entity.item.*; -import net.minecraft.world.entity.player.*; -import net.minecraft.world.item.*; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.level.*; -import net.minecraft.world.phys.*; -import net.neoforged.neoforge.common.*; -import net.neoforged.neoforge.event.entity.item.ItemExpireEvent; -import net.neoforged.neoforge.event.entity.living.LivingDeathEvent; -import net.neoforged.neoforge.event.entity.living.LivingDropsEvent; -import team.lodestar.lodestone.handlers.*; -import team.lodestar.lodestone.helpers.*; - -import javax.annotation.*; -import java.util.*; -import java.util.stream.*; - -import static net.minecraft.world.entity.EquipmentSlot.*; - -public class SpiritHarvestHandler { - - public static void spawnSpiritsOnDeath(LivingDeathEvent event) { - if (event.isCanceled()) { - return; - } - var target = event.getEntity(); - if (target instanceof Player) { - return; - } - var soulData = MalumLivingEntityDataCapability.getCapability(target).soulData; - if (soulData.soulless) { - return; - } - if (CommonConfig.SOULLESS_SPAWNERS.getConfigValue() && soulData.spawnerSpawned) { - return; - } - var source = event.getSource(); - var attacker = source.getEntity() instanceof LivingEntity living ? living : target.getLastHurtByMob(); - if (soulData.exposedSoulDuration > 0) { - if (attacker == null) { - spawnSpirits(event.getEntity()); - } else { - ItemStack stack = SoulDataHandler.getSoulHunterWeapon(source, attacker); - spawnSpirits(target, attacker, stack); - } - soulData.soulless = true; - } - } - - public static void primeItemForShatter(LivingDropsEvent event) { - if (event.isCanceled()) { - return; - } - var entityLiving = event.getEntity(); - var capability = MalumLivingEntityDataCapability.getCapability(entityLiving); - if (capability.soulsToApplyToDrops != null) { - getSpiritData(entityLiving).ifPresent(spiritData -> { - var spiritItem = spiritData.spiritItem; - if (spiritItem != null) { - for (ItemEntity itemEntity : event.getDrops()) { - if (spiritItem.test(itemEntity.getItem())) { - primeItemForShatter(itemEntity, capability); - } - } - } - }); - } - } - - public static void primeItemForShatter(ItemEntity entity, MalumLivingEntityDataCapability data) { - MalumItemDataCapability.getCapabilityOptional(entity).ifPresent((e) -> { - e.soulsToDrop = data.soulsToApplyToDrops.stream().map(ItemStack::copy).collect(Collectors.toList()); - e.attackerForSouls = data.killerUUID; - }); - entity.setNeverPickUp(); - entity.age = entity.lifespan - 20; //TODO: AT this fella - entity.setNoGravity(true); - entity.setDeltaMovement(entity.getDeltaMovement().multiply(1, 0.5, 1)); - } - - public static void shatterItem(ItemExpireEvent event) { - if (((AccessorEvent) event).malum$isCancelled()) { - return; - } - - ItemEntity entity = event.getEntity(); - if (entity.level() instanceof ServerLevel level) { - MalumItemDataCapability.getCapabilityOptional(entity).ifPresent((e) -> { - LivingEntity attacker = null; - if (e.attackerForSouls != null) { - if (level.getEntity(e.attackerForSouls) instanceof LivingEntity living) { - attacker = living; - } - } - - if (e.soulsToDrop != null) { - List stacks = new ArrayList<>(); - for (int i = 0; i < entity.getItem().getCount(); i++) { - e.soulsToDrop.stream().map(ItemStack::copy).forEach(stacks::add); - } - createSpiritEntities(level, stacks, entity.position(), attacker); - } - }); - } - } - - public static void pickupSpirit(LivingEntity collector, ItemStack stack) { - triggerSpiritCollection(collector); -// if (collector instanceof Player player) { -// for (NonNullList playerInventory : player.getInventory().compartments) { -// //TODO: need AT for compartments -// for (ItemStack item : playerInventory) { -// if (item.getItem() instanceof SpiritPouchItem) { -// var inventory = SpiritPouchItem.getInventory(item); -// ItemStack result = inventory.addItem(stack); -// if (result.isEmpty()) { -// var random = collector.getRandom(); -// float pitch = ((random.nextFloat() - random.nextFloat()) * 0.7F + 1.0F) * 2.0F; //this kinda smells but we want it to match vanilla -// -// player.playSound(SoundEvents.ITEM_PICKUP, 0.2F, pitch); -// if (player.containerMenu instanceof SpiritPouchContainer pouchMenu) { -// pouchMenu.update(inventory); -// } -// return; -// } -// } -// } -// } -// } - ItemHelper.giveItemToEntity(collector, stack); - } - - public static void triggerSpiritCollection(LivingEntity collector) { - var collectionEvent = new CollectSpiritEvent(collector); - var attribute = collector.getAttributeValue(AttributeRegistry.ARCANE_RESONANCE); - ItemEventHandler.getEventResponders(collector).forEach(lookup -> lookup.run(IMalumEventResponderItem.class, - (eventResponderItem, stack) -> eventResponderItem.spiritCollectionEvent(collectionEvent, collector, attribute))); - NeoForge.EVENT_BUS.post(collectionEvent); - } - - public static void spawnSpirits(LivingEntity target) { - spawnSpirits(getSpiritDropsRaw(target), target, null); - } - - public static void spawnSpirits(LivingEntity target, LivingEntity attacker, ItemStack harvestStack) { - spawnSpirits(getSpawnedSpirits(target, attacker, harvestStack), target, attacker); - } - - public static void spawnSpirits(List spirits, LivingEntity target, LivingEntity attacker) { - if (spirits.isEmpty()) { - return; - } - getSpiritData(target).ifPresent(data -> { - if (data.spiritItem != null) { - MalumLivingEntityDataCapability.getCapabilityOptional(target).ifPresent((e) -> { - e.soulsToApplyToDrops = spirits; - if (attacker != null) { - e.killerUUID = attacker.getUUID(); - } - }); - } else { - spawnItemsAsSpirits(spirits, target, attacker); - } - }); - } - - public static void spawnItemAsSpirit(ItemStack spirit, LivingEntity target, LivingEntity attacker) { - spawnItemsAsSpirits(List.of(spirit), target, attacker); - } - - public static void spawnItemsAsSpirits(Collection spirits, LivingEntity target, LivingEntity attacker) { - createSpiritEntities(target.level(), spirits, target.position().add(0, target.getBbHeight() / 2f, 0), attacker); - } - - public static void createSpiritEntities(Level level, Collection spirits, Vec3 position, @Nullable LivingEntity attacker) { - createSpiritEntities(level, spirits, position, spirits.stream().mapToInt(ItemStack::getCount).sum(), attacker); - } - - private static void createSpiritEntities(Level level, Collection spirits, Vec3 position, float totalCount, @Nullable LivingEntity attacker) { - if (attacker == null) { - attacker = level.getNearestPlayer(position.x, position.y, position.z, 8, e -> true); - } - final UUID attackerUUID = attacker == null ? null : attacker.getUUID(); - float speed = 0.15f + 0.25f / (totalCount + 1); - var random = level.random; - for (ItemStack stack : spirits) { - if (stack.isEmpty()) { - continue; - } - boolean noFancySpirits = CommonConfig.NO_FANCY_SPIRITS.getConfigValue(); - for (int j = 0; j < stack.getCount(); j++) { - final ItemStack droppedSpirit = ItemHelper.copyWithNewCount(stack, 1); - if (noFancySpirits) { - ItemEntity itemEntity = new ItemEntity(level, position.x, position.y, position.z, droppedSpirit); - itemEntity.setDefaultPickUpDelay(); - itemEntity.setDeltaMovement( - Mth.nextFloat(random, -0.1F, 0.1F), - Mth.nextFloat(random, 0.25f, 0.5f), - Mth.nextFloat(random, -0.1F, 0.1F)); - level.addFreshEntity(itemEntity); - continue; - } - SpiritItemEntity entity = new SpiritItemEntity(level, attackerUUID, droppedSpirit, - position.x, - position.y, - position.z, - RandomHelper.randomBetween(random, -speed, speed), - RandomHelper.randomBetween(random, 0.05f, 0.06f), - RandomHelper.randomBetween(random, -speed, speed)); - level.addFreshEntity(entity); - } - } - level.playSound(null, position.x, position.y, position.z, SoundRegistry.SOUL_SHATTER, SoundSource.PLAYERS, 1.0F, 0.7f + random.nextFloat() * 0.4f); - } - - public static List getSpawnedSpirits(LivingEntity entity, LivingEntity attacker, ItemStack harvestStack) { - return getSpiritData(entity).map(data -> applySpiritLootBonuses(getSpiritDropsRaw(data), attacker, harvestStack)).orElse(Collections.emptyList()); - } - - public static List applySpiritLootBonuses(List spirits, LivingEntity attacker, ItemStack weapon) { - if (spirits.isEmpty()) { - return spirits; - } - int spiritBonus = 0; - if (attacker.getAttribute(AttributeRegistry.SPIRIT_SPOILS) != null) { - spiritBonus += Mth.ceil(attacker.getAttributeValue(AttributeRegistry.SPIRIT_SPOILS)); - } - if (!weapon.isEmpty()) { - HolderGetter enchantmentLookup = attacker.level().registryAccess() - .asGetterLookup().lookupOrThrow(Registries.ENCHANTMENT); - final int spiritPlunder = weapon.getEnchantmentLevel(enchantmentLookup.getOrThrow(EnchantmentRegistry.SPIRIT_PLUNDER)); - if (spiritPlunder > 0) { - weapon.hurtAndBreak(spiritPlunder, attacker, MAINHAND); - } - spiritBonus += spiritPlunder; - } - for (int i = 0; i < spiritBonus; i++) { - int random = attacker.getRandom().nextInt(spirits.size()); - spirits.get(random).grow(1); - } - return spirits; - } - - public static List getSpiritDropsRaw(LivingEntity entity) { - return getSpiritData(entity).map(SpiritHarvestHandler::getSpiritDropsRaw).orElse(Collections.emptyList()); - } - - public static List getSpiritDropsRaw(EntitySpiritDropData data) { - return data != null ? data.dataEntries.stream().map(SpiritIngredient::getStack).collect(Collectors.toList()) : (Collections.emptyList()); - } - - public static Optional getSpiritData(LivingEntity entity) { - ResourceLocation key = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()); - if (SpiritDataReloadListener.HAS_NO_DATA.contains(key)) - return Optional.empty(); - - EntitySpiritDropData spiritData = SpiritDataReloadListener.SPIRIT_DATA.get(key); - if (spiritData != null) - return Optional.of(spiritData); - - if (!entity.canUsePortal(false)) - return Optional.of(SpiritDataReloadListener.DEFAULT_BOSS_SPIRIT_DATA); - - if (!CommonConfig.USE_DEFAULT_SPIRIT_VALUES.getConfigValue()) - return Optional.empty(); - - return switch (entity.getType().getCategory()) { - case MONSTER -> Optional.of(SpiritDataReloadListener.DEFAULT_MONSTER_SPIRIT_DATA); - case CREATURE -> Optional.of(SpiritDataReloadListener.DEFAULT_CREATURE_SPIRIT_DATA); - case AMBIENT -> Optional.of(SpiritDataReloadListener.DEFAULT_AMBIENT_SPIRIT_DATA); - case AXOLOTLS -> Optional.of(SpiritDataReloadListener.DEFAULT_AXOLOTL_SPIRIT_DATA); - case UNDERGROUND_WATER_CREATURE -> Optional.of(SpiritDataReloadListener.DEFAULT_UNDERGROUND_WATER_CREATURE_SPIRIT_DATA); - case WATER_CREATURE -> Optional.of(SpiritDataReloadListener.DEFAULT_WATER_CREATURE_SPIRIT_DATA); - case WATER_AMBIENT -> Optional.of(SpiritDataReloadListener.DEFAULT_WATER_AMBIENT_SPIRIT_DATA); - default -> Optional.empty(); - }; - } - - public static MalumSpiritType getSpiritType(String spirit) { - return SpiritTypeRegistry.SPIRITS.getOrDefault(spirit, SpiritTypeRegistry.SACRED_SPIRIT); - } -} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/handlers/StaffAbilityHandler.java b/src/main/java/com/sammy/malum/core/handlers/StaffAbilityHandler.java new file mode 100644 index 000000000..d6173dc9b --- /dev/null +++ b/src/main/java/com/sammy/malum/core/handlers/StaffAbilityHandler.java @@ -0,0 +1,26 @@ +package com.sammy.malum.core.handlers; + +import com.sammy.malum.registry.common.*; +import net.minecraft.world.entity.player.*; +import net.neoforged.neoforge.event.tick.*; + +public class StaffAbilityHandler { + + public static void recoverStaffCharges(PlayerTickEvent.Post event) { + Player player = event.getEntity(); + if (!player.level().isClientSide) { + var reserveStaffCharges = player.getAttribute(AttributeRegistry.RESERVE_STAFF_CHARGES); + if (reserveStaffCharges != null) { + var data = player.getData(AttachmentTypeRegistry.RESERVE_STAFF_CHARGES); + if (data.reserveChargeCount < reserveStaffCharges.getValue()) { + data.reserveChargeProgress++; + if (data.reserveChargeProgress >= 600) { + data.reserveChargeProgress = 0; + data.reserveChargeCount++; +// MalumPlayerDataCapability.syncTrackingAndSelf(player); + } + } + } + } + } +} diff --git a/src/main/java/com/sammy/malum/core/handlers/TouchOfDarknessHandler.java b/src/main/java/com/sammy/malum/core/handlers/TouchOfDarknessHandler.java index dd1af10ef..ceb09c4d1 100644 --- a/src/main/java/com/sammy/malum/core/handlers/TouchOfDarknessHandler.java +++ b/src/main/java/com/sammy/malum/core/handlers/TouchOfDarknessHandler.java @@ -1,23 +1,13 @@ package com.sammy.malum.core.handlers; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; import com.sammy.malum.*; import com.sammy.malum.client.VoidRevelationHandler; -import com.sammy.malum.common.block.curiosities.weeping_well.PrimordialSoupBlock; -import com.sammy.malum.common.block.curiosities.weeping_well.VoidConduitBlock; import com.sammy.malum.common.block.curiosities.weeping_well.VoidConduitBlockEntity; -import com.sammy.malum.common.capability.MalumLivingEntityDataCapability; -import com.sammy.malum.common.capability.MalumPlayerDataCapability; +import com.sammy.malum.common.capabilities.*; import com.sammy.malum.common.packets.VoidRejectionPayload; -import com.sammy.malum.registry.client.ShaderRegistry; import com.sammy.malum.registry.common.*; import com.sammy.malum.registry.common.item.ItemRegistry; import com.sammy.malum.visual_effects.networked.data.PositionEffectData; -import net.minecraft.client.*; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.BlockPos; import net.minecraft.resources.*; import net.minecraft.server.level.*; @@ -29,247 +19,109 @@ import net.minecraft.world.entity.ai.attributes.*; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.event.tick.EntityTickEvent; import net.neoforged.neoforge.network.*; import team.lodestar.lodestone.helpers.*; -import team.lodestar.lodestone.helpers.block.*; -import team.lodestar.lodestone.systems.easing.Easing; -import team.lodestar.lodestone.systems.rendering.VFXBuilders; -import team.lodestar.lodestone.systems.rendering.shader.ExtendedShaderInstance; -import java.util.Optional; -import java.util.function.Consumer; +import java.util.*; import static com.sammy.malum.client.VoidRevelationHandler.RevelationType.BLACK_CRYSTAL; public class TouchOfDarknessHandler { public static final ResourceLocation GRAVITY_MODIFIER_ID = MalumMod.malumPath("weeping_well_reduced_gravity"); - public static final float MAX_AFFLICTION = 100f; - - public boolean isNearWeepingWell; - public int weepingWellInfluence; - - public int expectedAffliction; - public int afflictionDuration; - public float currentAffliction; - - public int progressToRejection; - public int rejection; - - public static final Codec CODEC = RecordCodecBuilder.create(obj -> obj.group( - Codec.BOOL.fieldOf("isNearWeepingWell").forGetter(h -> h.isNearWeepingWell), - Codec.INT.fieldOf("weepingWellInfluence").forGetter(h -> h.weepingWellInfluence), - Codec.INT.fieldOf("expectedAffliction").forGetter(h -> h.expectedAffliction), - Codec.INT.fieldOf("afflictionDuration").forGetter(h -> h.afflictionDuration), - Codec.FLOAT.fieldOf("currentAffliction").forGetter(h -> h.currentAffliction), - Codec.INT.fieldOf("progressToRejection").forGetter(h -> h.progressToRejection), - Codec.INT.fieldOf("rejection").forGetter(h -> h.rejection) - ).apply(obj, TouchOfDarknessHandler::new)); - - public TouchOfDarknessHandler() {} - - public TouchOfDarknessHandler(boolean isNearWeepingWell, int weepingWellInfluence, int expectedAffliction, int afflictionDuration, float currentAffliction, int progressToRejection, int rejection) { - this.isNearWeepingWell = isNearWeepingWell; - this.weepingWellInfluence = weepingWellInfluence; - this.expectedAffliction = expectedAffliction; - this.afflictionDuration = afflictionDuration; - this.currentAffliction = currentAffliction; - this.progressToRejection = progressToRejection; - this.rejection = rejection; - } public static void handlePrimordialSoupContact(LivingEntity livingEntity) { - TouchOfDarknessHandler touchOfDarknessHandler = MalumLivingEntityDataCapability.getCapability(livingEntity).touchOfDarknessHandler; - if (touchOfDarknessHandler.rejection > 0) { + var data = livingEntity.getData(AttachmentTypeRegistry.VOID_INFLUENCE); + if (data.isInRejectedState) { return; } livingEntity.setDeltaMovement(livingEntity.getDeltaMovement().scale(0.4f)); - touchOfDarknessHandler.afflict(100); - } - - public static Optional checkForWeepingWell(LivingEntity livingEntity) { - return BlockEntityHelper.getBlockEntitiesStream(VoidConduitBlockEntity.class, livingEntity.level(), livingEntity.blockPosition(), 8).findFirst(); + data.setAfflictionLevel(100); + data.setGoopStatus(); } public static void entityTick(EntityTickEvent.Pre event) { if (event.getEntity() instanceof LivingEntity livingEntity) { - Level level = livingEntity.level(); - TouchOfDarknessHandler handler = MalumLivingEntityDataCapability.getCapability(livingEntity).touchOfDarknessHandler; - - if (livingEntity instanceof Player player) { - if (level.getGameTime() % 20L == 0) { - final Optional voidConduitBlockEntity = checkForWeepingWell(player); - handler.isNearWeepingWell = voidConduitBlockEntity.isPresent(); - } - if (handler.isNearWeepingWell) { - handler.weepingWellInfluence++; - } - } - Block block = level.getBlockState(livingEntity.blockPosition()).getBlock(); - boolean isInTheGoop = block instanceof PrimordialSoupBlock || block instanceof VoidConduitBlock; - if (!isInTheGoop) { - block = level.getBlockState(livingEntity.blockPosition().above()).getBlock(); - isInTheGoop = block instanceof PrimordialSoupBlock || block instanceof VoidConduitBlock; - } - //VALUE UPDATES - if (handler.afflictionDuration > 0) { - handler.afflictionDuration--; - if (handler.afflictionDuration == 0) { - handler.expectedAffliction = 0; - } - } - if (handler.currentAffliction < handler.expectedAffliction) { - handler.currentAffliction = Math.min(MAX_AFFLICTION, handler.currentAffliction + 1.5f); - } - if (handler.currentAffliction > handler.expectedAffliction) { - handler.currentAffliction = Math.max(handler.currentAffliction - (handler.expectedAffliction == 0 ? 1.5f : 0.75f), handler.expectedAffliction); - } - //GRAVITY - - AttributeInstance gravity = livingEntity.getAttribute(Attributes.GRAVITY); + var level = livingEntity.level(); + var data = livingEntity.getData(AttachmentTypeRegistry.VOID_INFLUENCE); + data.update(livingEntity); + var gravity = livingEntity.getAttribute(Attributes.GRAVITY); if (gravity != null) { - boolean hasModifier = gravity.getModifier(GRAVITY_MODIFIER_ID) != null; - if (hasModifier) { + if (gravity.getModifier(GRAVITY_MODIFIER_ID) != null) { gravity.removeModifier(GRAVITY_MODIFIER_ID); } - if (handler.progressToRejection > 0) { + if (data.isInRejectedState) { gravity.addTransientModifier(getEntityGravityAttributeModifier(livingEntity)); } } - //REJECTION - if (isInTheGoop) { - if (!(livingEntity instanceof Player player) || (!player.isSpectator())) { - handler.progressToRejection++; - if (!level.isClientSide) { - if (livingEntity instanceof Player && level.getGameTime() % 6L == 0) { - float volume = 0.5f + handler.progressToRejection * 0.02f; - float pitch = 0.5f + handler.progressToRejection * 0.03f; - SoundHelper.playSound(livingEntity, SoundRegistry.SONG_OF_THE_VOID.get(), SoundSource.HOSTILE, volume, pitch); - } - if (handler.rejection == 0 && handler.progressToRejection > 60) { - handler.reject(livingEntity); - } - } - } - } else { - handler.progressToRejection = 0; - } - - //MOTION - if (handler.rejection > 0) { - handler.rejection--; - float intensity = handler.rejection / 40f; - Vec3 movement = livingEntity.getDeltaMovement(); - livingEntity.setDeltaMovement(movement.x, Math.pow(intensity, 2), movement.z); + if (data.isInGoop()) { + handleRejectionState(level, livingEntity); } } } - public void afflict(int expectedAffliction) { - if (this.expectedAffliction > expectedAffliction) { - return; + public static void handleRejectionState(Level level, LivingEntity living) { + var data = living.getData(AttachmentTypeRegistry.VOID_INFLUENCE); + if (!level.isClientSide) { + if (living instanceof Player && level.getGameTime() % 6L == 0) { + float volume = 0.5f + data.voidRejection * 0.02f; + float pitch = 0.5f + data.voidRejection * 0.03f; + SoundHelper.playSound(living, SoundRegistry.SONG_OF_THE_VOID.get(), SoundSource.HOSTILE, volume, pitch); + } + if (data.wasJustRejected()) { + if (!(living instanceof Player player)) { + living.remove(Entity.RemovalReason.DISCARDED); + return; + } + launchPlayer(player); + } } - this.expectedAffliction = expectedAffliction; - this.afflictionDuration = 60; - } - - public void reject(LivingEntity livingEntity) { - if (!(livingEntity instanceof Player player)) { - livingEntity.remove(Entity.RemovalReason.DISCARDED); - return; + if (data.isInRejectedState && data.voidRejection > 0) { + float intensity = data.voidRejection / VoidInfluenceData.MAX_REJECTION; + Vec3 movement = living.getDeltaMovement(); + living.setDeltaMovement(movement.x, Math.pow(intensity, 2), movement.z); } + } - var playerDataCapability = MalumPlayerDataCapability.getCapability(player); - - final Level level = livingEntity.level(); - progressToRejection = 0; - rejection = 40; + public static void launchPlayer(Player player) { + var data = player.getData(AttachmentTypeRegistry.PROGRESSION_DATA); + var level = player.level(); if (level instanceof ServerLevel serverLevel) { - final Optional voidConduitBlockEntity = checkForWeepingWell(livingEntity); + final Optional voidConduitBlockEntity = VoidInfluenceData.checkForWeepingWell(player); if (voidConduitBlockEntity.isPresent()) { VoidConduitBlockEntity weepingWell = voidConduitBlockEntity.get(); BlockPos worldPosition = weepingWell.getBlockPos(); - ParticleEffectTypeRegistry.WEEPING_WELL_REACTS.createPositionedEffect(serverLevel, new PositionEffectData(worldPosition.getX()+0.5f, worldPosition.getY()+0.6f, worldPosition.getZ()+0.5f)); - } - else { - ParticleEffectTypeRegistry.WEEPING_WELL_REACTS.createEntityEffect(livingEntity); + ParticleEffectTypeRegistry.WEEPING_WELL_REACTS.createPositionedEffect(serverLevel, new PositionEffectData(worldPosition.getX() + 0.5f, worldPosition.getY() + 0.6f, worldPosition.getZ() + 0.5f)); + } else { + ParticleEffectTypeRegistry.WEEPING_WELL_REACTS.createEntityEffect(player); } if (!player.isCreative()) { - livingEntity.hurt(DamageTypeHelper.create(level, DamageTypeRegistry.VOODOO), 4); + player.hurt(DamageTypeHelper.create(level, DamageTypeRegistry.VOODOO), 4); } - if (!playerDataCapability.hasBeenRejected) { - SpiritHarvestHandler.spawnItemAsSpirit(ItemRegistry.UMBRAL_SPIRIT.get().getDefaultInstance(), player, player); + if (!data.hasBeenRejected) { + SoulHarvestHandler.spawnSpirits(level, player, player.position(), List.of(ItemRegistry.ENCYCLOPEDIA_ARCANA.get().getDefaultInstance())); } - PacketDistributor.sendToPlayersTrackingEntityAndSelf(livingEntity, new VoidRejectionPayload(livingEntity.getId())); - SoundHelper.playSound(livingEntity, SoundRegistry.VOID_REJECTION.get(), 2f, Mth.nextFloat(livingEntity.getRandom(), 0.5f, 0.8f)); + PacketDistributor.sendToPlayersTrackingEntityAndSelf(player, new VoidRejectionPayload(player.getId())); + SoundHelper.playSound(player, SoundRegistry.VOID_REJECTION.get(), 2f, Mth.nextFloat(player.getRandom(), 0.5f, 0.8f)); } else { VoidRevelationHandler.seeTheRevelation(BLACK_CRYSTAL); } - playerDataCapability.hasBeenRejected = true; - livingEntity.addEffect(new MobEffectInstance(MobEffectRegistry.REJECTED, 400, 0)); + data.hasBeenRejected = true; + player.addEffect(new MobEffectInstance(MobEffectRegistry.REJECTED, 400, 0)); } public static AttributeModifier getEntityGravityAttributeModifier(LivingEntity livingEntity) { return new AttributeModifier(GRAVITY_MODIFIER_ID, updateEntityGravity(livingEntity), AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL); } - public static double updateEntityGravity(LivingEntity livingEntity) { - TouchOfDarknessHandler handler = MalumLivingEntityDataCapability.getCapability(livingEntity).touchOfDarknessHandler; - if (handler.progressToRejection > 0) { - return -Math.min(60, handler.progressToRejection) / 60f; + public static double updateEntityGravity(LivingEntity living) { + var data = living.getData(AttachmentTypeRegistry.VOID_INFLUENCE); + if (data.voidRejection > 0) { + return -Math.min(60, data.voidRejection) / 60f; } return 0; } - - public static class ClientOnly { - - public static void renderDarknessVignette(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { - Minecraft minecraft = Minecraft.getInstance(); - PoseStack poseStack = guiGraphics.pose(); - Player player = minecraft.player; - TouchOfDarknessHandler darknessHandler = MalumLivingEntityDataCapability.getCapability(player).touchOfDarknessHandler; - if (darknessHandler.currentAffliction == 0f) { - return; - } - int screenWidth = minecraft.getWindow().getGuiScaledWidth(); - int screenHeight = minecraft.getWindow().getGuiScaledHeight(); - - float effectStrength = Easing.SINE_IN_OUT.ease(darknessHandler.currentAffliction / MAX_AFFLICTION, 0, 1, 1); - float alpha = Math.min(1, effectStrength * 5); - float zoom = 0.5f + Math.min(0.35f, effectStrength); - float intensity = 1f + (effectStrength > 0.5f ? (effectStrength - 0.5f) * 2.5f : 0); - - ExtendedShaderInstance shaderInstance = (ExtendedShaderInstance) ShaderRegistry.TOUCH_OF_DARKNESS.getInstance().get(); - shaderInstance.safeGetUniform("Speed").set(1000f); - Consumer setZoom = f -> shaderInstance.safeGetUniform("Zoom").set(f); - Consumer setIntensity = f -> shaderInstance.safeGetUniform("Intensity").set(f); - VFXBuilders.ScreenVFXBuilder builder = VFXBuilders.createScreen() - .setPosColorTexLightmapDefaultFormat() - .setPositionWithWidth(0, 0, screenWidth, screenHeight) - .setColor(0, 0, 0) - .setAlpha(alpha) - .setShader(ShaderRegistry.TOUCH_OF_DARKNESS.getInstance()); - - poseStack.pushPose(); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - - setZoom.accept(zoom); - setIntensity.accept(intensity); - builder.draw(poseStack); - - setZoom.accept(zoom * 1.25f + 0.15f); - setIntensity.accept(intensity * 0.8f + 0.5f); - builder.setAlpha(0.5f * alpha).draw(poseStack); - - RenderSystem.disableBlend(); - poseStack.popPose(); - - shaderInstance.setUniformDefaults(); - } - } -} +} \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/handlers/client/HiddenBladeRenderHandler.java b/src/main/java/com/sammy/malum/core/handlers/client/HiddenBladeRenderHandler.java new file mode 100644 index 000000000..9d7f68b09 --- /dev/null +++ b/src/main/java/com/sammy/malum/core/handlers/client/HiddenBladeRenderHandler.java @@ -0,0 +1,102 @@ +package com.sammy.malum.core.handlers.client; + +import com.mojang.blaze3d.systems.*; +import com.sammy.malum.*; +import com.sammy.malum.common.item.curiosities.curios.sets.weeping.*; +import com.sammy.malum.registry.common.*; +import net.minecraft.client.*; +import net.minecraft.client.gui.*; +import net.minecraft.resources.*; +import net.minecraft.util.*; +import net.neoforged.neoforge.client.event.*; +import org.lwjgl.opengl.*; +import team.lodestar.lodestone.registry.client.*; +import team.lodestar.lodestone.systems.rendering.*; +import team.lodestar.lodestone.systems.rendering.shader.*; + +public class HiddenBladeRenderHandler { + + public static int fadeOut; + + public static void tick(ClientTickEvent event) { + var player = Minecraft.getInstance().player; + if (player != null) { + var cooldown = player.getData(AttachmentTypeRegistry.CURIO_DATA).hiddenBladeNecklaceCooldown; + if (cooldown == 0) { + if (player.hasEffect(MobEffectRegistry.WICKED_INTENT)) { + if (fadeOut > 30) { + fadeOut = 30; + } + fadeOut -= 2; + return; + } else if (fadeOut < 0) { + fadeOut = 20; + } + if (fadeOut < 80) { + fadeOut++; + } + } else { + fadeOut = 0; + } + } + } + + public static void renderHiddenBladeCooldown(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { + var minecraft = Minecraft.getInstance(); + var poseStack = guiGraphics.pose(); + if (!minecraft.options.hideGui) { + var player = minecraft.player; + if (!player.isCreative() && !player.isSpectator()) { + var cooldown = player.getData(AttachmentTypeRegistry.CURIO_DATA).hiddenBladeNecklaceCooldown; + if (cooldown > 0 || fadeOut <= 80) { + int left = guiGraphics.guiWidth() / 2 - 8; + int top = guiGraphics.guiHeight() - 52; + poseStack.pushPose(); +// gui.setupOverlayRenderState(true, false); + RenderSystem.setShaderTexture(0, getTexture()); + RenderSystem.depthMask(true); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + ExtendedShaderInstance shaderInstance = (ExtendedShaderInstance) LodestoneShaders.DISTORTED_TEXTURE.getInstance().get(); + shaderInstance.safeGetUniform("YFrequency").set(15f); + shaderInstance.safeGetUniform("XFrequency").set(15f); + shaderInstance.safeGetUniform("Speed").set(550f); + shaderInstance.safeGetUniform("Intensity").set(120f); + var builder = VFXBuilders.createScreen() + .setPosColorTexLightmapDefaultFormat() + .setShader(() -> shaderInstance); + + float size = 16; + double delta = Mth.clamp((CurioHiddenBladeNecklace.COOLDOWN_DURATION - cooldown) / (float) CurioHiddenBladeNecklace.COOLDOWN_DURATION, 0, 1); + delta -= 0.125f; + final boolean secondRow = delta >= 0.5f; + int xOffset = 16 * (Mth.floor(delta * 8)) - (secondRow ? 64 : 0); + int yOffset = secondRow ? 16 : 0; + + if (fadeOut > 20) { + final boolean hasEffect = player.hasEffect(MobEffectRegistry.WICKED_INTENT); + builder.setAlpha((80 - fadeOut) / (hasEffect ? 10f : 60f)); + } + builder.setPosColorTexLightmapDefaultFormat() + .setPositionWithWidth(left, top, size, size) + .setUVWithWidth(xOffset, yOffset, 16, 16, 64) + .draw(poseStack); + if (fadeOut > 0 && fadeOut < 20) { + float glow = (10 - Math.abs(10 - fadeOut)) / 10f; + RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + + builder.setAlpha(glow).draw(poseStack); + } + + shaderInstance.setUniformDefaults(); + RenderSystem.disableBlend(); + poseStack.popPose(); + } + } + } + } + + public static ResourceLocation getTexture() { + return MalumMod.malumPath("textures/gui/hud/hidden_blade.png"); + } +} diff --git a/src/main/java/com/sammy/malum/core/handlers/client/SoulWardRenderHandler.java b/src/main/java/com/sammy/malum/core/handlers/client/SoulWardRenderHandler.java index 03494f36d..49a8fb3ed 100644 --- a/src/main/java/com/sammy/malum/core/handlers/client/SoulWardRenderHandler.java +++ b/src/main/java/com/sammy/malum/core/handlers/client/SoulWardRenderHandler.java @@ -2,7 +2,6 @@ import com.mojang.blaze3d.systems.*; import com.sammy.malum.*; -import com.sammy.malum.common.capability.*; import com.sammy.malum.registry.common.*; import net.minecraft.client.*; import net.minecraft.client.gui.*; @@ -25,8 +24,8 @@ public class SoulWardRenderHandler { public static void tick(ClientTickEvent event) { final LocalPlayer player = Minecraft.getInstance().player; if (player != null) { - var handler = MalumPlayerDataCapability.getCapability(player).soulWardHandler; - if (handler.getSoulWard() >= player.getAttributeValue(AttributeRegistry.SOUL_WARD_CAPACITY)) { + var data = player.getData(AttachmentTypeRegistry.SOUL_WARD); + if (data.getSoulWard() >= player.getAttributeValue(AttributeRegistry.SOUL_WARD_CAPACITY)) { if (fadeOut < 80) { fadeOut++; } @@ -42,8 +41,8 @@ public static void renderSoulWard(GuiGraphics guiGraphics, DeltaTracker deltaTra if (!minecraft.options.hideGui) { var player = minecraft.player; if (!player.isCreative() && !player.isSpectator()) { - var handler = MalumPlayerDataCapability.getCapability(player).soulWardHandler; - double soulWard = handler.getSoulWard(); + var data = player.getData(AttachmentTypeRegistry.SOUL_WARD); + double soulWard = data.getSoulWard(); if (soulWard > 0) { float absorb = Mth.ceil(player.getAbsorptionAmount()); float maxHealth = (float) player.getAttribute(Attributes.MAX_HEALTH).getValue(); diff --git a/src/main/java/com/sammy/malum/core/handlers/client/TouchOfDarknessRenderHandler.java b/src/main/java/com/sammy/malum/core/handlers/client/TouchOfDarknessRenderHandler.java new file mode 100644 index 000000000..2f8e8d452 --- /dev/null +++ b/src/main/java/com/sammy/malum/core/handlers/client/TouchOfDarknessRenderHandler.java @@ -0,0 +1,63 @@ +package com.sammy.malum.core.handlers.client; + +import com.mojang.blaze3d.systems.*; +import com.mojang.blaze3d.vertex.*; +import com.sammy.malum.common.capabilities.*; +import com.sammy.malum.registry.client.*; +import com.sammy.malum.registry.common.*; +import net.minecraft.client.*; +import net.minecraft.client.gui.*; +import net.minecraft.world.entity.player.*; +import team.lodestar.lodestone.systems.easing.*; +import team.lodestar.lodestone.systems.rendering.*; +import team.lodestar.lodestone.systems.rendering.shader.*; + +import java.util.function.*; + +public class TouchOfDarknessRenderHandler { + + public static void renderDarknessVignette(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { + Minecraft minecraft = Minecraft.getInstance(); + PoseStack poseStack = guiGraphics.pose(); + Player player = minecraft.player; + var data = player.getData(AttachmentTypeRegistry.VOID_INFLUENCE); + if (data.voidAffliction == 0f) { + return; + } + int screenWidth = minecraft.getWindow().getGuiScaledWidth(); + int screenHeight = minecraft.getWindow().getGuiScaledHeight(); + + float effectStrength = Easing.SINE_IN_OUT.ease(data.voidAffliction / VoidInfluenceData.MAX_AFFLICTION, 0, 1, 1); + float alpha = Math.min(1, effectStrength * 5); + float zoom = 0.5f + Math.min(0.35f, effectStrength); + float intensity = 1f + (effectStrength > 0.5f ? (effectStrength - 0.5f) * 2.5f : 0); + + ExtendedShaderInstance shaderInstance = (ExtendedShaderInstance) ShaderRegistry.TOUCH_OF_DARKNESS.getInstance().get(); + shaderInstance.safeGetUniform("Speed").set(1000f); + Consumer setZoom = f -> shaderInstance.safeGetUniform("Zoom").set(f); + Consumer setIntensity = f -> shaderInstance.safeGetUniform("Intensity").set(f); + VFXBuilders.ScreenVFXBuilder builder = VFXBuilders.createScreen() + .setPosColorTexLightmapDefaultFormat() + .setPositionWithWidth(0, 0, screenWidth, screenHeight) + .setColor(0, 0, 0) + .setAlpha(alpha) + .setShader(ShaderRegistry.TOUCH_OF_DARKNESS.getInstance()); + + poseStack.pushPose(); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + + setZoom.accept(zoom); + setIntensity.accept(intensity); + builder.draw(poseStack); + + setZoom.accept(zoom * 1.25f + 0.15f); + setIntensity.accept(intensity * 0.8f + 0.5f); + builder.setAlpha(0.5f * alpha).draw(poseStack); + + RenderSystem.disableBlend(); + poseStack.popPose(); + + shaderInstance.setUniformDefaults(); + } +} diff --git a/src/main/java/com/sammy/malum/core/handlers/enchantment/ReplenishingHandler.java b/src/main/java/com/sammy/malum/core/handlers/enchantment/ReplenishingHandler.java index d0f99884f..0da9b0474 100644 --- a/src/main/java/com/sammy/malum/core/handlers/enchantment/ReplenishingHandler.java +++ b/src/main/java/com/sammy/malum/core/handlers/enchantment/ReplenishingHandler.java @@ -42,7 +42,7 @@ public static void triggerReplenishing(DamageSource source, LivingEntity attacke public static void replenishStaffCooldown(AbstractStaffItem staff, Player player, int pLevel) { ItemCooldowns cooldowns = player.getCooldowns(); int ratio = (int) (staff.getCooldownDuration(player.level(), player) * (0.25f * pLevel)); - cooldowns.tickCount += ratio; //TODO: access transform these fellas + cooldowns.tickCount += ratio; for (Map.Entry itemCooldownInstanceEntry : cooldowns.cooldowns.entrySet()) { if (itemCooldownInstanceEntry.getKey().equals(staff)) { continue; diff --git a/src/main/java/com/sammy/malum/core/listeners/SpiritDataReloadListener.java b/src/main/java/com/sammy/malum/core/listeners/SpiritDataReloadListener.java index c7237fd83..80225bfc4 100644 --- a/src/main/java/com/sammy/malum/core/listeners/SpiritDataReloadListener.java +++ b/src/main/java/com/sammy/malum/core/listeners/SpiritDataReloadListener.java @@ -1,11 +1,11 @@ package com.sammy.malum.core.listeners; import com.google.gson.*; +import com.mojang.datafixers.util.*; import com.mojang.serialization.JsonOps; import com.sammy.malum.MalumMod; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.systems.recipe.SpiritIngredient; -import com.sammy.malum.core.systems.spirit.EntitySpiritDropData; +import com.sammy.malum.core.systems.spirit.*; import com.sammy.malum.registry.common.SpiritTypeRegistry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; @@ -64,57 +64,42 @@ protected void apply(Map objectIn, ResourceManage SPIRIT_DATA.clear(); HAS_NO_DATA.clear(); for (JsonElement entry : objectIn.values()) { - JsonObject object = entry.getAsJsonObject(); - String name = object.getAsJsonPrimitive("registry_name").getAsString(); - ResourceLocation resourceLocation = ResourceLocation.tryParse(name); + var object = entry.getAsJsonObject(); + var name = object.getAsJsonPrimitive("registry_name").getAsString(); + var resourceLocation = ResourceLocation.tryParse(name); if (resourceLocation != null && !BuiltInRegistries.ENTITY_TYPE.containsKey(resourceLocation)) { continue; } if (!object.has("primary_type")) { - MalumMod.LOGGER.info("Entity with registry name: " + name + " lacks a primary spirit type. Skipping file."); + MalumMod.LOGGER.warn("Entity with registry name: {} lacks a primary spirit type. This is a datapack error.", name); continue; } - String primaryType = object.getAsJsonPrimitive("primary_type").getAsString(); - boolean isEmpty = primaryType.equals("none"); - if (SPIRIT_DATA.containsKey(resourceLocation)) { - if (isEmpty) - MalumMod.LOGGER.info("Entity with registry name: " + name + " already has spirit data associated with it. Removing."); - else - MalumMod.LOGGER.info("Entity with registry name: " + name + " already has spirit data associated with it. Overwriting."); - } else if (HAS_NO_DATA.contains(resourceLocation) && !isEmpty) { - MalumMod.LOGGER.info("Entity with registry name: " + name + " already has empty spirit data associated with it. Overwriting."); - } + var primaryType = object.getAsJsonPrimitive("primary_type").getAsString(); if (primaryType.equals("none")) { + MalumMod.LOGGER.info("Removed spirit drops for entity with registry name: {}", name); SPIRIT_DATA.remove(resourceLocation); HAS_NO_DATA.add(resourceLocation); } else { + MalumMod.LOGGER.info("Added spirit drops for entity with registry name: {}", name); JsonArray array = object.getAsJsonArray("spirits"); - SPIRIT_DATA.put(resourceLocation, new EntitySpiritDropData(SpiritHarvestHandler.getSpiritType(primaryType), getSpiritData(array), getSpiritItem(object))); + SPIRIT_DATA.put(resourceLocation, new EntitySpiritDropData(MalumSpiritType.getSpiritType(primaryType), getSpiritDrops(array), getItemAsSoul(object))); HAS_NO_DATA.remove(resourceLocation); } } } - private static List getSpiritData(JsonArray array) { + private static List getSpiritDrops(JsonArray array) { List spiritData = new ArrayList<>(); for (JsonElement spiritElement : array) { JsonObject spiritObject = spiritElement.getAsJsonObject(); String spiritName = spiritObject.getAsJsonPrimitive("spirit").getAsString(); int count = spiritObject.getAsJsonPrimitive("count").getAsInt(); - spiritData.add(new SpiritIngredient(SpiritHarvestHandler.getSpiritType(spiritName), count)); + spiritData.add(new SpiritIngredient(MalumSpiritType.getSpiritType(spiritName), count)); } return spiritData; } - private static Ingredient getSpiritItem(JsonObject object) { - if (!object.has("spirit_item")) { - return null; - } - - try { - return Ingredient.CODEC.decode(JsonOps.INSTANCE, object.get("spirit_item")).getOrThrow().getFirst(); - } catch (IllegalStateException ignored) { - return null; - } + private static Ingredient getItemAsSoul(JsonObject object) { + return object.has("spirit_item") ? Ingredient.CODEC.decode(JsonOps.INSTANCE, object.get("spirit_item")).map(Pair::getFirst).result().orElse(null) : null; } } \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/systems/events/ModifySoulWardPropertiesEvent.java b/src/main/java/com/sammy/malum/core/systems/events/ModifySoulWardPropertiesEvent.java index bedfe3a6c..bc25a820d 100644 --- a/src/main/java/com/sammy/malum/core/systems/events/ModifySoulWardPropertiesEvent.java +++ b/src/main/java/com/sammy/malum/core/systems/events/ModifySoulWardPropertiesEvent.java @@ -1,6 +1,6 @@ package com.sammy.malum.core.systems.events; -import com.sammy.malum.core.handlers.*; +import com.sammy.malum.common.capabilities.*; import net.minecraft.world.damagesource.*; import net.minecraft.world.entity.*; @@ -14,8 +14,8 @@ public class ModifySoulWardPropertiesEvent extends SoulWardEvent { private double newMagicDamageAbsorption; private double newSoulWardIntegrity; - public ModifySoulWardPropertiesEvent(LivingEntity entity, SoulWardHandler soulWardHandler, DamageSource source, double physicalDamageAbsorption, double magicDamageAbsorption, double soulWardIntegrity) { - super(entity, soulWardHandler, source); + public ModifySoulWardPropertiesEvent(LivingEntity entity, SoulWardData soulWardData, DamageSource source, double physicalDamageAbsorption, double magicDamageAbsorption, double soulWardIntegrity) { + super(entity, soulWardData, source); this.physicalDamageAbsorption = physicalDamageAbsorption; this.magicDamageAbsorption = magicDamageAbsorption; this.soulWardIntegrity = soulWardIntegrity; diff --git a/src/main/java/com/sammy/malum/core/systems/events/SoulWardDamageEvent.java b/src/main/java/com/sammy/malum/core/systems/events/SoulWardDamageEvent.java index 3dcfe26ad..b59274e3a 100644 --- a/src/main/java/com/sammy/malum/core/systems/events/SoulWardDamageEvent.java +++ b/src/main/java/com/sammy/malum/core/systems/events/SoulWardDamageEvent.java @@ -1,6 +1,6 @@ package com.sammy.malum.core.systems.events; -import com.sammy.malum.core.handlers.*; +import com.sammy.malum.common.capabilities.*; import net.minecraft.world.damagesource.*; import net.minecraft.world.entity.*; @@ -9,8 +9,8 @@ public class SoulWardDamageEvent extends SoulWardEvent { private final double absorbedDamage; private final double soulWardLost; - public SoulWardDamageEvent(LivingEntity entity, SoulWardHandler soulWardHandler, DamageSource source, double absorbedDamage, double soulWardLost) { - super(entity, soulWardHandler, source); + public SoulWardDamageEvent(LivingEntity entity, SoulWardData soulWardData, DamageSource source, double absorbedDamage, double soulWardLost) { + super(entity, soulWardData, source); this.absorbedDamage = absorbedDamage; this.soulWardLost = soulWardLost; } diff --git a/src/main/java/com/sammy/malum/core/systems/events/SoulWardEvent.java b/src/main/java/com/sammy/malum/core/systems/events/SoulWardEvent.java index edca9c057..9f0cf4e37 100644 --- a/src/main/java/com/sammy/malum/core/systems/events/SoulWardEvent.java +++ b/src/main/java/com/sammy/malum/core/systems/events/SoulWardEvent.java @@ -1,23 +1,23 @@ package com.sammy.malum.core.systems.events; -import com.sammy.malum.core.handlers.*; +import com.sammy.malum.common.capabilities.*; import net.minecraft.world.damagesource.*; import net.minecraft.world.entity.*; import net.neoforged.neoforge.event.entity.living.*; public abstract class SoulWardEvent extends LivingEvent { - private final SoulWardHandler soulWardHandler; + private final SoulWardData soulWardData; private final DamageSource source; - public SoulWardEvent(LivingEntity entity, SoulWardHandler soulWardHandler, DamageSource source) { + public SoulWardEvent(LivingEntity entity, SoulWardData soulWardData, DamageSource source) { super(entity); - this.soulWardHandler = soulWardHandler; + this.soulWardData = soulWardData; this.source = source; } - public SoulWardHandler getSoulWardHandler() { - return soulWardHandler; + public SoulWardData getSoulWardHandler() { + return soulWardData; } public DamageSource getSource() { diff --git a/src/main/java/com/sammy/malum/core/systems/spirit/EntitySpiritDropData.java b/src/main/java/com/sammy/malum/core/systems/spirit/EntitySpiritDropData.java index ed96d3372..b88e064e1 100644 --- a/src/main/java/com/sammy/malum/core/systems/spirit/EntitySpiritDropData.java +++ b/src/main/java/com/sammy/malum/core/systems/spirit/EntitySpiritDropData.java @@ -1,11 +1,18 @@ package com.sammy.malum.core.systems.spirit; +import com.sammy.malum.config.*; +import com.sammy.malum.core.listeners.*; import com.sammy.malum.core.systems.recipe.*; import com.sammy.malum.registry.common.*; +import net.minecraft.core.registries.*; +import net.minecraft.resources.*; +import net.minecraft.world.entity.*; +import net.minecraft.world.item.*; import net.minecraft.world.item.crafting.*; import javax.annotation.*; import java.util.*; +import java.util.stream.*; public class EntitySpiritDropData { @@ -15,13 +22,48 @@ public class EntitySpiritDropData { public final int totalSpirits; public final List dataEntries; @Nullable - public final Ingredient spiritItem; + public final Ingredient itemAsSoul; - public EntitySpiritDropData(MalumSpiritType primaryType, List dataEntries, @Nullable Ingredient spiritItem) { + public EntitySpiritDropData(MalumSpiritType primaryType, List dataEntries, @Nullable Ingredient itemAsSoul) { this.primaryType = primaryType; this.totalSpirits = dataEntries.stream().mapToInt(SpiritIngredient::getCount).sum(); this.dataEntries = dataEntries; - this.spiritItem = spiritItem; + this.itemAsSoul = itemAsSoul; + } + + public static List getSpiritStacks(LivingEntity entity) { + return getSpiritData(entity).map(EntitySpiritDropData::getSpiritStacks).orElse(Collections.emptyList()); + } + + public static List getSpiritStacks(EntitySpiritDropData data) { + return data != null ? data.dataEntries.stream().map(SpiritIngredient::getStack).collect(Collectors.toList()) : (Collections.emptyList()); + } + + public static Optional getSpiritData(LivingEntity entity) { + ResourceLocation key = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()); + if (SpiritDataReloadListener.HAS_NO_DATA.contains(key)) + return Optional.empty(); + + EntitySpiritDropData spiritData = SpiritDataReloadListener.SPIRIT_DATA.get(key); + if (spiritData != null) + return Optional.of(spiritData); + + if (!entity.canUsePortal(false)) + return Optional.of(SpiritDataReloadListener.DEFAULT_BOSS_SPIRIT_DATA); + + if (!CommonConfig.USE_DEFAULT_SPIRIT_VALUES.getConfigValue()) + return Optional.empty(); + + return switch (entity.getType().getCategory()) { + case MONSTER -> Optional.of(SpiritDataReloadListener.DEFAULT_MONSTER_SPIRIT_DATA); + case CREATURE -> Optional.of(SpiritDataReloadListener.DEFAULT_CREATURE_SPIRIT_DATA); + case AMBIENT -> Optional.of(SpiritDataReloadListener.DEFAULT_AMBIENT_SPIRIT_DATA); + case AXOLOTLS -> Optional.of(SpiritDataReloadListener.DEFAULT_AXOLOTL_SPIRIT_DATA); + case UNDERGROUND_WATER_CREATURE -> Optional.of(SpiritDataReloadListener.DEFAULT_UNDERGROUND_WATER_CREATURE_SPIRIT_DATA); + case WATER_CREATURE -> Optional.of(SpiritDataReloadListener.DEFAULT_WATER_CREATURE_SPIRIT_DATA); + case WATER_AMBIENT -> Optional.of(SpiritDataReloadListener.DEFAULT_WATER_AMBIENT_SPIRIT_DATA); + default -> Optional.empty(); + }; } public static Builder builder(MalumSpiritType type) { @@ -35,7 +77,7 @@ public static Builder builder(MalumSpiritType type, int count) { public static class Builder { private final MalumSpiritType type; private final List spirits = new ArrayList<>(); - private Ingredient spiritItem = null; + private Ingredient itemAsSoul = null; public Builder(MalumSpiritType type) { this.type = type; @@ -50,13 +92,13 @@ public Builder withSpirit(MalumSpiritType spiritType, int count) { return this; } - public Builder withSpiritItem(Ingredient spiritItem) { - this.spiritItem = spiritItem; + public Builder withItemAsSoul(Ingredient itemAsSoul) { + this.itemAsSoul = itemAsSoul; return this; } public EntitySpiritDropData build() { - return new EntitySpiritDropData(type, spirits, spiritItem); + return new EntitySpiritDropData(type, spirits, itemAsSoul); } } } \ No newline at end of file diff --git a/src/main/java/com/sammy/malum/core/systems/spirit/MalumSpiritType.java b/src/main/java/com/sammy/malum/core/systems/spirit/MalumSpiritType.java index 70d0ed569..14c20e232 100644 --- a/src/main/java/com/sammy/malum/core/systems/spirit/MalumSpiritType.java +++ b/src/main/java/com/sammy/malum/core/systems/spirit/MalumSpiritType.java @@ -53,6 +53,10 @@ public MalumSpiritType(String identifier, SpiritVisualMotif visualMotif, Supplie this.itemColor = itemColor; } + public static MalumSpiritType getSpiritType(String spirit) { + return SpiritTypeRegistry.SPIRITS.getOrDefault(spirit, SpiritTypeRegistry.SACRED_SPIRIT); + } + public String getIdentifier() { return identifier; } diff --git a/src/main/java/com/sammy/malum/registry/common/AttachmentTypeRegistry.java b/src/main/java/com/sammy/malum/registry/common/AttachmentTypeRegistry.java new file mode 100644 index 000000000..6a1949112 --- /dev/null +++ b/src/main/java/com/sammy/malum/registry/common/AttachmentTypeRegistry.java @@ -0,0 +1,42 @@ +package com.sammy.malum.registry.common; + +import com.sammy.malum.*; +import com.sammy.malum.common.capabilities.*; +import com.sammy.malum.common.capabilities.soul_data.*; +import net.neoforged.neoforge.attachment.*; +import net.neoforged.neoforge.registries.*; + +import java.util.function.*; + +public class AttachmentTypeRegistry { + + public static final DeferredRegister> ATTACHMENT_TYPES = DeferredRegister.create(NeoForgeRegistries.ATTACHMENT_TYPES, MalumMod.MALUM); + + public static final Supplier> LIVING_SOUL_INFO = ATTACHMENT_TYPES.register( + "living_soul_info", () -> AttachmentType.builder(LivingSoulData::new).serialize(LivingSoulData.CODEC).build()); + + public static final Supplier> PROJECTILE_SOUL_INFO = ATTACHMENT_TYPES.register( + "projectile_soul_info", () -> AttachmentType.builder(ProjectileSoulData::new).serialize(ProjectileSoulData.CODEC).build()); + + public static final Supplier> CACHED_SPIRIT_DROPS = ATTACHMENT_TYPES.register( + "cached_spirit_drops", () -> AttachmentType.builder(CachedSpiritDropsData::new).serialize(CachedSpiritDropsData.CODEC).build()); + + public static final Supplier> PROGRESSION_DATA = ATTACHMENT_TYPES.register( + "progression_data", () -> AttachmentType.builder(ProgressionData::new).serialize(ProgressionData.CODEC).build()); + + public static final Supplier> CURIO_DATA = ATTACHMENT_TYPES.register( + "curio_data", () -> AttachmentType.builder(CurioData::new).serialize(CurioData.CODEC).build()); + + public static final Supplier> SOUL_WARD = ATTACHMENT_TYPES.register( + "soul_ward", () -> AttachmentType.builder(SoulWardData::new).serialize(SoulWardData.CODEC).build()); + + public static final Supplier> RESERVE_STAFF_CHARGES = ATTACHMENT_TYPES.register( + "reserve_staff_charges", () -> AttachmentType.builder(StaffAbilityData::new).serialize(StaffAbilityData.CODEC).build()); + + public static final Supplier> VOID_INFLUENCE = ATTACHMENT_TYPES.register( + "void_influence", () -> AttachmentType.builder(VoidInfluenceData::new).serialize(VoidInfluenceData.CODEC).build()); + + public static final Supplier> MALIGNANT_INFLUENCE = ATTACHMENT_TYPES.register( + "malignant_influence", () -> AttachmentType.builder(MalignantInfluenceData::new).serialize(MalignantInfluenceData.CODEC).build()); + +} diff --git a/src/main/java/com/sammy/malum/registry/common/DamageTypeRegistry.java b/src/main/java/com/sammy/malum/registry/common/DamageTypeRegistry.java index 8d3181c17..7dadea75a 100644 --- a/src/main/java/com/sammy/malum/registry/common/DamageTypeRegistry.java +++ b/src/main/java/com/sammy/malum/registry/common/DamageTypeRegistry.java @@ -11,6 +11,7 @@ public class DamageTypeRegistry { public static final String SCYTHE_SWEEP_IDENTIFIER = "scythe_sweep"; public static final ResourceKey VOODOO = ResourceKey.create(Registries.DAMAGE_TYPE, MalumMod.malumPath("voodoo")); + public static final ResourceKey VOID = ResourceKey.create(Registries.DAMAGE_TYPE, MalumMod.malumPath("void")); public static final ResourceKey SCYTHE_MELEE = ResourceKey.create(Registries.DAMAGE_TYPE, MalumMod.malumPath("scythe_melee")); public static final ResourceKey SCYTHE_SWEEP = ResourceKey.create(Registries.DAMAGE_TYPE, MalumMod.malumPath("scythe_sweep")); diff --git a/src/main/java/com/sammy/malum/registry/common/PacketRegistry.java b/src/main/java/com/sammy/malum/registry/common/PacketRegistry.java index 41a8c96b3..290acc1d4 100644 --- a/src/main/java/com/sammy/malum/registry/common/PacketRegistry.java +++ b/src/main/java/com/sammy/malum/registry/common/PacketRegistry.java @@ -33,8 +33,7 @@ public static void registerNetworkStuff(RegisterPayloadHandlersEvent event) { MALUM_CHANNEL.playToClient(registrar, "aerial_block_fall_rite_effect", AerialBlockFallRiteEffectPacket.class, AerialBlockFallRiteEffectPacket::new); MALUM_CHANNEL.playToClient(registrar, "spirit_rite_activation", SpiritRiteActivationEffectPacket.class, SpiritRiteActivationEffectPacket::new); - MALUM_CHANNEL.playToClient(registrar, "sync_malum_player_capability", SyncMalumPlayerCapabilityDataPacket.class, SyncMalumPlayerCapabilityDataPacket::new); - MALUM_CHANNEL.playToClient(registrar, "sync_living_capability_data", SyncLivingCapabilityDataPacket.class, SyncLivingCapabilityDataPacket::new); + MALUM_CHANNEL.playToClient(registrar, "sync_soul_ward_data", SyncSoulWardDataPayload.class, SyncSoulWardDataPayload::new); MALUM_CHANNEL.playToClient(registrar, "blight_mist_particle", BlockSparkleParticlePacket.class, BlockSparkleParticlePacket::new); MALUM_CHANNEL.playToClient(registrar, "blight_transformation_item_particle", BlightTransformItemParticlePacket.class, BlightTransformItemParticlePacket::new); diff --git a/src/main/java/com/sammy/malum/registry/common/block/BlockRegistry.java b/src/main/java/com/sammy/malum/registry/common/block/BlockRegistry.java index 88cef66fd..f9565af2f 100644 --- a/src/main/java/com/sammy/malum/registry/common/block/BlockRegistry.java +++ b/src/main/java/com/sammy/malum/registry/common/block/BlockRegistry.java @@ -24,7 +24,7 @@ import com.sammy.malum.common.block.storage.pedestal.*; import com.sammy.malum.common.block.storage.stand.*; import com.sammy.malum.common.block.the_device.*; -import com.sammy.malum.core.handlers.*; +import com.sammy.malum.core.systems.spirit.*; import com.sammy.malum.registry.common.*; import com.sammy.malum.registry.common.item.*; import com.sammy.malum.registry.common.worldgen.*; @@ -490,7 +490,7 @@ public static void setBlockColors(RegisterColorHandlersEvent.Block event) { }, SOULWOOD_LEAVES.get(), BUDDING_SOULWOOD_LEAVES.get(), HANGING_SOULWOOD_LEAVES.get()); blockColors.register((s, l, p, c) -> { - var spiritType = SpiritHarvestHandler.getSpiritType(s.getValue(SpiritMoteBlock.SPIRIT_TYPE)); + var spiritType = MalumSpiritType.getSpiritType(s.getValue(SpiritMoteBlock.SPIRIT_TYPE)); var color = spiritType.getPrimaryColor(); int red = color.getRed(); int green = color.getGreen(); diff --git a/src/main/java/com/sammy/malum/visual_effects/ScreenParticleEffects.java b/src/main/java/com/sammy/malum/visual_effects/ScreenParticleEffects.java index 712aaf951..ff6156496 100644 --- a/src/main/java/com/sammy/malum/visual_effects/ScreenParticleEffects.java +++ b/src/main/java/com/sammy/malum/visual_effects/ScreenParticleEffects.java @@ -1,9 +1,8 @@ package com.sammy.malum.visual_effects; -import com.sammy.malum.common.capability.*; import com.sammy.malum.common.item.*; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.systems.spirit.*; +import com.sammy.malum.registry.common.*; import net.minecraft.client.*; import net.minecraft.client.player.*; import net.minecraft.util.*; @@ -158,13 +157,12 @@ public float getVoidParticleIntensity() { @Override public void spawnEarlyParticles(ScreenParticleHolder target, Level level, float partialTick, ItemStack stack, float x, float y) { final LocalPlayer player = Minecraft.getInstance().player; - final TouchOfDarknessHandler handler = MalumLivingEntityDataCapability.getCapability(player).touchOfDarknessHandler; - isNearWell = handler.isNearWeepingWell; + isNearWell = player.getData(AttachmentTypeRegistry.VOID_INFLUENCE).isNearWeepingWell; if (!isNearWell) { return; } if (level.getGameTime() % 20L == 0) { - isItemReal = Minecraft.getInstance().player.getInventory().contains(stack); + isItemReal = player.getInventory().contains(stack); } if (isItemReal) { IVoidItem.super.spawnEarlyParticles(target, level, partialTick, stack, x, y); diff --git a/src/main/java/com/sammy/malum/visual_effects/networked/data/ColorEffectData.java b/src/main/java/com/sammy/malum/visual_effects/networked/data/ColorEffectData.java index a22d6afa7..5701ee893 100644 --- a/src/main/java/com/sammy/malum/visual_effects/networked/data/ColorEffectData.java +++ b/src/main/java/com/sammy/malum/visual_effects/networked/data/ColorEffectData.java @@ -1,7 +1,6 @@ package com.sammy.malum.visual_effects.networked.data; import com.sammy.malum.MalumMod; -import com.sammy.malum.core.handlers.*; import com.sammy.malum.core.systems.recipe.SpiritIngredient; import com.sammy.malum.core.systems.spirit.MalumSpiritType; import net.minecraft.network.FriendlyByteBuf; @@ -62,7 +61,7 @@ public ColorEffectData(FriendlyByteBuf buf) { colorRecordList.add(new ColorRecord( new Color(buf.readInt()), new Color(buf.readInt()), - buf.readBoolean() ? SpiritHarvestHandler.getSpiritType(buf.readUtf()) : null + buf.readBoolean() ? MalumSpiritType.getSpiritType(buf.readUtf()) : null )); } }