diff --git a/src/main/java/com/minelittlepony/unicopia/UTags.java b/src/main/java/com/minelittlepony/unicopia/UTags.java index e8c3a65f..1c76ab57 100644 --- a/src/main/java/com/minelittlepony/unicopia/UTags.java +++ b/src/main/java/com/minelittlepony/unicopia/UTags.java @@ -4,6 +4,7 @@ import com.minelittlepony.unicopia.item.toxin.Toxics; import net.minecraft.block.Block; import net.minecraft.entity.EntityType; +import net.minecraft.entity.effect.StatusEffect; import net.minecraft.item.Item; import net.minecraft.registry.*; import net.minecraft.registry.tag.TagKey; @@ -36,6 +37,8 @@ public interface UTags { TagKey> TRANSFORMABLE_ENTITIES = entity("transformable"); + TagKey PINEAPPLE_EFFECTS = effect("pineapple_effects"); + static TagKey item(String name) { return TagKey.of(RegistryKeys.ITEM, Unicopia.id(name)); } @@ -48,6 +51,10 @@ public interface UTags { return TagKey.of(RegistryKeys.ENTITY_TYPE, Unicopia.id(name)); } + static TagKey effect(String name) { + return TagKey.of(RegistryKeys.STATUS_EFFECT, Unicopia.id(name)); + } + static void bootstrap() { Toxics.bootstrap(); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/PineappleItem.java b/src/main/java/com/minelittlepony/unicopia/item/PineappleItem.java new file mode 100644 index 00000000..14360d98 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/PineappleItem.java @@ -0,0 +1,40 @@ +package com.minelittlepony.unicopia.item; + +import com.minelittlepony.unicopia.AwaitTickQueue; +import com.minelittlepony.unicopia.UTags; +import com.minelittlepony.unicopia.util.RegistryUtils; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.world.World; + +public class PineappleItem extends Item { + public PineappleItem(Settings settings) { + super(settings); + } + + @Override + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { + if (isFood()) { + user.eatFood(world, stack.copy()); + if (!world.isClient) { + stack.damage(1, user, u -> { + AwaitTickQueue.scheduleTask(u.world, w -> { + w.playSoundFromEntity(null, u, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 1, 0.7F); + }); + }); + + if (world.random.nextInt(20) == 0) { + RegistryUtils.pickRandom(world, UTags.PINEAPPLE_EFFECTS, e -> !user.hasStatusEffect(e)).ifPresent(effect -> { + user.addStatusEffect(new StatusEffectInstance(effect, 10, 1)); + }); + } + } + } + return stack; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItems.java b/src/main/java/com/minelittlepony/unicopia/item/UItems.java index 6b04956e..192dc4b4 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/item/UItems.java @@ -75,6 +75,8 @@ public interface UItems { Item PINECONE = register("pinecone", new Item(new Item.Settings().food(UFoodComponents.PINECONE).maxCount(3)), ItemGroups.FOOD_AND_DRINK); Item ACORN = register("acorn", new Item(new Item.Settings().food(UFoodComponents.ACORN).maxCount(16)), ItemGroups.FOOD_AND_DRINK); Item MANGO = register("mango", new Item(new Item.Settings().food(UFoodComponents.MANGO)), ItemGroups.FOOD_AND_DRINK); + Item BANANA = register("banana", new Item(new Item.Settings().food(UFoodComponents.BANANA)), ItemGroups.FOOD_AND_DRINK); + Item PINEAPPLE = register("pineapple", new PineappleItem(new Item.Settings().food(UFoodComponents.BANANA).maxDamage(3)), ItemGroups.FOOD_AND_DRINK); Item PEBBLES = register("pebbles", new RacePredicatedAliasedBlockItem(UBlocks.ROCKS, new Item.Settings(), Race::canUseEarth), ItemGroups.NATURAL); Item ROCK = register("rock", new HeavyProjectileItem(new Item.Settings(), 3), ItemGroups.NATURAL); diff --git a/src/main/java/com/minelittlepony/unicopia/item/toxin/UFoodComponents.java b/src/main/java/com/minelittlepony/unicopia/item/toxin/UFoodComponents.java index 8e7d56d7..5670e89c 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/toxin/UFoodComponents.java +++ b/src/main/java/com/minelittlepony/unicopia/item/toxin/UFoodComponents.java @@ -42,6 +42,7 @@ public interface UFoodComponents { FoodComponent PINECONE = builder(0, 0.01F).snack().alwaysEdible().build(); FoodComponent ACORN = builder(1, 0.01F).snack().alwaysEdible().build(); FoodComponent MANGO = builder(8, 0.8F).alwaysEdible().build(); + FoodComponent BANANA = builder(6, 0.9F).build(); static FoodComponent.Builder builder(int hunger, float saturation) { return new FoodComponent.Builder() diff --git a/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java b/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java index d2619e91..a5930adb 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.util; +import java.util.Optional; +import java.util.function.Predicate; import java.util.stream.Stream; import com.mojang.serialization.Lifecycle; @@ -7,9 +9,11 @@ import com.mojang.serialization.Lifecycle; import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; import net.minecraft.registry.tag.TagKey; import net.minecraft.util.Identifier; +import net.minecraft.util.Util; import net.minecraft.registry.*; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntryList; +import net.minecraft.registry.entry.RegistryEntryList.Named; import net.minecraft.world.World; public interface RegistryUtils { @@ -28,4 +32,21 @@ public interface RegistryUtils { static Stream valuesForTag(World world, TagKey key) { return entriesForTag(world, key).stream().map(RegistryEntry::value); } + + static Optional pickRandom(World world, TagKey key) { + return world.getRegistryManager().getOptional(key.registry()) + .flatMap(registry -> registry.getEntryList(key)) + .flatMap(entries -> entries.getRandom(world.random)) + .map(RegistryEntry::value); + } + + static Optional pickRandom(World world, TagKey key, Predicate filter) { + return Util.getRandomOrEmpty(world.getRegistryManager().getOptional(key.registry()) + .flatMap(registry -> registry.getEntryList(key)) + .stream() + .flatMap(Named::stream) + .map(RegistryEntry::value) + .filter(filter) + .toList(), world.random); + } } diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index b837e5f6..78a014bc 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -74,6 +74,8 @@ "item.unicopia.burned_juice": "Burned Juice", "item.unicopia.mango": "Mango", + "item.unicopia.banana": "Banana", + "item.unicopia.pineapple": "Pineapple", "item.unicopia.sunglasses": "Sunglasses", "item.unicopia.broken_sunglasses": "Broken Sunglasses", diff --git a/src/main/resources/assets/unicopia/models/item/banana.json b/src/main/resources/assets/unicopia/models/item/banana.json new file mode 100644 index 00000000..ebc8e4a0 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/banana.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "unicopia:item/banana" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/pineapple.json b/src/main/resources/assets/unicopia/models/item/pineapple.json new file mode 100644 index 00000000..0c243a7f --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/pineapple.json @@ -0,0 +1,20 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "unicopia:item/pineapple" + }, + "overrides": [ + { + "predicate": { + "damage": 0.3 + }, + "model": "unicopia:item/pineapple_bite1" + }, + { + "predicate": { + "damage": 0.6 + }, + "model": "unicopia:item/pineapple_bite2" + } + ] +} diff --git a/src/main/resources/assets/unicopia/models/item/pineapple_bite1.json b/src/main/resources/assets/unicopia/models/item/pineapple_bite1.json new file mode 100644 index 00000000..ebe3b66c --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/pineapple_bite1.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "unicopia:item/pineapple_bite1" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/pineapple_bite2.json b/src/main/resources/assets/unicopia/models/item/pineapple_bite2.json new file mode 100644 index 00000000..044a6bce --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/pineapple_bite2.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "unicopia:item/pineapple_bite2" + } +} diff --git a/src/main/resources/assets/unicopia/textures/item/banana.png b/src/main/resources/assets/unicopia/textures/item/banana.png new file mode 100644 index 00000000..9074a939 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/banana.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/pineapple.png b/src/main/resources/assets/unicopia/textures/item/pineapple.png new file mode 100644 index 00000000..651102c5 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/pineapple.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/pineapple_bite1.png b/src/main/resources/assets/unicopia/textures/item/pineapple_bite1.png new file mode 100644 index 00000000..0981c3b7 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/pineapple_bite1.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/pineapple_bite2.png b/src/main/resources/assets/unicopia/textures/item/pineapple_bite2.png new file mode 100644 index 00000000..155a85c2 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/pineapple_bite2.png differ diff --git a/src/main/resources/data/c/tags/items/banana.json b/src/main/resources/data/c/tags/items/banana.json new file mode 100644 index 00000000..f2e0bcc6 --- /dev/null +++ b/src/main/resources/data/c/tags/items/banana.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "unicopia:banana" + ] +} diff --git a/src/main/resources/data/c/tags/items/bananas.json b/src/main/resources/data/c/tags/items/bananas.json new file mode 100644 index 00000000..f2e0bcc6 --- /dev/null +++ b/src/main/resources/data/c/tags/items/bananas.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "unicopia:banana" + ] +} diff --git a/src/main/resources/data/c/tags/items/fruit.json b/src/main/resources/data/c/tags/items/fruit.json index 2f6d5efe..6cd22ee2 100644 --- a/src/main/resources/data/c/tags/items/fruit.json +++ b/src/main/resources/data/c/tags/items/fruit.json @@ -1,6 +1,8 @@ { "replace": false, "values": [ - "unicopia:mango" + "unicopia:mango", + "unicopia:banana", + "unicopia:pineapple" ] } diff --git a/src/main/resources/data/c/tags/items/fruits.json b/src/main/resources/data/c/tags/items/fruits.json index 2f6d5efe..6cd22ee2 100644 --- a/src/main/resources/data/c/tags/items/fruits.json +++ b/src/main/resources/data/c/tags/items/fruits.json @@ -1,6 +1,8 @@ { "replace": false, "values": [ - "unicopia:mango" + "unicopia:mango", + "unicopia:banana", + "unicopia:pineapple" ] } diff --git a/src/main/resources/data/c/tags/items/pineapple.json b/src/main/resources/data/c/tags/items/pineapple.json new file mode 100644 index 00000000..60c5a61e --- /dev/null +++ b/src/main/resources/data/c/tags/items/pineapple.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "unicopia:pineapple" + ] +} diff --git a/src/main/resources/data/c/tags/items/pineapples.json b/src/main/resources/data/c/tags/items/pineapples.json new file mode 100644 index 00000000..60c5a61e --- /dev/null +++ b/src/main/resources/data/c/tags/items/pineapples.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "unicopia:pineapple" + ] +} diff --git a/src/main/resources/data/unicopia/tags/status_effect/pineapple_effects.json b/src/main/resources/data/unicopia/tags/status_effect/pineapple_effects.json new file mode 100644 index 00000000..5f8e5576 --- /dev/null +++ b/src/main/resources/data/unicopia/tags/status_effect/pineapple_effects.json @@ -0,0 +1,9 @@ +{ + "replace": false, + "values": [ + "minecraft:regeneration", + "minecraft:absorption", + "minecraft:luck", + "minecraft:haste" + ] +}