-
Notifications
You must be signed in to change notification settings - Fork 81
/
BlockNetherLargeGlowshroom.java
232 lines (193 loc) · 6.3 KB
/
BlockNetherLargeGlowshroom.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package com.progwml6.natura.nether.block.shrooms;
import java.util.Random;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.progwml6.natura.nether.NaturaNether;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockNetherLargeGlowshroom extends Block
{
public static final PropertyEnum<EnumType> VARIANT = PropertyEnum.<EnumType> create("variant", EnumType.class);
private final Block smallState;
private final int glowshroomMeta;
public BlockNetherLargeGlowshroom(Block smallStateIn, int glowshroomMetaIn)
{
super(Material.WOOD);
this.setLightLevel(0.625f);
this.smallState = smallStateIn;
this.glowshroomMeta = glowshroomMetaIn;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random random)
{
return Math.max(0, random.nextInt(10) - 7);
}
@Override
public int damageDropped(IBlockState state)
{
return this.glowshroomMeta;
}
/**
* Get the Item that this Block should drop when harvested.
*/
@Override
@Nullable
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(this.smallState);
}
@Nonnull
@Override
public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player)
{
return new ItemStack(Item.getItemFromBlock(this.smallState), 1, this.glowshroomMeta);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
@Override
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(VARIANT, EnumType.byMetadata(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
@Override
public int getMetaFromState(IBlockState state)
{
return state.getValue(VARIANT).getMeta();
}
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, VARIANT);
}
@Override
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.TRANSLUCENT;
}
@Override
public boolean isFullCube(IBlockState state)
{
return false;
}
@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
@Override
@Deprecated
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
Block block = blockAccess.getBlockState(pos.offset(side)).getBlock();
if (block == NaturaNether.netherLargeBlueGlowshroom || block == NaturaNether.netherLargePurpleGlowshroom)
{
return false;
}
else
{
return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
}
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
if (worldIn.getBlockState(pos.up()).getBlock() instanceof BlockNetherLargeGlowshroom)
{
return null;
}
else
{
return new AxisAlignedBB(pos.getX(), pos.getY() + 0.9375, pos.getZ(), pos.getX() + 1.0D, pos.getY() + 1.0D, pos.getZ() + 1.0D);
}
}
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
if (entityIn.motionY < 0)
{
entityIn.motionY *= 0.25F;
}
entityIn.fallDistance -= 0.25f;
if (entityIn.motionY == 0f)
{
entityIn.motionX *= 0.25f;
entityIn.motionZ *= 0.25f;
}
if (entityIn instanceof EntityLiving)
{
EntityLiving living = (EntityLiving) entityIn;
living.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 100, 0));
}
}
public static enum EnumType implements IStringSerializable
{
NORTH_WEST(1, "north_west"), NORTH(2, "north"), NORTH_EAST(3, "north_east"), WEST(4, "west"), CENTER(5, "center"), EAST(6, "east"), SOUTH_WEST(7, "south_west"), SOUTH(8, "south"), SOUTH_EAST(9, "south_east"), STEM(10, "stem"), ALL_INSIDE(0, "all_inside"), ALL_OUTSIDE(14, "all_outside"), ALL_STEM(15, "all_stem");
private static final EnumType[] META_LOOKUP = new EnumType[16];
private final int meta;
private final String name;
private EnumType(int meta, String name)
{
this.meta = meta;
this.name = name;
}
public int getMeta()
{
return this.meta;
}
@Override
public String toString()
{
return this.name;
}
public static EnumType byMetadata(int meta)
{
if (meta < 0 || meta >= META_LOOKUP.length)
{
meta = 0;
}
EnumType enumtype = META_LOOKUP[meta];
return enumtype == null ? META_LOOKUP[0] : enumtype;
}
@Override
public String getName()
{
return this.name;
}
static
{
for (EnumType enumtype : values())
{
META_LOOKUP[enumtype.getMeta()] = enumtype;
}
}
}
}