提取近战伤害属性
This commit is contained in:
parent
76ce80ed30
commit
e93114b911
5 changed files with 18 additions and 20 deletions
|
@ -25,6 +25,8 @@ public class DefaultGunData {
|
|||
public double spread;
|
||||
@SerializedName("Damage")
|
||||
public double damage;
|
||||
@SerializedName("MeleeDamage")
|
||||
public double meleeDamage;
|
||||
@SerializedName("Headshot")
|
||||
public double headshot = 1.5;
|
||||
@SerializedName("Velocity")
|
||||
|
|
|
@ -160,6 +160,10 @@ public class GunData {
|
|||
return (rawDamage() + item.getCustomDamage(stack)) * perkDamageRate();
|
||||
}
|
||||
|
||||
public double meleeDamage() {
|
||||
return defaultGunData().meleeDamage;
|
||||
}
|
||||
|
||||
public double explosionDamage() {
|
||||
return defaultGunData().explosionDamage;
|
||||
}
|
||||
|
|
|
@ -154,12 +154,14 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
}
|
||||
|
||||
private static final ResourceLocation SPEED_ID = Mod.loc("gun_movement_speed");
|
||||
private static final ResourceLocation DAMAGE_ID = Mod.loc("gun_melee_damage");
|
||||
|
||||
@Override
|
||||
public @NotNull ItemAttributeModifiers getDefaultAttributeModifiers(@NotNull ItemStack stack) {
|
||||
var list = new ArrayList<>(super.getDefaultAttributeModifiers(stack).modifiers());
|
||||
var data = GunData.from(stack);
|
||||
|
||||
// 移速
|
||||
list.add(new ItemAttributeModifiers.Entry(
|
||||
Attributes.MOVEMENT_SPEED,
|
||||
new AttributeModifier(SPEED_ID,
|
||||
|
@ -169,6 +171,15 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
|||
EquipmentSlotGroup.MAINHAND
|
||||
));
|
||||
|
||||
// 近战伤害
|
||||
if (data.meleeDamage() > 0) {
|
||||
list.add(new ItemAttributeModifiers.Entry(
|
||||
Attributes.ATTACK_DAMAGE,
|
||||
new AttributeModifier(DAMAGE_ID, data.meleeDamage(), AttributeModifier.Operation.ADD_VALUE),
|
||||
EquipmentSlotGroup.MAINHAND
|
||||
));
|
||||
}
|
||||
|
||||
return new ItemAttributeModifiers(list, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,14 +20,10 @@ import net.minecraft.core.particles.ParticleTypes;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
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.entity.player.Player;
|
||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ItemAttributeModifiers;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -38,7 +34,6 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
|||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -184,21 +179,6 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, EnergyStorag
|
|||
return Optional.of(new SecondaryCataclysmImageComponent(pStack));
|
||||
}
|
||||
|
||||
private static final ResourceLocation DAMAGE_ID = Mod.loc("secondary_cataclysm_attack_damage");
|
||||
|
||||
@Override
|
||||
public @NotNull ItemAttributeModifiers getDefaultAttributeModifiers(@NotNull ItemStack stack) {
|
||||
var list = new ArrayList<>(super.getDefaultAttributeModifiers(stack).modifiers());
|
||||
|
||||
list.add(new ItemAttributeModifiers.Entry(
|
||||
Attributes.ATTACK_DAMAGE,
|
||||
new AttributeModifier(DAMAGE_ID, 19, AttributeModifier.Operation.ADD_VALUE),
|
||||
EquipmentSlotGroup.MAINHAND
|
||||
));
|
||||
|
||||
return new ItemAttributeModifiers(list, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMeleeAttack(ItemStack stack) {
|
||||
return true;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
"RecoilX": 0.004,
|
||||
"RecoilY": 0.023,
|
||||
"Damage": 30,
|
||||
"MeleeDamage": 19,
|
||||
"ExplosionDamage": 50,
|
||||
"ExplosionRadius": 5,
|
||||
"Velocity": 3.75,
|
||||
|
|
Loading…
Add table
Reference in a new issue