This commit is contained in:
@@ -13,11 +13,18 @@ import net.minecraft.util.Identifier;
|
||||
|
||||
public class ModItems {
|
||||
|
||||
public static final Item STUB = registerItem(
|
||||
public static final Item STUB = registerStubItem(
|
||||
Identifier.of(Gtamfmd.MOD_ID, "stub"), new Item.Settings());
|
||||
|
||||
public static final Item RUBY = registerItem(
|
||||
Identifier.of(Gtamfmd.MOD_ID, "ruby"), new Item.Settings());
|
||||
|
||||
private static Item registerStubItem(Identifier identifier, Settings settings) {
|
||||
return Registry.register(Registries.ITEM, identifier, new StubItem(
|
||||
settings.useItemPrefixedTranslationKey()
|
||||
.registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier))));
|
||||
}
|
||||
|
||||
private static Item registerItem(Identifier identifier, Settings settings) {
|
||||
RegistryKey<Item> registrykey = RegistryKey.of(RegistryKeys.ITEM, identifier);
|
||||
Item item = new Item(settings.useItemPrefixedTranslationKey().registryKey(registrykey));
|
||||
|
||||
51
src/main/java/de/jottyfan/minecraft/item/StubItem.java
Normal file
51
src/main/java/de/jottyfan/minecraft/item/StubItem.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package de.jottyfan.minecraft.item;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.joml.Random;
|
||||
|
||||
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.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
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(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
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 scatter = new Random().nextFloat();
|
||||
ItemEntity entity = new ItemEntity(world, pos.getX(),
|
||||
pos.getY(), pos.getZ(), stack, scatter, scatter, 0.2);
|
||||
world.spawnEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user