ItemFishFood .java

net.minecraft.item.ItemFishFood (class): members: FishType, cooked, getSaturationModifier, getPotionEffect, getHealAmount, onFoodEaten, getSubItems.

net.minecraft.itemclass171 linescommonextends ItemFood6.0 KB

API Surface (15)

int getHealAmount(ItemStack stack)
float getSaturationModifier(ItemStack stack)
String getPotionEffect(ItemStack stack)
void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player)
void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems)
String getUnlocalizedName(ItemStack stack)
int getMetadata()
String getUnlocalizedName()
int getUncookedHealAmount()
float getUncookedSaturationModifier()
int getCookedHealAmount()
float getCookedSaturationModifier()
boolean canCook()
ItemFishFood.FishType byMetadata(int meta)
ItemFishFood.FishType byItemStack(ItemStack stack)

Fields & Constants (1)

cooked

String literals (4)

"cooked"
"salmon"
"clownfish"
"pufferfish"

Full Source

ItemFishFood.java171 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import com.google.common.collect.Maps;
4
import java.util.List;
5
import java.util.Map;
6
import net.minecraft.creativetab.CreativeTabs;
7
import net.minecraft.entity.player.EntityPlayer;
8
import net.minecraft.potion.Potion;
9
import net.minecraft.potion.PotionEffect;
10
import net.minecraft.potion.PotionHelper;
11
import net.minecraft.world.World;
12
13
public class ItemFishFood extends ItemFood
14
{
15
    /** Indicates whether this fish is "cooked" or not. */
16
    private final boolean cooked;
17
18
    public ItemFishFood(boolean cooked)
19
    {
20
        super(0, 0.0F, false);
21
        this.cooked = cooked;
22
    }
23
24
    public int getHealAmount(ItemStack stack)
25
    {
26
        ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
27
        return this.cooked && itemfishfood$fishtype.canCook() ? itemfishfood$fishtype.getCookedHealAmount() : itemfishfood$fishtype.getUncookedHealAmount();
28
    }
29
30
    public float getSaturationModifier(ItemStack stack)
31
    {
32
        ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
33
        return this.cooked && itemfishfood$fishtype.canCook() ? itemfishfood$fishtype.getCookedSaturationModifier() : itemfishfood$fishtype.getUncookedSaturationModifier();
34
    }
35
36
    public String getPotionEffect(ItemStack stack)
37
    {
38
        return ItemFishFood.FishType.byItemStack(stack) == ItemFishFood.FishType.PUFFERFISH ? PotionHelper.pufferfishEffect : null;
39
    }
40
41
    protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player)
42
    {
43
        ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
44
45
        if (itemfishfood$fishtype == ItemFishFood.FishType.PUFFERFISH)
46
        {
47
            player.addPotionEffect(new PotionEffect(Potion.poison.id, 1200, 3));
48
            player.addPotionEffect(new PotionEffect(Potion.hunger.id, 300, 2));
49
            player.addPotionEffect(new PotionEffect(Potion.confusion.id, 300, 1));
50
        }
51
52
        super.onFoodEaten(stack, worldIn, player);
53
    }
54
55
    /**
56
     * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
57
     */
58
    public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems)
59
    {
60
        for (ItemFishFood.FishType itemfishfood$fishtype : ItemFishFood.FishType.values())
61
        {
62
            if (!this.cooked || itemfishfood$fishtype.canCook())
63
            {
64
                subItems.add(new ItemStack(this, 1, itemfishfood$fishtype.getMetadata()));
65
            }
66
        }
67
    }
68
69
    /**
70
     * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
71
     * different names based on their damage or NBT.
72
     */
73
    public String getUnlocalizedName(ItemStack stack)
74
    {
75
        ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
76
        return this.getUnlocalizedName() + "." + itemfishfood$fishtype.getUnlocalizedName() + "." + (this.cooked && itemfishfood$fishtype.canCook() ? "cooked" : "raw");
77
    }
78
79
    public static enum FishType
80
    {
81
        COD(0, "cod", 2, 0.1F, 5, 0.6F),
82
        SALMON(1, "salmon", 2, 0.1F, 6, 0.8F),
83
        CLOWNFISH(2, "clownfish", 1, 0.1F),
84
        PUFFERFISH(3, "pufferfish", 1, 0.1F);
85
86
        private static final Map<Integer, ItemFishFood.FishType> META_LOOKUP = Maps.<Integer, ItemFishFood.FishType>newHashMap();
87
        private final int meta;
88
        private final String unlocalizedName;
89
        private final int uncookedHealAmount;
90
        private final float uncookedSaturationModifier;
91
        private final int cookedHealAmount;
92
        private final float cookedSaturationModifier;
93
        private boolean cookable = false;
94
95
        private FishType(int meta, String unlocalizedName, int uncookedHeal, float uncookedSaturation, int cookedHeal, float cookedSaturation)
96
        {
97
            this.meta = meta;
98
            this.unlocalizedName = unlocalizedName;
99
            this.uncookedHealAmount = uncookedHeal;
100
            this.uncookedSaturationModifier = uncookedSaturation;
101
            this.cookedHealAmount = cookedHeal;
102
            this.cookedSaturationModifier = cookedSaturation;
103
            this.cookable = true;
104
        }
105
106
        private FishType(int meta, String unlocalizedName, int uncookedHeal, float uncookedSaturation)
107
        {
108
            this.meta = meta;
109
            this.unlocalizedName = unlocalizedName;
110
            this.uncookedHealAmount = uncookedHeal;
111
            this.uncookedSaturationModifier = uncookedSaturation;
112
            this.cookedHealAmount = 0;
113
            this.cookedSaturationModifier = 0.0F;
114
            this.cookable = false;
115
        }
116
117
        public int getMetadata()
118
        {
119
            return this.meta;
120
        }
121
122
        public String getUnlocalizedName()
123
        {
124
            return this.unlocalizedName;
125
        }
126
127
        public int getUncookedHealAmount()
128
        {
129
            return this.uncookedHealAmount;
130
        }
131
132
        public float getUncookedSaturationModifier()
133
        {
134
            return this.uncookedSaturationModifier;
135
        }
136
137
        public int getCookedHealAmount()
138
        {
139
            return this.cookedHealAmount;
140
        }
141
142
        public float getCookedSaturationModifier()
143
        {
144
            return this.cookedSaturationModifier;
145
        }
146
147
        public boolean canCook()
148
        {
149
            return this.cookable;
150
        }
151
152
        public static ItemFishFood.FishType byMetadata(int meta)
153
        {
154
            ItemFishFood.FishType itemfishfood$fishtype = (ItemFishFood.FishType)META_LOOKUP.get(Integer.valueOf(meta));
155
            return itemfishfood$fishtype == null ? COD : itemfishfood$fishtype;
156
        }
157
158
        public static ItemFishFood.FishType byItemStack(ItemStack stack)
159
        {
160
            return stack.getItem() instanceof ItemFishFood ? byMetadata(stack.getMetadata()) : COD;
161
        }
162
163
        static {
164
            for (ItemFishFood.FishType itemfishfood$fishtype : values())
165
            {
166
                META_LOOKUP.put(Integer.valueOf(itemfishfood$fishtype.getMetadata()), itemfishfood$fishtype);
167
            }
168
        }
169
    }
170
}
171

Deobfuscated MCP 1.8.9 source of ItemFishFood from Marcelektro/MavenMCP-1.8.9 (net/minecraft/item/ItemFishFood.java), stored verbatim.