added tool (stub)
This commit is contained in:
1 parent
96c4be6a0d
commit
0b4936f47d
3 files changed
+61
-1
No files matched your search
@@ -14,7 +14,7 @@ public class ModItems extends ModItemsRegistrator {
|
|||||||
public static final Item RAW_TIN = registerItem("raw_tin");
|
public static final Item RAW_TIN = registerItem("raw_tin");
|
||||||
public static final Item RUBY = registerItem("ruby");
|
public static final Item RUBY = registerItem("ruby");
|
||||||
public static final Item CHILI = registerItem("chili");
|
public static final Item CHILI = registerItem("chili");
|
||||||
public static final Item STUB = registerItem("stub");
|
public static final Item STUB = registerItem("stub", StubItem::new);
|
||||||
public static final Item TIN_INGOT = registerItem("tin_ingot");
|
public static final Item TIN_INGOT = registerItem("tin_ingot");
|
||||||
public static final Item TIN_DUST = registerItem("tin_dust");
|
public static final Item TIN_DUST = registerItem("tin_dust");
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,17 @@ public abstract class ModItemsRegistrator {
|
|||||||
return registerItem(name, new Item.Properties(), Item::new);
|
return registerItem(name, new Item.Properties(), Item::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* register a new item with the name and its item class
|
||||||
|
*
|
||||||
|
* @param name the name
|
||||||
|
* @param function the item class
|
||||||
|
* @return the registered item
|
||||||
|
*/
|
||||||
|
public static final Item registerItem(String name, Function<Item.Properties, Item> function) {
|
||||||
|
return registerItem(name, new Item.Properties(), function);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register a new item with the name, the properties and the Item class reference
|
* register a new item with the name, the properties and the Item class reference
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package de.jottyfan.minecraft.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the stub item definition; specifies, what the stub can do
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InteractionResult useOn(UseOnContext context) {
|
||||||
|
Level level = context.getLevel();
|
||||||
|
BlockPos pos = context.getClickedPos();
|
||||||
|
Block block = level.getBlockState(pos).getBlock();
|
||||||
|
if (SLASH_MAP.containsKey(block) && !level.isClientSide()) {
|
||||||
|
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
|
||||||
|
level.playSound(null, pos, SoundEvents.HOE_TILL.value(), SoundSource.BLOCKS);
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
ItemStack stack = new ItemStack(SLASH_MAP.get(block));
|
||||||
|
float scatter = new Random().nextFloat();
|
||||||
|
ItemEntity entity = new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
||||||
|
stack, scatter, scatter, 0.2);
|
||||||
|
level.addFreshEntity(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return InteractionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user