turned jewelers hammer into adanced item and added durability

This commit is contained in:
Steven 2023-10-10 02:05:24 -04:00
parent fa5306fd9e
commit 6d8705c91d
2 changed files with 52 additions and 1 deletions

View file

@ -3,6 +3,7 @@ package com.skdevstudios.util_rings.init;
import com.skdevstudios.util_rings.UtilRings;
import com.skdevstudios.util_rings.items.GrowthRing;
import com.skdevstudios.util_rings.items.IronRing;
import com.skdevstudios.util_rings.items.JewelersHammer;
import com.skdevstudios.util_rings.items.MagnetRing;
import com.skdevstudios.util_rings.items.VolcanicGlassRing;
@ -21,7 +22,7 @@ public class ItemsInit {
public static final RegistryObject<Item> IRON_RING_TOP = ITEMS.register("iron_ring_top", () -> new Item(new Item.Properties().stacksTo(1)));
public static final RegistryObject<Item> IRON_RING_BOTTOM = ITEMS.register("iron_ring_bottom", () -> new Item(new Item.Properties().stacksTo(1)));
public static final RegistryObject<Item> IRON_RING_RIGHT = ITEMS.register("iron_ring_right", () -> new Item(new Item.Properties().stacksTo(1)));
public static final RegistryObject<Item> JEWELERS_HAMMER = ITEMS.register("jewelers_hammer", () -> new Item(new Item.Properties().stacksTo(1)));
public static final RegistryObject<Item> JEWELERS_HAMMER = ITEMS.register("jewelers_hammer", () -> new JewelersHammer());
public static final RegistryObject<Item> RAW_LEAD = ITEMS.register("raw_lead", () -> new Item(new Item.Properties().stacksTo(64)));
public static final RegistryObject<Item> LEAD_DUST = ITEMS.register("lead_dust", () -> new Item(new Item.Properties().stacksTo(64)));
public static final RegistryObject<Item> LEAD_NUGGET = ITEMS.register("lead_nugget", () -> new Item(new Item.Properties().stacksTo(64)));

View file

@ -0,0 +1,50 @@
package com.skdevstudios.util_rings.items;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
public class JewelersHammer extends Item {
public JewelersHammer() {
super(new Item.Properties().stacksTo(1).defaultDurability(5));
}
@Override
public void onCraftedBy(ItemStack pStack, Level pLevel, Player pPlayer) {
super.onCraftedBy(pStack, pLevel, pPlayer);
}
@Override
public InteractionResult useOn(UseOnContext context) {
Level world = context.getLevel();
BlockPos pos = context.getClickedPos().relative(context.getClickedFace());
BlockState targetState = world.getBlockState(pos);
if (targetState.isAir() && !world.isClientSide()) {
world.playSound(
null,
pos,
SoundEvents.ANVIL_HIT,
SoundSource.PLAYERS,
1.0F,
1.0F
);
// Decrease the item's durability by 1
ItemStack itemStack = context.getItemInHand();
itemStack.hurtAndBreak(1, context.getPlayer(), playerEntity -> playerEntity.broadcastBreakEvent(context.getHand()));
return InteractionResult.SUCCESS;
}
return InteractionResult.FAIL;
}
}