From 55a559321a751cac6620fb25e15480129cbd9b50 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 25 Apr 2020 18:41:48 +0200 Subject: [PATCH] Pull food values out into some constants --- .../unicopia/item/AppleItem.java | 4 +- .../unicopia/item/MossItem.java | 8 +- .../unicopia/item/RottenTomatoItem.java | 5 +- .../unicopia/item/TomatoItem.java | 12 +- .../unicopia/item/TomatoSeedsItem.java | 5 +- .../unicopia/item/UFoodComponents.java | 27 +++ .../minelittlepony/unicopia/item/UItems.java | 206 +++++++++++------- .../unicopia/item/ZapAppleItem.java | 2 +- .../minelittlepony/unicopia/toxin/Toxic.java | 63 +++++- .../unicopia/toxin/ToxicBlockItem.java | 45 +--- .../unicopia/toxin/ToxicItem.java | 47 +--- 11 files changed, 243 insertions(+), 181 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/item/UFoodComponents.java diff --git a/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java index 98608c05..79720d6f 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java @@ -5,7 +5,6 @@ import javax.annotation.Nullable; import com.minelittlepony.unicopia.ducks.IItemEntity; import com.minelittlepony.unicopia.entity.ItemEntityCapabilities; -import com.minelittlepony.unicopia.toxin.Toxic; import com.minelittlepony.unicopia.toxin.Toxicity; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.EntityType; @@ -20,7 +19,7 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -public class AppleItem extends Item implements Toxic, ItemEntityCapabilities.TickableItem { +public class AppleItem extends Item implements ItemEntityCapabilities.TickableItem { public AppleItem(FoodComponent components) { super(new Item.Settings() @@ -69,7 +68,6 @@ public class AppleItem extends Item implements Toxic, ItemEntityCapabilities.Tic tooltip.add(getToxicity(stack).getTooltip()); } - @Override public Toxicity getToxicity(ItemStack stack) { return Toxicity.SAFE; } diff --git a/src/main/java/com/minelittlepony/unicopia/item/MossItem.java b/src/main/java/com/minelittlepony/unicopia/item/MossItem.java index 36039759..811ea166 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/MossItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/MossItem.java @@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.blockstate.StateMaps; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.toxin.ToxicItem; import com.minelittlepony.unicopia.toxin.Toxicity; +import com.minelittlepony.unicopia.toxin.Toxin; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -21,7 +22,7 @@ import net.minecraft.world.World; public class MossItem extends ToxicItem { public MossItem(Item.Settings settings) { - super(settings, 2, 1, UseAction.EAT, Toxicity.FAIR); + super(settings, UseAction.EAT, Toxicity.MILD, Toxin.FOOD); } public boolean tryConvert(World world, BlockState state, BlockPos pos, @Nullable PlayerEntity player) { @@ -45,9 +46,4 @@ public class MossItem extends ToxicItem { return false; } - - @Override - public Toxicity getToxicity(ItemStack stack) { - return Toxicity.MILD; - } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/RottenTomatoItem.java b/src/main/java/com/minelittlepony/unicopia/item/RottenTomatoItem.java index faa2a7c1..dba28d81 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/RottenTomatoItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/RottenTomatoItem.java @@ -19,9 +19,8 @@ import net.minecraft.world.World; public class RottenTomatoItem extends TomatoItem implements TossableItem { - public RottenTomatoItem(int hunger, float saturation) { - super(hunger, saturation); - + public RottenTomatoItem(Settings settings) { + super(settings); setDispenseable(); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/TomatoItem.java b/src/main/java/com/minelittlepony/unicopia/item/TomatoItem.java index 13fc1a36..3d8d11c7 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/TomatoItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/TomatoItem.java @@ -2,22 +2,14 @@ package com.minelittlepony.unicopia.item; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.item.FoodComponent; import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class TomatoItem extends Item { - public TomatoItem(int hunger, float saturation) { - super(new Settings() - .group(ItemGroup.FOOD) - .food(new FoodComponent.Builder() - .hunger(hunger) - .saturationModifier(saturation) - .build()) - ); + public TomatoItem(Settings settings) { + super(settings); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/TomatoSeedsItem.java b/src/main/java/com/minelittlepony/unicopia/item/TomatoSeedsItem.java index 5fcdec6c..7f78da44 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/TomatoSeedsItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/TomatoSeedsItem.java @@ -7,14 +7,13 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemUsageContext; import net.minecraft.util.ActionResult; public class TomatoSeedsItem extends Item { - public TomatoSeedsItem() { - super(new Settings().group(ItemGroup.MATERIALS)); + public TomatoSeedsItem(Item.Settings settings) { + super(settings); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/UFoodComponents.java b/src/main/java/com/minelittlepony/unicopia/item/UFoodComponents.java new file mode 100644 index 00000000..0b584a6f --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/UFoodComponents.java @@ -0,0 +1,27 @@ +package com.minelittlepony.unicopia.item; + +import net.minecraft.item.FoodComponent; + +public interface UFoodComponents { + + FoodComponent BAD_TOMATO = builder(3, 14).build(); + FoodComponent TOMATO = builder(4, 13).build(); + FoodComponent GOOD_TOMATO = builder(6, 14).build(); + + FoodComponent ALFALFA_SEEDS = builder(1, 4).build(); + FoodComponent ALFALFA_LEAVES = builder(1, 3).build(); + FoodComponent DAFODIL_DAISY_SANDWICH = builder(3, 2).build(); + FoodComponent HAY_BURGER = builder(3, 4).build(); + FoodComponent HAY_FRIES = builder(1, 5).build(); + FoodComponent SALAD = builder(4, 2).build(); + FoodComponent RANDOM_FOLIAGE = builder(2, 1).build(); + FoodComponent JUICE = builder(2, 2).build(); + FoodComponent BURNED_JUICE = builder(3, 1).build(); + FoodComponent WORMS = builder(1, 0).alwaysEdible().build(); + + static FoodComponent.Builder builder(int hunger, float saturation) { + return new FoodComponent.Builder() + .hunger(hunger) + .saturationModifier(saturation); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItems.java b/src/main/java/com/minelittlepony/unicopia/item/UItems.java index e4191ff9..69cabdb5 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/item/UItems.java @@ -12,6 +12,7 @@ import com.minelittlepony.unicopia.toxin.Toxicity; import com.minelittlepony.unicopia.toxin.Toxin; import net.minecraft.item.Item; +import net.minecraft.item.Item.Settings; import net.minecraft.item.ItemGroup; import net.minecraft.block.Blocks; import net.minecraft.item.AliasedBlockItem; @@ -37,47 +38,47 @@ public interface UItems { ZapAppleItem ZAP_APPLE = register(new ZapAppleItem(), "zap_apple"); AppleItem ROTTEN_APPLE = register(new RottenAppleItem(FoodComponents.APPLE), "rotten_apple"); - AppleItem cooked_zap_apple = register(new AppleItem(FoodComponents.APPLE), "cooked_zap_apple"); + AppleItem COOKED_ZAP_APPLE = register(new AppleItem(FoodComponents.APPLE), "cooked_zap_apple"); - Item CLOUD_MATTER = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "cloud_matter"); - Item DEW_DROP = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "dew_drop"); + Item CLOUD_MATTER = register(new Item(new Settings().group(ItemGroup.MATERIALS)), "cloud_matter"); + Item DEW_DROP = register(new Item(new Settings().group(ItemGroup.MATERIALS)), "dew_drop"); CloudPlacerItem RACING_CLOUD_SPAWNER = register(new CloudPlacerItem(UEntities.RACING_CLOUD), "racing_cloud_spawner"); CloudPlacerItem CONSTRUCTION_CLOUD_SPAWNER = register(new CloudPlacerItem(UEntities.CONSTRUCTION_CLOUD), "construction_cloud_spawner"); CloudPlacerItem WILD_CLOUD_SPAWNER = register(new CloudPlacerItem(UEntities.WILD_CLOUD), "wild_cloud_spawner"); - Item CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.CLOUD_BLOCK, new Item.Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "cloud_block"); - Item ENCHANTED_CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.ENCHANTED_CLOUD_BLOCK, new Item.Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "enchanted_cloud_block"); - Item PACKED_CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.DENSE_CLOUD_BLOCK, new Item.Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "packed_cloud_block"); + Item CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.CLOUD_BLOCK, new Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "cloud_block"); + Item ENCHANTED_CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.ENCHANTED_CLOUD_BLOCK, new Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "enchanted_cloud_block"); + Item PACKED_CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.DENSE_CLOUD_BLOCK, new Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "packed_cloud_block"); - Item CLOUD_STAIRS = register(new PredicatedBlockItem(UBlocks.CLOUD_STAIRS, new Item.Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "cloud_stairs"); + Item CLOUD_STAIRS = register(new PredicatedBlockItem(UBlocks.CLOUD_STAIRS, new Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "cloud_stairs"); - Item CLOUD_FENCE = register(new PredicatedBlockItem(UBlocks.CLOUD_FENCE, new Item.Settings().group(ItemGroup.DECORATIONS), INTERACT_WITH_CLOUDS), "cloud_fence"); + Item CLOUD_FENCE = register(new PredicatedBlockItem(UBlocks.CLOUD_FENCE, new Settings().group(ItemGroup.DECORATIONS), INTERACT_WITH_CLOUDS), "cloud_fence"); - Item CLOUD_ANVIL = register(new PredicatedBlockItem(UBlocks.CLOUD_ANVIL, new Item.Settings().group(ItemGroup.DECORATIONS), INTERACT_WITH_CLOUDS), "cloud_anvil"); + Item CLOUD_ANVIL = register(new PredicatedBlockItem(UBlocks.CLOUD_ANVIL, new Settings().group(ItemGroup.DECORATIONS), INTERACT_WITH_CLOUDS), "cloud_anvil"); Item MUSIC_DISC_CRUSADE = register(createRecord(USounds.RECORD_CRUSADE), "music_disc_crusade"); Item MUSIC_DISC_PET = register(createRecord(USounds.RECORD_PET), "music_disc_pet"); Item MUSIC_DISC_POPULAR = register(createRecord(USounds.RECORD_POPULAR), "music_disc_popular"); Item MUSIC_DISC_FUNK = register(createRecord(USounds.RECORD_FUNK), "music_disc_funk"); - Item HIVE_WALL_BLOCK = register(new BlockItem(UBlocks.HIVE_WALL_BLOCK, new Item.Settings().group(ItemGroup.BUILDING_BLOCKS)), "hive_wall_block"); - Item CHITIN_SHELL = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "chitin_shell"); - Item CHITIN_SHELL_BLOCK = register(new BlockItem(UBlocks.CHITIN_SHELL_BLOCK, new Item.Settings().group(ItemGroup.BUILDING_BLOCKS)), "chitin_shell_block"); - Item CHISELED_CHITIN_SHELL_BLOCK = register(new BlockItem(UBlocks.CHISELED_CHITIN_SHELL_BLOCK, new Item.Settings().group(ItemGroup.BUILDING_BLOCKS)), "chiseled_chitin_shell_block"); - Item SLIME_DROP = register(new BlockItem(UBlocks.SLIME_DROP, new Item.Settings().group(ItemGroup.MATERIALS)), "slime_drop"); - Item SLIME_LAYER = register(new BlockItem(UBlocks.SLIME_LAYER, new Item.Settings().group(ItemGroup.DECORATIONS)), "slime_layer"); + Item HIVE_WALL_BLOCK = register(new BlockItem(UBlocks.HIVE_WALL_BLOCK, new Settings().group(ItemGroup.BUILDING_BLOCKS)), "hive_wall_block"); + Item CHITIN_SHELL = register(new Item(new Settings().group(ItemGroup.MATERIALS)), "chitin_shell"); + Item CHITIN_SHELL_BLOCK = register(new BlockItem(UBlocks.CHITIN_SHELL_BLOCK, new Settings().group(ItemGroup.BUILDING_BLOCKS)), "chitin_shell_block"); + Item CHISELED_CHITIN_SHELL_BLOCK = register(new BlockItem(UBlocks.CHISELED_CHITIN_SHELL_BLOCK, new Settings().group(ItemGroup.BUILDING_BLOCKS)), "chiseled_chitin_shell_block"); + Item SLIME_DROP = register(new BlockItem(UBlocks.SLIME_DROP, new Settings().group(ItemGroup.MATERIALS)), "slime_drop"); + Item SLIME_LAYER = register(new BlockItem(UBlocks.SLIME_LAYER, new Settings().group(ItemGroup.DECORATIONS)), "slime_layer"); - Item MISTED_GLASS_DOOR = register(new TallBlockItem(UBlocks.MISTED_GLASS_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "misted_glass_door"); - Item LIBRARY_DOOR = register(new TallBlockItem(UBlocks.LIBRARY_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "library_door"); - Item BAKERY_DOOR = register(new TallBlockItem(UBlocks.BAKERY_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "bakery_door"); - Item DIAMOND_DOOR = register(new TallBlockItem(UBlocks.DIAMOND_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "diamond_door"); + Item MISTED_GLASS_DOOR = register(new TallBlockItem(UBlocks.MISTED_GLASS_DOOR, new Settings().group(ItemGroup.REDSTONE)), "misted_glass_door"); + Item LIBRARY_DOOR = register(new TallBlockItem(UBlocks.LIBRARY_DOOR, new Settings().group(ItemGroup.REDSTONE)), "library_door"); + Item BAKERY_DOOR = register(new TallBlockItem(UBlocks.BAKERY_DOOR, new Settings().group(ItemGroup.REDSTONE)), "bakery_door"); + Item DIAMOND_DOOR = register(new TallBlockItem(UBlocks.DIAMOND_DOOR, new Settings().group(ItemGroup.REDSTONE)), "diamond_door"); - Item SUGAR_BLOCK = register(new BlockItem(UBlocks.SUGAR_BLOCK, new Item.Settings().group(ItemGroup.BUILDING_BLOCKS)), "sugar_block"); + Item SUGAR_BLOCK = register(new BlockItem(UBlocks.SUGAR_BLOCK, new Settings().group(ItemGroup.BUILDING_BLOCKS)), "sugar_block"); - Item CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.CLOUD_SLAB, new Item.Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "cloud_slab"); - Item ENCHANTED_CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.ENCHANTED_CLOUD_SLAB, new Item.Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "enchanted_cloud_slab"); - Item DENSE_CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.DENSE_CLOUD_SLAB, new Item.Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "dense_cloud_slab"); + Item CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.CLOUD_SLAB, new Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "cloud_slab"); + Item ENCHANTED_CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.ENCHANTED_CLOUD_SLAB, new Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "enchanted_cloud_slab"); + Item DENSE_CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.DENSE_CLOUD_SLAB, new Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "dense_cloud_slab"); MagicGemItem GEM = register(new MagicGemItem(), "gem"); MagicGemItem CORRUPTED_GEM = register(new CursedMagicGemItem(), "corrupted_gem"); @@ -86,30 +87,25 @@ public interface UItems { AlicornAmuletItem ALICORN_AMULET = register(new AlicornAmuletItem(), "alicorn_amulet"); SpellbookItem SPELLBOOK = register(new SpellbookItem(), "spellbook"); - Item STAFF_MEADOW_BROOK = register(new StaffItem(new Item.Settings().maxCount(1).maxDamage(2)), "staff_meadow_brook"); - Item STAFF_REMEMBERANCE = register(new EnchantedStaffItem(new Item.Settings(), new ScorchSpell()), "staff_remembrance"); + Item STAFF_MEADOW_BROOK = register(new StaffItem(new Settings().maxCount(1).maxDamage(2)), "staff_meadow_brook"); + Item STAFF_REMEMBERANCE = register(new EnchantedStaffItem(new Settings(), new ScorchSpell()), "staff_remembrance"); - Item SPEAR = register(new SpearItem(new Item.Settings().maxCount(1).maxDamage(500)), "spear"); + Item SPEAR = register(new SpearItem(new Settings().maxCount(1).maxDamage(500)), "spear"); - MossItem MOSS = register(new MossItem(new Item.Settings()), "moss"); + MossItem MOSS = register(new MossItem(new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE)), "moss"); - Item ALFALFA_SEEDS = register(new AliasedBlockItem(UBlocks.ALFALFA_CROPS, new Item.Settings() + Item ALFALFA_SEEDS = register(new AliasedBlockItem(UBlocks.ALFALFA_CROPS, new Settings() .group(ItemGroup.MATERIALS) - .food(new FoodComponent.Builder() - .hunger(1) - .saturationModifier(4) - .build())), "alfalfa_seeds"); - Item ALFALFA_LEAVES = register(new Item(new Item.Settings() + .food(UFoodComponents.ALFALFA_SEEDS)), "alfalfa_seeds"); + Item ALFALFA_LEAVES = register(new Item(new Settings() .group(ItemGroup.FOOD) - .food(new FoodComponent.Builder() - .hunger(1) - .saturationModifier(3) - .build())), "alfalfa_leaves"); + .food(UFoodComponents.ALFALFA_LEAVES)), "alfalfa_leaves"); - Item ENCHANTED_TORCH = register(new BlockItem(UBlocks.ENCHANTED_TORCH, new Item.Settings().group(ItemGroup.DECORATIONS)), "enchanted_torch"); + Item ENCHANTED_TORCH = register(new BlockItem(UBlocks.ENCHANTED_TORCH, new Settings().group(ItemGroup.DECORATIONS)), "enchanted_torch"); - Item CEREAL = register(new SugaryItem(new Item.Settings() + Item CEREAL = register(new SugaryItem(new Settings() .group(ItemGroup.FOOD) .food(new FoodComponent.Builder() .hunger(9) @@ -117,7 +113,7 @@ public interface UItems { .build()) .maxCount(1) .recipeRemainder(Items.BOWL), 1), "cereal"); - Item SUGAR_CEREAL = register(new SugaryItem(new Item.Settings() + Item SUGAR_CEREAL = register(new SugaryItem(new Settings() .group(ItemGroup.FOOD) .food(new FoodComponent.Builder() .hunger(20) @@ -126,36 +122,56 @@ public interface UItems { .maxCount(1) .recipeRemainder(Items.BOWL), 110), "sugar_cereal"); - TomatoSeedsItem TOMATO_SEEDS = register(new TomatoSeedsItem(), "tomato_seeds"); - TomatoItem TOMATO = register(new TomatoItem(4, 34), "tomato"); - RottenTomatoItem ROTTEN_TOMATO = register(new RottenTomatoItem(4, 34), "rotten_tomato"); + TomatoSeedsItem TOMATO_SEEDS = register(new TomatoSeedsItem(new Settings().group(ItemGroup.MATERIALS)), "tomato_seeds"); + TomatoItem TOMATO = register(new TomatoItem(new Settings() + .group(ItemGroup.FOOD) + .food(UFoodComponents.TOMATO)), "tomato"); + RottenTomatoItem ROTTEN_TOMATO = register(new RottenTomatoItem(new Settings() + .group(ItemGroup.FOOD) + .food(UFoodComponents.BAD_TOMATO)), "rotten_tomato"); - TomatoItem CLOUDSDALE_TOMATO = register(new TomatoItem(16, 4), "cloudsdale_tomato"); - RottenTomatoItem ROTTEN_CLOUDSDALE_TOMATO = register(new RottenTomatoItem(5, 34), "rotten_cloudsdale_tomato"); + TomatoItem CLOUDSDALE_TOMATO = register(new TomatoItem(new Settings() + .group(ItemGroup.FOOD) + .food(UFoodComponents.GOOD_TOMATO)), "cloudsdale_tomato"); + RottenTomatoItem ROTTEN_CLOUDSDALE_TOMATO = register(new RottenTomatoItem(new Settings() + .group(ItemGroup.FOOD) + .food(UFoodComponents.BAD_TOMATO)), "rotten_cloudsdale_tomato"); - Item APPLE_SEEDS = register(new BlockItem(UBlocks.APPLE_SAPLING, new Item.Settings().group(ItemGroup.DECORATIONS)), "apple_seeds"); - Item APPLE_LEAVES = register(new BlockItem(UBlocks.APPLE_LEAVES, new Item.Settings().group(ItemGroup.DECORATIONS)), "apple_leaves"); + Item APPLE_SEEDS = register(new BlockItem(UBlocks.APPLE_SAPLING, new Settings().group(ItemGroup.DECORATIONS)), "apple_seeds"); + Item APPLE_LEAVES = register(new BlockItem(UBlocks.APPLE_LEAVES, new Settings().group(ItemGroup.DECORATIONS)), "apple_leaves"); - Item DAFFODIL_DAISY_SANDWICH = register(new ToxicItem(new Item.Settings(), 3, 2, UseAction.EAT, Toxicity::fromStack, Toxin.FOOD), "daffodil_daisy_sandwich"); - Item HAY_BURGER = register(new ToxicItem(new Item.Settings(), 3, 4, UseAction.EAT, Toxicity::fromStack, Toxin.FOOD), "hay_burger"); - Item HAY_FRIES = register(new ToxicItem(new Item.Settings(), 1, 5, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), "hay_fries"); - Item SALAD = register(new ToxicItem(new Item.Settings().recipeRemainder(Items.BOWL), 4, 2, UseAction.EAT, Toxicity::fromStack, Toxin.FOOD), "salad"); + Item DAFFODIL_DAISY_SANDWICH = register(new ToxicItem(new Settings() + .food(UFoodComponents.DAFODIL_DAISY_SANDWICH), UseAction.EAT, Toxicity::fromStack, Toxin.FOOD), "daffodil_daisy_sandwich"); + Item HAY_BURGER = register(new ToxicItem(new Settings() + .food(UFoodComponents.HAY_BURGER), UseAction.EAT, Toxicity::fromStack, Toxin.FOOD), "hay_burger"); + Item HAY_FRIES = register(new ToxicItem(new Settings() + .food(UFoodComponents.HAY_FRIES), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), "hay_fries"); + Item SALAD = register(new ToxicItem(new Settings() + .food(UFoodComponents.SALAD) + .recipeRemainder(Items.BOWL), UseAction.EAT, Toxicity::fromStack, Toxin.FOOD), "salad"); - Item WHEAT_WORMS = register(new ToxicItem(new Item.Settings(), 1, 0, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD), "wheat_worms"); - Item MUG = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "mug"); - Item CIDER = register(new ToxicItem(new Item.Settings().recipeRemainder(MUG), 4, 2, UseAction.DRINK, Toxicity.MILD, Toxin.FOOD), "apple_cider"); - Item JUICE = register(new ToxicItem(new Item.Settings().recipeRemainder(Items.GLASS_BOTTLE), 2, 2, UseAction.DRINK, Toxicity.SAFE, Toxin.FOOD), "juice"); - Item BURNED_JUICE = register(new ToxicItem(new Item.Settings().recipeRemainder(Items.GLASS_BOTTLE), 3, 1, UseAction.DRINK, Toxicity.FAIR, Toxin.FOOD), "burned_juice"); + Item WHEAT_WORMS = register(new ToxicItem(new Settings() + .food(UFoodComponents.WORMS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD), "wheat_worms"); + Item MUG = register(new Item(new Settings().group(ItemGroup.MATERIALS)), "mug"); + Item CIDER = register(new ToxicItem(new Settings() + .food(UFoodComponents.SALAD) + .recipeRemainder(MUG), UseAction.DRINK, Toxicity.MILD, Toxin.FOOD), "apple_cider"); + Item JUICE = register(new ToxicItem(new Settings() + .recipeRemainder(Items.GLASS_BOTTLE) + .food(UFoodComponents.JUICE), UseAction.DRINK, Toxicity.SAFE, Toxin.FOOD), "juice"); + Item BURNED_JUICE = register(new ToxicItem(new Settings() + .recipeRemainder(Items.GLASS_BOTTLE) + .food(UFoodComponents.BURNED_JUICE), UseAction.DRINK, Toxicity.FAIR, Toxin.FOOD), "burned_juice"); - Item CLOUD_SPAWN_EGG = register(new SpawnEggItem(UEntities.CLOUD, 0x4169e1, 0x7fff00, new Item.Settings().group(ItemGroup.MISC)), "cloud_spawn_egg"); - Item BUTTERFLY_SPAWN_EGG = register(new SpawnEggItem(UEntities.BUTTERFLY, 0x222200, 0xaaeeff, new Item.Settings().group(ItemGroup.MISC)), "butterfly_spawn_egg"); + Item CLOUD_SPAWN_EGG = register(new SpawnEggItem(UEntities.CLOUD, 0x4169e1, 0x7fff00, new Settings().group(ItemGroup.MISC)), "cloud_spawn_egg"); + Item BUTTERFLY_SPAWN_EGG = register(new SpawnEggItem(UEntities.BUTTERFLY, 0x222200, 0xaaeeff, new Settings().group(ItemGroup.MISC)), "butterfly_spawn_egg"); static T register(T item, String name) { return Registry.ITEM.add(new Identifier("unicopia", name), item); } static MusicDiscItem createRecord(SoundEvent sound) { - return new MusicDiscItem(1, sound, new Item.Settings() + return new MusicDiscItem(1, sound, new Settings() .maxCount(1) .group(ItemGroup.MISC) .rarity(Rarity.RARE) @@ -174,26 +190,62 @@ public interface UItems { AppleItem APPLE = register(new AppleItem(FoodComponents.APPLE), Items.APPLE); - Item GRASS = register(new ToxicBlockItem(Blocks.GRASS, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.NAUSEA)), Items.GRASS); - Item FERN = register(new ToxicBlockItem(Blocks.FERN, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.STRENGTH)), Items.FERN); - Item DEAD_BUSH = register(new ToxicBlockItem(Blocks.DEAD_BUSH, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.NAUSEA)), Items.DEAD_BUSH); + Item GRASS = register(new ToxicBlockItem(Blocks.GRASS, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.NAUSEA)), Items.GRASS); + Item FERN = register(new ToxicBlockItem(Blocks.FERN, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.STRENGTH)), Items.FERN); + Item DEAD_BUSH = register(new ToxicBlockItem(Blocks.DEAD_BUSH, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.NAUSEA)), Items.DEAD_BUSH); - Item DANDELION = register(new ToxicBlockItem(Blocks.DANDELION, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.DANDELION); - Item POPPY = register(new ToxicBlockItem(Blocks.POPPY, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD), Items.POPPY); - Item BLUE_ORCHID = register(new ToxicBlockItem(Blocks.BLUE_ORCHID, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.BLUE_ORCHID); - Item ALLIUM = register(new ToxicBlockItem(Blocks.ALLIUM, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.FAIR, Toxin.FOOD), Items.ALLIUM); - Item AZUER_BLUET = register(new ToxicBlockItem(Blocks.AZURE_BLUET, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.RADIOACTIVITY)), Items.AZURE_BLUET); - Item RED_TULIP = register(new ToxicBlockItem(Blocks.RED_TULIP, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.RED_TULIP); - Item ORANGE_TULIP = register(new ToxicBlockItem(Blocks.ORANGE_TULIP, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.ORANGE_TULIP); - Item WHITE_TULIP = register(new ToxicBlockItem(Blocks.WHITE_TULIP, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.FAIR, Toxin.FOOD), Items.WHITE_TULIP); - Item PINK_TULIP = register(new ToxicBlockItem(Blocks.PINK_TULIP, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.PINK_TULIP); - Item OXEYE_DAISY = register(new ToxicBlockItem(Blocks.OXEYE_DAISY, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.BLINDNESS)), Items.OXEYE_DAISY); - Item CORNFLOWER = register(new ToxicBlockItem(Blocks.CORNFLOWER, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.CORNFLOWER); + Item DANDELION = register(new ToxicBlockItem(Blocks.DANDELION, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.DANDELION); + Item POPPY = register(new ToxicBlockItem(Blocks.POPPY, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD), Items.POPPY); + Item BLUE_ORCHID = register(new ToxicBlockItem(Blocks.BLUE_ORCHID, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.BLUE_ORCHID); + Item ALLIUM = register(new ToxicBlockItem(Blocks.ALLIUM, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.FAIR, Toxin.FOOD), Items.ALLIUM); + Item AZUER_BLUET = register(new ToxicBlockItem(Blocks.AZURE_BLUET, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.RADIOACTIVITY)), Items.AZURE_BLUET); + Item RED_TULIP = register(new ToxicBlockItem(Blocks.RED_TULIP, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.RED_TULIP); + Item ORANGE_TULIP = register(new ToxicBlockItem(Blocks.ORANGE_TULIP, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.ORANGE_TULIP); + Item WHITE_TULIP = register(new ToxicBlockItem(Blocks.WHITE_TULIP, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.FAIR, Toxin.FOOD), Items.WHITE_TULIP); + Item PINK_TULIP = register(new ToxicBlockItem(Blocks.PINK_TULIP, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.PINK_TULIP); + Item OXEYE_DAISY = register(new ToxicBlockItem(Blocks.OXEYE_DAISY, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.BLINDNESS)), Items.OXEYE_DAISY); + Item CORNFLOWER = register(new ToxicBlockItem(Blocks.CORNFLOWER, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.CORNFLOWER); - Item ROSE_BUSH = register(new ToxicBlockItem(Blocks.ROSE_BUSH, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.DAMAGE)), Items.ROSE_BUSH); - Item PEONY = register(new ToxicBlockItem(Blocks.PEONY, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.PEONY); - Item TALL_GRASS = register(new ToxicBlockItem(Blocks.TALL_GRASS, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.TALL_GRASS); - Item LARGE_FERN = register(new ToxicBlockItem(Blocks.LARGE_FERN, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.DAMAGE)), Items.LARGE_FERN); + Item ROSE_BUSH = register(new ToxicBlockItem(Blocks.ROSE_BUSH, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.DAMAGE)), Items.ROSE_BUSH); + Item PEONY = register(new ToxicBlockItem(Blocks.PEONY, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.PEONY); + Item TALL_GRASS = register(new ToxicBlockItem(Blocks.TALL_GRASS, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.TALL_GRASS); + Item LARGE_FERN = register(new ToxicBlockItem(Blocks.LARGE_FERN, new Settings() + .food(UFoodComponents.RANDOM_FOLIAGE) + .group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.DAMAGE)), Items.LARGE_FERN); static T register(T newItem, Item oldItem) { return Registry.ITEM.set(Registry.ITEM.getRawId(oldItem), Registry.ITEM.getId(oldItem), newItem); diff --git a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java index 140dacc9..e9738cda 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java @@ -40,7 +40,7 @@ public class ZapAppleItem extends AppleItem { UItems.SWEET_APPLE, UItems.SOUR_APPLE, UItems.ROTTEN_APPLE, - UItems.cooked_zap_apple + UItems.COOKED_ZAP_APPLE ); public ZapAppleItem() { diff --git a/src/main/java/com/minelittlepony/unicopia/toxin/Toxic.java b/src/main/java/com/minelittlepony/unicopia/toxin/Toxic.java index 93220731..9328fa18 100644 --- a/src/main/java/com/minelittlepony/unicopia/toxin/Toxic.java +++ b/src/main/java/com/minelittlepony/unicopia/toxin/Toxic.java @@ -1,8 +1,63 @@ package com.minelittlepony.unicopia.toxin; -import net.minecraft.item.ItemStack; +import java.util.function.Function; +import java.util.function.Supplier; -@FunctionalInterface -public interface Toxic { - Toxicity getToxicity(ItemStack stack); +import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.entity.player.Pony; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.UseAction; +import net.minecraft.world.World; + +public class Toxic { + + private final Item item; + + private final UseAction action; + private final Function toxicity; + private final Toxin toxin; + + Toxic(Item item, UseAction action, Toxin toxin, Function toxicity) { + this.item = item; + this.action = action; + this.toxin = toxin; + this.toxicity = toxicity; + } + + public UseAction getUseAction(ItemStack stack) { + return action; + } + + public Text getTooltip(ItemStack stack) { + return toxicity.apply(stack).getTooltip(); + } + + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) { + if (entity instanceof PlayerEntity) { + Race race = Pony.of((PlayerEntity)entity).getSpecies(); + Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : this.toxicity.apply(stack); + + toxin.addSecondaryEffects((PlayerEntity)entity, toxicity, stack); + } + + return new ItemStack(item.getRecipeRemainder()); + } + + public TypedActionResult use(World world, PlayerEntity player, Hand hand, Supplier> sup) { + Race race = Pony.of(player).getSpecies(); + + if (race.isDefault() || race == Race.CHANGELING) { + return new TypedActionResult<>(ActionResult.FAIL, player.getStackInHand(hand)); + } + + return sup.get(); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/toxin/ToxicBlockItem.java b/src/main/java/com/minelittlepony/unicopia/toxin/ToxicBlockItem.java index 6867bb22..9aab5de0 100644 --- a/src/main/java/com/minelittlepony/unicopia/toxin/ToxicBlockItem.java +++ b/src/main/java/com/minelittlepony/unicopia/toxin/ToxicBlockItem.java @@ -4,19 +4,13 @@ import java.util.List; import javax.annotation.Nullable; -import com.minelittlepony.unicopia.Race; -import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.block.Block; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.util.UseAction; @@ -24,54 +18,31 @@ import net.minecraft.world.World; public class ToxicBlockItem extends BlockItem { - private final UseAction action; - private final Toxicity toxicity; - private final Toxin toxin; + private final Toxic toxic; - public ToxicBlockItem(Block block, Item.Settings settings, int hunger, float saturation, UseAction action, Toxicity toxicity, Toxin toxin) { - super(block, settings - .group(ItemGroup.FOOD) - .food(new FoodComponent.Builder() - .hunger(hunger) - .saturationModifier(saturation) - .build())); - this.toxicity = toxicity; - this.action = action; - this.toxin = toxin; + public ToxicBlockItem(Block block, Settings settings, UseAction action, Toxicity toxicity, Toxin toxin) { + super(block, settings); + toxic = new Toxic(this, action, toxin, stack -> toxicity); } @Override public UseAction getUseAction(ItemStack stack) { - return action; + return toxic.getUseAction(stack); } @Override public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - tooltip.add(toxicity.getTooltip()); + tooltip.add(toxic.getTooltip(stack)); } @Override public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) { super.finishUsing(stack, world, entity); - - if (entity instanceof PlayerEntity) { - Race race = Pony.of((PlayerEntity)entity).getSpecies(); - Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : this.toxicity; - - toxin.addSecondaryEffects((PlayerEntity)entity, toxicity, stack); - } - - return new ItemStack(getRecipeRemainder()); + return toxic.finishUsing(stack, world, entity); } @Override public TypedActionResult use(World world, PlayerEntity player, Hand hand) { - Race race = Pony.of(player).getSpecies(); - - if (race.isDefault() || race == Race.CHANGELING) { - return new TypedActionResult<>(ActionResult.FAIL, player.getStackInHand(hand)); - } - - return super.use(world, player, hand); + return toxic.use(world, player, hand, () -> super.use(world, player, hand)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/toxin/ToxicItem.java b/src/main/java/com/minelittlepony/unicopia/toxin/ToxicItem.java index ea6e27c6..1fb6ed7f 100644 --- a/src/main/java/com/minelittlepony/unicopia/toxin/ToxicItem.java +++ b/src/main/java/com/minelittlepony/unicopia/toxin/ToxicItem.java @@ -5,17 +5,13 @@ import java.util.function.Function; import javax.annotation.Nullable; -import com.minelittlepony.unicopia.Race; -import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.FoodComponent; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.util.UseAction; @@ -23,58 +19,35 @@ import net.minecraft.world.World; public class ToxicItem extends Item { - private final UseAction action; - private final Function toxicity; - private final Toxin toxin; + private final Toxic toxic; - public ToxicItem(Item.Settings settings, int hunger, float saturation, UseAction action, Toxicity toxicity, Toxin toxin) { - this(settings, hunger, saturation, action, stack -> toxicity, toxin); + public ToxicItem(Item.Settings settings, UseAction action, Toxicity toxicity, Toxin toxin) { + this(settings, action, stack -> toxicity, toxin); } - public ToxicItem(Item.Settings settings, int hunger, float saturation, UseAction action, Function toxicity, Toxin toxin) { - super(settings - .group(ItemGroup.FOOD) - .food(new FoodComponent.Builder() - .hunger(hunger) - .saturationModifier(saturation) - .build())); - this.toxicity = toxicity; - this.action = action; - this.toxin = toxin; + public ToxicItem(Item.Settings settings, UseAction action, Function toxicity, Toxin toxin) { + super(settings.group(ItemGroup.FOOD)); + this.toxic = new Toxic(this, action, toxin, toxicity); } @Override public UseAction getUseAction(ItemStack stack) { - return action; + return toxic.getUseAction(stack); } @Override public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - tooltip.add(toxicity.apply(stack).getTooltip()); + tooltip.add(toxic.getTooltip(stack)); } @Override public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) { super.finishUsing(stack, world, entity); - - if (entity instanceof PlayerEntity) { - Race race = Pony.of((PlayerEntity)entity).getSpecies(); - Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : this.toxicity.apply(stack); - - toxin.addSecondaryEffects((PlayerEntity)entity, toxicity, stack); - } - - return new ItemStack(getRecipeRemainder()); + return toxic.finishUsing(stack, world, entity); } @Override public TypedActionResult use(World world, PlayerEntity player, Hand hand) { - Race race = Pony.of(player).getSpecies(); - - if (race.isDefault() || race == Race.CHANGELING) { - return new TypedActionResult<>(ActionResult.FAIL, player.getStackInHand(hand)); - } - - return super.use(world, player, hand); + return toxic.use(world, player, hand, () -> super.use(world, player, hand)); } }