| 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.block.BlockJukebox;
|
| 7 | import net.minecraft.block.state.IBlockState;
|
| 8 | import net.minecraft.creativetab.CreativeTabs;
|
| 9 | import net.minecraft.entity.player.EntityPlayer;
|
| 10 | import net.minecraft.init.Blocks;
|
| 11 | import net.minecraft.stats.StatList;
|
| 12 | import net.minecraft.util.BlockPos;
|
| 13 | import net.minecraft.util.EnumFacing;
|
| 14 | import net.minecraft.util.StatCollector;
|
| 15 | import net.minecraft.world.World;
|
| 16 |
|
| 17 | public class ItemRecord extends Item
|
| 18 | {
|
| 19 | private static final Map<String, ItemRecord> RECORDS = Maps.<String, ItemRecord>newHashMap();
|
| 20 |
|
| 21 | /** The name of the record. */
|
| 22 | public final String recordName;
|
| 23 |
|
| 24 | protected ItemRecord(String name)
|
| 25 | {
|
| 26 | this.recordName = name;
|
| 27 | this.maxStackSize = 1;
|
| 28 | this.setCreativeTab(CreativeTabs.tabMisc);
|
| 29 | RECORDS.put("records." + name, this);
|
| 30 | }
|
| 31 |
|
| 32 | /**
|
| 33 | * Called when a Block is right-clicked with this Item
|
| 34 | */
|
| 35 | public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
| 36 | {
|
| 37 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 38 |
|
| 39 | if (iblockstate.getBlock() == Blocks.jukebox && !((Boolean)iblockstate.getValue(BlockJukebox.HAS_RECORD)).booleanValue())
|
| 40 | {
|
| 41 | if (worldIn.isRemote)
|
| 42 | {
|
| 43 | return true;
|
| 44 | }
|
| 45 | else
|
| 46 | {
|
| 47 | ((BlockJukebox)Blocks.jukebox).insertRecord(worldIn, pos, iblockstate, stack);
|
| 48 | worldIn.playAuxSFXAtEntity((EntityPlayer)null, 1005, pos, Item.getIdFromItem(this));
|
| 49 | --stack.stackSize;
|
| 50 | playerIn.triggerAchievement(StatList.field_181740_X);
|
| 51 | return true;
|
| 52 | }
|
| 53 | }
|
| 54 | else
|
| 55 | {
|
| 56 | return false;
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * allows items to add custom lines of information to the mouseover description
|
| 62 | */
|
| 63 | public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
|
| 64 | {
|
| 65 | tooltip.add(this.getRecordNameLocal());
|
| 66 | }
|
| 67 |
|
| 68 | public String getRecordNameLocal()
|
| 69 | {
|
| 70 | return StatCollector.translateToLocal("item.record." + this.recordName + ".desc");
|
| 71 | }
|
| 72 |
|
| 73 | /**
|
| 74 | * Return an item rarity from EnumRarity
|
| 75 | */
|
| 76 | public EnumRarity getRarity(ItemStack stack)
|
| 77 | {
|
| 78 | return EnumRarity.RARE;
|
| 79 | }
|
| 80 |
|
| 81 | /**
|
| 82 | * Return the record item corresponding to the given name.
|
| 83 | */
|
| 84 | public static ItemRecord getRecord(String name)
|
| 85 | {
|
| 86 | return (ItemRecord)RECORDS.get(name);
|
| 87 | }
|
| 88 | }
|
| 89 |
|