|
14 | 14 | import net.minecraft.MethodsReturnNonnullByDefault; |
15 | 15 | import net.minecraft.core.NonNullList; |
16 | 16 | import net.minecraft.network.chat.Component; |
| 17 | +import net.minecraft.sounds.SoundEvent; |
17 | 18 | import net.minecraft.world.InteractionHand; |
18 | 19 | import net.minecraft.world.InteractionResult; |
19 | 20 | import net.minecraft.world.InteractionResultHolder; |
|
23 | 24 | import net.minecraft.world.entity.ai.attributes.Attribute; |
24 | 25 | import net.minecraft.world.entity.ai.attributes.AttributeModifier; |
25 | 26 | import net.minecraft.world.entity.player.Player; |
| 27 | +import net.minecraft.world.food.FoodProperties; |
26 | 28 | import net.minecraft.world.item.CreativeModeTab; |
27 | 29 | import net.minecraft.world.item.Item; |
28 | 30 | import net.minecraft.world.item.ItemStack; |
29 | 31 | import net.minecraft.world.item.TooltipFlag; |
| 32 | +import net.minecraft.world.item.UseAnim; |
30 | 33 | import net.minecraft.world.item.context.UseOnContext; |
31 | 34 | import net.minecraft.world.item.crafting.RecipeType; |
32 | 35 | import net.minecraft.world.item.enchantment.Enchantment; |
@@ -212,6 +215,16 @@ public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity livi |
212 | 215 | return stack; |
213 | 216 | } |
214 | 217 |
|
| 218 | + @Override |
| 219 | + public UseAnim getUseAnimation(ItemStack stack) { |
| 220 | + for (IItemComponent component : components) { |
| 221 | + if (component instanceof IInteractionItem interactionItem) { |
| 222 | + return interactionItem.getUseAnimation(stack); |
| 223 | + } |
| 224 | + } |
| 225 | + return super.getUseAnimation(stack); |
| 226 | + } |
| 227 | + |
215 | 228 | @Override |
216 | 229 | public InteractionResult onItemUseFirst(ItemStack itemStack, UseOnContext context) { |
217 | 230 | for (IItemComponent component : components) { |
@@ -345,12 +358,52 @@ public int getBurnTime(ItemStack itemStack, @Nullable RecipeType<?> recipeType) |
345 | 358 | return burnTime; |
346 | 359 | } |
347 | 360 |
|
| 361 | + @Override |
| 362 | + public @Nullable FoodProperties getFoodProperties(ItemStack stack, @Nullable LivingEntity entity) { |
| 363 | + for (IItemComponent component : components) { |
| 364 | + if (component instanceof IEdibleItem foodBehavior) { |
| 365 | + return foodBehavior.getFoodProperties(stack, entity); |
| 366 | + } |
| 367 | + } |
| 368 | + return super.getFoodProperties(stack, entity); |
| 369 | + } |
| 370 | + |
| 371 | + @Override |
| 372 | + public boolean isEdible() { |
| 373 | + for (IItemComponent component : components) { |
| 374 | + if (component instanceof IEdibleItem foodBehavior) { |
| 375 | + return foodBehavior.isEdible(); |
| 376 | + } |
| 377 | + } |
| 378 | + return super.isEdible(); |
| 379 | + } |
| 380 | + |
| 381 | + @Override |
| 382 | + public SoundEvent getEatingSound() { |
| 383 | + for (IItemComponent component : components) { |
| 384 | + if (component instanceof IEdibleItem foodBehavior) { |
| 385 | + return foodBehavior.getEatingSound(); |
| 386 | + } |
| 387 | + } |
| 388 | + return super.getEatingSound(); |
| 389 | + } |
| 390 | + |
| 391 | + @Override |
| 392 | + public SoundEvent getDrinkingSound() { |
| 393 | + for (IItemComponent component : components) { |
| 394 | + if (component instanceof IEdibleItem foodBehavior) { |
| 395 | + return foodBehavior.getDrinkingSound(); |
| 396 | + } |
| 397 | + } |
| 398 | + return super.getDrinkingSound(); |
| 399 | + } |
| 400 | + |
348 | 401 | public void burnTime(int burnTime) { |
349 | 402 | this.burnTime = burnTime; |
350 | 403 | } |
351 | 404 |
|
352 | 405 | /** |
353 | | - * Attempts to get an fully charged variant of this electric item |
| 406 | + * Attempts to get a fully charged variant of this electric item |
354 | 407 | * |
355 | 408 | * @param chargeAmount amount of charge |
356 | 409 | * @return charged electric item stack |
|
0 commit comments