Skip to content

Commit 0bf520f

Browse files
committed
-fixed projectile damage
1 parent 1f65d0c commit 0bf520f

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

common/src/main/java/smartin/miapi/attributes/AttributeRegistry.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import net.minecraft.sound.SoundEvents;
1717
import net.minecraft.util.math.BlockPos;
1818
import net.minecraft.util.math.Vec3d;
19+
import smartin.miapi.entity.ItemProjectileEntity;
1920
import smartin.miapi.events.MiapiEvents;
2021
import smartin.miapi.events.MiapiProjectileEvents;
21-
import smartin.miapi.entity.ItemProjectileEntity;
2222
import smartin.miapi.modules.abilities.util.WrappedSoundEvent;
2323
import smartin.miapi.modules.properties.AttributeProperty;
2424

@@ -54,7 +54,6 @@ public class AttributeRegistry {
5454
public static EntityAttribute PROJECTILE_PIERCING;
5555

5656

57-
5857
public static void setup() {
5958
MiapiEvents.LIVING_HURT.register((livingHurtEvent -> {
6059
if (livingHurtEvent.livingEntity.getAttributes().hasAttribute(DAMAGE_RESISTANCE)) {
@@ -116,7 +115,7 @@ public static void setup() {
116115

117116
MiapiProjectileEvents.MODULAR_PROJECTILE_ENTITY_HIT.register(listener -> {
118117
ItemProjectileEntity projectile = listener.projectile;
119-
if(projectile.isCritical()){
118+
if (projectile.isCritical()) {
120119
projectile.setDamage(projectile.getDamage() * AttributeProperty.getActualValue(projectile.asItemStack(), EquipmentSlot.MAINHAND, AttributeRegistry.PROJECTILE_CRIT_MULTIPLIER));
121120
}
122121
return EventResult.pass();

common/src/main/java/smartin/miapi/entity/ItemProjectileEntity.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public ItemProjectileEntity(World world, Position position, ItemStack itemStack)
6262
this.dataTracker.set(THROWING_STACK, thrownStack);
6363
this.dataTracker.set(LOYALTY, (byte) EnchantmentHelper.getLoyalty(itemStack));
6464
this.dataTracker.set(ENCHANTED, itemStack.hasGlint());
65+
setup();
6566
}
6667

6768
public ItemProjectileEntity(World world, LivingEntity owner, ItemStack stack) {
@@ -77,9 +78,15 @@ public ItemProjectileEntity(World world, LivingEntity owner, ItemStack stack) {
7778
if (getBowItem().isEmpty() && owner != null) {
7879
setBowItem(owner.getActiveItem());
7980
}
81+
setup();
8082
MiapiProjectileEvents.MODULAR_PROJECTILE_DATA_TRACKER_SET.invoker().dataTracker(this, this.getDataTracker());
8183
}
8284

85+
private void setup(){
86+
ItemStack projectileStack = this.asItemStack();
87+
this.setDamage(AttributeProperty.getActualValue(projectileStack,EquipmentSlot.MAINHAND,AttributeRegistry.PROJECTILE_DAMAGE));
88+
}
89+
8390
public void setPreferredSlot(int slotID) {
8491
this.dataTracker.set(PREFERRED_SLOT, slotID);
8592
}
@@ -265,7 +272,7 @@ public float getProjectileDamage() {
265272
float damage = (float) getDamage();
266273
if (this.getSpeedDamage()) {
267274
float speed = (float) this.getVelocity().length();
268-
damage = damage * speed;
275+
damage = MathHelper.ceil(MathHelper.clamp((double)speed * damage, 0.0, 2.147483647E9));
269276
}
270277
return damage;
271278
}

common/src/main/java/smartin/miapi/item/modular/items/ModularBow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import smartin.miapi.attributes.AttributeRegistry;
2222
import smartin.miapi.client.model.ModularModelPredicateProvider;
2323
import smartin.miapi.config.MiapiConfig;
24+
import smartin.miapi.entity.ItemProjectileEntity;
2425
import smartin.miapi.events.MiapiProjectileEvents;
2526
import smartin.miapi.item.modular.ModularItem;
26-
import smartin.miapi.entity.ItemProjectileEntity;
2727
import smartin.miapi.modules.properties.AttributeProperty;
2828
import smartin.miapi.modules.properties.DisplayNameProperty;
2929

common/src/main/resources/data/miapi/modules/arrow/head/arrow_custom_head.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
"arrow_head"
88
],
99
"attributes": [
10+
{
11+
"attribute": "miapi:generic.projectile_damage",
12+
"value": "2",
13+
"operation": "+",
14+
"slot": "mainhand",
15+
"uuid": "AAAAAAAA-4180-4865-B01B-BCCE9785ACA3"
16+
},
1017
{
1118
"attribute": "miapi:generic.projectile_speed",
1219
"value": " - 0.2",

common/src/main/resources/data/miapi/modules/arrow/head/arrow_head.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
"arrow_head"
2828
],
2929
"attributes": [
30+
{
31+
"attribute": "miapi:generic.projectile_damage",
32+
"value": "2",
33+
"operation": "+",
34+
"slot": "mainhand",
35+
"uuid": "AAAAAAAA-4180-4865-B01B-BCCE9785ACA3"
36+
},
3037
{
3138
"attribute": "miapi:generic.projectile_speed",
3239
"value": "( - [material.density] ) / 10",

0 commit comments

Comments
 (0)