added item stub slash action

This commit is contained in:
Jottyfan
2025-05-03 15:49:53 +02:00
parent 2fedfdc700
commit c06c231dce
3 changed files with 56 additions and 2 deletions

View File

@ -9,7 +9,7 @@ yarn_mappings=1.21.5+build.1
loader_version=0.16.10
# Mod Properties
mod_version=1.21.5.0
mod_version=1.21.5.1
maven_group=de.jottyfan.quickiemod
archives_base_name=quickiemod

View File

@ -0,0 +1,54 @@
package de.jottyfan.quickiemod.item;
import java.util.Map;
import java.util.Random;
import de.jottyfan.quickiemod.block.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.Items;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemStub extends AbstractIdentifiedItem {
public ItemStub(Identifier identifier) {
super(identifier, 64);
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
Map<Block, Item> SLASH_MAP = Map.of(
Blocks.HAY_BLOCK, Items.WHEAT,
Blocks.DRIED_KELP_BLOCK, Items.DRIED_KELP,
ModBlocks.BLOCK_KELPSTACK, Items.KELP);
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
Block clickedBlock = world.getBlockState(pos).getBlock();
if (SLASH_MAP.containsKey(clickedBlock)) {
if (!world.isClient()) {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
world.playSound(null, pos, SoundEvents.ITEM_HOE_TILL,
SoundCategory.BLOCKS);
for (int i = 0; i < 9; i++) {
ItemStack stack = new ItemStack(SLASH_MAP.get(clickedBlock));
float xScatter = new Random().nextFloat();
float yScatter = new Random().nextFloat();
ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
stack, xScatter, yScatter, 0.2);
world.spawnEntity(entity);
}
}
}
return ActionResult.SUCCESS;
}
}

View File

@ -17,7 +17,7 @@ import net.minecraft.util.Identifier;
*/
public class ModItems {
public static final Item ITEM_STUB = registerItem(ModIdentifiers.ITEM_STUB,
new Item64Stack(ModIdentifiers.ITEM_STUB));
new ItemStub(ModIdentifiers.ITEM_STUB));
public static final Item ITEM_SPEEDPOWDER = registerItem(ModIdentifiers.ITEM_SPEEDPOWDER,
new Item64Stack(ModIdentifiers.ITEM_SPEEDPOWDER));
public static final Item ITEM_QUICKIEPOWDER = registerItem(ModIdentifiers.ITEM_QUICKIEPOWDER,