001 package net.minecraft.block; 002 003 import net.minecraft.block.material.Material; 004 import net.minecraft.creativetab.CreativeTabs; 005 import net.minecraft.entity.item.EntityItem; 006 import net.minecraft.entity.player.EntityPlayer; 007 import net.minecraft.item.ItemStack; 008 import net.minecraft.tileentity.TileEntity; 009 import net.minecraft.world.World; 010 011 public class BlockJukeBox extends BlockContainer 012 { 013 protected BlockJukeBox(int par1, int par2) 014 { 015 super(par1, par2, Material.wood); 016 this.setCreativeTab(CreativeTabs.tabDecorations); 017 } 018 019 /** 020 * Returns the block texture based on the side being looked at. Args: side 021 */ 022 public int getBlockTextureFromSide(int par1) 023 { 024 return this.blockIndexInTexture + (par1 == 1 ? 1 : 0); 025 } 026 027 /** 028 * Called upon block activation (right click on the block.) 029 */ 030 public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) 031 { 032 if (par1World.getBlockMetadata(par2, par3, par4) == 0) 033 { 034 return false; 035 } 036 else 037 { 038 this.ejectRecord(par1World, par2, par3, par4); 039 return true; 040 } 041 } 042 043 public void func_85106_a(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack) 044 { 045 if (!par1World.isRemote) 046 { 047 TileEntityRecordPlayer var6 = (TileEntityRecordPlayer)par1World.getBlockTileEntity(par2, par3, par4); 048 049 if (var6 != null) 050 { 051 var6.record = par5ItemStack.copy(); 052 var6.onInventoryChanged(); 053 par1World.setBlockMetadataWithNotify(par2, par3, par4, 1); 054 } 055 } 056 } 057 058 /** 059 * Ejects the current record inside of the jukebox. 060 */ 061 public void ejectRecord(World par1World, int par2, int par3, int par4) 062 { 063 if (!par1World.isRemote) 064 { 065 TileEntityRecordPlayer var5 = (TileEntityRecordPlayer)par1World.getBlockTileEntity(par2, par3, par4); 066 067 if (var5 != null) 068 { 069 ItemStack var6 = var5.record; 070 071 if (var6 != null) 072 { 073 par1World.playAuxSFX(1005, par2, par3, par4, 0); 074 par1World.playRecord((String)null, par2, par3, par4); 075 var5.record = null; 076 var5.onInventoryChanged(); 077 par1World.setBlockMetadataWithNotify(par2, par3, par4, 0); 078 float var7 = 0.7F; 079 double var8 = (double)(par1World.rand.nextFloat() * var7) + (double)(1.0F - var7) * 0.5D; 080 double var10 = (double)(par1World.rand.nextFloat() * var7) + (double)(1.0F - var7) * 0.2D + 0.6D; 081 double var12 = (double)(par1World.rand.nextFloat() * var7) + (double)(1.0F - var7) * 0.5D; 082 ItemStack var14 = var6.copy(); 083 EntityItem var15 = new EntityItem(par1World, (double)par2 + var8, (double)par3 + var10, (double)par4 + var12, var14); 084 var15.delayBeforeCanPickup = 10; 085 par1World.spawnEntityInWorld(var15); 086 } 087 } 088 } 089 } 090 091 /** 092 * ejects contained items into the world, and notifies neighbours of an update, as appropriate 093 */ 094 public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) 095 { 096 this.ejectRecord(par1World, par2, par3, par4); 097 super.breakBlock(par1World, par2, par3, par4, par5, par6); 098 } 099 100 /** 101 * Drops the block items with a specified chance of dropping the specified items 102 */ 103 public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) 104 { 105 if (!par1World.isRemote) 106 { 107 super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, 0); 108 } 109 } 110 111 /** 112 * Returns a new instance of a block's tile entity class. Called on placing the block. 113 */ 114 public TileEntity createNewTileEntity(World par1World) 115 { 116 return new TileEntityRecordPlayer(); 117 } 118 }