Refreshing drink

- Switch to using food properties and simplify BuildersTeaItem#finishUsingItem
- Fixes Creators-of-Create/Create#7295
This commit is contained in:
IThundxr 2025-01-19 10:58:01 -05:00
parent 664a7fa954
commit 0c277b1b95
Failed to generate hash of commit
2 changed files with 27 additions and 41 deletions

View file

@ -73,6 +73,8 @@ import com.tterrag.registrate.util.nullness.NonNullBiConsumer;
import net.minecraft.core.registries.Registries;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterials;
@ -152,7 +154,16 @@ public class AllItems {
public static final ItemEntry<BuildersTeaItem> BUILDERS_TEA = REGISTRATE.item("builders_tea", BuildersTeaItem::new)
.tag(AllItemTags.UPRIGHT_ON_BELT.tag)
.properties(p -> p.stacksTo(16))
.properties(p -> p
.stacksTo(16)
.food(new FoodProperties.Builder()
.nutrition(1)
.saturationMod(.6F)
.alwaysEat()
.effect(() -> new MobEffectInstance(MobEffects.DIG_SPEED, 3 * 60 * 20, 0, false, false, false), 1F)
.build()
)
)
.lang("Builder's Tea")
.register();

View file

@ -1,12 +1,5 @@
package com.simibubi.create.content.equipment;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
@ -15,48 +8,30 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
public class BuildersTeaItem extends Item {
public BuildersTeaItem(Properties p_i48487_1_) {
super(p_i48487_1_);
public BuildersTeaItem(Properties properties) {
super(properties);
}
public ItemStack finishUsingItem(ItemStack stack, Level world, LivingEntity entity) {
Player playerentity = entity instanceof Player ? (Player) entity : null;
if (playerentity instanceof ServerPlayer)
CriteriaTriggers.CONSUME_ITEM.trigger((ServerPlayer) playerentity, stack);
if (!world.isClientSide)
entity.addEffect(new MobEffectInstance(MobEffects.DIG_SPEED, 3 * 60 * 20, 0, false, false, false));
if (playerentity != null) {
playerentity.awardStat(Stats.ITEM_USED.get(this));
playerentity.getFoodData().eat(1, .6F);
if (!playerentity.getAbilities().instabuild)
stack.shrink(1);
public @NotNull ItemStack finishUsingItem(@NotNull ItemStack stack, @NotNull Level level, @NotNull LivingEntity livingEntity) {
ItemStack eatResult = super.finishUsingItem(stack, level, livingEntity);
if (livingEntity instanceof Player player && !player.getAbilities().instabuild) {
if (eatResult.isEmpty()) {
return Items.GLASS_BOTTLE.getDefaultInstance();
} else {
player.getInventory().add(Items.GLASS_BOTTLE.getDefaultInstance());
}
}
if (playerentity == null || !playerentity.getAbilities().instabuild) {
if (stack.isEmpty())
return new ItemStack(Items.GLASS_BOTTLE);
if (playerentity != null)
playerentity.getInventory().add(new ItemStack(Items.GLASS_BOTTLE));
}
return stack;
return eatResult;
}
public int getUseDuration(ItemStack p_77626_1_) {
public int getUseDuration(@NotNull ItemStack stack) {
return 42;
}
public UseAnim getUseAnimation(ItemStack p_77661_1_) {
public @NotNull UseAnim getUseAnimation(@NotNull ItemStack stack) {
return UseAnim.DRINK;
}
public InteractionResultHolder<ItemStack> use(Level p_77659_1_, Player p_77659_2_, InteractionHand p_77659_3_) {
p_77659_2_.startUsingItem(p_77659_3_);
return InteractionResultHolder.success(p_77659_2_.getItemInHand(p_77659_3_));
}
}