forked from GregTechCEu/GregTech-Modern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
327 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...eu/gtceu/api/item/forge/GTBucketItem.java → ...gtechceu/gtceu/api/item/GTBucketItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/com/gregtechceu/gtceu/api/item/component/FoodStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.gregtechceu.gtceu.api.item.component; | ||
|
||
import com.gregtechceu.gtceu.utils.GTUtil; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.food.FoodProperties; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.TooltipFlag; | ||
import net.minecraft.world.item.UseAnim; | ||
import net.minecraft.world.level.Level; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Simple {@link IEdibleItem} implementation. | ||
* | ||
* @author GateGuardian | ||
* @date : 2024/7/22 | ||
*/ | ||
public class FoodStats implements IEdibleItem, IInteractionItem, IAddInformation { | ||
|
||
protected final FoodProperties properties; | ||
|
||
protected final boolean isDrink; | ||
|
||
@Nullable | ||
protected final Supplier<ItemStack> containerItem; | ||
|
||
public FoodStats(FoodProperties properties, boolean isDrink, @Nullable Supplier<ItemStack> containerItem) { | ||
this.properties = properties; | ||
this.isDrink = isDrink; | ||
this.containerItem = containerItem; | ||
} | ||
|
||
@Override | ||
public FoodProperties getFoodProperties(ItemStack stack, @Nullable LivingEntity entity) { | ||
return properties; | ||
} | ||
|
||
@Override | ||
public boolean isEdible() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public SoundEvent getEatingSound() { | ||
return isDrink ? getDrinkingSound() : IEdibleItem.super.getEatingSound(); | ||
} | ||
|
||
@Override | ||
public UseAnim getUseAnimation(ItemStack stack) { | ||
return isDrink ? UseAnim.DRINK : UseAnim.EAT; | ||
} | ||
|
||
@Override | ||
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents, | ||
TooltipFlag isAdvanced) { | ||
GTUtil.addPotionTooltip(properties.getEffects(), tooltipComponents); | ||
} | ||
|
||
@Override | ||
public ItemStack finishUsingItem(ItemStack food, Level level, LivingEntity livingEntity) { | ||
Player player = livingEntity instanceof Player ? (Player) livingEntity : null; | ||
var stack = livingEntity.eat(level, food); | ||
if (containerItem != null && (player == null || !player.getAbilities().instabuild)) { | ||
var container = containerItem.get(); | ||
if (stack.isEmpty()) { | ||
return container; | ||
} | ||
|
||
if (player != null) { | ||
if (!player.getInventory().add(container)) { | ||
player.drop(container, true); | ||
} | ||
} | ||
} | ||
return stack; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/gregtechceu/gtceu/api/item/component/IEdibleItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.gregtechceu.gtceu.api.item.component; | ||
|
||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.food.FoodProperties; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface IEdibleItem { | ||
|
||
FoodProperties getFoodProperties(ItemStack stack, @Nullable LivingEntity entity); | ||
|
||
boolean isEdible(); | ||
|
||
default SoundEvent getEatingSound() { | ||
return SoundEvents.GENERIC_EAT; | ||
} | ||
|
||
default SoundEvent getDrinkingSound() { | ||
return SoundEvents.GENERIC_DRINK; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...u/common/data/forge/GTBiomeModifiers.java → ...u/gtceu/common/data/GTBiomeModifiers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.