From 824438f564d6b8767b320bfe2618876495777dd6 Mon Sep 17 00:00:00 2001 From: StrangerGamer-A Date: Wed, 2 Oct 2024 09:47:12 -0700 Subject: [PATCH] Added A Custom Advanced Item --- .../strangergamer/mccourse/item/ModItems.java | 4 +++ .../mccourse/item/custom/ChainsawItem.java | 34 ++++++++++++++++++ .../resources/assets/mccourse/lang/en_us.json | 3 ++ .../resources/assets/mccourse/lang/fr_fr.json | 2 ++ .../resources/assets/mccourse/lang/pt_br.json | 3 ++ .../assets/mccourse/models/item/chainsaw.json | 6 ++++ .../mccourse/textures/item/chainsaw.png | Bin 0 -> 425 bytes .../data/mccourse/recipe/chainsaw.json | 21 +++++++++++ 8 files changed, 73 insertions(+) create mode 100644 src/main/java/net/strangergamer/mccourse/item/custom/ChainsawItem.java create mode 100644 src/main/resources/assets/mccourse/models/item/chainsaw.json create mode 100644 src/main/resources/assets/mccourse/textures/item/chainsaw.png create mode 100644 src/main/resources/data/mccourse/recipe/chainsaw.json diff --git a/src/main/java/net/strangergamer/mccourse/item/ModItems.java b/src/main/java/net/strangergamer/mccourse/item/ModItems.java index d036f16..15d61a4 100644 --- a/src/main/java/net/strangergamer/mccourse/item/ModItems.java +++ b/src/main/java/net/strangergamer/mccourse/item/ModItems.java @@ -5,6 +5,7 @@ import net.neoforged.neoforge.registries.DeferredItem; import net.neoforged.neoforge.registries.DeferredRegister; import net.strangergamer.mccourse.MCCourseMod; +import net.strangergamer.mccourse.item.custom.ChainsawItem; public class ModItems { public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MCCourseMod.MOD_ID); @@ -12,6 +13,9 @@ public class ModItems { public static final DeferredItem BLACK_OPAL = ITEMS.registerSimpleItem("black_opal"); public static final DeferredItem RAW_BLACK_OPAL = ITEMS.registerSimpleItem("raw_black_opal"); + public static final DeferredItem CHAINSAW = + ITEMS.registerItem("chainsaw", ChainsawItem::new, new Item.Properties().durability(32)); + public static void register(IEventBus eventBus) { ITEMS.register(eventBus); } diff --git a/src/main/java/net/strangergamer/mccourse/item/custom/ChainsawItem.java b/src/main/java/net/strangergamer/mccourse/item/custom/ChainsawItem.java new file mode 100644 index 0000000..a183b53 --- /dev/null +++ b/src/main/java/net/strangergamer/mccourse/item/custom/ChainsawItem.java @@ -0,0 +1,34 @@ +package net.strangergamer.mccourse.item.custom; + +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; + +import java.util.Objects; + +public class ChainsawItem extends Item { + public ChainsawItem(Properties pProperties) { + super(pProperties); + } + + @Override + public InteractionResult useOn(UseOnContext pContext) { + Level level = pContext.getLevel(); + + if(!level.isClientSide()) { + if(level.getBlockState(pContext.getClickedPos()).is(BlockTags.LOGS)) { + level.destroyBlock(pContext.getClickedPos(), true, pContext.getPlayer()); + + pContext.getItemInHand().hurtAndBreak(1, ((ServerLevel) level), ((ServerPlayer) pContext.getPlayer()), + item -> Objects.requireNonNull(pContext.getPlayer()).onEquippedItemBroken(item, EquipmentSlot.MAINHAND)); + } + } + + return InteractionResult.CONSUME; + } +} diff --git a/src/main/resources/assets/mccourse/lang/en_us.json b/src/main/resources/assets/mccourse/lang/en_us.json index ac61da1..2f73c2f 100644 --- a/src/main/resources/assets/mccourse/lang/en_us.json +++ b/src/main/resources/assets/mccourse/lang/en_us.json @@ -2,8 +2,11 @@ "item.mccourse.black_opal": "Black Opal", "item.mccourse.raw_black_opal": "Raw Black Opal", + "item.mccourse.chainsaw": "Chainsaw", + "block.mccourse.black_opal_block": "Block of Black Opal", "block.mccourse.raw_black_opal_block": "Block of Raw Black Opal", + "block.mccourse.black_opal_ore": "Black Opal Ore", "block.mccourse.black_opal_deepslate_ore": "Deepslate Black Opal Ore", "block.mccourse.black_opal_end_ore": "End Black Opal Ore", diff --git a/src/main/resources/assets/mccourse/lang/fr_fr.json b/src/main/resources/assets/mccourse/lang/fr_fr.json index 8e104f6..88c6d1e 100644 --- a/src/main/resources/assets/mccourse/lang/fr_fr.json +++ b/src/main/resources/assets/mccourse/lang/fr_fr.json @@ -2,6 +2,8 @@ "item.mccourse.black_opal": "Opale noire", "item.mccourse.raw_black_opal": "Opale noire brute", + "item.mccourse.chainsaw": "Tronçonneuse", + "block.mccourse.black_opal_block": "Bloc d’opale noire", "block.mccourse.raw_black_opal_block": "Bloc d’opale noire brute", "block.mccourse.black_opal_ore": "Minerai d’opale noire", diff --git a/src/main/resources/assets/mccourse/lang/pt_br.json b/src/main/resources/assets/mccourse/lang/pt_br.json index b9c20c6..bf8c8bf 100644 --- a/src/main/resources/assets/mccourse/lang/pt_br.json +++ b/src/main/resources/assets/mccourse/lang/pt_br.json @@ -2,8 +2,11 @@ "item.mccourse.black_opal": "Opala Negra", "item.mccourse.raw_black_opal": "Opala Negra Crua", + "item.mccourse.chainsaw": "Motosserra", + "block.mccourse.black_opal_block": "Bloco de Opala Negra", "block.mccourse.raw_black_opal_block": "Bloco de Opala Negra Crua", + "block.mccourse.black_opal_ore": "Minério de Opala Negra", "block.mccourse.black_opal_deepslate_ore": "Minério de Opala Negra de Deepslate", "block.mccourse.black_opal_end_ore": "Minério de Opala Negra de End", diff --git a/src/main/resources/assets/mccourse/models/item/chainsaw.json b/src/main/resources/assets/mccourse/models/item/chainsaw.json new file mode 100644 index 0000000..71359f2 --- /dev/null +++ b/src/main/resources/assets/mccourse/models/item/chainsaw.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "mccourse:item/chainsaw" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/mccourse/textures/item/chainsaw.png b/src/main/resources/assets/mccourse/textures/item/chainsaw.png new file mode 100644 index 0000000000000000000000000000000000000000..a984146c5ed251d62b8be82932fe0c9327d54a48 GIT binary patch literal 425 zcmV;a0apHrP)Px$V@X6oR5*>TlD|s=VHn51uMh=FKO`cp@!qDlu?UVkLKM0oIIyWvxJhztl>UTh z%T1^u2%U0?6BO~FO&ku+@u1}hClf@ThVn*jiuhEJpf`oj?{*F$Bv0|0m^U&Ay_q*5uIo*77N zZ=v!0$U^3JE<*sog+lFIhT6Fd)y|J8pU=-V`x_KhK}WlrD0IdsAFiN390d+s_Li}} z8Vj2zM6McLX1U(X@RXn0jsU>@+eT07zV>n}a2PV7VUd zUf0lbS`7H?2LPOIGjN&zk$O&xUA&A!VTsGcg+kwhbCI}A5|=}5bD{XJ@vnRUQJu%^ T>z