diff --git a/src/main/java/com/minelittlepony/unicopia/UBlocks.java b/src/main/java/com/minelittlepony/unicopia/UBlocks.java index 6e57e4f3..ee803f4d 100644 --- a/src/main/java/com/minelittlepony/unicopia/UBlocks.java +++ b/src/main/java/com/minelittlepony/unicopia/UBlocks.java @@ -22,6 +22,7 @@ import com.minelittlepony.unicopia.block.DutchDoorBlock; import com.minelittlepony.unicopia.block.SugarBlock; import com.minelittlepony.unicopia.block.UPot; import com.minelittlepony.unicopia.item.AppleItem; +import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.world.structure.CustomSaplingGenerator; import com.minelittlepony.unicopia.block.BlockTomatoPlant; import com.minelittlepony.unicopia.block.BlockCloudDoor; @@ -101,7 +102,9 @@ public class UBlocks { return Registry.BLOCK.add(new Identifier(Unicopia.MODID, name), block); } - static void registerColors(ItemColors items, BlockColors blocks) { + public static void bootstrap() { + ItemColors items; + BlockColors blocks; items.register((stack, tint) -> { BlockState state = ((BlockItem)stack.getItem()).getBlock().getDefaultState(); @@ -121,8 +124,4 @@ public class UBlocks { return GrassColors.getColor(0.5D, 1); }, apple_leaves); } - - static void bootstrap() { - - } } diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index ab5a0527..a7264077 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -19,6 +19,7 @@ import com.minelittlepony.unicopia.enchanting.recipe.AffineIngredients; import com.minelittlepony.unicopia.enchanting.recipe.SpecialRecipe; import com.minelittlepony.unicopia.enchanting.recipe.SpellRecipe; import com.minelittlepony.unicopia.inventory.gui.SpellBookContainer; +import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.inventory.gui.GuiSpellBook; import com.minelittlepony.unicopia.network.MsgPlayerAbility; import com.minelittlepony.unicopia.network.MsgPlayerCapabilities; diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockAlfalfa.java b/src/main/java/com/minelittlepony/unicopia/block/BlockAlfalfa.java index fab1ab10..2e9bd6ea 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockAlfalfa.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockAlfalfa.java @@ -4,7 +4,7 @@ import java.util.Random; import javax.annotation.Nullable; -import com.minelittlepony.unicopia.UItems; +import com.minelittlepony.unicopia.item.UItems; import net.minecraft.block.BlockState; import net.minecraft.block.CropBlock; diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockTomatoPlant.java b/src/main/java/com/minelittlepony/unicopia/block/BlockTomatoPlant.java index 2f15c232..f7b8a22f 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockTomatoPlant.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockTomatoPlant.java @@ -2,7 +2,7 @@ package com.minelittlepony.unicopia.block; import java.util.Random; -import com.minelittlepony.unicopia.UItems; +import com.minelittlepony.unicopia.item.UItems; import net.minecraft.block.Block; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/minelittlepony/unicopia/client/ClientHooks.java b/src/main/java/com/minelittlepony/unicopia/client/ClientHooks.java index d4dde396..807235ea 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/ClientHooks.java +++ b/src/main/java/com/minelittlepony/unicopia/client/ClientHooks.java @@ -3,10 +3,10 @@ package com.minelittlepony.unicopia.client; import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.UBlocks; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.client.gui.UHud; import com.minelittlepony.unicopia.entity.capabilities.ICamera; import com.minelittlepony.unicopia.entity.capabilities.IPlayer; +import com.minelittlepony.unicopia.item.UItems; import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.MinecraftClient; diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AbstractSpecialRecipe.java b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AbstractSpecialRecipe.java index 63e6875e..2c897d3f 100644 --- a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AbstractSpecialRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AbstractSpecialRecipe.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.List; import com.google.common.collect.Lists; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.inventory.gui.SpellBookInventory; +import com.minelittlepony.unicopia.item.UItems; import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SpellRecipe.java b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SpellRecipe.java index eb8ffd4f..ac0b4ddb 100644 --- a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SpellRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SpellRecipe.java @@ -1,8 +1,8 @@ package com.minelittlepony.unicopia.enchanting.recipe; import com.google.gson.JsonObject; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.inventory.gui.SpellBookInventory; +import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import net.minecraft.inventory.CraftingInventory; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java index 1a31e80e..edf3981d 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java @@ -8,9 +8,9 @@ import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.UBlocks; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.ability.PowerCloudBase.ICloudEntity; +import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.particles.ParticleEmitter; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/SpellbookEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/SpellbookEntity.java index bc769b75..480d4835 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/SpellbookEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/SpellbookEntity.java @@ -1,7 +1,8 @@ package com.minelittlepony.unicopia.entity; import com.minelittlepony.unicopia.EquinePredicates; -import com.minelittlepony.unicopia.UItems; +import com.minelittlepony.unicopia.item.UItems; + import net.minecraft.container.Container; import net.minecraft.container.NameableContainerProvider; import net.minecraft.entity.EntityType; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/SpellcastEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/SpellcastEntity.java index 49f694e0..b7994baa 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/SpellcastEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/SpellcastEntity.java @@ -9,7 +9,7 @@ import org.apache.commons.lang3.StringUtils; import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.Race; -import com.minelittlepony.unicopia.UItems; +import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.magic.Affinity; import com.minelittlepony.unicopia.magic.ICaster; import com.minelittlepony.unicopia.magic.IMagicEffect; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/capabilities/PlayerCapabilities.java b/src/main/java/com/minelittlepony/unicopia/entity/capabilities/PlayerCapabilities.java index 02875ef9..28e447ec 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/capabilities/PlayerCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/capabilities/PlayerCapabilities.java @@ -9,7 +9,6 @@ import com.google.common.collect.Maps; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.UEffects; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.IAbilityReceiver; import com.minelittlepony.unicopia.enchanting.PageState; @@ -19,6 +18,7 @@ import com.minelittlepony.unicopia.entity.IFood; import com.minelittlepony.unicopia.entity.IGravity; import com.minelittlepony.unicopia.entity.IInventory; import com.minelittlepony.unicopia.entity.ITrap; +import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.magic.Affinity; import com.minelittlepony.unicopia.magic.IAttachedEffect; import com.minelittlepony.unicopia.magic.IHeldEffect; diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/BuildInTexturesBakery.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/BuildInTexturesBakery.java deleted file mode 100644 index 60f27ed1..00000000 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/BuildInTexturesBakery.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.minelittlepony.unicopia.forgebullshit; - -import java.util.Set; - -import net.minecraft.util.Identifier; - -/** - * Provides access to the built in texture locations. - * This is needed to add things like custom backgrounds for slots. - * - */ -@Deprecated -public final class BuildInTexturesBakery extends ModelBakery { - private BuildInTexturesBakery() { - super(null, null, null); - } - - public static Set getBuiltInTextures() { - return LOCATIONS_BUILTIN_TEXTURES; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/ItemModels.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/ItemModels.java deleted file mode 100644 index 14197c0e..00000000 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/ItemModels.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.minelittlepony.unicopia.forgebullshit; - -import java.util.Objects; - -import javax.annotation.Nonnull; - -import net.minecraft.item.Item; - -@Deprecated -public class ItemModels { - - /** - * Registers models and item variants for all of the provided textures. - */ - public static void registerAll(Item...items) { - for (Item i : items) { - registerAll(i, 1, new ModelIdentifier(i.getRegistryName().toString())); - } - } - - private static void registerAll(@Nonnull Item item, int maxMeta, ModelIdentifier resource) { - for (int i = 0; i < maxMeta; i++) { - ModelLoader.setCustomModelIdentifier(item, i, resource); - } - } - - /** - * Registers a model for the given item and all associated variants. - */ - public static void registerAllVariants(@Nonnull Item item, String... variants) { - registerAllVariants(item, item.getRegistryName().getNamespace(), variants); - } - - public static void registerAllVariants(@Nonnull Item item, String domain, String... variants) { - for (int i = 0; i < variants.length; i++) { - ModelLoader.setCustomModelIdentifier(item, i, new ModelIdentifier(domain + ":" + variants[i])); - } - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/OreReplacer.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/OreReplacer.java index bda03472..3d332abf 100644 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/OreReplacer.java +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/OreReplacer.java @@ -9,7 +9,13 @@ import org.apache.logging.log4j.Logger; import com.google.common.collect.Lists; import com.google.common.collect.Streams; +import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.recipe.Ingredient; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeType; +import net.minecraft.util.DefaultedList; /** * An Ore Replacer. @@ -25,25 +31,24 @@ public class OreReplacer { public static final IIngredientRemapper VANILLA = new IIngredientRemapper() { @Override - public boolean canRemap(IRecipe recipe) { - return recipe.getClass() == ShapedRecipes.class - || recipe.getClass() == ShapelessRecipes.class; + public boolean canRemap(Recipe recipe) { + return recipe.getType() == RecipeType.CRAFTING; } @Override - public int replaceIngredients(OreReplacer sender, IRecipe recipe) { - NonNullList ingredients = recipe.getIngredients(); + public int replaceIngredients(OreReplacer sender, Recipe recipe) { + DefaultedList ingredients = recipe.getPreviewInputs(); int replacements = 0; for (int i = 0; i < ingredients.size(); i++) { Ingredient ingredient = ingredients.get(i); - NonNullList newStacks = NonNullList.create(); + DefaultedList newStacks = DefaultedList.of(); boolean altered = false; - ItemStack[] stacks = ingredient.getMatchingStacks(); + ItemStack[] stacks = ingredient.getStackArray(); for (int k = 0; k < stacks.length; k++) { ItemStack stack = stacks[k]; @@ -59,7 +64,7 @@ public class OreReplacer { if (altered) { replacements++; - ingredients.set(i, Ingredient.fromStacks(newStacks.stream().distinct().toArray(ItemStack[]::new))); + ingredients.set(i, Ingredient.ofStacks(newStacks.stream().distinct().toArray(ItemStack[]::new))); } } @@ -106,7 +111,7 @@ public class OreReplacer { log.info("Replaced {} ingredients.", replacements); } - public boolean replaceOre(ItemStack stack, NonNullList newStacks) { + public boolean replaceOre(ItemStack stack, DefaultedList newStacks) { return ores.stream().filter(ore -> ore.matches(stack)).peek(ore -> ore.getSubItems(stack, newStacks) ).findFirst().isPresent(); @@ -114,22 +119,22 @@ public class OreReplacer { public interface IIngredientRemapper { - boolean canRemap(IRecipe recipe); + boolean canRemap(Recipe recipe); - int replaceIngredients(OreReplacer sender, IRecipe recipe); + int replaceIngredients(OreReplacer sender, Recipe recipe); } @FunctionalInterface public interface IOre { boolean matches(ItemStack stack); - default void getSubItems(ItemStack stack, NonNullList newStacks) { - NonNullList newList = NonNullList.create(); + default void getSubItems(ItemStack stack, DefaultedList newStacks) { + DefaultedList newList = DefaultedList.of(); - stack.getItem().getSubItems(CreativeTabs.SEARCH, newList); + stack.getItem().appendStacks(ItemGroup.SEARCH, newList); - if (stack.hasTagCompound()) { - newList.forEach(i -> i.setTagCompound(stack.getTagCompound().copy())); + if (stack.hasTag()) { + newList.forEach(i -> i.setTag((CompoundTag)stack.getTag().copy())); } newStacks.addAll(newList); diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/UnFuckedItemSnow.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/UnFuckedItemSnow.java deleted file mode 100644 index 7bb16d18..00000000 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/UnFuckedItemSnow.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.minelittlepony.unicopia.forgebullshit; - -import net.minecraft.block.Block; -import net.minecraft.block.SnowBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; - -/** - * A fixed ItemSnow class - */ -@Deprecated -public class UnFuckedItemSnow extends ItemSnow { - - public UnFuckedItemSnow(Block block) { - super(block); - } - - @Override - public boolean canPlaceBlockOnSide(World world, BlockPos pos, Direction side, PlayerEntity player, ItemStack stack) { - BlockState state = world.getBlockState(pos); - - // Check explicitly for the maximum layers. - // Without this layered blocks get stuck on the second layer because of a change introduced with Forge's patches. - if (state.getBlock() instanceof SnowBlock && state.getValue(SnowBlock.LAYERS) < 8) { - return true; - } - - // return (state.getBlock() != net.minecraft.init.Blocks.SNOW_LAYER || ((Integer)state.getValue(BlockSnow.LAYERS)) > 7) ? super.canPlaceBlockOnSide(world, pos, side, player, stack) : true; - return super.canPlaceBlockOnSide(world, pos, side, player, stack); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java index 9ae0ca72..db090ab6 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java @@ -8,7 +8,6 @@ import javax.annotation.Nullable; import com.google.common.collect.Multimap; import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.ducks.IItemEntity; import com.minelittlepony.unicopia.entity.capabilities.IPlayer; import com.minelittlepony.unicopia.magic.Affinity; diff --git a/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java index 2b93e6ee..b0fb257b 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java @@ -1,37 +1,29 @@ package com.minelittlepony.unicopia.item; import java.util.List; -import java.util.function.Supplier; - import javax.annotation.Nullable; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.ducks.IItemEntity; import com.minelittlepony.unicopia.entity.capabilities.ItemEntityCapabilities; -import com.minelittlepony.unicopia.item.consumables.IEdible; +import com.minelittlepony.unicopia.item.consumables.Toxic; import com.minelittlepony.unicopia.item.consumables.Toxicity; -import com.minelittlepony.util.collection.Pool; -import com.minelittlepony.util.collection.Weighted; - import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.EntityType; import net.minecraft.entity.ItemEntity; import net.minecraft.item.FoodComponent; -import net.minecraft.item.FoodComponents; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.particle.ParticleTypes; -import net.minecraft.tag.BlockTags; -import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -public class AppleItem extends Item implements IEdible, ItemEntityCapabilities.TickableItem { +public class AppleItem extends Item implements Toxic, ItemEntityCapabilities.TickableItem { - private static final Pool>> typeVariantMap = Pool.of(PlanksBlock.Type.OAK, + // TODO: Move this to a datapack + /*private static final Pool>> TYPE_VARIANT_POOL = Pool.of(PlanksBlock.Type.OAK, PlanksBlock.Type.OAK, new Weighted>() .put(1, () -> new ItemStack(UItems.rotten_apple)) .put(2, () -> new ItemStack(UItems.green_apple)) @@ -58,13 +50,14 @@ public class AppleItem extends Item implements IEdible, ItemEntityCapabilities.T .put(2, () -> new ItemStack(UItems.sweet_apple)) .put(5, () -> new ItemStack(UItems.zap_apple) ) - ); + );*/ public static ItemStack getRandomItemStack(Object variant) { - return typeVariantMap.getOptional(variant) + return new ItemStack(UItems.VanillaOverrides.red_apple); + /*return TYPE_VARIANT_POOL.getOptional(variant) .flatMap(Weighted::get) .map(Supplier::get) - .orElse(ItemStack.EMPTY); + .orElse(ItemStack.EMPTY);*/ } public AppleItem(FoodComponent components) { @@ -111,11 +104,11 @@ public class AppleItem extends Item implements IEdible, ItemEntityCapabilities.T @Override public void appendTooltip(ItemStack stack, @Nullable World worldIn, List tooltip, TooltipContext context) { - tooltip.add(getToxicityLevel(stack).getTooltip()); + tooltip.add(getToxicity(stack).getTooltip()); } @Override - public Toxicity getToxicityLevel(ItemStack stack) { + public Toxicity getToxicity(ItemStack stack) { return Toxicity.SAFE; } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/ExtendedShearsItem.java b/src/main/java/com/minelittlepony/unicopia/item/ExtendedShearsItem.java index 17c94e59..e1379730 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ExtendedShearsItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ExtendedShearsItem.java @@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.item; import javax.annotation.Nullable; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.magic.items.IDispensable; import net.minecraft.block.BlockState; import net.minecraft.block.DispenserBlock; diff --git a/src/main/java/com/minelittlepony/unicopia/item/MossItem.java b/src/main/java/com/minelittlepony/unicopia/item/MossItem.java index 900e47cb..e326d4e6 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/MossItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/MossItem.java @@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.item; import javax.annotation.Nullable; import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.item.consumables.EdibleItem; +import com.minelittlepony.unicopia.item.consumables.ToxicItem; import com.minelittlepony.unicopia.item.consumables.Toxicity; import com.minelittlepony.util.collection.ReversableStateMapList; import net.minecraft.block.Block; @@ -14,10 +14,11 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; +import net.minecraft.util.UseAction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public class MossItem extends EdibleItem { +public class MossItem extends ToxicItem { public static final ReversableStateMapList AFFECTED = new ReversableStateMapList(); @@ -35,7 +36,7 @@ public class MossItem extends EdibleItem { } public MossItem(Item.Settings settings) { - super(settings); + super(settings, 2, 1, UseAction.EAT, Toxicity.FAIR); } public boolean tryConvert(World world, BlockState state, BlockPos pos, @Nullable PlayerEntity player) { @@ -61,7 +62,7 @@ public class MossItem extends EdibleItem { } @Override - public Toxicity getToxicityLevel(ItemStack stack) { + public Toxicity getToxicity(ItemStack stack) { return Toxicity.MILD; } } diff --git a/src/main/java/com/minelittlepony/unicopia/UItems.java b/src/main/java/com/minelittlepony/unicopia/item/UItems.java similarity index 55% rename from src/main/java/com/minelittlepony/unicopia/UItems.java rename to src/main/java/com/minelittlepony/unicopia/item/UItems.java index 6379dad2..4beeb655 100644 --- a/src/main/java/com/minelittlepony/unicopia/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/item/UItems.java @@ -1,71 +1,37 @@ -package com.minelittlepony.unicopia; +package com.minelittlepony.unicopia.item; -import com.minelittlepony.unicopia.item.AlicornAmuletItem; -import com.minelittlepony.unicopia.item.SugaryItem; -import com.minelittlepony.unicopia.item.AppleItem; -import com.minelittlepony.unicopia.item.CloudPlacerItem; -import com.minelittlepony.unicopia.item.ExtendedShearsItem; -import com.minelittlepony.unicopia.item.CursedMagicGemItem; -import com.minelittlepony.unicopia.item.EnchantedStaffItem; -import com.minelittlepony.unicopia.item.MossItem; -import com.minelittlepony.unicopia.item.BagOfHoldingItem; -import com.minelittlepony.unicopia.item.RottenAppleItem; -import com.minelittlepony.unicopia.item.RottenTomatoItem; -import com.minelittlepony.unicopia.item.SpearItem; -import com.minelittlepony.unicopia.item.MagicGemItem; -import com.minelittlepony.unicopia.item.SpellbookItem; -import com.minelittlepony.unicopia.item.StaffItem; -import com.minelittlepony.unicopia.item.TomatoItem; -import com.minelittlepony.unicopia.item.TomatoSeedsItem; -import com.minelittlepony.unicopia.item.ZapAppleItem; -import com.minelittlepony.unicopia.item.PredicatedBlockItem; -import com.minelittlepony.unicopia.item.StickItem; -import com.minelittlepony.unicopia.item.URecord; -import com.minelittlepony.unicopia.item.consumables.BushToxicityDeterminent; -import com.minelittlepony.unicopia.item.consumables.CookedToxicityDeterminent; -import com.minelittlepony.unicopia.item.consumables.FlowerToxicityDeterminent; -import com.minelittlepony.unicopia.item.consumables.DelegatedEdibleItem; +import com.minelittlepony.unicopia.item.consumables.DynamicToxicItem; +import com.minelittlepony.unicopia.item.consumables.ToxicBlockItem; +import com.minelittlepony.unicopia.item.consumables.ToxicItem; import com.minelittlepony.unicopia.item.consumables.Toxicity; -import com.minelittlepony.unicopia.item.consumables.DelegateFoodItem; +import com.minelittlepony.unicopia.item.consumables.Toxin; +import com.minelittlepony.unicopia.item.consumables.DynamicToxicBlockItem; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import com.minelittlepony.unicopia.magic.spells.SpellScorch; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; -import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.client.color.item.ItemColors; +import net.minecraft.item.AliasedBlockItem; import net.minecraft.item.BlockItem; import net.minecraft.item.FoodComponent; import net.minecraft.item.FoodComponents; -import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.TallBlockItem; -import net.minecraft.item.Item.Settings; -import net.minecraft.util.Identifier; import net.minecraft.util.UseAction; import net.minecraft.util.registry.Registry; import static com.minelittlepony.unicopia.EquinePredicates.*; -import javax.annotation.Nullable; - import com.minelittlepony.unicopia.ServerInteractionManager; -import com.minelittlepony.unicopia.Unicopia; -import com.minelittlepony.unicopia.entity.ConstructionCloudEntity; -import com.minelittlepony.unicopia.entity.RacingCloudEntity; -import com.minelittlepony.unicopia.entity.WildCloudEntity; -import com.minelittlepony.unicopia.forgebullshit.BuildInTexturesBakery; -import com.minelittlepony.unicopia.forgebullshit.OreReplacer; -import com.minelittlepony.unicopia.forgebullshit.UnFuckedItemSnow; +import com.minelittlepony.unicopia.UBlocks; +import com.minelittlepony.unicopia.UEntities; +import com.minelittlepony.unicopia.USounds; public class UItems { - private static final StickItem stick = register(new StickItem(), "minecraft", "stick"); - private static final ExtendedShearsItem shears = register(new ExtendedShearsItem(), "minecraft", "shears"); - - public static final AppleItem red_apple = register(new AppleItem(FoodComponents.APPLE), "minecraft", "apple"); public static final AppleItem green_apple = register(new AppleItem(FoodComponents.APPLE), "apple_green"); public static final AppleItem sweet_apple = register(new AppleItem(FoodComponents.APPLE), "apple_sweet"); public static final AppleItem sour_apple = register(new AppleItem(FoodComponents.APPLE), "apple_sour"); @@ -130,10 +96,12 @@ public class UItems { public static final MossItem moss = register(new MossItem(new Item.Settings()), "moss"); - public static final Item alfalfa_seeds = new ItemSeedFood(1, 4, UBlocks.alfalfa, Blocks.FARMLAND) - .setTranslationKey("alfalfa_seeds") - .setRegistryName(Unicopia.MODID, "alfalfa_seeds") - .setCreativeTab(CreativeTabs.MATERIALS); + public static final Item alfalfa_seeds = register(new AliasedBlockItem(UBlocks.alfalfa, new Item.Settings() + .group(ItemGroup.MATERIALS) + .food(new FoodComponent.Builder() + .hunger(1) + .saturationModifier(4) + .build())), "alfalfa_seeds"); public static final Item enchanted_torch = register(new BlockItem(UBlocks.enchanted_torch, new Item.Settings().group(ItemGroup.DECORATIONS)), "enchanted_torch"); @@ -167,85 +135,36 @@ public class UItems { public static final TomatoItem cloudsdale_tomato = register(new TomatoItem(16, 4), "cloudsdale_tomato"); public static final RottenTomatoItem rotten_cloudsdale_tomato = register(new RottenTomatoItem(5, 34), "rotten_cloudsdale_tomato"); - public static final TomatoSeedsItem tomato_seeds = new TomatoSeedsItem(Unicopia.MODID, "tomato_seeds"); + public static final TomatoSeedsItem tomato_seeds = register(new TomatoSeedsItem(), "tomato_seeds"); - public static final Item apple_seeds = new UItemDecoration(UBlocks.apple_tree, Unicopia.MODID, "apple_seeds"); + public static final Item apple_seeds = register(new BlockItem(UBlocks.apple_tree, new Item.Settings().group(ItemGroup.DECORATIONS)), "apple_seeds"); + public static final Item apple_leaves = register(new BlockItem(UBlocks.apple_leaves, new Item.Settings().group(ItemGroup.DECORATIONS)), "apple_leaves"); - public static final Item apple_leaves = new BlockItem(UBlocks.apple_leaves); - - public static final Item double_plant = new DelegateFoodItem(Blocks.TALL_GRASS, stack -> - BlockDoublePlant.EnumPlantType.byMetadata(stack.getMetadata()).getTranslationKey() - ).setFoodDelegate(new DelegatedEdibleItem(new BushToxicityDeterminent())) - .setTranslationKey("doublePlant"); - - public static final Item tall_grass = new DelegateFoodItem(Blocks.GRASS, stack -> { - switch (stack.getMetadata()) { - case 0: return "shrub"; - case 1: return "grass"; - case 2: return "fern"; - default: return ""; - } - }).setFoodDelegate(new DelegatedEdibleItem(stack -> { - switch (stack.getMetadata()) { - default: - case 0: return Toxicity.SAFE; - case 1: return Toxicity.SAFE; - case 2: return Toxicity.SEVERE; - } - })); - - public static final Item yellow_flower = new DelegateFoodItem(Blocks.YELLOW_FLOWER, stack -> - BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.YELLOW, stack.getMetadata()).getTranslationKey() - ).setFoodDelegate(new DelegatedEdibleItem(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.YELLOW))) - .setTranslationKey("flower"); - - public static final Item red_flower = new DelegateFoodItem(Blocks.RED_FLOWER, stack -> - BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.RED, stack.getMetadata()).getTranslationKey() - ).setFoodDelegate(new DelegatedEdibleItem(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.RED))) - .setTranslationKey("rose"); - - public static final Item daffodil_daisy_sandwich = new DelegatedEdibleItem(Unicopia.MODID, "daffodil_daisy_sandwich", 3, 2, CookedToxicityDeterminent.instance) - .setHasSubtypes(true); - public static final Item hay_burger = new DelegatedEdibleItem(Unicopia.MODID, "hay_burger", 3, 4, CookedToxicityDeterminent.instance) - .setHasSubtypes(true); - public static final Item hay_fries = new DelegatedEdibleItem(Unicopia.MODID, "hay_fries", 1, 5, stack -> Toxicity.SAFE); - public static final Item salad = new DelegatedEdibleItem(Unicopia.MODID, "salad", 4, 2, CookedToxicityDeterminent.instance) - .setHasSubtypes(true) - .setContainerItem(Items.BOWL); - - public static final Item wheat_worms = new DelegatedEdibleItem(Unicopia.MODID, "wheat_worms", 1, 0, stack -> Toxicity.SEVERE); + public static final Item daffodil_daisy_sandwich = register(new DynamicToxicItem(new Item.Settings(), 3, 2, UseAction.EAT, Toxicity::fromStack), "daffodil_daisy_sandwich"); + public static final Item hay_burger = register(new DynamicToxicItem(new Item.Settings(), 3, 4, UseAction.EAT, Toxicity::fromStack), "hay_burger"); + public static final Item hay_fries = register(new ToxicItem(new Item.Settings(), 1, 5, UseAction.EAT, Toxicity.SAFE), "hay_fries"); + public static final Item salad = register(new DynamicToxicItem(new Item.Settings().recipeRemainder(Items.BOWL), 4, 2, UseAction.EAT, Toxicity::fromStack), "salad"); + public static final Item wheat_worms = register(new ToxicItem(new Item.Settings(), 1, 0, UseAction.EAT, Toxicity.SEVERE), "wheat_worms"); public static final Item mug = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "mug"); - public static final Item apple_cider = new DelegatedEdibleItem(Unicopia.MODID, "apple_cider", 4, 2, stack -> Toxicity.MILD) - .setUseAction(UseAction.DRINK) - .setContainerItem(mug) - .setFull3D(); - public static final Item juice = new DelegatedEdibleItem(Unicopia.MODID, "juice", 2, 2, stack -> Toxicity.SAFE) - .setUseAction(UseAction.DRINK) - .setContainerItem(Items.GLASS_BOTTLE); - public static final Item burned_juice = new DelegatedEdibleItem(Unicopia.MODID, "burned_juice", 3, 1, stack -> Toxicity.FAIR) - .setUseAction(UseAction.DRINK) - .setContainerItem(Items.GLASS_BOTTLE); + public static final Item apple_cider = register(new ToxicItem(new Item.Settings().recipeRemainder(mug), 4, 2, UseAction.DRINK, Toxicity.MILD), "apple_cider"); + public static final Item juice = register(new ToxicItem(new Item.Settings().recipeRemainder(Items.GLASS_BOTTLE), 2, 2, UseAction.DRINK, Toxicity.SAFE), "juice"); + public static final Item burned_juice = register(new ToxicItem(new Item.Settings().recipeRemainder(Items.GLASS_BOTTLE), 3, 1, UseAction.DRINK, Toxicity.FAIR), "burned_juice"); - private static T register(T item, String namespace, String name) { - return Registry.ITEM.add(new Identifier(namespace, name), item); + private static T register(T newItem, Item oldItem) { + return Registry.ITEM.add(Registry.ITEM.getId(oldItem), newItem); } + private static T register(T item, String name) { return register(item, name); } - static void bootstrap() { - RegistryLockSpinner.open(Item.REGISTRY, Items.class, r -> r - .replace(Items.APPLE, red_apple) - .replace(Item.getItemFromBlock(Blocks.TALLGRASS), tall_grass) - .replace(Item.getItemFromBlock(Blocks.DOUBLE_PLANT), double_plant) - .replace(Item.getItemFromBlock(Blocks.YELLOW_FLOWER), yellow_flower) - .replace(Item.getItemFromBlock(Blocks.RED_FLOWER), red_flower)); + public static void bootstrap() { if (ServerInteractionManager.isClientSide()) { - BuildInTexturesBakery.getBuiltInTextures().add(new Identifier(Unicopia.MODID, "items/empty_slot_gem")); + //BuildInTexturesBakery.getBuiltInTextures().add(new Identifier(Unicopia.MODID, "items/empty_slot_gem")); - ItemColors registry; + ItemColors registry = null; registry.register((stack, tint) -> { if (MAGI.test(MinecraftClient.getInstance().player)) { return SpellRegistry.instance().getSpellTintFromStack(stack); @@ -255,12 +174,36 @@ public class UItems { }, spell, curse); } - FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(zap_apple), new ItemStack(cooked_zap_apple), 0.1F); - FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(juice), new ItemStack(burned_juice), 0); - FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(cuccoon), new ItemStack(chitin_shell), 0.3F); + // FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(zap_apple), new ItemStack(cooked_zap_apple), 0.1F); + // FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(juice), new ItemStack(burned_juice), 0); + // FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(cuccoon), new ItemStack(chitin_shell), 0.3F); + } - new OreReplacer() - .registerAll(stack -> stack.getItem().getRegistryName().equals(red_apple.getRegistryName())) - .done(); + static class VanillaOverrides { + public static final StickItem stick = register(new StickItem(), Items.STICK); + public static final ExtendedShearsItem shears = register(new ExtendedShearsItem(), Items.SHEARS); + + public static final AppleItem red_apple = register(new AppleItem(FoodComponents.APPLE), Items.APPLE); + + public static final Item grass = register(new DynamicToxicBlockItem(Blocks.GRASS, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.NAUSEA), Items.GRASS); + public static final Item fern = register(new DynamicToxicBlockItem(Blocks.FERN, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE, Toxin.STRENGTH), Items.FERN); + public static final Item dead_bush = register(new DynamicToxicBlockItem(Blocks.DEAD_BUSH, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE, Toxin.NAUSEA), Items.DEAD_BUSH); + + public static final Item dandelion = register(new ToxicBlockItem(Blocks.DANDELION, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE), Items.DANDELION); + public static final Item poppy = register(new ToxicBlockItem(Blocks.POPPY, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE), Items.POPPY); + public static final Item blue_orchid = register(new ToxicBlockItem(Blocks.BLUE_ORCHID, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE), Items.BLUE_ORCHID); + public static final Item allium = register(new ToxicBlockItem(Blocks.ALLIUM, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.FAIR), Items.ALLIUM); + public static final Item azure_bluet = register(new DynamicToxicBlockItem(Blocks.AZURE_BLUET, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.RADIOACTIVITY), Items.AZURE_BLUET); + public static final Item red_tulip = register(new ToxicBlockItem(Blocks.RED_TULIP, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE), Items.RED_TULIP); + public static final Item orange_tulip = register(new ToxicBlockItem(Blocks.ORANGE_TULIP, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE), Items.ORANGE_TULIP); + public static final Item white_tulip = register(new ToxicBlockItem(Blocks.WHITE_TULIP, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.FAIR), Items.WHITE_TULIP); + public static final Item pink_tulip = register(new ToxicBlockItem(Blocks.PINK_TULIP, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE), Items.PINK_TULIP); + public static final Item oxeye_daisy = register(new DynamicToxicBlockItem(Blocks.OXEYE_DAISY, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE, Toxin.BLINDNESS), Items.OXEYE_DAISY); + public static final Item cornflower = register(new ToxicBlockItem(Blocks.CORNFLOWER, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE), Items.CORNFLOWER); + + public static final Item rose_bush = register(new DynamicToxicBlockItem(Blocks.ROSE_BUSH, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE, Toxin.DAMAGE), Items.ROSE_BUSH); + public static final Item peony = register(new ToxicBlockItem(Blocks.PEONY, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE), Items.PEONY); + public static final Item tall_grass = register(new ToxicBlockItem(Blocks.TALL_GRASS, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SAFE), Items.TALL_GRASS); + public static final Item large_fern = register(new DynamicToxicBlockItem(Blocks.LARGE_FERN, new Item.Settings().group(ItemGroup.DECORATIONS), 2, 1, UseAction.EAT, Toxicity.SEVERE, Toxin.DAMAGE), Items.LARGE_FERN); } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java index 1eba0636..c9019444 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java @@ -4,7 +4,6 @@ package com.minelittlepony.unicopia.item; import java.util.List; import com.google.common.collect.Lists; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.item.consumables.Toxicity; import com.minelittlepony.util.MagicalDamageSource; import com.minelittlepony.util.VecHelper; @@ -120,7 +119,7 @@ public class ZapAppleItem extends AppleItem { } @Override - public Toxicity getToxicityLevel(ItemStack stack) { + public Toxicity getToxicity(ItemStack stack) { return getAppearance(stack) == Items.AIR ? Toxicity.SEVERE : Toxicity.SAFE; } diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/BushToxicityDeterminent.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/BushToxicityDeterminent.java deleted file mode 100644 index 217b9e6c..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/BushToxicityDeterminent.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.minelittlepony.unicopia.item.consumables; - -import net.minecraft.block.BlockDoublePlant; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.init.StatusEffects; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.StatusEffectInstance; - -import static net.minecraft.block.BlockDoublePlant.EnumPlantType.*; - -public class BushToxicityDeterminent implements IEdible { - - BlockDoublePlant.EnumPlantType getType(ItemStack stack) { - return byMetadata(stack.getMetadata()); - } - - @Override - public Toxicity getToxicityLevel(ItemStack stack) { - switch (getType(stack)) { - case SUNFLOWER: - case GRASS: return Toxicity.SAFE; - case PAEONIA: - case SYRINGA: return Toxicity.FAIR; - case FERN: - case ROSE: return Toxicity.SEVERE; - default: return Toxicity.SAFE; - } - } - - @Override - public void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack) { - BlockDoublePlant.EnumPlantType type = getType(stack); - - if ((type == ROSE || type == FERN) - && player.world.rand.nextInt(30) == 0) { - player.addStatusEffectInstance(new StatusEffectInstance(StatusEffects.INSTANT_DAMAGE, 1, 1, false, false)); - } - - if (type == GRASS) { - player.addStatusEffectInstance(new StatusEffectInstance(StatusEffects.NAUSEA, 30, 1, false, false)); - } - - if (type == FERN) { - player.addStatusEffectInstance(new StatusEffectInstance(StatusEffects.STRENGTH, 30, 1, false, false)); - } - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/CookedToxicityDeterminent.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/CookedToxicityDeterminent.java deleted file mode 100644 index 77d5e064..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/CookedToxicityDeterminent.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.minelittlepony.unicopia.item.consumables; - -import net.minecraft.item.ItemStack; - -public class CookedToxicityDeterminent implements IEdible { - public static final IEdible instance = new CookedToxicityDeterminent(); - - @Override - public Toxicity getToxicityLevel(ItemStack stack) { - return Toxicity.byMetadata(stack.getMetadata()); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegateFoodItem.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegateFoodItem.java deleted file mode 100644 index 793112ad..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegateFoodItem.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.minelittlepony.unicopia.item.consumables; - -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.block.Block; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.world.World; - -public class DelegateFoodItem extends Item implements IEdible { - - @Nonnull - private ItemFood foodItem = new ItemFood(0, 0, false); - - public DelegateFoodItem(Block block, ItemMultiTexture.Mapper mapper) { - super(block, block, mapper); - } - - public DelegateFoodItem setFoodDelegate(@Nonnull ItemFood foodItem) { - this.foodItem = foodItem; - return this; - } - - @Override - public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { - foodItem.addInformation(stack, worldIn, tooltip, flagIn); - } - - @Override - public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) { - return foodItem.onItemUseFinish(stack, worldIn, entityLiving); - } - - @Override - public int getMaxItemUseDuration(ItemStack stack) { - return foodItem.getMaxItemUseDuration(stack); - } - - @Override - public EnumAction getItemUseAction(ItemStack stack) { - return foodItem.getItemUseAction(stack); - } - - @Override - public TypedActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, EnumHand handIn) { - return foodItem.onItemRightClick(worldIn, playerIn, handIn); - } - - @Override - public Toxicity getToxicityLevel(ItemStack stack) { - if (foodItem instanceof IEdible) { - return ((IEdible)foodItem).getToxicityLevel(stack); - } - return null; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegatedEdibleItem.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegatedEdibleItem.java deleted file mode 100644 index aedf7448..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegatedEdibleItem.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.minelittlepony.unicopia.item.consumables; - -import javax.annotation.Nonnull; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.UseAction; - -public class DelegatedEdibleItem extends EdibleItem { - - private final IEdible toxicityDeterminant; - - public DelegatedEdibleItem(Item.Settings settings, UseAction action, @Nonnull IEdible mapper) { - super(settings, action); - - toxicityDeterminant = mapper; - } - - @Override - public void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack) { - super.addSecondaryEffects(player, toxicity, stack); - - toxicityDeterminant.addSecondaryEffects(player, toxicity, stack); - } - - @Override - public Toxicity getToxicityLevel(ItemStack stack) { - return toxicityDeterminant.getToxicityLevel(stack); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/DynamicToxicBlockItem.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/DynamicToxicBlockItem.java new file mode 100644 index 00000000..21e8b6a3 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/DynamicToxicBlockItem.java @@ -0,0 +1,26 @@ +package com.minelittlepony.unicopia.item.consumables; + +import javax.annotation.Nonnull; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.UseAction; + +public class DynamicToxicBlockItem extends ToxicBlockItem { + + private final Toxin toxin; + + public DynamicToxicBlockItem(Block block, Item.Settings settings, int hunger, float saturation, UseAction action, Toxicity toxicity, @Nonnull Toxin toxin) { + super(block, settings, hunger, saturation, action, toxicity); + + this.toxin = toxin; + } + + @Override + public void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack) { + super.addSecondaryEffects(player, toxicity, stack); + toxin.addSecondaryEffects(player, toxicity, stack); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/DynamicToxicItem.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/DynamicToxicItem.java new file mode 100644 index 00000000..a9b0bd27 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/DynamicToxicItem.java @@ -0,0 +1,27 @@ +package com.minelittlepony.unicopia.item.consumables; + +import javax.annotation.Nonnull; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.UseAction; + +public class DynamicToxicItem extends ToxicItem { + + private final Toxic toxic; + + public DynamicToxicItem(Item.Settings settings, int hunger, float saturation, UseAction action, @Nonnull Toxic toxic) { + super(settings, hunger, saturation, action, Toxicity.SAFE); + this.toxic = toxic; + } + + @Override + public void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack) { + super.addSecondaryEffects(player, toxicity, stack); + } + + @Override + public Toxicity getToxicity(ItemStack stack) { + return toxic.getToxicity(stack); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/FlowerToxicityDeterminent.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/FlowerToxicityDeterminent.java deleted file mode 100644 index 4819f288..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/FlowerToxicityDeterminent.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.minelittlepony.unicopia.item.consumables; - -import net.minecraft.block.BlockFlower; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.init.StatusEffects; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.StatusEffectInstance; - -import static net.minecraft.block.BlockFlower.EnumFlowerType.*; - -public class FlowerToxicityDeterminent implements IEdible { - - private final BlockFlower.EnumFlowerColor color; - - public FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor color) { - this.color = color; - } - - BlockFlower.EnumFlowerType getType(ItemStack stack) { - return BlockFlower.EnumFlowerType.getType(color, stack.getMetadata()); - } - - @Override - public Toxicity getToxicityLevel(ItemStack stack) { - switch (getType(stack)) { - case DANDELION: - case PINK_TULIP: - case RED_TULIP: - case ORANGE_TULIP: - case HOUSTONIA: return Toxicity.SAFE; - case OXEYE_DAISY: - case POPPY: return Toxicity.SEVERE; - case BLUE_ORCHID: - case WHITE_TULIP: - case ALLIUM: return Toxicity.FAIR; - default: return Toxicity.SAFE; - } - } - - @Override - public void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack) { - BlockFlower.EnumFlowerType type = getType(stack); - - if (type == HOUSTONIA && player.world.rand.nextInt(30) == 0) { - player.addStatusEffectInstance(new StatusEffectInstance(StatusEffects.GLOWING, 10, 1, false, false)); - } - - if (type == OXEYE_DAISY) { - player.addStatusEffectInstance(new StatusEffectInstance(StatusEffects.BLINDNESS, 30, 1, false, false)); - } - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/IEdible.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/IEdible.java deleted file mode 100644 index f1bad69f..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/IEdible.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.minelittlepony.unicopia.item.consumables; - -import javax.annotation.Nonnull; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; - -@FunctionalInterface -public interface IEdible { - Toxicity getToxicityLevel(ItemStack stack); - - @Nonnull - default void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack) { - - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxic.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxic.java new file mode 100644 index 00000000..10b5e50e --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxic.java @@ -0,0 +1,8 @@ +package com.minelittlepony.unicopia.item.consumables; + +import net.minecraft.item.ItemStack; + +@FunctionalInterface +public interface Toxic { + Toxicity getToxicity(ItemStack stack); +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/ToxicBlockItem.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/ToxicBlockItem.java new file mode 100644 index 00000000..282bf79d --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/ToxicBlockItem.java @@ -0,0 +1,98 @@ +package com.minelittlepony.unicopia.item.consumables; + +import java.util.List; + +import javax.annotation.Nullable; + +import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.SpeciesList; +import com.minelittlepony.unicopia.UEffects; + +import net.minecraft.block.Block; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +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; +import net.minecraft.world.World; + +public class ToxicBlockItem extends BlockItem implements Toxic, Toxin { + + private final UseAction action; + private final Toxicity toxicity; + + public ToxicBlockItem(Block block, Item.Settings settings, int hunger, float saturation, UseAction action, Toxicity toxicity) { + super(block, settings + .group(ItemGroup.FOOD) + .food(new FoodComponent.Builder() + .hunger(hunger) + .saturationModifier(saturation) + .build())); + this.toxicity = toxicity; + this.action = action; + } + + @Override + public Toxicity getToxicity(ItemStack stack) { + return toxicity; + } + + @Override + public UseAction getUseAction(ItemStack stack) { + return action; + } + + @Override + public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { + tooltip.add(getToxicity(stack).getTooltip()); + } + + @Override + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) { + super.finishUsing(stack, world, entity); + + if (entity instanceof PlayerEntity) { + Race race = SpeciesList.instance().getPlayer((PlayerEntity)entity).getSpecies(); + Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : getToxicity(stack); + + addSecondaryEffects((PlayerEntity)entity, toxicity, stack); + } + + return new ItemStack(getRecipeRemainder()); + } + + @Override + public TypedActionResult use(World world, PlayerEntity player, Hand hand) { + Race race = SpeciesList.instance().getPlayer(player).getSpecies(); + + if (race.isDefault() || race == Race.CHANGELING) { + return new TypedActionResult<>(ActionResult.FAIL, player.getStackInHand(hand)); + } + + return super.use(world, player, hand); + } + + @Override + public void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack) { + + if (toxicity.toxicWhenRaw()) { + player.addPotionEffect(toxicity.getPoisonEffect()); + } + + if (toxicity.isLethal()) { + player.addPotionEffect(new StatusEffectInstance(UEffects.FOOD_POISONING, 300, 7, false, false)); + } else if (toxicity.toxicWhenCooked()) { + player.addPotionEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 3, 1, false, false)); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/EdibleItem.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/ToxicItem.java similarity index 77% rename from src/main/java/com/minelittlepony/unicopia/item/consumables/EdibleItem.java rename to src/main/java/com/minelittlepony/unicopia/item/consumables/ToxicItem.java index e8cd7cc4..40971b85 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/EdibleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/ToxicItem.java @@ -13,7 +13,9 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; 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; @@ -22,28 +24,35 @@ import net.minecraft.util.TypedActionResult; import net.minecraft.util.UseAction; import net.minecraft.world.World; -public class EdibleItem extends Item implements IEdible { +public class ToxicItem extends Item implements Toxic, Toxin { + private final UseAction action; private final Toxicity toxicity; - public EdibleItem(Item.Settings settings, Toxicity toxicity) { - super(settings); + public ToxicItem(Item.Settings settings, int hunger, float saturation, UseAction action, Toxicity toxicity) { + super(settings + .group(ItemGroup.FOOD) + .food(new FoodComponent.Builder() + .hunger(hunger) + .saturationModifier(saturation) + .build())); this.toxicity = toxicity; + this.action = action; } @Override - public Toxicity getToxicityLevel(ItemStack stack) { + public Toxicity getToxicity(ItemStack stack) { return toxicity; } @Override public UseAction getUseAction(ItemStack stack) { - return UseAction.EAT; + return action; } @Override public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - tooltip.add(getToxicityLevel(stack).getTooltip()); + tooltip.add(getToxicity(stack).getTooltip()); } @Override @@ -52,7 +61,7 @@ public class EdibleItem extends Item implements IEdible { if (entity instanceof PlayerEntity) { Race race = SpeciesList.instance().getPlayer((PlayerEntity)entity).getSpecies(); - Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : getToxicityLevel(stack); + Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : getToxicity(stack); addSecondaryEffects((PlayerEntity)entity, toxicity, stack); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxicity.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxicity.java index f0e065f1..17d62823 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxicity.java +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxicity.java @@ -1,7 +1,14 @@ package com.minelittlepony.unicopia.item.consumables; +import java.util.Arrays; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; @@ -16,6 +23,7 @@ public enum Toxicity { private final int level; private final int duration; + private static final Map REGISTRY; private static final Toxicity[] values = values(); Toxicity(int level, int duration) { @@ -53,10 +61,22 @@ public enum Toxicity { return text; } + public static Toxicity fromStack(ItemStack stack) { + if (stack.hasTag()) { + CompoundTag tag = stack.getSubTag("toxicity"); + if (tag != null) { + return REGISTRY.getOrDefault(tag.asString(), SAFE); + } + } + return SAFE; + } + + @Deprecated public static Toxicity byMetadata(int metadata) { return values[metadata % values.length]; } + @Deprecated public static String[] getVariants(String key) { String[] result = new String[values.length]; @@ -66,4 +86,8 @@ public enum Toxicity { return result; } + + static { + REGISTRY = Arrays.stream(values()).collect(Collectors.toMap(Toxicity::name, Function.identity())); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxin.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxin.java new file mode 100644 index 00000000..78933ac5 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/Toxin.java @@ -0,0 +1,31 @@ +package com.minelittlepony.unicopia.item.consumables; + +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; + +@FunctionalInterface +public interface Toxin { + Toxin DAMAGE = (player, toxicity, stack) -> { + if (player.world.random.nextInt(30) == 0) { + player.addPotionEffect(new StatusEffectInstance(StatusEffects.INSTANT_DAMAGE, 1, 1, false, false)); + } + }; + Toxin RADIOACTIVITY = (player, toxicity, stack) -> { + if (player.world.random.nextInt(30) == 0) { + player.addPotionEffect(new StatusEffectInstance(StatusEffects.GLOWING, 10, 1, false, false)); + } + }; + Toxin NAUSEA = (player, toxicity, stack) -> { + player.addPotionEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 30, 1, false, false)); + }; + Toxin STRENGTH = (player, toxicity, stack) -> { + player.addPotionEffect(new StatusEffectInstance(StatusEffects.STRENGTH, 30, 1, false, false)); + }; + Toxin BLINDNESS = (player, toxicity, stack) -> { + player.addPotionEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 30, 1, false, false)); + }; + + void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack); +} diff --git a/src/main/java/com/minelittlepony/unicopia/magic/ITossedEffect.java b/src/main/java/com/minelittlepony/unicopia/magic/ITossedEffect.java index 16da02ae..c5f6da96 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/ITossedEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/ITossedEffect.java @@ -2,8 +2,8 @@ package com.minelittlepony.unicopia.magic; import javax.annotation.Nullable; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.entity.ProjectileEntity; +import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import com.minelittlepony.unicopia.projectile.IAdvancedProjectile; import com.minelittlepony.unicopia.projectile.ITossable; diff --git a/src/main/java/com/minelittlepony/unicopia/world/BlockInteractions.java b/src/main/java/com/minelittlepony/unicopia/world/BlockInteractions.java index 04a01d89..e7a3ca53 100644 --- a/src/main/java/com/minelittlepony/unicopia/world/BlockInteractions.java +++ b/src/main/java/com/minelittlepony/unicopia/world/BlockInteractions.java @@ -3,8 +3,8 @@ package com.minelittlepony.unicopia.world; import java.util.List; import com.minelittlepony.unicopia.UBlocks; -import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.block.ITillable; +import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import net.minecraft.block.Block;