Skip to content

Commit

Permalink
Added A Custom Advanced Item
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangerGamer-A committed Oct 2, 2024
1 parent 2e1b5bb commit 824438f
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/strangergamer/mccourse/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
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);

public static final DeferredItem<Item> BLACK_OPAL = ITEMS.registerSimpleItem("black_opal");
public static final DeferredItem<Item> RAW_BLACK_OPAL = ITEMS.registerSimpleItem("raw_black_opal");

public static final DeferredItem<Item> CHAINSAW =
ITEMS.registerItem("chainsaw", ChainsawItem::new, new Item.Properties().durability(32));

public static void register(IEventBus eventBus) {
ITEMS.register(eventBus);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/mccourse/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/mccourse/lang/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/mccourse/lang/pt_br.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/mccourse/models/item/chainsaw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "mccourse:item/chainsaw"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/main/resources/data/mccourse/recipe/chainsaw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
" #",
" # ",
"+ "
],
"key": {
"#": {
"item": "minecraft:iron_ingot"
},
"+": {
"item": "minecraft:leather"
}
},
"result": {
"id": "mccourse:black_opal_block",
"count": 1
}
}

0 comments on commit 824438f

Please sign in to comment.