added tool functionality to stub
build / build (push) Has been cancelled

This commit is contained in:
Jottyfan
2026-05-03 15:24:03 +02:00
parent a2503c5b1a
commit f43fb09233
2 changed files with 56 additions and 1 deletions
@@ -0,0 +1,51 @@
package de.jottyfan.minecraft.gta.item;
import java.util.Map;
import org.joml.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
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;
public class StubItem extends Item {
private static final Map<Block, Item> SLASH_MAP = Map.of(
Blocks.HAY_BLOCK, Items.WHEAT,
Blocks.DRIED_KELP_BLOCK, Items.DRIED_KELP);
public StubItem(Properties properties) {
super(properties);
SLASH_MAP.toString();
}
@Override
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
BlockPos pos = context.getClickedPos();
Block clickedBlock = level.getBlockState(pos).getBlock();
if (SLASH_MAP.containsKey(clickedBlock)) {
if (!level.isClientSide()) {
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
level.playSound(null, pos, SoundEvents.HOE_TILL, SoundSource.BLOCKS);
for (int i = 0; i < 9; i++) {
ItemStack stack = new ItemStack(SLASH_MAP.get(clickedBlock));
float scatter = new Random().nextFloat();
ItemEntity entiry = new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
stack, scatter, scatter, 0.2);
level.addFreshEntity(entiry);
}
}
}
return InteractionResult.SUCCESS;
}
}
@@ -12,9 +12,13 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.Item.Properties;
public class UnoItems {
public static final Item STUB = registerItem(Identifier.fromNamespaceAndPath(Uno.MOD_ID, "stub"));
public static final Item STUB = registerStubItem(Identifier.fromNamespaceAndPath(Uno.MOD_ID, "stub"));
public static final Item RUBY = registerItem(Identifier.fromNamespaceAndPath(Uno.MOD_ID, "ruby"));
private static final Item registerStubItem(Identifier identifier) {
return registerItem(identifier, new Item.Properties(), StubItem::new);
}
private static final Item registerItem(Identifier identifier) {
return registerItem(identifier, new Item.Properties(), Item::new);
}