summaryrefslogtreecommitdiff
path: root/src/main/java/com/sosnitzka/taiga/blocks/BlockCobble.java
blob: 357fb7611a2452d743ca0a0a9dba7622b9262f9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.sosnitzka.taiga.blocks;

import com.sosnitzka.taiga.generic.BasicBlock;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import static slimeknights.tconstruct.TConstruct.random;

public class BlockCobble extends BasicBlock {

    public BlockCobble(String name, Material material, float hardness, float resistance, int harvestlevel, float
            light, String oreDictPrefix) {
        super(name, material, hardness, resistance, harvestlevel, light, oreDictPrefix);
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void breakMoonRock(BlockEvent.BreakEvent e) {
        if (e.getWorld().getBlockState(e.getPos()).getBlock().equals(this)) {
            if (!e.getWorld().isRemote && random.nextFloat() > .9) {
                e.setCanceled(true);
                if (random.nextBoolean()) {
                    e.getWorld().setBlockState(e.getPos(), Blocks.LAVA.getDefaultState());
                } else {
                    e.getWorld().newExplosion(null, e.getPos().getX(), e.getPos().getY() + 1 / 16f, e.getPos().getZ()
                            , 0.5f + random.nextFloat() * 1.5f, false, true);
                }
            }
        }
    }

}