VolcanicGlassRing addded right click logic, Added Curios

This commit is contained in:
Steven 2023-10-01 22:39:26 -04:00
parent 4cf84cea1e
commit c2d3d991b1
4 changed files with 36 additions and 5 deletions

View file

@ -1,9 +1,15 @@
package com.skdevstudios.util_rings.items;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
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.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import top.theillusivec4.curios.api.SlotContext;
import top.theillusivec4.curios.api.type.capability.ICurioItem;
@ -13,9 +19,24 @@ public class VolcanicGlassRing extends Item implements ICurioItem {
}
@Override
public InteractionResult useOn(UseOnContext context){
return null;
//TODO: Add right click spawns obsidian block
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()) {
// Check if the target block is air and place obsidian
BlockState obsidian = Blocks.OBSIDIAN.defaultBlockState();
world.setBlockAndUpdate(pos, obsidian);
// Play a sound effect at the placed block position
world.playSound(null, pos, SoundEvents.STONE_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F);
return InteractionResult.SUCCESS;
}
return InteractionResult.FAIL;
}
@Override
public void curioTick(SlotContext slotContext, ItemStack stack) {

View file

@ -0,0 +1,4 @@
{
"entities": ["player"],
"slots": ["ring"]
}

View file

@ -0,0 +1,3 @@
{
"size": 2
}

View file

@ -1,12 +1,15 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
" # ",
"@#@",
"# #",
" # "
"@#@"
],
"key": {
"#": {
"item": "minecraft:iron_ingot"
},
"@": {
"item": "minecraft:iron_nugget"
}
},