Skip to content

Commit 6aa1911

Browse files
committed
Split bonemeal branches into smaller methods
Seriously, those if branches were HUGE
1 parent 9d54770 commit 6aa1911

File tree

1 file changed

+109
-94
lines changed

1 file changed

+109
-94
lines changed

src/java/growthcraft/grapes/event/BonemealEventGrapes.java

+109-94
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package growthcraft.grapes.event;
22

33
import growthcraft.core.GrowthCraftCore;
4+
import growthcraft.core.utils.BlockFlags;
45
import growthcraft.grapes.GrowthCraftGrapes;
56
import growthcraft.grapes.block.BlockGrapeVine0;
67
import growthcraft.grapes.block.BlockGrapeVine1;
@@ -13,77 +14,98 @@
1314

1415
public class BonemealEventGrapes
1516
{
16-
@SubscribeEvent
17-
public void onUseBonemeal(BonemealEvent event)
17+
private void bonemealGrapeVine0(BonemealEvent event)
1818
{
19-
if (event.block == GrowthCraftGrapes.grapeVine0)
20-
{
21-
BlockGrapeVine0 vine = (BlockGrapeVine0)event.block;
22-
int meta = event.world.getBlockMetadata(event.x, event.y, event.z);
19+
BlockGrapeVine0 vine = (BlockGrapeVine0)event.block;
20+
int meta = event.world.getBlockMetadata(event.x, event.y, event.z);
2321

24-
if (!event.world.isRemote)
22+
if (!event.world.isRemote)
23+
{
24+
int i = MathHelper.getRandomIntegerInRange(event.world.rand, 1, 2);
25+
if (meta == 0)
2526
{
26-
int i = MathHelper.getRandomIntegerInRange(event.world.rand, 1, 2);
27-
if (meta == 0)
27+
if (i == 1)
2828
{
29-
if (i == 1)
30-
{
31-
vine.incrementGrowth(event.world, event.x, event.y, event.z, meta);
32-
}
33-
else if (i == 2)
34-
{
35-
event.world.setBlock(event.x, event.y, event.z, GrowthCraftGrapes.grapeVine1, 0, 2);
36-
}
29+
vine.incrementGrowth(event.world, event.x, event.y, event.z, meta);
30+
}
31+
else if (i == 2)
32+
{
33+
event.world.setBlock(event.x, event.y, event.z, GrowthCraftGrapes.grapeVine1, 0, BlockFlags.UPDATE_CLIENT);
34+
}
35+
}
36+
else if (meta == 1)
37+
{
38+
if (i == 1)
39+
{
40+
event.world.setBlock(event.x, event.y, event.z, GrowthCraftGrapes.grapeVine1, 0, BlockFlags.UPDATE_CLIENT);
3741
}
38-
else if (meta == 1)
42+
else if (i == 2)
3943
{
40-
if (i == 1)
44+
if (event.world.getBlock(event.x, event.y + 1, event.z) == GrowthCraftCore.ropeBlock)
4145
{
42-
event.world.setBlock(event.x, event.y, event.z, GrowthCraftGrapes.grapeVine1, 0, 2);
46+
event.world.setBlock(event.x, event.y, event.z, GrowthCraftGrapes.grapeVine1, 1, BlockFlags.UPDATE_CLIENT);
47+
event.world.setBlock(event.x, event.y + 1, event.z, GrowthCraftGrapes.grapeLeaves, 0, BlockFlags.UPDATE_CLIENT);
4348
}
44-
else if (i == 2)
49+
else
4550
{
46-
if (event.world.getBlock(event.x, event.y + 1, event.z) == GrowthCraftCore.ropeBlock)
47-
{
48-
event.world.setBlock(event.x, event.y, event.z, GrowthCraftGrapes.grapeVine1, 1, 2);
49-
event.world.setBlock(event.x, event.y + 1, event.z, GrowthCraftGrapes.grapeLeaves, 0, 2);
50-
}
51-
else
52-
{
53-
event.world.setBlock(event.x, event.y, event.z, GrowthCraftGrapes.grapeVine1, 0, 2);
54-
}
51+
event.world.setBlock(event.x, event.y, event.z, GrowthCraftGrapes.grapeVine1, 0, BlockFlags.UPDATE_CLIENT);
5552
}
5653
}
5754
}
55+
}
56+
event.setResult(Result.ALLOW);
57+
}
58+
59+
private void bonemealGrapeVine1(BonemealEvent event)
60+
{
61+
BlockGrapeVine1 vine = (BlockGrapeVine1)event.block;
62+
int meta = event.world.getBlockMetadata(event.x, event.y, event.z);
63+
if (meta == 0 && event.world.getBlock(event.x, event.y + 1, event.z) == GrowthCraftCore.ropeBlock)
64+
{
65+
if (!event.world.isRemote)
66+
{
67+
vine.incrementGrowth(event.world, event.x, event.y, event.z, meta);
68+
event.world.setBlock(event.x, event.y + 1, event.z, GrowthCraftGrapes.grapeLeaves, 0, BlockFlags.UPDATE_CLIENT);
69+
}
5870
event.setResult(Result.ALLOW);
5971
}
60-
else if (event.block == GrowthCraftGrapes.grapeVine1)
72+
if (meta == 0 && event.world.isAirBlock(event.x, event.y + 1, event.z))
6173
{
62-
BlockGrapeVine1 vine = (BlockGrapeVine1)event.block;
63-
int meta = event.world.getBlockMetadata(event.x, event.y, event.z);
64-
if (meta == 0 && event.world.getBlock(event.x, event.y + 1, event.z) == GrowthCraftCore.ropeBlock)
74+
if (!event.world.isRemote)
6575
{
66-
if (!event.world.isRemote)
67-
{
68-
vine.incrementGrowth(event.world, event.x, event.y, event.z, meta);
69-
event.world.setBlock(event.x, event.y + 1, event.z, GrowthCraftGrapes.grapeLeaves, 0, 2);
70-
}
71-
event.setResult(Result.ALLOW);
76+
vine.incrementGrowth(event.world, event.x, event.y, event.z, meta);
77+
event.world.setBlock(event.x, event.y + 1, event.z, GrowthCraftGrapes.grapeVine1, 0, BlockFlags.UPDATE_CLIENT);
7278
}
73-
if (meta == 0 && event.world.isAirBlock(event.x, event.y + 1, event.z))
79+
event.setResult(Result.ALLOW);
80+
}
81+
else if (meta == 0 && event.world.getBlock(event.x, event.y + 1, event.z) == GrowthCraftGrapes.grapeLeaves)
82+
{
83+
if (!event.world.isRemote)
7484
{
75-
if (!event.world.isRemote)
76-
{
77-
vine.incrementGrowth(event.world, event.x, event.y, event.z, meta);
78-
event.world.setBlock(event.x, event.y + 1, event.z, GrowthCraftGrapes.grapeVine1, 0, 2);
79-
}
80-
event.setResult(Result.ALLOW);
85+
vine.incrementGrowth(event.world, event.x, event.y, event.z, meta);
8186
}
82-
else if (meta == 0 && event.world.getBlock(event.x, event.y + 1, event.z) == GrowthCraftGrapes.grapeLeaves)
87+
event.setResult(Result.ALLOW);
88+
}
89+
else
90+
{
91+
event.setResult(Result.DENY);
92+
}
93+
}
94+
95+
private void bonemealGrapeLeaves(BonemealEvent event)
96+
{
97+
boolean flag = !checkValidity(event.world, event.x, event.y, event.z - 1);
98+
boolean flag1 = !checkValidity(event.world, event.x, event.y, event.z + 1);
99+
boolean flag2 = !checkValidity(event.world, event.x - 1, event.y, event.z);
100+
boolean flag3 = !checkValidity(event.world, event.x + 1, event.y, event.z);
101+
102+
if (flag1 && flag2 && flag3 && flag)
103+
{
104+
if (event.world.isAirBlock(event.x, event.y - 1, event.z))
83105
{
84106
if (!event.world.isRemote)
85107
{
86-
vine.incrementGrowth(event.world, event.x, event.y, event.z, meta);
108+
event.world.setBlock(event.x, event.y - 1, event.z, GrowthCraftGrapes.grapeBlock, 0, BlockFlags.UPDATE_CLIENT);
87109
}
88110
event.setResult(Result.ALLOW);
89111
}
@@ -92,61 +114,54 @@ else if (meta == 0 && event.world.getBlock(event.x, event.y + 1, event.z) == Gr
92114
event.setResult(Result.DENY);
93115
}
94116
}
95-
else if (event.block == GrowthCraftGrapes.grapeLeaves)
117+
else
96118
{
97-
boolean flag = !checkValidity(event.world, event.x, event.y, event.z - 1);
98-
boolean flag1 = !checkValidity(event.world, event.x, event.y, event.z + 1);
99-
boolean flag2 = !checkValidity(event.world, event.x - 1, event.y, event.z);
100-
boolean flag3 = !checkValidity(event.world, event.x + 1, event.y, event.z);
101-
102-
if (flag1 && flag2 && flag3 && flag)
119+
if (!event.world.isRemote)
103120
{
104-
if (event.world.isAirBlock(event.x, event.y - 1, event.z))
121+
int r = event.world.rand.nextInt(4);
122+
123+
if (r == 0 && checkValidity(event.world, event.x, event.y, event.z - 1))
105124
{
106-
if (!event.world.isRemote)
107-
{
108-
event.world.setBlock(event.x, event.y - 1, event.z, GrowthCraftGrapes.grapeBlock);
109-
}
110-
event.setResult(Result.ALLOW);
125+
event.world.setBlock(event.x, event.y, event.z - 1, GrowthCraftGrapes.grapeLeaves, 0, BlockFlags.UPDATE_CLIENT);
126+
return;
111127
}
112-
else
128+
129+
if (r == 1 && checkValidity(event.world, event.x, event.y, event.z + 1))
113130
{
114-
event.setResult(Result.DENY);
131+
event.world.setBlock(event.x, event.y, event.z + 1, GrowthCraftGrapes.grapeLeaves, 0, BlockFlags.UPDATE_CLIENT);
132+
return;
115133
}
116-
}
117-
else
118-
{
119-
if (!event.world.isRemote)
120-
{
121-
int r = event.world.rand.nextInt(4);
122-
123-
if (r == 0 && checkValidity(event.world, event.x, event.y, event.z - 1))
124-
{
125-
event.world.setBlock(event.x, event.y, event.z - 1, GrowthCraftGrapes.grapeLeaves);
126-
return;
127-
}
128-
129-
if (r == 1 && checkValidity(event.world, event.x, event.y, event.z + 1))
130-
{
131-
event.world.setBlock(event.x, event.y, event.z + 1, GrowthCraftGrapes.grapeLeaves);
132-
return;
133-
}
134-
135-
if (r == 2 && checkValidity(event.world, event.x - 1, event.y, event.z))
136-
{
137-
event.world.setBlock(event.x - 1, event.y, event.z, GrowthCraftGrapes.grapeLeaves);
138-
return;
139-
}
140134

141-
if (r == 3 && checkValidity(event.world, event.x + 1, event.y, event.z))
142-
{
143-
event.world.setBlock(event.x + 1, event.y, event.z, GrowthCraftGrapes.grapeLeaves);
144-
return;
145-
}
135+
if (r == 2 && checkValidity(event.world, event.x - 1, event.y, event.z))
136+
{
137+
event.world.setBlock(event.x - 1, event.y, event.z, GrowthCraftGrapes.grapeLeaves, 0, BlockFlags.UPDATE_CLIENT);
138+
return;
146139
}
147140

148-
event.setResult(Result.ALLOW);
141+
if (r == 3 && checkValidity(event.world, event.x + 1, event.y, event.z))
142+
{
143+
event.world.setBlock(event.x + 1, event.y, event.z, GrowthCraftGrapes.grapeLeaves, 0, BlockFlags.UPDATE_CLIENT);
144+
return;
145+
}
149146
}
147+
event.setResult(Result.ALLOW);
148+
}
149+
}
150+
151+
@SubscribeEvent
152+
public void onUseBonemeal(BonemealEvent event)
153+
{
154+
if (event.block == GrowthCraftGrapes.grapeVine0)
155+
{
156+
bonemealGrapeVine0(event);
157+
}
158+
else if (event.block == GrowthCraftGrapes.grapeVine1)
159+
{
160+
bonemealGrapeVine1(event);
161+
}
162+
else if (event.block == GrowthCraftGrapes.grapeLeaves)
163+
{
164+
bonemealGrapeLeaves(event);
150165
}
151166
}
152167

0 commit comments

Comments
 (0)