Skip to content

Commit

Permalink
Add support for the Enable melee damage checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldorion committed May 17, 2021
1 parent 4089ba5 commit 6f23227
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
### Snapshot 1
* [#83] Added support for custom living entities
Note: Flying entities are not 100% implemented. Entity inventory and Ranged attacks are not implemented.
* Added minimum and maximal enchantment level parameters
* Added minimum and maximal enchantment level parameters
* Added Enable melee damage checkbox for custom items
* [Bugfix #102] Some block triggers caused build errors
* [Bugfix #105] Blocks mined with a tool using a lower harvest level dropped.
* [Bugfix] Some sound mappings did not work properly
Expand Down
27 changes: 14 additions & 13 deletions src/fabric-1.16.5/templates/item.java.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ public class ${name}Item extends Item {
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
return (float)(${data.toolType}F);
}

@Override
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) {
if (slot == EquipmentSlot.MAINHAND) {
return ImmutableMultimap.of(
EntityAttributes.GENERIC_ATTACK_DAMAGE,
new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_ID, "item_damage", (double) ${data.damageVsEntity - 2}, EntityAttributeModifier.Operation.ADDITION),

EntityAttributes.GENERIC_ATTACK_SPEED,
new EntityAttributeModifier(ATTACK_SPEED_MODIFIER_ID, "item_attack_speed", -2.4, EntityAttributeModifier.Operation.ADDITION)
);
<#if data.enableMeleeDamage>
@Override
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) {
if (slot == EquipmentSlot.MAINHAND) {
return ImmutableMultimap.of(
EntityAttributes.GENERIC_ATTACK_DAMAGE,
new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_ID, "item_damage", (double) ${data.damageVsEntity - 2}, EntityAttributeModifier.Operation.ADDITION),

EntityAttributes.GENERIC_ATTACK_SPEED,
new EntityAttributeModifier(ATTACK_SPEED_MODIFIER_ID, "item_attack_speed", -2.4, EntityAttributeModifier.Operation.ADDITION)
);
}
return super.getAttributeModifiers(slot);
}
return super.getAttributeModifiers(slot);
}
</#if>

<#if data.hasGlow>
@Environment(EnvType.CLIENT)
Expand Down

0 comments on commit 6f23227

Please sign in to comment.