BlockRedstoneTorch .java

net.minecraft.block.BlockRedstoneTorch (class): members: toggles, Toggle, isAssociatedBlock, isOn, randomTick, canProvidePower, getWeakPower, tickRate.

net.minecraft.blockclass229 linescommonextends BlockTorch7.3 KB

API Surface (13)

int tickRate(World worldIn)
void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
void breakBlock(World worldIn, BlockPos pos, IBlockState state)
int getWeakPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side)
void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random)
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
int getStrongPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side)
Item getItemDropped(IBlockState state, Random rand, int fortune)
boolean canProvidePower()
void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
Item getItem(World worldIn, BlockPos pos)
boolean isAssociatedBlock(Block other)

Fields & Constants (2)

toggles
isOn

String literals (1)

"random.fizz"

Full Source

BlockRedstoneTorch.java229 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Maps;
5
import java.util.List;
6
import java.util.Map;
7
import java.util.Random;
8
import net.minecraft.block.state.IBlockState;
9
import net.minecraft.creativetab.CreativeTabs;
10
import net.minecraft.init.Blocks;
11
import net.minecraft.item.Item;
12
import net.minecraft.util.BlockPos;
13
import net.minecraft.util.EnumFacing;
14
import net.minecraft.util.EnumParticleTypes;
15
import net.minecraft.world.IBlockAccess;
16
import net.minecraft.world.World;
17
18
public class BlockRedstoneTorch extends BlockTorch
19
{
20
    private static Map<World, List<BlockRedstoneTorch.Toggle>> toggles = Maps.<World, List<BlockRedstoneTorch.Toggle>>newHashMap();
21
    private final boolean isOn;
22
23
    private boolean isBurnedOut(World worldIn, BlockPos pos, boolean turnOff)
24
    {
25
        if (!toggles.containsKey(worldIn))
26
        {
27
            toggles.put(worldIn, Lists.<BlockRedstoneTorch.Toggle>newArrayList());
28
        }
29
30
        List<BlockRedstoneTorch.Toggle> list = (List)toggles.get(worldIn);
31
32
        if (turnOff)
33
        {
34
            list.add(new BlockRedstoneTorch.Toggle(pos, worldIn.getTotalWorldTime()));
35
        }
36
37
        int i = 0;
38
39
        for (int j = 0; j < list.size(); ++j)
40
        {
41
            BlockRedstoneTorch.Toggle blockredstonetorch$toggle = (BlockRedstoneTorch.Toggle)list.get(j);
42
43
            if (blockredstonetorch$toggle.pos.equals(pos))
44
            {
45
                ++i;
46
47
                if (i >= 8)
48
                {
49
                    return true;
50
                }
51
            }
52
        }
53
54
        return false;
55
    }
56
57
    protected BlockRedstoneTorch(boolean isOn)
58
    {
59
        this.isOn = isOn;
60
        this.setTickRandomly(true);
61
        this.setCreativeTab((CreativeTabs)null);
62
    }
63
64
    /**
65
     * How many world ticks before ticking
66
     */
67
    public int tickRate(World worldIn)
68
    {
69
        return 2;
70
    }
71
72
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
73
    {
74
        if (this.isOn)
75
        {
76
            for (EnumFacing enumfacing : EnumFacing.values())
77
            {
78
                worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
79
            }
80
        }
81
    }
82
83
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
84
    {
85
        if (this.isOn)
86
        {
87
            for (EnumFacing enumfacing : EnumFacing.values())
88
            {
89
                worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
90
            }
91
        }
92
    }
93
94
    public int getWeakPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side)
95
    {
96
        return this.isOn && state.getValue(FACING) != side ? 15 : 0;
97
    }
98
99
    private boolean shouldBeOff(World worldIn, BlockPos pos, IBlockState state)
100
    {
101
        EnumFacing enumfacing = ((EnumFacing)state.getValue(FACING)).getOpposite();
102
        return worldIn.isSidePowered(pos.offset(enumfacing), enumfacing);
103
    }
104
105
    /**
106
     * Called randomly when setTickRandomly is set to true (used by e.g. crops to grow, etc.)
107
     */
