Skip to content

Commit

Permalink
Attribute Test #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Starexify committed Jan 20, 2025
1 parent 455b879 commit e0cb18e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/main/java/net/nova/big_swords/init/BSToolMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public class BSToolMaterial {
public static final Identifier MIN_CHARGED_DAMAGE_ID = BigSwordsR.rl("min_charged_damage");
public static final Identifier MAX_CHARGED_DAMAGE_ID = BigSwordsR.rl("max_charged_damage");

public static AttributeModifiersComponent createScytheAttributeModifier(ToolMaterial toolMaterial, float attackDamage, float attackSpeed, float minDamage, float maxDamage) {
return AttributeModifiersComponent.builder().add(
BSEntityAttributes.CHARGED_DAMAGE,
new EntityAttributeModifier(MIN_CHARGED_DAMAGE_ID, minDamage, EntityAttributeModifier.Operation.ADD_VALUE),
AttributeModifierSlot.MAINHAND
).add(
BSEntityAttributes.CHARGED_DAMAGE,
new EntityAttributeModifier(MAX_CHARGED_DAMAGE_ID, maxDamage, EntityAttributeModifier.Operation.ADD_VALUE),
AttributeModifierSlot.MAINHAND
).build();
}

public static Item.Settings applyBaseSettings(Item.Settings settings, ToolMaterial toolMaterial) {
return settings.maxDamage(toolMaterial.durability()).repairable(toolMaterial.repairItems()).enchantable(toolMaterial.enchantmentValue());
}
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/net/nova/big_swords/item/ScytheItem.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package net.nova.big_swords.item;

import net.fabricmc.fabric.api.item.v1.FabricItem;
import net.fabricmc.fabric.impl.item.FabricItemInternals;
import net.minecraft.block.BlockState;
import net.minecraft.component.ComponentChanges;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.MergedComponentMap;
import net.minecraft.component.type.AttributeModifierSlot;
import net.minecraft.component.type.AttributeModifiersComponent;
import net.minecraft.enchantment.EnchantmentEffectContext;
Expand Down Expand Up @@ -35,7 +31,10 @@
import net.minecraft.world.RaycastContext;
import net.minecraft.world.World;
import net.nova.big_swords.BigSwordsR;
import net.nova.big_swords.init.*;
import net.nova.big_swords.init.BSDataComponents;
import net.nova.big_swords.init.BSItems;
import net.nova.big_swords.init.BSToolMaterial;
import net.nova.big_swords.init.Sounds;

import java.util.List;
import java.util.Random;
Expand All @@ -46,17 +45,17 @@ public class ScytheItem extends HoeItem {
public final Random random = new Random();

public ScytheItem(ToolMaterial material, float attackDamage, float attackSpeed, float minChargedDamage, float maxChargedDamage, Settings settings) {
super(material, attackDamage, attackSpeed, settings);
super(material, attackDamage, attackSpeed, settings.component(DataComponentTypes.ATTRIBUTE_MODIFIERS, BSToolMaterial.createScytheAttributeModifier(material, attackDamage, attackSpeed, minChargedDamage, maxChargedDamage)));

AttributeModifiersComponent modifiersComponent = AttributeModifiersComponent.builder().add(
/* AttributeModifiersComponent.builder().add(
BSEntityAttributes.CHARGED_DAMAGE,
new EntityAttributeModifier(BSToolMaterial.MIN_CHARGED_DAMAGE_ID, minChargedDamage, EntityAttributeModifier.Operation.ADD_VALUE),
AttributeModifierSlot.MAINHAND
).add(
BSEntityAttributes.CHARGED_DAMAGE,
new EntityAttributeModifier(BSToolMaterial.MAX_CHARGED_DAMAGE_ID, maxChargedDamage, EntityAttributeModifier.Operation.ADD_VALUE),
AttributeModifierSlot.MAINHAND
).build();
).build()
ComponentChanges changes = ComponentChanges.builder().add(DataComponentTypes.ATTRIBUTE_MODIFIERS, modifiersComponent).build();
MergedComponentMap components = MergedComponentMap.create(getComponents(), changes);
Expand All @@ -67,7 +66,7 @@ public ScytheItem(ToolMaterial material, float attackDamage, float attackSpeed,
BSEntityAttributes.CHARGED_DAMAGE,
new EntityAttributeModifier(BSToolMaterial.MIN_CHARGED_DAMAGE_ID, minChargedDamage, EntityAttributeModifier.Operation.ADD_VALUE),
AttributeModifierSlot.MAINHAND
).build();
).build();*/

this.minDamage = minChargedDamage;
this.maxDamage = maxChargedDamage;
Expand Down

0 comments on commit e0cb18e

Please sign in to comment.