2018-09-12 01:29:49 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
2019-01-31 14:58:24 +01:00
|
|
|
import java.util.List;
|
2019-02-07 10:46:59 +01:00
|
|
|
import java.util.function.Supplier;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-01-31 14:58:24 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.edibles.IEdible;
|
|
|
|
import com.minelittlepony.unicopia.edibles.Toxicity;
|
2019-02-17 00:08:19 +01:00
|
|
|
import com.minelittlepony.unicopia.init.UItems;
|
2019-02-07 10:46:59 +01:00
|
|
|
import com.minelittlepony.util.collection.Pool;
|
|
|
|
import com.minelittlepony.util.collection.Weighted;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
import net.minecraft.block.BlockPlanks;
|
2019-01-31 14:58:24 +01:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
2019-02-07 11:14:41 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2019-03-13 21:54:59 +01:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.item.ItemFood;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2019-03-13 21:54:59 +01:00
|
|
|
import net.minecraft.util.EnumParticleTypes;
|
2019-02-07 11:14:41 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2019-03-13 21:54:59 +01:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2019-01-31 14:58:24 +01:00
|
|
|
import net.minecraft.world.World;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-02-07 10:46:59 +01:00
|
|
|
public class ItemApple extends ItemFood implements IEdible {
|
|
|
|
|
|
|
|
public static final Pool<Object, Weighted<Supplier<ItemStack>>> typeVariantMap = Pool.of(BlockPlanks.EnumType.OAK,
|
|
|
|
BlockPlanks.EnumType.OAK, new Weighted<Supplier<ItemStack>>()
|
|
|
|
.put(1, () -> new ItemStack(UItems.rotten_apple))
|
2019-02-07 11:14:41 +01:00
|
|
|
.put(2, () -> new ItemStack(UItems.green_apple))
|
|
|
|
.put(3, () -> new ItemStack(UItems.red_apple)),
|
2019-02-07 10:46:59 +01:00
|
|
|
BlockPlanks.EnumType.SPRUCE, new Weighted<Supplier<ItemStack>>()
|
2019-02-07 11:14:41 +01:00
|
|
|
.put(1, () -> new ItemStack(UItems.sour_apple))
|
|
|
|
.put(2, () -> new ItemStack(UItems.green_apple))
|
|
|
|
.put(3, () -> new ItemStack(UItems.sweet_apple))
|
2019-02-07 10:46:59 +01:00
|
|
|
.put(4, () -> new ItemStack(UItems.rotten_apple)),
|
|
|
|
BlockPlanks.EnumType.BIRCH, new Weighted<Supplier<ItemStack>>()
|
|
|
|
.put(1, () -> new ItemStack(UItems.rotten_apple))
|
2019-02-07 11:14:41 +01:00
|
|
|
.put(2, () -> new ItemStack(UItems.sweet_apple))
|
|
|
|
.put(5, () -> new ItemStack(UItems.green_apple)),
|
2019-02-07 10:46:59 +01:00
|
|
|
BlockPlanks.EnumType.JUNGLE, new Weighted<Supplier<ItemStack>>()
|
2019-02-07 11:14:41 +01:00
|
|
|
.put(5, () -> new ItemStack(UItems.green_apple))
|
|
|
|
.put(2, () -> new ItemStack(UItems.sweet_apple))
|
|
|
|
.put(1, () -> new ItemStack(UItems.sour_apple)),
|
2019-02-07 10:46:59 +01:00
|
|
|
BlockPlanks.EnumType.ACACIA, new Weighted<Supplier<ItemStack>>()
|
|
|
|
.put(1, () -> new ItemStack(UItems.rotten_apple))
|
2019-02-07 11:14:41 +01:00
|
|
|
.put(2, () -> new ItemStack(UItems.sweet_apple))
|
|
|
|
.put(5, () -> new ItemStack(UItems.green_apple)),
|
2019-02-07 10:46:59 +01:00
|
|
|
BlockPlanks.EnumType.DARK_OAK, new Weighted<Supplier<ItemStack>>()
|
|
|
|
.put(1, () -> new ItemStack(UItems.rotten_apple))
|
2019-02-07 11:14:41 +01:00
|
|
|
.put(2, () -> new ItemStack(UItems.sweet_apple))
|
2019-02-07 10:46:59 +01:00
|
|
|
.put(5, () -> new ItemStack(UItems.zap_apple)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
public static ItemStack getRandomItemStack(Object variant) {
|
|
|
|
return typeVariantMap.getOptional(variant)
|
|
|
|
.flatMap(Weighted::get)
|
|
|
|
.map(Supplier::get)
|
|
|
|
.orElse(ItemStack.EMPTY);
|
2019-02-06 21:24:22 +01:00
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-02-06 21:24:22 +01:00
|
|
|
public ItemApple(String domain, String name) {
|
|
|
|
super(4, 3, false);
|
2019-02-07 10:46:59 +01:00
|
|
|
|
2019-02-06 21:24:22 +01:00
|
|
|
setTranslationKey(name);
|
2019-01-29 11:33:11 +01:00
|
|
|
|
2019-02-06 21:24:22 +01:00
|
|
|
if (!"minecraft".contentEquals(domain)) {
|
|
|
|
setRegistryName(domain, name);
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-03-13 21:54:59 +01:00
|
|
|
@Override
|
|
|
|
public boolean onEntityItemUpdate(EntityItem item) {
|
|
|
|
|
|
|
|
if (!item.isDead && item.ticksExisted > item.lifespan * 0.9) {
|
|
|
|
|
|
|
|
if (!item.world.isRemote) {
|
|
|
|
item.setDead();
|
|
|
|
|
|
|
|
EntityItem neu = new EntityItem(item.world);
|
|
|
|
neu.copyLocationAndAnglesFrom(item);
|
|
|
|
neu.setItem(new ItemStack(UItems.rotten_apple));
|
|
|
|
|
|
|
|
item.world.spawnEntity(neu);
|
|
|
|
|
|
|
|
EntityItem copy = new EntityItem(item.world);
|
|
|
|
copy.copyLocationAndAnglesFrom(item);
|
|
|
|
copy.setItem(item.getItem());
|
|
|
|
copy.getItem().shrink(1);
|
|
|
|
|
|
|
|
item.world.spawnEntity(copy);
|
|
|
|
} else {
|
|
|
|
float bob = MathHelper.sin(((float)item.getAge() + 1) / 10F + item.hoverStart) * 0.1F + 0.1F;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
item.world.spawnParticle(EnumParticleTypes.SPELL_MOB, item.posX, item.posY + bob, item.posZ,
|
|
|
|
item.world.rand.nextGaussian() - 0.5F,
|
|
|
|
item.world.rand.nextGaussian() - 0.5F,
|
|
|
|
item.world.rand.nextGaussian() - 0.5F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-07 11:14:41 +01:00
|
|
|
@Override
|
|
|
|
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
|
|
|
|
if (this == UItems.red_apple && isInCreativeTab(tab)) {
|
|
|
|
items.add(new ItemStack(this));
|
|
|
|
items.add(new ItemStack(UItems.green_apple));
|
|
|
|
items.add(new ItemStack(UItems.sweet_apple));
|
|
|
|
items.add(new ItemStack(UItems.sour_apple));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 14:58:24 +01:00
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
|
|
|
tooltip.add(getToxicityLevel(stack).getTooltip());
|
2019-01-27 16:34:12 +01:00
|
|
|
}
|
|
|
|
|
2019-01-31 14:58:24 +01:00
|
|
|
@Override
|
|
|
|
public Toxicity getToxicityLevel(ItemStack stack) {
|
|
|
|
return Toxicity.SAFE;
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|