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;
|
2018-09-12 01:29:49 +02:00
|
|
|
import java.util.Random;
|
|
|
|
|
2019-01-31 14:58:24 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2019-01-13 21:05:40 +01:00
|
|
|
import com.minelittlepony.unicopia.UItems;
|
2019-01-31 14:58:24 +01:00
|
|
|
import com.minelittlepony.unicopia.edibles.IEdible;
|
|
|
|
import com.minelittlepony.unicopia.edibles.Toxicity;
|
2019-01-30 21:17:46 +01:00
|
|
|
import com.minelittlepony.unicopia.forgebullshit.IMultiItem;
|
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;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.item.ItemFood;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.NonNullList;
|
2019-01-31 14:58:24 +01:00
|
|
|
import net.minecraft.world.World;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-01-31 14:58:24 +01:00
|
|
|
public class ItemApple extends ItemFood implements IMultiItem, IEdible {
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
private int[] typeRarities = new int[0];
|
2019-01-13 21:05:40 +01:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
private String[] subTypes = new String[0];
|
2019-01-13 21:05:40 +01:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
private String[] variants = subTypes;
|
|
|
|
|
2019-01-13 21:05:40 +01:00
|
|
|
public ItemStack getRandomApple(Random rand, Object variant) {
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
int[] rarity = typeRarities;
|
2019-01-13 21:05:40 +01:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
int result = 0;
|
2019-01-13 21:05:40 +01:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
for (int i = 0; i < rarity.length && i < subTypes.length; i++) {
|
|
|
|
if (rand.nextInt(rarity[i]) == 0) {
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
}
|
2019-01-13 21:05:40 +01:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
if (variant == BlockPlanks.EnumType.JUNGLE) {
|
2019-01-13 21:05:40 +01:00
|
|
|
result = oneOr(result, 0, 1);
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
2019-01-13 21:05:40 +01:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
if (variant == BlockPlanks.EnumType.BIRCH) {
|
2019-01-13 21:05:40 +01:00
|
|
|
result = oneOr(result, 0, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variant == BlockPlanks.EnumType.SPRUCE) {
|
|
|
|
if (result == 0) {
|
|
|
|
return new ItemStack(UItems.rotten_apple, 1);
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
2019-01-13 21:05:40 +01:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
if (variant == BlockPlanks.EnumType.DARK_OAK) {
|
2019-01-13 21:05:40 +01:00
|
|
|
if (result == 1) {
|
|
|
|
return new ItemStack(UItems.zap_apple, 1);
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
2019-01-06 22:31:34 +01:00
|
|
|
|
2019-01-13 21:05:40 +01:00
|
|
|
if (variant == BlockPlanks.EnumType.ACACIA) {
|
|
|
|
result = oneOr(result, 0, 4);
|
|
|
|
}
|
2019-01-06 22:31:34 +01:00
|
|
|
|
2019-01-13 21:05:40 +01:00
|
|
|
return new ItemStack(this, 1, result);
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
2019-01-13 21:05:40 +01:00
|
|
|
int oneOr(int initial, int a, int b) {
|
|
|
|
if (initial == a) {
|
|
|
|
return b;
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-01-13 21:05:40 +01:00
|
|
|
if (initial == b) {
|
|
|
|
return a;
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-01-13 21:05:40 +01:00
|
|
|
return initial;
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
2019-01-13 21:05:40 +01:00
|
|
|
public ItemApple(String domain, String name) {
|
|
|
|
super(4, 3, false);
|
|
|
|
setTranslationKey(name);
|
2019-01-29 11:33:11 +01:00
|
|
|
|
|
|
|
if (!"minecraft".contentEquals(domain)) {
|
|
|
|
setRegistryName(domain, name);
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ItemApple setSubTypes(String... types) {
|
2019-01-27 16:34:12 +01:00
|
|
|
setHasSubtypes(types.length > 0);
|
2019-01-13 21:05:40 +01:00
|
|
|
setMaxDamage(0);
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
subTypes = types;
|
2019-01-13 21:05:40 +01:00
|
|
|
variants = new String[subTypes.length];
|
2019-01-06 22:31:34 +01:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
setTranslationKey(variants[0] = types[0]);
|
2019-01-06 22:31:34 +01:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
for (int i = 1; i < variants.length; i++) {
|
2019-01-13 21:05:40 +01:00
|
|
|
variants[i] = variants[0] + "_" + subTypes[i % subTypes.length];
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemApple setTypeRarities(int ... rarity) {
|
|
|
|
typeRarities = rarity;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-30 21:17:46 +01:00
|
|
|
@Override
|
2018-09-12 01:29:49 +02:00
|
|
|
public String[] getVariants() {
|
|
|
|
return variants;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
|
2018-09-16 00:40:52 +02:00
|
|
|
if (isInCreativeTab(tab)) {
|
2019-01-13 21:05:40 +01:00
|
|
|
items.add(new ItemStack(this, 1, 0));
|
|
|
|
|
|
|
|
for (int i = 1; i < subTypes.length; i++) {
|
2019-01-06 22:31:34 +01:00
|
|
|
items.add(new ItemStack(this, 1, i));
|
2018-09-16 00:40:52 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetadata(ItemStack stack) {
|
|
|
|
if (getHasSubtypes()) {
|
|
|
|
return super.getMetadata(stack) % subTypes.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getMetadata(stack);
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
@Override
|
|
|
|
public String getTranslationKey(ItemStack stack) {
|
2019-01-27 16:34:12 +01:00
|
|
|
if (getHasSubtypes()) {
|
2019-01-13 21:05:40 +01:00
|
|
|
int meta = Math.max(0, stack.getMetadata() % subTypes.length);
|
2019-01-06 22:31:34 +01:00
|
|
|
|
2019-01-27 16:34:12 +01:00
|
|
|
if (meta > 0) {
|
|
|
|
return super.getTranslationKey(stack) + "." + subTypes[meta];
|
|
|
|
}
|
2019-01-13 21:05:40 +01:00
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-01-13 21:05:40 +01:00
|
|
|
return super.getTranslationKey(stack);
|
2018-09-12 01:29:49 +02: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
|
|
|
}
|