This commit is contained in:
LZX committed 2026-07-25 23:26:05 +08:00
1 parent 426cb569f1
commit 4e8170051e
64 files changed
+797 -79

No files matched your search

@@ -0,0 +1,19 @@
package com.lzxnone.terraria.damage;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.damagesource.DamageType;
public class ModDamageTypes {
public static final ResourceKey<DamageType> PLAYER_NORMAL_ATTACK = create("player_normal_attack");
public static final ResourceKey<DamageType> PLAYER_REAL_ATTACK = create("player_real_attack");
private static ResourceKey<DamageType> create(String name) {
return ResourceKey.create(
Registries.DAMAGE_TYPE,
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, name)
);
}
}
@@ -0,0 +1,22 @@
package com.lzxnone.terraria.enchantment;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.enchantment.Enchantment;
public class ModEnchantments {
public static final ResourceKey<Enchantment> MANA_LEAK = create("mana_leak");
public static final ResourceKey<Enchantment> MANA_EFFICIENCY = create("mana_efficiency");
public static final ResourceKey<Enchantment> MANA_GATHERING = create("mana_gathering");
public static final ResourceKey<Enchantment> MANA_GATHERING_CURSE = create("mana_gathering_curse");
public static final ResourceKey<Enchantment> ARCANE_AMPLIFICATION = create("arcane_amplification");
private static ResourceKey<Enchantment> create(String name) {
return ResourceKey.create(
Registries.ENCHANTMENT,
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, name)
);
}
}
@@ -124,7 +124,7 @@ public class BeeSummon extends Bee {
if(owner == null) return false;
boolean isHurt;
if(owner instanceof Player player) {
isHurt = DamageUtil.attack(player, target, (float) BeeKeeper.getBeeDamage());
isHurt = DamageUtil.normalAttack(this, target, (float) BeeKeeper.getBeeDamage(), 1.0f);
}else {
DamageSource damageSource = this.damageSources().mobAttack(owner);
isHurt = target.hurt(damageSource, (float) BeeKeeper.getBeeDamage());
@@ -0,0 +1,177 @@
package com.lzxnone.terraria.item.weapon;
import com.lzxnone.terraria.enchantment.ModEnchantments;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import java.util.function.IntSupplier;
public class MagicWeapon extends Item {
private static final String MANA_CONSUME_PROGRESS_KEY = "magicManaConsumeProgress";
private static final String MANA_RECOVER_PROGRESS_KEY = "magicManaRecoverProgress";
private static final double MANA_LEAK_CONSUME_MULTIPLIER = 1.25D;
private static final double MANA_EFFICIENCY_CONSUME_MULTIPLIER = 0.85D;
private static final double MANA_GATHERING_RECOVER_MULTIPLIER = 1.25D;
private static final double MANA_GATHERING_CURSE_RECOVER_MULTIPLIER = 0.5D;
private static final double ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER = 1.15D;
private final int enchantmentValue;
private final IntSupplier manaConsumeRate;
private final IntSupplier manaRecoverRate;
public MagicWeapon(Tier tier, Properties properties, int manaConsumeRate, int manaRecoverRate) {
this(tier, properties, () -> manaConsumeRate, () -> manaRecoverRate);
}
public MagicWeapon(Tier tier, Properties properties, IntSupplier manaConsumeRate, IntSupplier manaRecoverRate) {
super(properties.durability(tier.getUses()));
this.enchantmentValue = tier.getEnchantmentValue();
this.manaConsumeRate = manaConsumeRate;
this.manaRecoverRate = manaRecoverRate;
}
public MagicWeapon(Properties properties) {
super(properties);
this.enchantmentValue = 0;
this.manaConsumeRate = () -> 1;
this.manaRecoverRate = () -> 1;
}
@Override
public void onUseTick(Level level, LivingEntity entity, ItemStack stack, int count) {
if(!canUseMagic(stack, entity)) {
entity.stopUsingItem();
return;
}
if(!level.isClientSide()) {
if(!tryConsumeMana(level, entity, stack, getFinalManaConsumeRate(stack, entity))) {
entity.stopUsingItem();
return;
}
}
onMagicUseTick(level, entity, stack, count);
}
@Override
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
super.inventoryTick(stack, level, entity, slotId, isSelected);
if(level.isClientSide() || !(entity instanceof LivingEntity livingEntity)) return;
if(livingEntity.getUseItem() == stack) return;
recoverMana(stack, getFinalManaRecoverRate(stack, livingEntity));
}
protected void onMagicUseTick(Level level, LivingEntity entity, ItemStack stack, int count) {
}
protected int getManaConsumeRate(ItemStack stack, LivingEntity entity) {
return Math.max(0, manaConsumeRate.getAsInt());
}
protected int getManaRecoverRate(ItemStack stack, LivingEntity entity) {
return Math.max(0, manaRecoverRate.getAsInt());
}
protected double getFinalManaConsumeRate(ItemStack stack, LivingEntity entity) {
double rate = getManaConsumeRate(stack, entity);
int leakLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_LEAK);
int efficiencyLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_EFFICIENCY);
rate *= Math.pow(MANA_LEAK_CONSUME_MULTIPLIER, leakLevel);
rate *= Math.pow(MANA_EFFICIENCY_CONSUME_MULTIPLIER, efficiencyLevel);
return Math.max(0.0D, rate);
}
protected double getFinalManaRecoverRate(ItemStack stack, LivingEntity entity) {
double rate = getManaRecoverRate(stack, entity);
int gatheringLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_GATHERING);
int curseLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_GATHERING_CURSE);
rate *= Math.pow(MANA_GATHERING_RECOVER_MULTIPLIER, gatheringLevel);
rate *= Math.pow(MANA_GATHERING_CURSE_RECOVER_MULTIPLIER, curseLevel);
return Math.max(0.0D, rate);
}
public static float applyMagicDamageBonus(ItemStack stack, LivingEntity entity, float damage) {
double finalDamage = damage;
int amplificationLevel = getEnchantmentLevel(entity, stack, ModEnchantments.ARCANE_AMPLIFICATION);
finalDamage *= Math.pow(ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER, amplificationLevel);
return (float) Math.max(0.0D, finalDamage);
}
protected boolean canUseMagic(ItemStack stack, LivingEntity entity) {
return !isManaEmpty(stack);
}
protected boolean isManaEmpty(ItemStack stack) {
return stack.isDamageableItem() && stack.getDamageValue() >= stack.getMaxDamage();
}
protected boolean tryConsumeMana(Level level, LivingEntity entity, ItemStack stack, double amount) {
if(amount <= 0.0D || entity.hasInfiniteMaterials()) return true;
if(!stack.isDamageableItem() || isManaEmpty(stack)) return false;
int pendingDamage = addManaProgress(stack, MANA_CONSUME_PROGRESS_KEY, amount);
if(pendingDamage <= 0) return true;
int damage = pendingDamage;
if(level instanceof ServerLevel serverLevel) {
damage = EnchantmentHelper.processDurabilityChange(serverLevel, stack, damage);
}
if(damage <= 0) return true;
int nextDamage = Math.min(stack.getDamageValue() + damage, stack.getMaxDamage());
stack.setDamageValue(nextDamage);
return nextDamage < stack.getMaxDamage();
}
protected void recoverMana(ItemStack stack, double amount) {
if(amount <= 0.0D || !stack.isDamageableItem() || stack.getDamageValue() <= 0) return;
int recoverAmount = addManaProgress(stack, MANA_RECOVER_PROGRESS_KEY, amount);
if(recoverAmount <= 0) return;
stack.setDamageValue(Math.max(0, stack.getDamageValue() - recoverAmount));
}
private int addManaProgress(ItemStack stack, String key, double amount) {
double progress = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
.copyTag()
.getDouble(key) + amount;
int wholeAmount = (int) Math.floor(progress);
double nextProgress = progress - wholeAmount;
CustomData.update(DataComponents.CUSTOM_DATA, stack, tag -> tag.putDouble(key, nextProgress));
return wholeAmount;
}
private static int getEnchantmentLevel(LivingEntity entity, ItemStack stack, ResourceKey<Enchantment> enchantment) {
return entity.registryAccess()
.lookupOrThrow(Registries.ENCHANTMENT)
.get(enchantment)
.map(stack::getEnchantmentLevel)
.orElse(0);
}
@Override
public boolean isEnchantable(ItemStack stack) {
return stack.getMaxStackSize() == 1;
}
@Override
public int getEnchantmentValue(ItemStack stack) {
return enchantmentValue;
}
}
@@ -0,0 +1,31 @@
package com.lzxnone.terraria.item.weapon;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
public class MeleeWeapon extends Item {
private final int enchantmentValue;
public MeleeWeapon(Tier tier, Properties properties) {
super(properties.durability(tier.getUses()));
this.enchantmentValue = tier.getEnchantmentValue();
}
public MeleeWeapon(Properties properties) {
super(properties);
this.enchantmentValue = 0;
}
@Override
public boolean isEnchantable(ItemStack stack) {
return stack.getMaxStackSize() == 1;
}
@Override
public int getEnchantmentValue(ItemStack stack) {
return enchantmentValue;
}
}
@@ -0,0 +1,4 @@
package com.lzxnone.terraria.item.weapon;
public class RangedWeapon {
}
@@ -0,0 +1,4 @@
package com.lzxnone.terraria.item.weapon;
public class SummonWeapon {
}
@@ -8,6 +8,7 @@ import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior;
import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.item.weapon.MagicWeapon;
import com.lzxnone.terraria.item.weapon.melee.Mace;
import com.lzxnone.terraria.particle.DustParticleOptions;
import com.lzxnone.terraria.ui.config.ConfigFactory;
@@ -38,6 +39,7 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
@@ -53,11 +55,11 @@ import org.jspecify.annotations.NonNull;
import java.util.List;
import java.util.Optional;
public class LastPrism extends Item {
public class LastPrism extends MagicWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String DAMAGE_PATH = "weapon.last_prism.damage";
public static final float DAMAGE_DEFAULT = 100.0f;
public static final float DAMAGE_DEFAULT = 1.0f;
public static final float DAMAGE_MIN = 0.0f;
public static final float DAMAGE_MAX = 8388600.0f;
@@ -67,7 +69,7 @@ public class LastPrism extends Item {
public static final int CHARGE_TIME_MAX = 72000;
public static final String MAX_USE_TIME_PATH = "weapon.last_prism.max_use_time";
public static final int MAX_USE_TIME_DEFAULT = 60 * 20;
public static final int MAX_USE_TIME_DEFAULT = 1200;
public static final int MAX_USE_TIME_MIN = 1;
public static final int MAX_USE_TIME_MAX = 72000;
@@ -76,8 +78,23 @@ public class LastPrism extends Item {
public static final double MAX_RANGE_MIN = 1.0;
public static final double MAX_RANGE_MAX = 512.0;
public static final String MANA_CONSUME_RATE_PATH = "weapon.last_prism.mana_consume_rate";
public static final int MANA_CONSUME_RATE_DEFAULT = 20;
public static final int MANA_CONSUME_RATE_MIN = 0;
public static final int MANA_CONSUME_RATE_MAX = 72000;
public static final String MANA_RECOVER_RATE_PATH = "weapon.last_prism.mana_recover_rate";
public static final int MANA_RECOVER_RATE_DEFAULT = 20;
public static final int MANA_RECOVER_RATE_MIN = 0;
public static final int MANA_RECOVER_RATE_MAX = 72000;
public LastPrism() {
super(new Properties().stacksTo(1).rarity(Rarity.EPIC));
super(
Tiers.NETHERITE,
new Item.Properties().stacksTo(1).fireResistant().rarity(Rarity.EPIC),
LastPrism::getManaConsumeRate,
LastPrism::getManaRecoverRate
);
}
public static final IConfigData CONFIG_DATA = new IConfigData() {
@@ -87,6 +104,8 @@ public class LastPrism extends Item {
ConfigFactory.loadIntConfig(CHARGE_TIME_PATH, configText("last_prism_charge_time"), configTooltip("last_prism_charge_time"), CHARGE_TIME_DEFAULT, CHARGE_TIME_MIN, CHARGE_TIME_MAX);
ConfigFactory.loadIntConfig(MAX_USE_TIME_PATH, configText("last_prism_max_use_time"), configTooltip("last_prism_max_use_time"), MAX_USE_TIME_DEFAULT, MAX_USE_TIME_MIN, MAX_USE_TIME_MAX);
ConfigFactory.loadDoubleConfig(MAX_RANGE_PATH, configText("last_prism_max_range"), configTooltip("last_prism_max_range"), MAX_RANGE_DEFAULT, MAX_RANGE_MIN, MAX_RANGE_MAX);
ConfigFactory.loadIntConfig(MANA_CONSUME_RATE_PATH, configText("last_prism_mana_consume_rate"), configTooltip("last_prism_mana_consume_rate"), MANA_CONSUME_RATE_DEFAULT, MANA_CONSUME_RATE_MIN, MANA_CONSUME_RATE_MAX);
ConfigFactory.loadIntConfig(MANA_RECOVER_RATE_PATH, configText("last_prism_mana_recover_rate"), configTooltip("last_prism_mana_recover_rate"), MANA_RECOVER_RATE_DEFAULT, MANA_RECOVER_RATE_MIN, MANA_RECOVER_RATE_MAX);
}
};
@@ -114,6 +133,14 @@ public class LastPrism extends Item {
return Math.clamp(ConfigUtil.readDouble(MAX_RANGE_PATH, MAX_RANGE_DEFAULT), MAX_RANGE_MIN, MAX_RANGE_MAX);
}
public static int getManaConsumeRate() {
return Math.clamp(ConfigUtil.readInt(MANA_CONSUME_RATE_PATH, MANA_CONSUME_RATE_DEFAULT), MANA_CONSUME_RATE_MIN, MANA_CONSUME_RATE_MAX);
}
public static int getManaRecoverRate() {
return Math.clamp(ConfigUtil.readInt(MANA_RECOVER_RATE_PATH, MANA_RECOVER_RATE_DEFAULT), MANA_RECOVER_RATE_MIN, MANA_RECOVER_RATE_MAX);
}
public static final ConfigListItem CONFIG_LIST_ITEM = new ConfigListItem(
"last_prism",
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "textures/item/last_prism.png"),
@@ -288,7 +315,8 @@ public class LastPrism extends Item {
AABB entityBox = hitEntity.getBoundingBox().inflate(beamData.radius());
Optional<Vec3> clipResult = entityBox.clip(beamData.start(), beamData.end());
if(entityBox.contains(beamData.start()) || clipResult.isPresent()) {
if(DamageUtil.attack(player, hitEntity, getDamage() * beamData.ratio())) {
float damage = MagicWeapon.applyMagicDamageBonus(stack, player, getDamage() * beamData.ratio());
if(DamageUtil.normalAttack(beam, hitEntity, damage, 0.1f)) {
hitEntity.invulnerableTime = 5;
}
}
@@ -365,6 +393,8 @@ public class LastPrism extends Item {
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
if(!canUseMagic(stack, player)) return InteractionResultHolder.fail(stack);
if(stack.is(ModItems.LAST_PRISM.get()) && !player.level().isClientSide()) {
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
@@ -422,17 +452,16 @@ public class LastPrism extends Item {
}
@Override
public void onUseTick(Level level, LivingEntity livingEntity, ItemStack stack, int count) {
protected void onMagicUseTick(Level level, LivingEntity livingEntity, ItemStack stack, int count) {
if(!(livingEntity instanceof Player player)) return;
if(level.isClientSide()) return;
if(player.tickCount % 20 == 0) {
if(player.tickCount % 10 == 0) {
SoundUtil.playClientSound(player, ModSounds.BEAM2.get());
}
}
@Override
public int getUseDuration(ItemStack stack, LivingEntity entity) {
return getMaxUseTime();
return 72000;
}
private static void renderTetrahedronFace(
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.entity.ModEntities;
@@ -22,13 +23,12 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
public class BeeKeeper extends SwordItem {
public class BeeKeeper extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String MAX_BEES_PATH = "weapon.bee_keeper.max_bees";
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.effect.ModEffects;
@@ -37,7 +38,6 @@ import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.ItemAttributeModifiers;
@@ -58,7 +58,7 @@ import net.minecraft.network.chat.Component;
import java.util.Comparator;
import java.util.List;
public class BladeOfGrass extends SwordItem {
public class BladeOfGrass extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String PROJECTILE_DAMAGE_PATH = "weapon.blade_of_grass.projectile_damage";
@@ -243,7 +243,7 @@ public class BladeOfGrass extends SwordItem {
CompoundTag customData = projectile.getEntityData().get(StaticProjectile.CUSTOM_DATA);
if(!customData.contains("hitCount") || customData.getInt("hitCount") >= getProjectileMaxHitCount()) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.attack(player, target, (float) getProjectileDamage())) {
if(DamageUtil.normalAttack(projectile, target, (float) getProjectileDamage(), 1.0f)) {
int count = customData.getInt("hitCount");
count++;
if(target instanceof LivingEntity livingEntity && projectile.getRandom().nextInt(4) == 0) {
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.item.IItemWaveBehavior;
@@ -21,14 +22,13 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
public class BloodButcherer extends SwordItem {
public class BloodButcherer extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String EFFECT_DURATION_PATH = "weapon.blood_butcherer.effect_duration";
@@ -1,16 +1,16 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
public class CopperShortsword extends SwordItem {
public class CopperShortsword extends MeleeWeapon {
public CopperShortsword() {
super(Tiers.STONE, new Item.Properties().attributes(ItemAttributeModifiers.builder()
.add(Attributes.ATTACK_DAMAGE,
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.LzxnoneTerrariaClient;
import com.lzxnone.terraria.ModSounds;
@@ -67,7 +68,7 @@ import com.lzxnone.terraria.ui.config.IConfigData;
import java.util.*;
public class DevilsDevastation extends SwordItem {
public class DevilsDevastation extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String KILL_MODE_TIME_PATH = "weapon.devils_devastation.kill_mode_time";
@@ -382,7 +383,7 @@ public class DevilsDevastation extends SwordItem {
Entity owner = projectile.getOwner();
if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.attack(player, target, (float) getProjectileDamage())) {
if(DamageUtil.normalAttack(projectile, target, (float) getProjectileDamage(), 1.0f)) {
if(target instanceof LivingEntity le) {
MobEffectInstance effectInstance = new MobEffectInstance(ModEffects.DEMONIC_FLAMES, getProjectileEffectDuration(), 0);
le.addEffect(effectInstance);
@@ -614,7 +615,7 @@ public class DevilsDevastation extends SwordItem {
Entity owner = projectile.getOwner();
if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.attack(player, target, (float) getStuckProjectileDamage())) {
if(DamageUtil.normalAttack(projectile, target, (float) getStuckProjectileDamage(), 1.0f)) {
if(target instanceof LivingEntity le) {
MobEffectInstance effectInstance = new MobEffectInstance(ModEffects.DEMONIC_FLAMES, getStuckProjectileEffectDuration(), 0);
le.addEffect(effectInstance);
@@ -847,7 +848,7 @@ public class DevilsDevastation extends SwordItem {
Entity target = result.getEntity();
List<UUID> tempStuckList = target.getData(ModAttachments.STUCK_DEVILS_DEVASTATION_PROJECTILE);
boolean valid = !tempStuckList.isEmpty();
if(projectile.getOwner() instanceof Player player && DamageUtil.attack(player, target, (float) getKillModeProjectileDamage())) {
if(projectile.getOwner() instanceof Player player && DamageUtil.normalAttack(projectile, target, (float) getKillModeProjectileDamage(), 1.0f)) {
if(target instanceof LivingEntity le) {
MobEffectInstance effectInstance = new MobEffectInstance(ModEffects.DEMONIC_FLAMES, getKillModeProjectileEffectDuration(), 1);
le.addEffect(effectInstance);
@@ -1117,7 +1118,7 @@ public class DevilsDevastation extends SwordItem {
UUID uuid = customData.getUUID("uuid");
Entity entity = serverLevel.getEntity(uuid);
if(entity instanceof Player player) {
DamageUtil.attack(player, owner, (float) getMarkLightningDamage());
DamageUtil.normalAttack(player, owner, (float) getMarkLightningDamage(), 1.0f);
StaticSummon newSummon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), serverLevel);
newSummon.setOwner(player);
Vec3 pos = owner.getBoundingBox().getCenter();
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -28,7 +29,6 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.CustomData;
@@ -39,7 +39,7 @@ import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3f;
public class EnchantedSword extends SwordItem {
public class EnchantedSword extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String DAMAGE_PATH = "weapon.enchanted_sword.damage";
@@ -123,7 +123,7 @@ public class EnchantedSword extends SwordItem {
Entity owner = projectile.getOwner();
if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(projectile, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 5;
ParticleUtil.addParticles(
(ServerLevel) projectile.level(), ModParticles.COLORFUL_PARTICLE,
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior;
@@ -39,7 +40,7 @@ import com.lzxnone.terraria.ui.config.ConfigUtil;
import com.lzxnone.terraria.ui.config.IConfigData;
import net.minecraft.network.chat.Component;
public class Excalibur extends SwordItem {
public class Excalibur extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String ROTATE_RANGE_PATH = "weapon.excalibur.rotate_range";
@@ -151,7 +152,7 @@ public class Excalibur extends SwordItem {
if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount");
if(count < getMaxHitCount()) {
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(beam, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 20;
count++;
custom_data.putInt("hitEntityCount", count);
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -51,7 +52,7 @@ import net.minecraft.network.chat.Component;
import java.util.List;
import java.util.UUID;
public class FirstFractal extends SwordItem {
public class FirstFractal extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String PROJECTILE_DAMAGE_PATH = "weapon.first_fractal.projectile_damage";
@@ -411,7 +412,7 @@ public class FirstFractal extends SwordItem {
FilterUtil.createTargetFilter(summon, summon.getOwner())
);
for(Entity target : targets) {
if(DamageUtil.attack(player, target, (float) getProjectileDamage())) {
if(DamageUtil.normalAttack(summon, target, (float) getProjectileDamage(), 0.25f)) {
target.invulnerableTime = 10;
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -45,7 +46,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Locale;
public class InfluxWaver extends SwordItem {
public class InfluxWaver extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String DAMAGE_PATH = "weapon.influx_waver.damage";
@@ -224,7 +225,7 @@ public class InfluxWaver extends SwordItem {
Entity target = customData.contains("target") ? summon.level().getEntity(customData.getInt("target")) : null;
if(target != null && !hitTarget.getUUID().equals(target.getUUID())) return;
if(summon.getOwner() instanceof Player player && FilterUtil.createTargetFilter(player).test(hitTarget)) {
if(DamageUtil.attack(player, hitTarget, (float) getDamage())) {
if(DamageUtil.normalAttack(summon, hitTarget, (float) getDamage(), 1.0f)) {
hitTarget.invulnerableTime = 2;
}
customData.putBoolean("dead", false);
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
@@ -38,7 +39,6 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.phys.AABB;
@@ -50,7 +50,7 @@ import org.joml.Vector3f;
import java.util.Comparator;
import java.util.List;
public class LightsBane extends SwordItem {
public class LightsBane extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String BIG_DAMAGE_PATH = "weapon.lights_bane.big_damage";
@@ -204,7 +204,7 @@ public class LightsBane extends SwordItem {
List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner()));
for(Entity target : targets) {
float damage = customData.contains("big") && customData.getBoolean("big") ? (float) getBigDamage() : (float) getSmallDamage();
if(DamageUtil.attack(player, target, damage)) {
if(DamageUtil.normalAttack(summon, target, damage, 1.0f)) {
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -49,7 +50,7 @@ import net.minecraft.network.chat.Component;
import java.util.List;
public class Mace extends SwordItem {
public class Mace extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String PROJECTILE_SPEED_PATH = "weapon.mace.projectile_speed";
@@ -294,7 +295,7 @@ public class Mace extends SwordItem {
FilterUtil.createTargetFilter(projectile, player)
);
for(Entity target : targets) {
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(projectile, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 15;
}
}
@@ -508,7 +509,7 @@ public class Mace extends SwordItem {
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement()));
if(entityHitResult != null) {
Entity target = entityHitResult.getEntity();
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 10;
}
}
@@ -527,7 +528,7 @@ public class Mace extends SwordItem {
FilterUtil.createTargetFilter(summon, summon.getOwner())
);
for(Entity target : targets) {
DamageUtil.attack(player, target, (float) getDamage());
DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f);
}
}else if(state == State.THROWING_BACK.ordinal()){
Vec3 moveDir = player.getEyePosition().subtract(summon.position());
@@ -536,7 +537,7 @@ public class Mace extends SwordItem {
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement()));
if(entityHitResult != null) {
Entity target = entityHitResult.getEntity();
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 10;
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -42,7 +43,7 @@ import org.joml.Vector3f;
import java.util.List;
public class Meowmere extends SwordItem {
public class Meowmere extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String DAMAGE_PATH = "weapon.meowmere.damage";
@@ -206,7 +207,7 @@ public class Meowmere extends SwordItem {
if(entityHitResult != null) {
Entity target = entityHitResult.getEntity();
if(summon.getOwner() instanceof Player player) {
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) {
if(customData.contains("hitEntity") && customData.getInt("hitEntity") < 4) {
customData.putInt("hitEntity", customData.getInt("hitEntity") + 1);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
@@ -28,7 +29,6 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.phys.EntityHitResult;
@@ -43,7 +43,7 @@ import com.lzxnone.terraria.ui.config.ConfigUtil;
import com.lzxnone.terraria.ui.config.IConfigData;
import net.minecraft.network.chat.Component;
public class Muramasa extends SwordItem {
public class Muramasa extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String BEAM_DAMAGE_PATH = "weapon.muramasa.beam_damage";
@@ -261,7 +261,7 @@ public class Muramasa extends SwordItem {
Entity owner = projectile.getOwner();
if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.attack(player, target, (float) getBeamDamage())) {
if(DamageUtil.normalAttack(projectile, target, (float) getBeamDamage(), 1.0f)) {
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -50,7 +51,7 @@ import net.minecraft.network.chat.Component;
import java.util.List;
public class NightsEdge extends SwordItem {
public class NightsEdge extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String PROJECTILE_ALIGN_TO_BLADE_PATH = "weapon.nights_edge.projectile_align_to_blade";
@@ -317,7 +318,7 @@ public class NightsEdge extends SwordItem {
if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount");
if(count < getMaxHitCount()) {
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(beam, target, (float) getDamage(), 1.0f)) {
ParticleUtil.addParticles(
(ServerLevel) target.level(), ModParticles.NIGHTS_EDGE_HIT_PARTICLE.get(),
new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2.0, target.getZ()), new Vec3(0, 0, 0),
@@ -458,7 +459,7 @@ public class NightsEdge extends SwordItem {
List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner()));
for(Entity target : targets) {
if(count >= getProjectileMaxHitCount()) break;
if(DamageUtil.attack(player, target, (float) getProjectileDamage())) {
if(DamageUtil.normalAttack(summon, target, (float) getProjectileDamage(), 1.0f)) {
count++;
ParticleUtil.addParticles(
(ServerLevel) target.level(), ModParticles.NIGHTS_EDGE_HIT_PARTICLE.get(),
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -38,7 +39,7 @@ import org.joml.Vector3f;
import java.util.Comparator;
import java.util.List;
public class Seedler extends SwordItem {
public class Seedler extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String NUT_GRAVITY_PATH = "weapon.seedler.nut_gravity";
@@ -145,7 +146,7 @@ public class Seedler extends SwordItem {
if(entityHitResult != null) {
Entity target = entityHitResult.getEntity();
if(summon.getOwner() instanceof Player player) {
if(DamageUtil.attack(player, target, (float) getThornDamage())) {
if(DamageUtil.normalAttack(summon, target, (float) getThornDamage(), 1.0f)) {
target.invulnerableTime = 2;
}
}
@@ -261,7 +262,7 @@ public class Seedler extends SwordItem {
Entity owner = projectile.getOwner();
if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.attack(player, target, (float) getThornDamage())) {
if(DamageUtil.normalAttack(projectile, target, (float) getThornDamage(), 1.0f)) {
target.invulnerableTime = 2;
onDied(projectile);
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -34,7 +35,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.phys.*;
import org.joml.Vector3f;
public class StarWrath extends SwordItem {
public class StarWrath extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String DAMAGE_PATH = "weapon.star_wrath.damage";
@@ -139,7 +140,7 @@ public class StarWrath extends SwordItem {
Entity target = result.getEntity();
Entity owner = projectile.getOwner();
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(projectile, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 2;
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -37,7 +38,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.phys.*;
import org.joml.Vector3f;
public class Starfury extends SwordItem {
public class Starfury extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String DAMAGE_PATH = "weapon.starfury.damage";
@@ -119,7 +120,7 @@ public class Starfury extends SwordItem {
Entity owner = projectile.getOwner();
if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(projectile, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 5;
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -48,7 +49,7 @@ import org.joml.Vector3f;
import java.util.List;
public class TerraBlade extends SwordItem {
public class TerraBlade extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String PROJECTILE_ALIGN_TO_SWORD_BEAM_PATH = "weapon.terra_blade.projectile_align_to_sword_beam";
@@ -219,7 +220,7 @@ public class TerraBlade extends SwordItem {
if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount");
if(count < getSwordBeamMaxHitCount()) {
if(DamageUtil.attack(player, target, (float)getSwordBeamDamage())) {
if(DamageUtil.normalAttack(beam, target, (float)getSwordBeamDamage(), 0.1f)) {
target.invulnerableTime = 20;
count++;
custom_data.putInt("hitEntityCount", count);
@@ -487,7 +488,7 @@ public class TerraBlade extends SwordItem {
int count = customData.getInt("hitCount");
List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner()));
for(Entity target : targets) {
if(DamageUtil.attack(player, target, (float)getProjectileDamage() * (float)Math.pow(getProjectileDamageDecay(), count))) {
if(DamageUtil.normalAttack(summon, target, (float)getProjectileDamage() * (float)Math.pow(getProjectileDamageDecay(), count), 0.1f)) {
count++;
ParticleUtil.addParticles(
(ServerLevel) summon.level(), ModParticles.TERRA_BEAM_HIT_PARTICLE.get(),
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -46,7 +47,7 @@ import org.jspecify.annotations.NonNull;
import java.util.List;
public class Terragrim extends SwordItem {
public class Terragrim extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String HIT_RANGE_PATH = "weapon.terragrim.hit_range";
@@ -214,7 +215,7 @@ public class Terragrim extends SwordItem {
knockbackResist.setBaseValue(Math.max(0.9, originalResist));
}
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 0;
}
@@ -222,7 +223,7 @@ public class Terragrim extends SwordItem {
knockbackResist.setBaseValue(originalResist);
}
}else {
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 0;
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -50,7 +51,7 @@ import net.minecraft.network.chat.Component;
import java.util.Comparator;
import java.util.List;
public class TheHorsemansBlade extends SwordItem {
public class TheHorsemansBlade extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String BLADE_ROTATE_RANGE_PATH = "weapon.the_horsemans_blade.blade_rotate_range";
@@ -202,7 +203,7 @@ public class TheHorsemansBlade extends SwordItem {
if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount");
if(count < getBladeMaxHitCount()) {
if(DamageUtil.attack(player, target, (float) getBladeDamage())) {
if(DamageUtil.normalAttack(beam, target, (float) getBladeDamage(), 1.0f)) {
target.invulnerableTime = 20;
count++;
custom_data.putInt("hitEntityCount", count);
@@ -334,7 +335,7 @@ public class TheHorsemansBlade extends SwordItem {
summon.setYRot(xyRot[1]);
if(selfPos.distanceToSqr(targetPos) < 2.0D) {
if(summon.getOwner() instanceof Player player && FilterUtil.createLivingTargetFilter(player).test(target) && DamageUtil.attack(player, target, (float) getPumpkinDamage())) onDied(summon);
if(summon.getOwner() instanceof Player player && FilterUtil.createLivingTargetFilter(player).test(target) && DamageUtil.normalAttack(summon, target, (float) getPumpkinDamage(), 1.0f)) onDied(summon);
}
}else {
Vec3 dir = summon.getLookAngle().normalize();
@@ -359,7 +360,7 @@ public class TheHorsemansBlade extends SwordItem {
for(Entity hitEntity : hitEntities) {
if(target != null && hitEntity.getUUID() == target.getUUID()) continue;
if(summon.getOwner() instanceof Player player) {
if(DamageUtil.attack(player, target, (float) getPumpkinDamage())) {
if(DamageUtil.normalAttack(summon, hitEntity, (float) getPumpkinDamage(), 1.0f)) {
hitEntity.invulnerableTime = 2;
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -26,7 +27,7 @@ import net.minecraft.world.phys.Vec3;
import org.joml.Vector3f;
import org.jspecify.annotations.NonNull;
public class TrueCopperShortsword extends SwordItem {
public class TrueCopperShortsword extends MeleeWeapon {
public TrueCopperShortsword() {
super(Tiers.NETHERITE, new Item.Properties().attributes(ItemAttributeModifiers.builder()
.add(Attributes.ATTACK_DAMAGE,
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModRenderTypes;
@@ -42,7 +43,7 @@ import com.lzxnone.terraria.ui.config.ConfigUtil;
import com.lzxnone.terraria.ui.config.IConfigData;
import net.minecraft.network.chat.Component;
public class TrueExcalibur extends SwordItem {
public class TrueExcalibur extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String ROTATE_RANGE_PATH = "weapon.true_excalibur.rotate_range";
@@ -277,7 +278,7 @@ public class TrueExcalibur extends SwordItem {
if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount");
if(count < getMaxHitCount()) {
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(beam, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 20;
count++;
custom_data.putInt("hitEntityCount", count);
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -50,7 +51,7 @@ import net.minecraft.network.chat.Component;
import java.util.List;
public class TrueNightsEdge extends SwordItem {
public class TrueNightsEdge extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String PROJECTILE_ALIGN_TO_BLADE_PATH = "weapon.true_nights_edge.projectile_align_to_blade";
@@ -333,7 +334,7 @@ public class TrueNightsEdge extends SwordItem {
if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount");
if(count < getMaxHitCount()) {
if(DamageUtil.attack(player, target, (float) getDamage())) {
if(DamageUtil.normalAttack(beam, target, (float) getDamage(), 1.0f)) {
ParticleUtil.addParticles(
(ServerLevel) target.level(), ModParticles.NIGHTS_EDGE_HIT_PARTICLE.get(),
new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2.0, target.getZ()), new Vec3(0, 0, 0),
@@ -571,7 +572,7 @@ public class TrueNightsEdge extends SwordItem {
List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner()));
for(Entity target : targets) {
if(count >= getProjectileMaxHitCount()) break;
if(DamageUtil.attack(player, target, (float) getProjectileDamage())) {
if(DamageUtil.normalAttack(summon, target, (float) getProjectileDamage(), 1.0f)) {
count++;
ParticleUtil.addParticles(
(ServerLevel) target.level(), ModParticles.TRUE_NIGHTS_EDGE_HIT_PARTICLE.get(),
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -29,7 +30,6 @@ import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.phys.AABB;
@@ -41,7 +41,7 @@ import org.joml.Vector3f;
import java.util.Comparator;
import java.util.List;
public class Volcano extends SwordItem {
public class Volcano extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String EXPLOSION_RANGE_PATH = "weapon.volcano.explosion_range";
@@ -185,7 +185,7 @@ public class Volcano extends SwordItem {
for(LivingEntity livingEntity : targets) {
if(livingEntity.getUUID() == target.getUUID()) continue;
if(hitCount >= getExplosionMaxHitCount()) break;
if(DamageUtil.attack(player, livingEntity, (float) getExplosionDamage())) {
if(DamageUtil.normalAttack(player, livingEntity, (float) getExplosionDamage(), 1.0f)) {
livingTarget.igniteForSeconds(getIgniteSeconds());
hitCount++;
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
@@ -49,7 +50,7 @@ import net.minecraft.network.chat.Component;
import java.util.List;
public class Zenith extends SwordItem {
public class Zenith extends MeleeWeapon {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String DAMAGE_PATH = "weapon.zenith.damage";
@@ -507,7 +508,7 @@ public class Zenith extends SwordItem {
if(!projectile.level().isClientSide()) {
Entity target = result.getEntity();
if(projectile.getOwner() instanceof Player player && FilterUtil.createTargetFilter(projectile, projectile.getOwner()).test(target)) {
if(DamageUtil.attack(player, target, (float) (getDamage() + Math.random() * getDamage()))) {
if(DamageUtil.normalAttack(projectile, target, (float) (getDamage() + Math.random() * getDamage()), 0.25f)) {
target.invulnerableTime = 2;
}
}
@@ -1,15 +1,22 @@
package com.lzxnone.terraria.utils;
import com.lzxnone.terraria.damage.ModDamageTypes;
import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.summon.BeeSummon;
import com.lzxnone.terraria.entity.summon.StaticSummon;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.phys.Vec3;
import java.util.Objects;
@@ -62,4 +69,103 @@ public class DamageUtil {
return hasHurt;
}
public static boolean normalAttack(Entity attackEntity, Entity target, float damage, float knockbackScale) {
return entityAttack(attackEntity, target, damage, knockbackScale, ModDamageTypes.PLAYER_NORMAL_ATTACK, false);
}
public static boolean realAttack(Entity attackEntity, Entity target, float damage) {
return realAttack(attackEntity, target, damage, 0.0F);
}
public static boolean realAttack(Entity attackEntity, Entity target, float damage, float knockbackScale) {
return entityAttack(attackEntity, target, damage, knockbackScale, ModDamageTypes.PLAYER_REAL_ATTACK, true);
}
private static boolean entityAttack(
Entity attackEntity,
Entity target,
float damage,
float knockbackScale,
ResourceKey<DamageType> damageType,
boolean realDamage
) {
Player player = getAttackOwner(attackEntity);
if(player == null || !(attackEntity.level() instanceof ServerLevel serverLevel)) return false;
DamageSource source = attackEntity.level().damageSources().source(damageType, attackEntity, player);
float finalDamage = realDamage ? Math.max(0.0F, damage) : applyPlayerDamageEffects(player, damage);
float knockbackLevel = (float) player.getAttributeValue(Attributes.ATTACK_KNOCKBACK);
if(!realDamage) {
finalDamage = EnchantmentHelper.modifyDamage(serverLevel, player.getWeaponItem(), target, source, finalDamage);
knockbackLevel = EnchantmentHelper.modifyKnockback(serverLevel, player.getWeaponItem(), target, source, knockbackLevel);
}
finalDamage = Math.max(0.0F, finalDamage);
boolean hasHurt = target.hurt(source, finalDamage);
if(hasHurt) {
float finalKnockback = knockbackLevel * knockbackScale;
if(finalKnockback > 0.0F && target instanceof LivingEntity livingTarget) {
Vec3 knockbackDirection = getAttackKnockbackDirection(attackEntity, target);
livingTarget.knockback(finalKnockback * 0.5F, knockbackDirection.x, knockbackDirection.z);
}
if(!realDamage) {
EnchantmentHelper.doPostAttackEffects(serverLevel, target, source);
}
}
return hasHurt;
}
private static float applyPlayerDamageEffects(Player player, float damage) {
float finalDamage = damage;
if(player.hasEffect(MobEffects.DAMAGE_BOOST) && player.getEffect(MobEffects.DAMAGE_BOOST) != null) {
int amplifier = Objects.requireNonNull(player.getEffect(MobEffects.DAMAGE_BOOST)).getAmplifier();
finalDamage += (amplifier + 1) * 3.0F;
}
if(player.hasEffect(MobEffects.WEAKNESS) && player.getEffect(MobEffects.WEAKNESS) != null) {
int amplifier = Objects.requireNonNull(player.getEffect(MobEffects.WEAKNESS)).getAmplifier();
finalDamage -= (amplifier + 1) * 4.0F;
}
return Math.max(0.0F, finalDamage);
}
private static Player getAttackOwner(Entity attackEntity) {
if(attackEntity instanceof Player player) return player;
if(attackEntity instanceof StaticProjectile projectile) return getAttackOwner(projectile.getOwner());
if(attackEntity instanceof StaticSummon summon) return getAttackOwner(summon.getOwner());
if(attackEntity instanceof SwordBeam beam) return getAttackOwner(beam.getOwner());
if(attackEntity instanceof BeeSummon beeSummon) return getAttackOwner(beeSummon.owner);
return null;
}
private static Vec3 getAttackKnockbackDirection(Entity attackEntity, Entity target) {
Vec3 direction = attackEntity.getDeltaMovement();
if(direction.lengthSqr() < 1.0E-7D) {
direction = getStoredAttackDirection(attackEntity);
}
if(direction.lengthSqr() < 1.0E-7D) {
direction = target.position().subtract(attackEntity.position());
}
if(direction.lengthSqr() < 1.0E-7D) {
Player owner = getAttackOwner(attackEntity);
direction = target.position().subtract(owner != null ? owner.position() : attackEntity.position());
}
if(direction.lengthSqr() < 1.0E-7D) {
return new Vec3(0.0D, 0.0D, 1.0D);
}
return direction.normalize();
}
private static Vec3 getStoredAttackDirection(Entity attackEntity) {
if(attackEntity instanceof StaticProjectile projectile) {
return MathUtil.toVec3(projectile.getEntityData().get(StaticProjectile.DIRECTION));
}
if(attackEntity instanceof SwordBeam beam && beam.currentPosition != null && beam.prevPosition != null) {
return beam.currentPosition.subtract(beam.prevPosition);
}
return Vec3.ZERO;
}
}