Skip to content

Commit f30eec2

Browse files
committed
register spear items
1 parent 3cf2bf4 commit f30eec2

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/main/java/de/dertoaster/kerkercraft/init/KCItems.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import de.dertoaster.kerkercraft.common.services.KCServices;
44
import de.dertoaster.kerkercraft.world.item.KCItemProperties;
5+
import de.dertoaster.kerkercraft.world.item.weapon.melee.SpearItem;
56
import net.minecraft.world.item.Item;
7+
import net.minecraft.world.item.Items;
68
import net.minecraft.world.item.ToolMaterial;
79
import net.neoforged.neoforge.registries.DeferredItem;
810

911
public class KCItems {
1012

1113
// region Daggers
14+
// Pass it the sword values, it will calculate itself!
1215
public static DeferredItem<Item> STONE_DAGGER = KCServices.ITEM.registerSimpleItem(
1316
"stone_dagger",
1417
new KCItemProperties().dagger(ToolMaterial.STONE, 3.0F, -2.4F)
@@ -32,5 +35,30 @@ public class KCItems {
3235
// endregion Daggers
3336

3437
// region Spears
38+
public static DeferredItem<SpearItem> STONE_SPEAR = KCServices.ITEM.registerItem(
39+
"stone_spear",
40+
SpearItem::new,
41+
new KCItemProperties().spear(ToolMaterial.STONE, 2.5F, -2.7F)
42+
);
43+
public static DeferredItem<SpearItem> GOLDEN_SPEAR = KCServices.ITEM.registerItem(
44+
"golden_spear",
45+
SpearItem::new,
46+
new KCItemProperties().spear(ToolMaterial.GOLD, 2.5F, -2.7F)
47+
);
48+
public static DeferredItem<SpearItem> IRON_SPEAR = KCServices.ITEM.registerItem(
49+
"iron_spear",
50+
SpearItem::new,
51+
new KCItemProperties().spear(ToolMaterial.IRON, 2.5F, -2.7F)
52+
);
53+
public static DeferredItem<SpearItem> DIAMOND_SPEAR = KCServices.ITEM.registerItem(
54+
"diamond_spear",
55+
SpearItem::new,
56+
new KCItemProperties().spear(ToolMaterial.DIAMOND, 2.5F, -2.7F)
57+
);
58+
public static DeferredItem<SpearItem> NETHERITE_SPEAR = KCServices.ITEM.registerItem(
59+
"netherite_spear",
60+
SpearItem::new,
61+
new KCItemProperties().spear(ToolMaterial.NETHERITE, 2.5F, -2.7F).fireResistant()
62+
);
3563
// endregion Spears
3664
}

src/main/java/de/dertoaster/kerkercraft/world/item/KCItemProperties.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.dertoaster.kerkercraft.world.item;
22

33
import de.dertoaster.kerkercraft.init.KCAttributeModifiers;
4+
import de.dertoaster.kerkercraft.world.item.weapon.melee.SpearItem;
45
import net.minecraft.core.HolderGetter;
56
import net.minecraft.core.HolderSet;
67
import net.minecraft.core.component.DataComponents;
@@ -10,7 +11,9 @@
1011
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
1112
import net.minecraft.world.entity.ai.attributes.Attributes;
1213
import net.minecraft.world.item.Item;
14+
import net.minecraft.world.item.Rarity;
1315
import net.minecraft.world.item.ToolMaterial;
16+
import net.minecraft.world.item.TridentItem;
1417
import net.minecraft.world.item.component.ItemAttributeModifiers;
1518
import net.minecraft.world.item.component.Tool;
1619
import net.minecraft.world.item.component.Weapon;
@@ -25,7 +28,22 @@ public Item.Properties dagger(ToolMaterial material, float attackDamage, float a
2528
return applyDaggerProperties(material, new Item.Properties(), attackDamage, attackSpeed);
2629
}
2730

28-
public Item.Properties applyDaggerProperties(ToolMaterial material, Item.Properties properties, float attackDamage, float attackSpeed) {
31+
public Item.Properties spear(ToolMaterial material, float attackDamage, float attackSpeed) {
32+
return applySpearProperties(material, new Item.Properties(), attackDamage, attackSpeed);
33+
}
34+
35+
private Item.Properties applySpearProperties(ToolMaterial material, Item.Properties properties, float attackDamage, float attackSpeed) {
36+
HolderGetter<Block> holdergetter = BuiltInRegistries.acquireBootstrapRegistrationLookup(BuiltInRegistries.BLOCK);
37+
return material.applyCommonProperties(properties)
38+
.component(
39+
DataComponents.TOOL,
40+
TridentItem.createToolProperties()
41+
)
42+
.attributes(SpearItem.createAttributes(material, attackDamage, attackSpeed))
43+
.component(DataComponents.WEAPON, new Weapon(1));
44+
}
45+
46+
private Item.Properties applyDaggerProperties(ToolMaterial material, Item.Properties properties, float attackDamage, float attackSpeed) {
2947
HolderGetter<Block> holdergetter = BuiltInRegistries.acquireBootstrapRegistrationLookup(BuiltInRegistries.BLOCK);
3048
return material.applyCommonProperties(properties)
3149
.component(

0 commit comments

Comments
 (0)