-
Notifications
You must be signed in to change notification settings - Fork 81
/
BlockCloud.java
171 lines (145 loc) · 5.24 KB
/
BlockCloud.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.progwml6.natura.shared.block.clouds;
import java.util.Locale;
import com.progwml6.natura.library.NaturaRegistry;
import com.progwml6.natura.shared.NaturaCommons;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import slimeknights.mantle.block.EnumBlock;
public class BlockCloud extends EnumBlock<BlockCloud.CloudType>
{
public static PropertyEnum<CloudType> TYPE = PropertyEnum.create("type", CloudType.class);
public BlockCloud()
{
super(NaturaRegistry.cloud, TYPE, CloudType.class);
this.setCreativeTab(NaturaRegistry.tabWorld);
this.setHardness(0.3F);
this.setSoundType(SoundType.CLOTH);
}
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
if (state.getValue(BlockCloud.TYPE) == BlockCloud.CloudType.SULFUR && entityIn instanceof EntityArrow && !worldIn.isRemote)
{
EntityArrow entityarrow = (EntityArrow) entityIn;
if (entityarrow.isBurning())
{
this.explode(worldIn, pos, 1, entityarrow.shootingEntity instanceof EntityLiving ? (EntityLiving) entityarrow.shootingEntity : null);
worldIn.setBlockToAir(pos);
return;
}
}
if (entityIn.motionY < 0.0D)
{
entityIn.motionY *= 0.005D;
}
entityIn.fallDistance = 0.0F;
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack itemstack = playerIn.getHeldItem(hand);
if (!itemstack.isEmpty())
{
if (state.getValue(BlockCloud.TYPE) == BlockCloud.CloudType.SULFUR && itemstack.getItem() != Items.AIR && itemstack.getItem() == Items.FLINT_AND_STEEL)
{
worldIn.setBlockToAir(pos);
this.explode(worldIn, pos, 1, playerIn);
return true;
}
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
@Override
public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn)
{
}
public void explode(World world, BlockPos pos, int size, EntityLivingBase living)
{
world.createExplosion(living, pos.getX(), pos.getY(), pos.getZ(), size, true);
}
@Override
public boolean canDropFromExplosion(Explosion par1Explosion)
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.TRANSLUCENT;
}
@Deprecated
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return blockAccess.getBlockState(pos.offset(side)).getMaterial() == this.blockMaterial ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
@Override
public boolean isFullCube(IBlockState state)
{
return false;
}
@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
@Override
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos)
{
Material material = world.getBlockState(pos).getMaterial();
return material == this.blockMaterial ? false : super.isNormalCube(state, world, pos);
}
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
if (worldIn.getBlockState(pos.down()).getBlock() == NaturaCommons.clouds)
{
return null;
}
else
{
return new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1.0D, pos.getY() + 0.0625D, pos.getZ() + 1.0D);
}
}
public enum CloudType implements IStringSerializable, EnumBlock.IEnumMeta
{
WHITE, DARK, ASH, SULFUR;
public final int meta;
CloudType()
{
this.meta = this.ordinal();
}
@Override
public String getName()
{
return this.toString().toLowerCase(Locale.US);
}
@Override
public int getMeta()
{
return this.meta;
}
}
}