mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 07:17:58 +01:00
Added pineapples and bananas
This commit is contained in:
parent
83a9786e2b
commit
f2349199a5
21 changed files with 150 additions and 2 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "unicopia:item/banana"
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "unicopia:item/pineapple_bite1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "unicopia:item/pineapple_bite2"
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/unicopia/textures/item/banana.png
Normal file
BIN
src/main/resources/assets/unicopia/textures/item/banana.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
src/main/resources/assets/unicopia/textures/item/pineapple.png
Normal file
BIN
src/main/resources/assets/unicopia/textures/item/pineapple.png
Normal file
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 |
6
src/main/resources/data/c/tags/items/banana.json
Normal file
6
src/main/resources/data/c/tags/items/banana.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"unicopia:banana"
|
||||
]
|
||||
}
|
6
src/main/resources/data/c/tags/items/bananas.json
Normal file
6
src/main/resources/data/c/tags/items/bananas.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"unicopia:banana"
|
||||
]
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"unicopia:mango"
|
||||
"unicopia:mango",
|
||||
"unicopia:banana",
|
||||
"unicopia:pineapple"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"unicopia:mango"
|
||||
"unicopia:mango",
|
||||
"unicopia:banana",
|
||||
"unicopia:pineapple"
|
||||
]
|
||||
}
|
||||
|
|
6
src/main/resources/data/c/tags/items/pineapple.json
Normal file
6
src/main/resources/data/c/tags/items/pineapple.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"unicopia:pineapple"
|
||||
]
|
||||
}
|
6
src/main/resources/data/c/tags/items/pineapples.json
Normal file
6
src/main/resources/data/c/tags/items/pineapples.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"unicopia:pineapple"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"minecraft:regeneration",
|
||||
"minecraft:absorption",
|
||||
"minecraft:luck",
|
||||
"minecraft:haste"
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue