added first item stub
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package de.jottyfan.minecraft;
|
package de.jottyfan.minecraft;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.item.QuicklyItems;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,5 +12,6 @@ public class QuicklyClient implements ClientModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
|
QuicklyItems.registerModItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/main/java/de/jottyfan/minecraft/item/QuicklyItems.java
Normal file
36
src/main/java/de/jottyfan/minecraft/item/QuicklyItems.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package de.jottyfan.minecraft.item;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.Quickly;
|
||||||
|
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.world.item.CreativeModeTabs;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.Item.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class QuicklyItems {
|
||||||
|
public static final Item MY_ITEM = registerItem("stub", new Item.Properties(), p -> new Stub(p));
|
||||||
|
|
||||||
|
private static final Item registerItem(String name, Item.Properties properties, Function<Properties, Item> function) {
|
||||||
|
Identifier identifier = Identifier.fromNamespaceAndPath(Quickly.MOD_ID, name);
|
||||||
|
ResourceKey<Item> rc = ResourceKey.create(Registries.ITEM, identifier);
|
||||||
|
Item i = function.apply(properties.setId(rc).modelId(identifier).useItemDescriptionPrefix());
|
||||||
|
return Registry.register(BuiltInRegistries.ITEM, identifier, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerModItems() {
|
||||||
|
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.TOOLS_AND_UTILITIES).register(i -> {
|
||||||
|
i.accept(MY_ITEM);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
52
src/main/java/de/jottyfan/minecraft/item/Stub.java
Normal file
52
src/main/java/de/jottyfan/minecraft/item/Stub.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package de.jottyfan.minecraft.item;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.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 Stub extends Item {
|
||||||
|
|
||||||
|
public Stub(Properties properties) {
|
||||||
|
super(properties.stacksTo(64));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InteractionResult useOn(UseOnContext 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);
|
||||||
|
|
||||||
|
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 xScatter = new Random().nextFloat();
|
||||||
|
float yScatter = new Random().nextFloat();
|
||||||
|
ItemEntity entity = new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
||||||
|
stack, xScatter, yScatter, 0.2);
|
||||||
|
level.addFreshEntity(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return InteractionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
6
src/main/resources/assets/quickly/items/stub.json
Normal file
6
src/main/resources/assets/quickly/items/stub.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"model": {
|
||||||
|
"type": "minecraft:model",
|
||||||
|
"model": "quickly:item/stub"
|
||||||
|
}
|
||||||
|
}
|
||||||
3
src/main/resources/assets/quickly/lang/de_de.json
Normal file
3
src/main/resources/assets/quickly/lang/de_de.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"item.quickly.stub": "Stummel"
|
||||||
|
}
|
||||||
3
src/main/resources/assets/quickly/lang/en_us.json
Normal file
3
src/main/resources/assets/quickly/lang/en_us.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"item.quickly.stub": "stub"
|
||||||
|
}
|
||||||
6
src/main/resources/assets/quickly/models/item/stub.json
Normal file
6
src/main/resources/assets/quickly/models/item/stub.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "item/stick",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "quickly:item/stub"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
src/main/resources/assets/quickly/textures/item/stub.png
Normal file
BIN
src/main/resources/assets/quickly/textures/item/stub.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:campfire_cooking",
|
||||||
|
"ingredient": "quickly:stub",
|
||||||
|
"result": {
|
||||||
|
"id": "minecraft:torch"
|
||||||
|
},
|
||||||
|
"experience": 0.1,
|
||||||
|
"cookingtime": 20
|
||||||
|
}
|
||||||
10
src/main/resources/data/quickly/recipe/shapeless_stub.json
Normal file
10
src/main/resources/data/quickly/recipe/shapeless_stub.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shapeless",
|
||||||
|
"ingredients": [
|
||||||
|
"minecraft:stick"
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "quickly:stub",
|
||||||
|
"count": 4
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user