-
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
11 changed files
with
185 additions
and
5 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
77 changes: 77 additions & 0 deletions
77
src/main/java/com/megatrex4/ukrainian_dlight/item/CustomFoodItem.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,77 @@ | ||
package com.megatrex4.ukrainian_dlight.item; | ||
|
||
import java.util.List; | ||
|
||
import com.mojang.datafixers.util.Pair; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.item.TooltipContext; | ||
import net.minecraft.entity.effect.StatusEffectInstance; | ||
import net.minecraft.item.FoodComponent; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class CustomFoodItem extends Item { | ||
|
||
public CustomFoodItem(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
// This method adds tooltip information to the item when hovered over in the inventory | ||
@Override | ||
@Environment(EnvType.CLIENT) | ||
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) { | ||
super.appendTooltip(stack, world, tooltip, context); | ||
|
||
// Retrieve the FoodComponent of the item | ||
FoodComponent foodComponent = this.getFoodComponent(); | ||
|
||
// Check if the FoodComponent exists and if it has any status effects | ||
if (foodComponent != null && !foodComponent.getStatusEffects().isEmpty()) { | ||
// Call a method to add the status effects to the tooltip | ||
addFoodEffectTooltip(stack, tooltip, foodComponent.getStatusEffects()); | ||
} | ||
} | ||
|
||
// This method adds status effect information to the tooltip | ||
public static void addFoodEffectTooltip(ItemStack itemStack, List<Text> tooltip, List<Pair<StatusEffectInstance, Float>> effects) { | ||
// If there are no effects, add a message indicating that there are no effects | ||
if (effects.isEmpty()) { | ||
tooltip.add(Text.translatable("tooltip.ukrainian_delight.no_effects").formatted(Formatting.GRAY)); | ||
} else { | ||
// Iterate through each effect and add its information to the tooltip | ||
for (Pair<StatusEffectInstance, Float> pair : effects) { | ||
StatusEffectInstance effect = pair.getFirst(); | ||
String name = effect.getEffectType().getTranslationKey(); | ||
int duration = effect.getDuration() / 20; // Convert ticks to seconds | ||
int amplifier = effect.getAmplifier(); | ||
String durationString = formatDuration(duration); | ||
|
||
// Combine the effect name and duration, formatting them as blue text | ||
Text tooltipText = Text.translatable(name).formatted(Formatting.BLUE) | ||
.append(Text.of(" (" + durationString + ") ")); | ||
|
||
// Add the tooltip text to the list | ||
tooltip.add(tooltipText); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
// This method formats the duration of an effect | ||
private static String formatDuration(int duration) { | ||
int minutes = duration / 60; | ||
int seconds = duration % 60; | ||
|
||
return String.format("%d:%02d", minutes, seconds); | ||
} | ||
} |
45 changes: 44 additions & 1 deletion
45
src/main/java/com/megatrex4/ukrainian_dlight/item/ModFoodComponents.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 |
---|---|---|
@@ -1,7 +1,50 @@ | ||
package com.megatrex4.ukrainian_dlight.item; | ||
|
||
import net.minecraft.entity.effect.StatusEffect; | ||
import net.minecraft.entity.effect.StatusEffectInstance; | ||
import net.minecraft.item.FoodComponent; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ModFoodComponents { | ||
public static final FoodComponent VARENYK = new FoodComponent.Builder().hunger(3).saturationModifier(0.25f).snack().build(); | ||
// Define identifiers for effects from other mods | ||
public static final Identifier COMFORT = new Identifier("farmersdelight", "comfort"); | ||
public static final Identifier NOURISHMENT = new Identifier("farmersdelight", "nourishment"); | ||
public static final Identifier SATURATION = new Identifier("minecraft", "saturation"); | ||
|
||
// Define food components with multiple effects | ||
public static final FoodComponent VARENYK = createFoodComponent(3, 0.25f, COMFORT, 200, 0); | ||
public static final FoodComponent BORSCHT = createFoodComponent(4, 0.25f, NOURISHMENT, 200, 0); | ||
// public static final FoodComponent TOMATO = createFoodComponent(1, 0.1f); | ||
|
||
// Method to create food component with multiple effects | ||
public static FoodComponent createFoodComponent(int hunger, float saturation, @Nullable Identifier effectId, int duration, int amplifier) { | ||
if (effectId == null) { | ||
return createFoodComponent(hunger, saturation); | ||
} | ||
|
||
FoodComponent.Builder builder = new FoodComponent.Builder() | ||
.hunger(hunger) | ||
.saturationModifier(saturation); | ||
|
||
StatusEffect effect = Registries.STATUS_EFFECT.getOrEmpty(effectId).orElse(null); | ||
|
||
if (effect != null) { | ||
builder.statusEffect(new StatusEffectInstance(effect, duration, amplifier), 1.0F); | ||
} else { | ||
throw new IllegalArgumentException("Invalid effectId: " + effectId); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
// Overloaded method to create food component without effects | ||
public static FoodComponent createFoodComponent(int hunger, float saturation) { | ||
return new FoodComponent.Builder() | ||
.hunger(hunger) | ||
.saturationModifier(saturation) | ||
.build(); | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"item.minecraft.beetroot_soup": "Суп з буряка" | ||
} |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"itemgroup.ukrainian_delight": "Ukrainian Delight", | ||
|
||
"item.ukrainian_delight.varenyk": "Varenyk" | ||
"item.ukrainian_delight.varenyk": "Varenyk", | ||
"item.ukrainian_delight.borscht": "Borscht", | ||
|
||
"ukranian_delight.rei": "Ukrainian Delight" | ||
} |
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,6 @@ | ||
{ | ||
"itemgroup.ukrainian_delight": "Українська насолода", | ||
|
||
"item.ukrainian_delight.varenyk": "Вареник", | ||
"item.ukrainian_delight.borscht": "Борщ" | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/resources/data/ukrainian_delight/recipes/cooking/varenyk.json
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,29 @@ | ||
{ | ||
"type": "farmersdelight:cooking", | ||
"cookingtime": 200, | ||
"experience": 1.0, | ||
"ingredients": [ | ||
{ | ||
"tag": "c:dough" | ||
}, | ||
{ | ||
"item": "minecaft:carrot" | ||
}, | ||
{ | ||
"item": "minecraft:potato" | ||
}, | ||
{ | ||
"tag": "c:crops/onion" | ||
}, | ||
[ | ||
{ | ||
"tag": "c:raw_beef" | ||
} | ||
] | ||
], | ||
"recipe_book_tab": "misc", | ||
"result": { | ||
"count": 2, | ||
"item": "ukrainian_delight:varenyk" | ||
} | ||
} |