BlockRedstoneOre .java

net.minecraft.block.BlockRedstoneOre (class, 179 lines): members: isOn, quantityDroppedWithBonus, onBlockClicked, createStackedBlock, tickRate, updateTick.

net.minecraft.blockclass179 linescommonextends Block5.3 KB

API Surface (11)

int tickRate(World worldIn)
void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
void onEntityCollidedWithBlock(World worldIn, BlockPos pos, Entity entityIn)
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
Item getItemDropped(IBlockState state, Random rand, int fortune)
int quantityDroppedWithBonus(int fortune, Random random)
int quantityDropped(Random random)
void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
ItemStack createStackedBlock(IBlockState state)

Fields & Constants (1)

isOn

Full Source

BlockRedstoneOre.java179 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.Random;
4
import net.minecraft.block.material.Material;
5
import net.minecraft.block.state.IBlockState;
6
import net.minecraft.entity.Entity;
7
import net.minecraft.entity.player.EntityPlayer;
8
import net.minecraft.init.Blocks;
9
import net.minecraft.init.Items;
10
import net.minecraft.item.Item;
11
import net.minecraft.item.ItemStack;
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 BlockRedstoneOre extends Block
18
{
19
    private final boolean isOn;
20
21
    public BlockRedstoneOre(boolean isOn)
22
    {
23
        super(Material.rock);
24
25
        if (isOn)
26
        {
27
            this.setTickRandomly(true);
28
        }
29
30
        this.isOn = isOn;
31
    }
32
33
    /**
34
     * How many world ticks before ticking
35
     */
36
    public int tickRate(World worldIn)
37
    {
38
        return 30;
39
    }
40
41
    public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
42
    {
43
        this.activate(worldIn, pos);
44
        super.onBlockClicked(worldIn, pos, playerIn);
45
    }
46
47
    /**
48
     * Triggered whenever an entity collides with this block (enters into the block)
49
     */
50
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, Entity entityIn)
51
    {
52
        this.activate(worldIn, pos);
53
        super.onEntityCollidedWithBlock(worldIn, pos, entityIn);
54
    }
55
56
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
57
    {
58
        this.activate(worldIn, pos);
59
        return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);
60
    }
61
62
    private void activate(World worldIn, BlockPos pos)
63
    {
64
        this.spawnParticles(worldIn, pos);
65
66
        if (this == Blocks.redstone_ore)
67
        {
68
            worldIn.setBlockState(pos, Blocks.lit_redstone_ore.getDefaultState());
69
        }
70
    }
71
72
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
73
    {
74
        if (this == Blocks.lit_redstone_ore)
75
        {
76
            worldIn.setBlockState(pos, Blocks.redstone_ore.getDefaultState());
77
        }
78
    }
79
80
    /**
81
     * Get the Item that this Block should drop when harvested.
82
     */
83
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
84
    {
85
        return Items.redstone;
86
    }
87
88
    /**
89
     * Get the quantity dropped based on the given fortune level
90
     */
91
    public int quantityDroppedWithBonus(int fortune, Random random)
92
    {
93
        return this.quantityDropped(random) + random.nextInt(fortune + 1);
94
    }
95
96
    /**
97
     * Returns the quantity of items to drop on block destruction.
98
     */
99
    public int quantityDropped(Random random)
100
    {
101
        return 4 + random.nextInt(2);
102
    }
103
104
    /**
105
     * Spawns this Block's drops into the World as EntityItems.
106
     */
107
    public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
108
    {
109
        super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
110
111
        if (this.getItemDropped(state, worldIn.rand, fortune) != Item.getItemFromBlock(this))
112
        {
113
            int i = 1 + worldIn.rand.nextInt(5);
114
            this.dropXpOnBlockBreak(worldIn, pos, i);
115
        }
116
    }
117
118
    public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
119
    {
120
        if (this.isOn)
121
        {
122
            this.spawnParticles(worldIn, pos);
123
        }
124
    }
125
126
    private void spawnParticles(World worldIn, BlockPos pos)
127
    {
128
        Random random = worldIn.rand;
129
        double d0 = 0.0625D;
130
131
        for (int i = 0; i < 6; ++i)
132
        {
133
            double d1 = (double)((float)pos.getX() + random.nextFloat());
134
            double d2 = (double)((float)pos.getY() + random.nextFloat());
135
            double d3 = (double)((float)pos.getZ() + random.nextFloat());
136
137
            if (i == 0 && !worldIn.getBlockState(pos.up()).getBlock().isOpaqueCube())
138
            {
139
                d2 = (double)pos.getY() + d0 + 1.0D;
140
            }
141
142
            if (i == 1 && !worldIn.getBlockState(pos.down()).getBlock().isOpaqueCube())
143
            {
144
                d2 = (double)pos.getY() - d0;
145
            }
146
147
            if (i == 2 && !worldIn.getBlockState(pos.south()).getBlock().isOpaqueCube())
148
            {
149
                d3 = (double)pos.getZ() + d0 + 1.0D;
150
            }
151
152
            if (i == 3 && !worldIn.getBlockState(pos.north()).getBlock().isOpaqueCube())
153
            {
154
                d3 = (double)pos.getZ() - d0;
155
            }
156
157
            if (i == 4 && !worldIn.getBlockState(pos.east()).getBlock().isOpaqueCube())
158
            {
159
                d1 = (double)pos.getX() + d0 + 1.0D;
160
            }
161
162
            if (i == 5 && !worldIn.getBlockState(pos.west()).getBlock().isOpaqueCube())
163
            {
164
                d1 = (double)pos.getX() - d0;
165
            }
166
167
            if (d1 < (double)pos.getX() || d1 > (double)(pos.getX() + 1) || d2 < 0.0D || d2 > (double)(pos.getY() + 1) || d3 < (double)pos.getZ() || d3 > (double)(pos.getZ() + 1))
168
            {
169
                worldIn.spawnParticle(EnumParticleTypes.REDSTONE, d1, d2, d3, 0.0D, 0.0D, 0.0D, new int[0]);
170
            }
171
        }
172
    }
173
174
    protected ItemStack createStackedBlock(IBlockState state)
175
    {
176
        return new ItemStack(Blocks.redstone_ore);
177
    }
178
}
179

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