-
Notifications
You must be signed in to change notification settings - Fork 81
/
BlockNetherGlowshroom.java
222 lines (179 loc) · 6.44 KB
/
BlockNetherGlowshroom.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
package com.progwml6.natura.nether.block.shrooms;
import java.util.Locale;
import java.util.Random;
import javax.annotation.Nonnull;
import com.progwml6.natura.Natura;
import com.progwml6.natura.library.NaturaRegistry;
import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.world.worldgen.glowshroom.BaseGlowshroomGenerator;
import com.progwml6.natura.world.worldgen.glowshroom.nether.BlueGlowshroomGenerator;
import com.progwml6.natura.world.worldgen.glowshroom.nether.GreenGlowshroomGenerator;
import com.progwml6.natura.world.worldgen.glowshroom.nether.PurpleGlowshroomGenerator;
import net.minecraft.block.BlockMushroom;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import slimeknights.mantle.block.EnumBlock;
public class BlockNetherGlowshroom extends BlockMushroom
{
public static PropertyEnum<GlowshroomType> TYPE = PropertyEnum.create("type", GlowshroomType.class);
public BlockNetherGlowshroom()
{
super();
this.setLightLevel(0.625f);
this.setCreativeTab(NaturaRegistry.tabWorld);
this.setSoundType(SoundType.PLANT);
}
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (rand.nextInt(25) == 0)
{
int i = 5;
for (BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-4, -1, -4), pos.add(4, 1, 4)))
{
if (worldIn.getBlockState(blockpos).getBlock() == this)
{
--i;
if (i <= 0)
{
return;
}
}
}
BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1);
IBlockState currentState = worldIn.getBlockState(pos);
for (int k = 0; k < 4; ++k)
{
if (worldIn.isAirBlock(blockpos1) && this.canBlockStay(worldIn, blockpos1, currentState))
{
pos = blockpos1;
}
blockpos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1);
}
currentState = worldIn.getBlockState(pos);
if (worldIn.isAirBlock(blockpos1) && this.canBlockStay(worldIn, blockpos1, currentState))
{
worldIn.setBlockState(blockpos1, currentState, 3);
}
}
}
@Override
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list)
{
for (GlowshroomType type : GlowshroomType.values())
{
list.add(new ItemStack(this, 1, this.getMetaFromState(this.getDefaultState().withProperty(TYPE, type))));
}
}
@Override
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
if (pos.getY() >= 0 && pos.getY() < 256)
{
IBlockState iblockstate = worldIn.getBlockState(pos.down());
return (iblockstate.getBlock() == Blocks.MYCELIUM || iblockstate.getBlock() == Blocks.NETHERRACK || iblockstate.getBlock() == Blocks.SOUL_SAND || iblockstate.getBlock() == NaturaNether.netherTaintedSoil) ? true : (worldIn.getLight(pos) < 13 && iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this));
}
else
{
return false;
}
}
@Nonnull
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, TYPE);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta)
{
if (meta < 0 || meta >= GlowshroomType.values().length)
{
meta = 0;
}
GlowshroomType type = GlowshroomType.values()[meta];
return this.getDefaultState().withProperty(TYPE, type);
}
/**
* Convert the BlockState into the correct metadata value
*/
@Override
public int getMetaFromState(IBlockState state)
{
return state.getValue(TYPE).ordinal();
}
@Override
public int damageDropped(IBlockState state)
{
return this.getMetaFromState(state);
}
@Override
public boolean generateBigMushroom(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
BaseGlowshroomGenerator gen = new BaseGlowshroomGenerator();
IBlockState glowshroom;
switch (state.getValue(TYPE))
{
case GREEN:
glowshroom = NaturaNether.netherLargeGreenGlowshroom.getDefaultState();
gen = new GreenGlowshroomGenerator(glowshroom);
break;
case BLUE:
glowshroom = NaturaNether.netherLargeBlueGlowshroom.getDefaultState();
gen = new BlueGlowshroomGenerator(glowshroom);
break;
case PURPLE:
glowshroom = NaturaNether.netherLargePurpleGlowshroom.getDefaultState();
gen = new PurpleGlowshroomGenerator(glowshroom);
break;
default:
Natura.log.warn("BlockNetherGlowshroom Warning: Invalid meta, " + state.getValue(TYPE) + ". Please report!");
break;
}
worldIn.setBlockToAir(pos);
gen.generateShroom(rand, worldIn, pos);
// check if it generated
if (worldIn.isAirBlock(pos))
{
worldIn.setBlockState(pos, state, 4);
return false;
}
else
{
return true;
}
}
public enum GlowshroomType implements IStringSerializable, EnumBlock.IEnumMeta
{
GREEN, BLUE, PURPLE;
public final int meta;
GlowshroomType()
{
this.meta = this.ordinal();
}
@Override
public String getName()
{
return this.toString().toLowerCase(Locale.US);
}
@Override
public int getMeta()
{
return this.meta;
}
}
}