BlockNote .java

net.minecraft.block.BlockNote (class): members: INSTRUMENTS, onBlockEventReceived, onBlockClicked, createNewTileEntity, getRenderType, onBlockActivated.

net.minecraft.blockclass124 linescommonextends BlockContainer3.9 KB

API Surface (6)

void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
TileEntity createNewTileEntity(World worldIn, int meta)
boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam)
int getRenderType()

Fields & Constants (1)

INSTRUMENTS

String literals (4)

"harp"
"snare"
"bassattack"
"note."

Full Source

BlockNote.java124 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.block.state.IBlockState;
7
import net.minecraft.creativetab.CreativeTabs;
8
import net.minecraft.entity.player.EntityPlayer;
9
import net.minecraft.stats.StatList;
10
import net.minecraft.tileentity.TileEntity;
11
import net.minecraft.tileentity.TileEntityNote;
12
import net.minecraft.util.BlockPos;
13
import net.minecraft.util.EnumFacing;
14
import net.minecraft.util.EnumParticleTypes;
15
import net.minecraft.world.World;
16
17
public class BlockNote extends BlockContainer
18
{
19
    private static final List<String> INSTRUMENTS = Lists.newArrayList(new String[] {"harp", "bd", "snare", "hat", "bassattack"});
20
21
    public BlockNote()
22
    {
23
        super(Material.wood);
24
        this.setCreativeTab(CreativeTabs.tabRedstone);
25
    }
26
27
    /**
28
     * Called when a neighboring block changes.
29
     */
30
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
31
    {
32
        boolean flag = worldIn.isBlockPowered(pos);
33
        TileEntity tileentity = worldIn.getTileEntity(pos);
34
35
        if (tileentity instanceof TileEntityNote)
36
        {
37
            TileEntityNote tileentitynote = (TileEntityNote)tileentity;
38
39
            if (tileentitynote.previousRedstoneState != flag)
40
            {
41
                if (flag)
42
                {
43
                    tileentitynote.triggerNote(worldIn, pos);
44
                }
45
46
                tileentitynote.previousRedstoneState = flag;
47
            }
48
        }
49
    }
50
51
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
52
    {
53
        if (worldIn.isRemote)
54
        {
55
            return true;
56
        }
57
        else
58
        {
59
            TileEntity tileentity = worldIn.getTileEntity(pos);
60
61
            if (tileentity instanceof TileEntityNote)
62
            {
63
                TileEntityNote tileentitynote = (TileEntityNote)tileentity;
64
                tileentitynote.changePitch();
65
                tileentitynote.triggerNote(worldIn, pos);
66
                playerIn.triggerAchievement(StatList.field_181735_S);
67
            }
68
69
            return true;
70
        }
71
    }
72
73
    public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
74
    {
75
        if (!worldIn.isRemote)
76
        {
77
            TileEntity tileentity = worldIn.getTileEntity(pos);
78
79
            if (tileentity instanceof TileEntityNote)
80
            {
81
                ((TileEntityNote)tileentity).triggerNote(worldIn, pos);
82
                playerIn.triggerAchievement(StatList.field_181734_R);
83
            }
84
        }
85
    }
86
87
    /**
88
     * Returns a new instance of a block's tile entity class. Called on placing the block.
89
     */
90
    public TileEntity createNewTileEntity(World worldIn, int meta)
91
    {
92
        return new TileEntityNote();
93
    }
94
95
    private String getInstrument(int id)
96
    {
97
        if (id < 0 || id >= INSTRUMENTS.size())
98
        {
99
            id = 0;
100
        }
101
102
        return (String)INSTRUMENTS.get(id);
103
    }
104
105
    /**
106
     * Called on both Client and Server when World#addBlockEvent is called
107
     */
108
    public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam)
109
    {
110
        float f = (float)Math.pow(2.0D, (double)(eventParam - 12) / 12.0D);
111
        worldIn.playSoundEffect((double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, "note." + this.getInstrument(eventID), 3.0F, f);
112
        worldIn.spawnParticle(EnumParticleTypes.NOTE, (double)pos.getX() + 0.5D, (double)pos.getY() + 1.2D, (double)pos.getZ() + 0.5D, (double)eventParam / 24.0D, 0.0D, 0.0D, new int[0]);
113
        return true;
114
    }
115
116
    /**
117
     * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
118
     */
119
    public int getRenderType()
120
    {
121
        return 3;
122
    }
123
}
124

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