generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b51e85a
commit ccf97be
Showing
6 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/nateplays/my_neoforge_mod/item/custom/ChiselItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.nateplays.my_neoforge_mod.item.custom; | ||
|
||
import com.nateplays.my_neoforge_mod.block.ModBlocks; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.particles.ParticleOptions; | ||
import net.minecraft.core.particles.ParticleTypes; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.sounds.SoundSource; | ||
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 net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
|
||
import java.util.Map; | ||
|
||
public class ChiselItem extends Item { | ||
|
||
private static final Map<Block, Block> CHISEL_MAP = Map.of( | ||
Blocks.STONE, Blocks.STONE_BRICKS, | ||
ModBlocks.MACHALITE_ORE.get(), ModBlocks.MACHALITE_BLOCK.get() | ||
); | ||
|
||
public ChiselItem(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
public InteractionResult useOn(UseOnContext context) { | ||
Level level = context.getLevel(); | ||
Block clickedBlock = level.getBlockState(context.getClickedPos()).getBlock(); | ||
BlockPos clickedPos = context.getClickedPos(); | ||
|
||
if (CHISEL_MAP.containsKey(clickedBlock)) { | ||
if (!level.isClientSide()) { // only change things on server | ||
level.setBlockAndUpdate(clickedPos, CHISEL_MAP.get(clickedBlock).defaultBlockState()); | ||
|
||
if (context.getPlayer() != null && !context.getPlayer().isCreative()) { | ||
context.getItemInHand().hurtAndBreak(1, ((ServerLevel) level), context.getPlayer(), | ||
item -> context.getPlayer().onEquippedItemBroken(item, EquipmentSlot.MAINHAND)); | ||
} | ||
|
||
level.playSound(null, clickedPos, SoundEvents.GRINDSTONE_USE, SoundSource.BLOCKS); | ||
} | ||
|
||
level.addParticle(ParticleTypes.CHERRY_LEAVES, clickedPos.getX(), clickedPos.getY(), clickedPos.getZ(), | ||
0.0, 0.0, 0.0); | ||
} | ||
return InteractionResult.SUCCESS; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/my_neoforge_mod/models/item/chisel.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "my_neoforge_mod:item/chisel" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.