forked from GnomeWorks/dungeon-mobs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlockLavarock.java
119 lines (94 loc) · 3.55 KB
/
BlockLavarock.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.gw.dm.blocks;
import com.gw.dm.DungeonMobs;
import com.gw.dm.util.DungeonMobsHelper;
import com.gw.dm.util.MiscRegistrar;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.Random;
public class BlockLavarock extends ModBlockBase {
public static final PropertyInteger TIME_TO_LIVE = PropertyInteger.create("age", 0, 15);
public BlockLavarock() {
super(Material.ROCK);
setTickRandomly(true);
setRegistryName(new ResourceLocation(DungeonMobs.MODID, "lavarock"));
setUnlocalizedName(DungeonMobs.MODID + ".lavarock");
setDefaultState(blockState.getBaseState().withProperty(TIME_TO_LIVE, Integer.valueOf(6)));
setLightLevel(0.4375f);
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
MiscRegistrar.addBlock(this);
MiscRegistrar.addItem(new ItemBlock(this)
.setRegistryName(getRegistryName()));
}
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entity) {
entity.setFire(10);
if ((worldIn.getTotalWorldTime() % 10) == 0) entity.attackEntityFrom(DamageSource.LAVA, 4);
}
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState,
IBlockAccess world, BlockPos pos) {
float f = 0.0625F;
return new AxisAlignedBB((double) ((float) pos.getX() + f), (double) pos.getX(),
(double) ((float) pos.getY() + f), (double) ((float) (pos.getY() + 1) - f),
(double) (float) (pos.getZ() + f), (double) (float) (pos.getZ() + f));
}
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
super.updateTick(worldIn, pos, state, rand);
int foo = rand.nextInt(DungeonMobsHelper.getDifficulty(worldIn) + 1);
if (foo < 1) {
int age = state.getValue(TIME_TO_LIVE).intValue();
if (age > 0) {
worldIn.setBlockState(pos, getDefaultState()
.withProperty(TIME_TO_LIVE, Integer.valueOf(age - 1)));
} else {
worldIn.setBlockState(pos, Blocks.STONE.getDefaultState(), 3);
}
}
}
private boolean byWater(World world, BlockPos pos) {
for (EnumFacing enumfacing : EnumFacing.values()) {
if (world.getBlockState(pos.offset(enumfacing)).getMaterial()
== Material.WATER) {
return true;
}
}
return false;
}
@Override
public void onBlockDestroyedByPlayer(World world, BlockPos pos,
IBlockState state) {
world.setBlockState(pos, Blocks.LAVA.getDefaultState(), 3);
super.onBlockDestroyedByPlayer(world, pos, state);
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{TIME_TO_LIVE});
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(TIME_TO_LIVE, meta);
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(TIME_TO_LIVE).intValue();
}
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
}