Skip to content

Commit

Permalink
Read CHANGES.md
Browse files Browse the repository at this point in the history
  • Loading branch information
RadonCoding committed Apr 3, 2024
1 parent d2e696c commit c0170e7
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 179 deletions.
37 changes: 16 additions & 21 deletions src/main/java/radon/jujutsu_kaisen/ExperienceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,20 @@ public UUID getTargetUUID() {
return targetUUID;
}

private static float calculateStrength(LivingEntity entity) {
float strength = entity.getMaxHealth() * 0.1F;
private static float calculateStrength(LivingEntity target) {
float strength = target.getMaxHealth() * 0.1F;

AttributeMap attributes = entity.getAttributes();
AttributeMap attributes = target.getAttributes();

if (attributes.hasAttribute(Attributes.ARMOR_TOUGHNESS)) {
float armor = (float) entity.getArmorValue();
float toughness = (float) entity.getAttributeValue(Attributes.ARMOR_TOUGHNESS);
float armor = (float) target.getArmorValue();
float toughness = (float) target.getAttributeValue(Attributes.ARMOR_TOUGHNESS);
float f = 2.0F + toughness / 4.0F;
float f1 = Mth.clamp(armor - strength / f, armor * 0.2F, 20.0F);
strength /= 1.0F - f1 / 25.0F;
}

MobEffectInstance instance = entity.getEffect(MobEffects.DAMAGE_RESISTANCE);
MobEffectInstance instance = target.getEffect(MobEffects.DAMAGE_RESISTANCE);

if (instance != null) {
int resistance = instance.getAmplifier();
Expand All @@ -179,30 +179,25 @@ private static float calculateStrength(LivingEntity entity) {
}
}

int k = EnchantmentHelper.getDamageProtection(entity.getArmorSlots(), entity.damageSources().generic());
int k = EnchantmentHelper.getDamageProtection(target.getArmorSlots(), target.damageSources().generic());

if (k > 0) {
float f2 = Mth.clamp(k, 0.0F, 20.0F);
strength /= 1.0F - f2 / 25.0F;
}

if (attributes.hasAttribute(Attributes.ATTACK_DAMAGE)) {
strength += (float) entity.getAttributeValue(Attributes.ATTACK_DAMAGE);
}
if (attributes.hasAttribute(Attributes.MOVEMENT_SPEED)) {
strength += (float) entity.getAttributeValue(Attributes.MOVEMENT_SPEED);
}

if (entity instanceof PackCursedSpirit pack) {
if (target instanceof PackCursedSpirit pack) {
strength += pack.getMinCount() + ((float) (pack.getMaxCount() - pack.getMinCount()) / 2);
}

IJujutsuCapability cap = entity.getCapability(JujutsuCapabilityHandler.INSTANCE);
IJujutsuCapability cap = target.getCapability(JujutsuCapabilityHandler.INSTANCE);

if (cap != null) {
// Increase from target's experience
ISorcererData data = cap.getSorcererData();
strength += data.getExperience() * 0.01F;

// Increase if the target can heal
if (data.getType() == JujutsuType.CURSE || data.isUnlocked(JJKAbilities.RCT1.get())) {
strength *= 1.25F;
}
Expand All @@ -215,26 +210,26 @@ public void end(ServerLevel level) {
if (owner.isRemoved() || owner.isDeadOrDying() || target.isRemoved()) return;
if (this.damageDealtByOwner == 0.0F) return;

IJujutsuCapability cap = owner.getCapability(JujutsuCapabilityHandler.INSTANCE);
IJujutsuCapability ownerCap = owner.getCapability(JujutsuCapabilityHandler.INSTANCE);

if (cap == null) return;
if (ownerCap == null) return;

ISorcererData data = cap.getSorcererData();
ISorcererData ownerData = ownerCap.getSorcererData();

float experience = calculateStrength(target)
* (this.damageDealtByOwner / this.totalDamageDealt)
* ConfigHolder.SERVER.experienceMultiplier.get().floatValue();

if (experience < 0.1F) return;

if (data.addExperience(experience)) {
if (ownerData.addExperience(experience)) {
if (owner instanceof Player player) {
player.sendSystemMessage(Component.translatable(String.format("chat.%s.experience", JujutsuKaisen.MOD_ID), experience));
}
}

if (owner instanceof ServerPlayer player) {
PacketHandler.sendToClient(new SyncSorcererDataS2CPacket(data.serializeNBT()), player);
PacketHandler.sendToClient(new SyncSorcererDataS2CPacket(ownerData.serializeNBT()), player);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
import radon.jujutsu_kaisen.block.entity.CurseSpawnerBlockEntity;
import radon.jujutsu_kaisen.block.entity.JJKBlockEntities;
import radon.jujutsu_kaisen.data.JJKAttachmentTypes;
import radon.jujutsu_kaisen.data.mission.IMissionData;
import radon.jujutsu_kaisen.data.mission.level.IMissionLevelData;
import radon.jujutsu_kaisen.data.mission.Mission;
import radon.jujutsu_kaisen.entity.curse.base.CursedSpirit;
import radon.jujutsu_kaisen.tags.JJKEntityTypeTags;
import radon.jujutsu_kaisen.util.HelperMethods;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -38,7 +37,7 @@ public CurseSpawnerBlock(Properties pProperties) {

@Override
public void tick(@NotNull BlockState pState, @NotNull ServerLevel pLevel, @NotNull BlockPos pPos, @NotNull RandomSource pRandom) {
IMissionData data = pLevel.getData(JJKAttachmentTypes.MISSION);
IMissionLevelData data = pLevel.getData(JJKAttachmentTypes.MISSION_LEVEL);

if (!(pLevel.getBlockEntity(pPos) instanceof CurseSpawnerBlockEntity be)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.neoforged.neoforge.client.gui.widget.ExtendedSlider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import radon.jujutsu_kaisen.JujutsuKaisen;
import radon.jujutsu_kaisen.client.gui.screen.widget.ScrollableSlider;
import radon.jujutsu_kaisen.client.gui.screen.widget.VerticalSlider;
import radon.jujutsu_kaisen.data.JJKAttachmentTypes;
import radon.jujutsu_kaisen.data.mission.IMissionData;
import radon.jujutsu_kaisen.data.mission.level.IMissionLevelData;
import radon.jujutsu_kaisen.data.mission.Mission;
import radon.jujutsu_kaisen.data.mission.MissionGrade;
import radon.jujutsu_kaisen.network.PacketHandler;
Expand Down Expand Up @@ -71,7 +70,7 @@ public void refresh() {

this.cards.clear();

IMissionData data = this.minecraft.level.getData(JJKAttachmentTypes.MISSION);
IMissionLevelData data = this.minecraft.level.getData(JJKAttachmentTypes.MISSION_LEVEL);

Set<Mission> missions = data.getMissions();

Expand Down Expand Up @@ -193,7 +192,7 @@ protected void init() {

this.cards.clear();

IMissionData data = this.minecraft.level.getData(JJKAttachmentTypes.MISSION);
IMissionLevelData data = this.minecraft.level.getData(JJKAttachmentTypes.MISSION_LEVEL);

Set<Mission> missions = data.getMissions();

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/radon/jujutsu_kaisen/data/DataProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import radon.jujutsu_kaisen.data.ability.IAbilityData;
import radon.jujutsu_kaisen.data.capability.IJujutsuCapability;
import radon.jujutsu_kaisen.data.capability.JujutsuCapabilityHandler;
import radon.jujutsu_kaisen.data.mission.IMissionData;
import radon.jujutsu_kaisen.data.mission.level.IMissionLevelData;
import radon.jujutsu_kaisen.data.projection_sorcery.IProjectionSorceryData;
import radon.jujutsu_kaisen.data.sorcerer.ISorcererData;
import radon.jujutsu_kaisen.data.ten_shadows.ITenShadowsData;
Expand Down Expand Up @@ -42,13 +42,14 @@ public static void onLivingTick(LivingEvent.LivingTickEvent event) {
cap.getIdleTransfigurationData().tick();
cap.getMimicryData().tick();
cap.getCursedSpeechData().tick();
cap.getMissionData().tick();
}

@SubscribeEvent
public static void onLevelTick(TickEvent.LevelTickEvent event) {
if (event.phase == TickEvent.Phase.START) return;

IMissionData data = event.level.getData(JJKAttachmentTypes.MISSION);
IMissionLevelData data = event.level.getData(JJKAttachmentTypes.MISSION_LEVEL);
data.tick();
}

Expand Down Expand Up @@ -109,9 +110,10 @@ public static void onPlayerChangeDimension(PlayerEvent.PlayerChangedDimensionEve
PacketHandler.sendToClient(new SyncMimicryDataS2CPacket(cap.getMimicryData().serializeNBT()), player);
PacketHandler.sendToClient(new SyncCursedSpeechDataS2CPacket(cap.getCursedSpeechData().serializeNBT()), player);
PacketHandler.sendToClient(new SyncSkillDataSC2Packet(cap.getSkillData().serializeNBT()), player);
PacketHandler.sendToClient(new SyncMissionEntityDataS2CPacket(cap.getMissionData().serializeNBT()), player);

IMissionData data = player.level().getData(JJKAttachmentTypes.MISSION);
PacketHandler.broadcast(new SyncMissionDataS2CPacket(player.level().dimension(), data.serializeNBT()));
IMissionLevelData data = player.level().getData(JJKAttachmentTypes.MISSION_LEVEL);
PacketHandler.broadcast(new SyncMissionLevelDataS2CPacket(player.level().dimension(), data.serializeNBT()));
}

@SubscribeEvent
Expand All @@ -133,9 +135,10 @@ public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
PacketHandler.sendToClient(new SyncMimicryDataS2CPacket(cap.getMimicryData().serializeNBT()), player);
PacketHandler.sendToClient(new SyncCursedSpeechDataS2CPacket(cap.getCursedSpeechData().serializeNBT()), player);
PacketHandler.sendToClient(new SyncSkillDataSC2Packet(cap.getSkillData().serializeNBT()), player);
PacketHandler.sendToClient(new SyncMissionEntityDataS2CPacket(cap.getMissionData().serializeNBT()), player);

IMissionData data = player.level().getData(JJKAttachmentTypes.MISSION);
PacketHandler.broadcast(new SyncMissionDataS2CPacket(player.level().dimension(), data.serializeNBT()));
IMissionLevelData data = player.level().getData(JJKAttachmentTypes.MISSION_LEVEL);
PacketHandler.broadcast(new SyncMissionLevelDataS2CPacket(player.level().dimension(), data.serializeNBT()));
}

@SubscribeEvent
Expand All @@ -157,5 +160,6 @@ public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
PacketHandler.sendToClient(new SyncMimicryDataS2CPacket(cap.getMimicryData().serializeNBT()), player);
PacketHandler.sendToClient(new SyncCursedSpeechDataS2CPacket(cap.getCursedSpeechData().serializeNBT()), player);
PacketHandler.sendToClient(new SyncSkillDataSC2Packet(cap.getSkillData().serializeNBT()), player);
PacketHandler.sendToClient(new SyncMissionEntityDataS2CPacket(cap.getMissionData().serializeNBT()), player);
}
}
15 changes: 10 additions & 5 deletions src/main/java/radon/jujutsu_kaisen/data/JJKAttachmentTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
import radon.jujutsu_kaisen.data.mimicry.IMimicryData;
import radon.jujutsu_kaisen.data.mimicry.MimicryData;
import radon.jujutsu_kaisen.data.mimicry.MimicryDataSerializer;
import radon.jujutsu_kaisen.data.mission.IMissionData;
import radon.jujutsu_kaisen.data.mission.MissionData;
import radon.jujutsu_kaisen.data.mission.MissionDataSerializer;
import radon.jujutsu_kaisen.data.mission.entity.IMissionEntityData;
import radon.jujutsu_kaisen.data.mission.entity.MissionEntityData;
import radon.jujutsu_kaisen.data.mission.entity.MissionEntityDataSerializer;
import radon.jujutsu_kaisen.data.mission.level.IMissionLevelData;
import radon.jujutsu_kaisen.data.mission.level.MissionLevelData;
import radon.jujutsu_kaisen.data.mission.level.MissionLevelDataSerializer;
import radon.jujutsu_kaisen.data.projection_sorcery.IProjectionSorceryData;
import radon.jujutsu_kaisen.data.projection_sorcery.ProjectionSorcereryDataSerializer;
import radon.jujutsu_kaisen.data.projection_sorcery.ProjectionSorceryData;
Expand Down Expand Up @@ -71,6 +74,8 @@ public class JJKAttachmentTypes {
public static final Supplier<AttachmentType<ISkillData>> SKILL = ATTACHMENT_TYPES.register("skill",
AttachmentType.<ISkillData>builder(holder -> new SkillData()).serialize(new SkillDataSerializer()).copyOnDeath()::build);

public static final Supplier<AttachmentType<IMissionData>> MISSION = ATTACHMENT_TYPES.register("mission",
AttachmentType.<IMissionData>builder(holder -> new MissionData((Level) holder)).serialize(new MissionDataSerializer())::build);
public static final Supplier<AttachmentType<IMissionLevelData>> MISSION_LEVEL = ATTACHMENT_TYPES.register("mission_level",
AttachmentType.<IMissionLevelData>builder(holder -> new MissionLevelData((Level) holder)).serialize(new MissionLevelDataSerializer())::build);
public static final Supplier<AttachmentType<IMissionEntityData>> MISSION_ENTITY = ATTACHMENT_TYPES.register("mission_entity",
AttachmentType.<IMissionEntityData>builder(holder -> new MissionEntityData((LivingEntity) holder)).serialize(new MissionEntityDataSerializer()).copyOnDeath()::build);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import radon.jujutsu_kaisen.data.cursed_speech.ICursedSpeechData;
import radon.jujutsu_kaisen.data.idle_transfiguration.IIdleTransfigurationData;
import radon.jujutsu_kaisen.data.mimicry.IMimicryData;
import radon.jujutsu_kaisen.data.mission.entity.IMissionEntityData;
import radon.jujutsu_kaisen.data.projection_sorcery.IProjectionSorceryData;
import radon.jujutsu_kaisen.data.sorcerer.ISorcererData;
import radon.jujutsu_kaisen.data.stat.ISkillData;
Expand Down Expand Up @@ -34,4 +35,6 @@ public interface IJujutsuCapability {
ICursedSpeechData getCursedSpeechData();

ISkillData getSkillData();

IMissionEntityData getMissionData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import radon.jujutsu_kaisen.data.cursed_speech.ICursedSpeechData;
import radon.jujutsu_kaisen.data.idle_transfiguration.IIdleTransfigurationData;
import radon.jujutsu_kaisen.data.mimicry.IMimicryData;
import radon.jujutsu_kaisen.data.mission.entity.IMissionEntityData;
import radon.jujutsu_kaisen.data.projection_sorcery.IProjectionSorceryData;
import radon.jujutsu_kaisen.data.sorcerer.ISorcererData;
import radon.jujutsu_kaisen.data.stat.ISkillData;
Expand Down Expand Up @@ -75,4 +76,9 @@ public ICursedSpeechData getCursedSpeechData() {
public ISkillData getSkillData() {
return this.owner.getData(JJKAttachmentTypes.SKILL);
}

@Override
public IMissionEntityData getMissionData() {
return this.owner.getData(JJKAttachmentTypes.MISSION_ENTITY);
}
}
11 changes: 0 additions & 11 deletions src/main/java/radon/jujutsu_kaisen/data/mission/Mission.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Set;

public class Mission {
private boolean finalized;
private final MissionType type;
private final MissionGrade grade;
private final BlockPos pos;
Expand All @@ -29,20 +28,11 @@ public Mission(MissionType type, MissionGrade grade, BlockPos pos) {
}

public Mission(CompoundTag nbt) {
this.finalized = nbt.getBoolean("finalized");
this.type = MissionType.values()[nbt.getInt("type")];
this.grade = MissionGrade.values()[nbt.getInt("grade")];
this.pos = NbtUtils.readBlockPos(nbt.getCompound("pos"));
}

public boolean isFinalized() {
return this.finalized;
}

public void setFinalized(boolean finalized) {
this.finalized = finalized;
}

public MissionType getType() {
return this.type;
}
Expand All @@ -57,7 +47,6 @@ public BlockPos getPos() {

public CompoundTag serializeNBT() {
CompoundTag nbt = new CompoundTag();
nbt.putBoolean("finalized", this.finalized);
nbt.putInt("type", this.type.ordinal());
nbt.putInt("grade", this.grade.ordinal());
nbt.put("pos", NbtUtils.writeBlockPos(this.pos));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package radon.jujutsu_kaisen.data.mission.entity;

import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.neoforged.neoforge.common.util.INBTSerializable;
import org.jetbrains.annotations.Nullable;
import radon.jujutsu_kaisen.data.mission.Mission;
import radon.jujutsu_kaisen.data.mission.MissionGrade;
import radon.jujutsu_kaisen.data.mission.MissionType;

import java.util.Set;

public interface IMissionEntityData extends INBTSerializable<CompoundTag> {
void tick();

void setMission(@Nullable Mission mission);

@Nullable Mission getMission();
}
Loading

0 comments on commit c0170e7

Please sign in to comment.