0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【MCreator/NeoForge】食べ物のアニメーションをDrinkingにできない?

Posted at

どうも、Motchiyの友人ことさいほうへいきです。ところでマジでMotchiyって誰?
この記事では、MCreatorで飲み物を作ろうとした時、食事アニメーションがうまくDrinkに設定できなかったので、その時の記録を書いておこうと思います。

概要

MCreator 2025.1ユーザーです。
なんでか分かりませんが、Itemとして飲み物を作った時、Item AnimationをDrinkingに設定してるのにもかかわらずモグモグモシャモシャ食べてしまう怪現象に遭遇しました。
で、調べてみたところ、どうやら『アイテムを使うアニメーション』と『食べ物としてのアニメーション』は別枠扱いみたいでした。
ややこしい。

対象者

誰に:

  • MCreatorを使ってます
    目的は:
  • ゴクゴク飲めるFoodを作りたい。

ポーションはポーションとして作るので別枠ですね。この記事では、例えばお茶とかビールのような、Itemとして作る飲み物が目的です。🍵

MCreatorを多少使い慣れている人向けに書いていますので、分からない用語もちらほらあるかもしれません。
一応、僕は英語版ユーザーなので、日本語化してMCreatorを使っている方は頑張ってください。

さっそく、やりかた

普通に食べ物を作る

結論から言いますとこのやり方はJavaをいじります。
とはいえやっぱカスタムエレメントを書くのはだるいため、前回やったのと同様に、まずは雛形というかベースとなる食べ物を作っておきます。

名前や見た目、満腹度などを各種設定して保存しましょう。

Javaをいじくる

次はそのコードを編集します。コード編集はワークスペース画面の左側、三と✏のアイコンを押せばできます。

今回は記事用に新しくエレメントを作るのが面倒だったのでとりあえず僕が使っているコードをそのままはっつけるとします。
アーチャウ茶ですね。

AhchawTeaItem.java(編集前)

package net.mcreator.ahchawtea.item;

import net.minecraft.world.level.Level;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ItemUseAnimation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Item;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.LivingEntity;

import net.mcreator.ahchawtea.procedures.AhchawTeaPlayerFinishesUsingItemProcedure;

public class AhchawTeaItem extends Item {
	public AhchawTeaItem(Item.Properties properties) {
		super(properties.rarity(Rarity.COMMON).stacksTo(16).food((new FoodProperties.Builder()).nutrition(3).saturationModifier(0.3f).alwaysEdible().build()));
	}

	@Override
	public ItemUseAnimation getUseAnimation(ItemStack itemstack) {
		return ItemUseAnimation.DRINK;
	}

	@Override
	public ItemStack finishUsingItem(ItemStack itemstack, Level world, LivingEntity entity) {
		ItemStack retval = new ItemStack(Items.GLASS_BOTTLE);
		super.finishUsingItem(itemstack, world, entity);
		double x = entity.getX();
		double y = entity.getY();
		double z = entity.getZ();
		AhchawTeaPlayerFinishesUsingItemProcedure.execute(entity);
		if (itemstack.isEmpty()) {
			return retval;
		} else {
			if (entity instanceof Player player && !player.getAbilities().instabuild) {
				if (!player.getInventory().add(retval))
					player.drop(retval, false);
			}
			return itemstack;
		}
	}
}

長い!!
……けど、ここで重要なのはそのうちの一行だけです。

AhchawTeaItem.java
		super(properties.rarity(Rarity.COMMON).stacksTo(16).food((new FoodProperties.Builder()).nutrition(3).saturationModifier(0.3f).alwaysEdible().build()));

このコードは見ての通り、アイテムとしての基本データを設定しているものです。
では、ここを別の一行に置き換えてみましょう。

AhchawTeaItem.java
		super(properties.rarity(Rarity.COMMON).stacksTo(16).food((new FoodProperties(3,0.3f,true)), new Consumable(1.6f,ItemUseAnimation.DRINK,SoundEvents.GENERIC_DRINK,false, new ArrayList<>())));

コピーアンドペーストで置き換えて構いません。ただ、stacksTo(スタックできる数)やFoodProperties(それぞれ満腹度回復、隠し満腹度、いつでも食べられるか)などは各自で変更してください。

ついでにimportもいくらか追加があります。
ファイルの冒頭にこの2行を追加してください。

AhchawTeaItem.java
import java.util.ArrayList;
import net.minecraft.world.item.component.Consumable;

そして保存!
実行!
2025-09-24_08.52.44.png
おおおおお、飲めた。やったね。

おわり

というわけで今回は、食べ物を飲み物に変えてみました。
なにかご指摘等あれば、ぜひお寄せくださいm(_ _)m
ではまた。

参考にしたページ

【フードプロパティを追加】Forge Modding #17
https://moeya3d.com/neoforgemodding17/4626/

Consumables|NeoForged Docs
https://docs.neoforged.net/docs/items/consumables/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?