Added pineapples and bananas

This commit is contained in:
Sollace 2023-05-23 09:48:40 +01:00
parent 83a9786e2b
commit f2349199a5
21 changed files with 150 additions and 2 deletions

View file

@ -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<EntityType<?>> TRANSFORMABLE_ENTITIES = entity("transformable");
TagKey<StatusEffect> PINEAPPLE_EFFECTS = effect("pineapple_effects");
static TagKey<Item> 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<StatusEffect> effect(String name) {
return TagKey.of(RegistryKeys.STATUS_EFFECT, Unicopia.id(name));
}
static void bootstrap() {
Toxics.bootstrap();
}

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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()

View file

@ -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 <T> Stream<T> valuesForTag(World world, TagKey<T> key) {
return entriesForTag(world, key).stream().map(RegistryEntry::value);
}
static <T> Optional<T> pickRandom(World world, TagKey<T> key) {
return world.getRegistryManager().getOptional(key.registry())
.flatMap(registry -> registry.getEntryList(key))
.flatMap(entries -> entries.getRandom(world.random))
.map(RegistryEntry::value);
}
static <T> Optional<T> pickRandom(World world, TagKey<T> key, Predicate<T> 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);
}
}

View file

@ -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",

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/banana"
}
}

View file

@ -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"
}
]
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/pineapple_bite1"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/pineapple_bite2"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"unicopia:banana"
]
}

View file

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"unicopia:banana"
]
}

View file

@ -1,6 +1,8 @@
{
"replace": false,
"values": [
"unicopia:mango"
"unicopia:mango",
"unicopia:banana",
"unicopia:pineapple"
]
}

View file

@ -1,6 +1,8 @@
{
"replace": false,
"values": [
"unicopia:mango"
"unicopia:mango",
"unicopia:banana",
"unicopia:pineapple"
]
}

View file

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"unicopia:pineapple"
]
}

View file

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"unicopia:pineapple"
]
}

View file

@ -0,0 +1,9 @@
{
"replace": false,
"values": [
"minecraft:regeneration",
"minecraft:absorption",
"minecraft:luck",
"minecraft:haste"
]
}