108
    public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random)
109
    {
110
    }
111
112
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
113
    {
114
        boolean flag = this.shouldBeOff(worldIn, pos, state);
115
        List<BlockRedstoneTorch.Toggle> list = (List)toggles.get(worldIn);
116
117
        while (list != null && !list.isEmpty() && worldIn.getTotalWorldTime() - ((BlockRedstoneTorch.Toggle)list.get(0)).time > 60L)
118
        {
119
            list.remove(0);
120
        }
121
122
        if (this.isOn)
123
        {
124
            if (flag)
125
            {
126
                worldIn.setBlockState(pos, Blocks.unlit_redstone_torch.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
127
128
                if (this.isBurnedOut(worldIn, pos, true))
129
                {
130
                    worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), "random.fizz", 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);
131
132
                    for (int i = 0; i < 5; ++i)
133
                    {
134
                        double d0 = (double)pos.getX() + rand.nextDouble() * 0.6D + 0.2D;
135
                        double d1 = (double)pos.getY() + rand.nextDouble() * 0.6D + 0.2D;
136
                        double d2 = (double)pos.getZ() + rand.nextDouble() * 0.6D + 0.2D;
137
                        worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
138
                    }
139
140
                    worldIn.scheduleUpdate(pos, worldIn.getBlockState(pos).getBlock(), 160);
141
                }
142
            }
143
        }
144
        else if (!flag && !this.isBurnedOut(worldIn, pos, false))
145
        {
146
            worldIn.setBlockState(pos, Blocks.redstone_torch.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
147
        }
148
    }
149
150
    /**
151
     * Called when a neighboring block changes.
152
     */
153
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
154
    {
155
        if (!this.onNeighborChangeInternal(worldIn, pos, state))
156
        {
157
            if (this.isOn == this.shouldBeOff(worldIn, pos, state))
158
            {
159
                worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
160
            }
161
        }
162
    }
163
164
    public int getStrongPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side)
165
    {
166
        return side == EnumFacing.DOWN ? this.getWeakPower(worldIn, pos, state, side) : 0;
167
    }
168
169
    /**
170
     * Get the Item that this Block should drop when harvested.
171
     */
172
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
173
    {
174
        return Item.getItemFromBlock(Blocks.redstone_torch);
175
    }
176
177
    /**
178
     * Can this block provide power. Only wire currently seems to have this change based on its state.
179
     */
180
    public boolean canProvidePower()
181
    {
182
        return true;
183
    }
184
185
    public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
186
    {
187
        if (this.isOn)
188
        {
189
            double d0 = (double)pos.getX() + 0.5D + (rand.nextDouble() - 0.5D) * 0.2D;
190
            double d1 = (double)pos.getY() + 0.7D + (rand.nextDouble() - 0.5D) * 0.2D;
191
            double d2 = (double)pos.getZ() + 0.5D + (rand.nextDouble() - 0.5D) * 0.2D;
192
            EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
193
194
            if (enumfacing.getAxis().isHorizontal())
195
            {
196
                EnumFacing enumfacing1 = enumfacing.getOpposite();
197
                double d3 = 0.27D;
198
                d0 += 0.27D * (double)enumfacing1.getFrontOffsetX();
199
                d1 += 0.22D;
200
                d2 += 0.27D * (double)enumfacing1.getFrontOffsetZ();
201
            }
202
203
            worldIn.spawnParticle(EnumParticleTypes.REDSTONE, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
204
        }
205
    }
206
207
    public Item getItem(World worldIn, BlockPos pos)
208
    {
209
        return Item.getItemFromBlock(Blocks.redstone_torch);
210
    }
211
212
    public boolean isAssociatedBlock(Block other)
213
    {
214
        return other == Blocks.unlit_redstone_torch || other == Blocks.redstone_torch;
215
    }
216
217
    static class Toggle
218
    {
219
        BlockPos pos;
220
        long time;
221
222
        public Toggle(BlockPos pos, long time)
223
        {
224
            this.pos = pos;
225
            this.time = time;
226
        }
227
    }
228
}
229

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