-
Notifications
You must be signed in to change notification settings - Fork 81
/
TickHandlerWorldRetrogen.java
167 lines (141 loc) · 6.21 KB
/
TickHandlerWorldRetrogen.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
package com.progwml6.natura.world.worldgen.retrogen;
import java.util.List;
import java.util.Random;
import com.google.common.collect.LinkedListMultimap;
import com.progwml6.natura.Natura;
import com.progwml6.natura.common.config.Config;
import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.overworld.NaturaOverworld;
import com.progwml6.natura.world.NaturaWorld;
import com.progwml6.natura.world.worldgen.CloudGenerator;
import com.progwml6.natura.world.worldgen.CropGenerator;
import com.progwml6.natura.world.worldgen.GlowshroomGenerator;
import com.progwml6.natura.world.worldgen.NetherBerryBushesGenerator;
import com.progwml6.natura.world.worldgen.NetherMinableGenerator;
import com.progwml6.natura.world.worldgen.NetherTreesGenerator;
import com.progwml6.natura.world.worldgen.OverworldBerryBushesGenerator;
import com.progwml6.natura.world.worldgen.OverworldTreesGenerator;
import com.progwml6.natura.world.worldgen.VineGenerator;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.event.world.ChunkDataEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent;
public class TickHandlerWorldRetrogen
{
public static TickHandlerWorldRetrogen INSTANCE = new TickHandlerWorldRetrogen();
// Overworld
//@formatter:off
private OverworldTreesGenerator overworldTreesGenerator;
private OverworldBerryBushesGenerator overworldBerryBushesGenerator;
private CloudGenerator cloudGenerator;
private CropGenerator cropGenerator;
// Nether
private NetherTreesGenerator netherTreesGenerator;
private NetherBerryBushesGenerator netherBerryBushesGenerator;
private GlowshroomGenerator glowshroomGenerator;
private VineGenerator vineGenerator;
private NetherMinableGenerator netherMineableGenerator;
//@formatter:on
private final LinkedListMultimap<Integer, ChunkCoords> chunkRegenList = LinkedListMultimap.create();
public TickHandlerWorldRetrogen()
{
// Overworld
if (Natura.pulseManager.isPulseLoaded(NaturaOverworld.PulseId))
{
this.overworldTreesGenerator = new OverworldTreesGenerator();
this.overworldBerryBushesGenerator = new OverworldBerryBushesGenerator();
this.cloudGenerator = new CloudGenerator();
this.cropGenerator = new CropGenerator();
}
// Nether
if (Natura.pulseManager.isPulseLoaded(NaturaNether.PulseId))
{
this.netherTreesGenerator = new NetherTreesGenerator();
this.netherBerryBushesGenerator = new NetherBerryBushesGenerator();
this.glowshroomGenerator = new GlowshroomGenerator();
this.vineGenerator = new VineGenerator();
this.netherMineableGenerator = new NetherMinableGenerator();
}
}
@SubscribeEvent
public void onWorldTick(WorldTickEvent event)
{
if (event.phase != Phase.END)
{
return;
}
if (Config.doRetrogen)
{
World world = event.world;
int dimensionID = world.provider.getDimension();
List<ChunkCoords> chunkList = this.chunkRegenList.get(dimensionID);
if (!chunkList.isEmpty())
{
ChunkCoords coords = chunkList.get(0);
chunkList.remove(0);
// This bit is from FML's GameRegistry.generateWorld where the seed is constructed.
long worldSeed = world.getSeed();
Random random = new Random(worldSeed);
long xSeed = random.nextLong() >> 2 + 1L;
long zSeed = random.nextLong() >> 2 + 1L;
random.setSeed(xSeed * coords.xCoord + zSeed * coords.zCoord ^ worldSeed);
if (Natura.pulseManager.isPulseLoaded(NaturaOverworld.PulseId))
{
this.overworldTreesGenerator.retroGen(random, coords.xCoord, coords.zCoord, world);
this.overworldBerryBushesGenerator.retroGen(random, coords.xCoord, coords.zCoord, world);
if (Config.enableCloudBlocks)
{
this.cloudGenerator.retroGen(random, coords.xCoord, coords.zCoord, world);
}
this.cropGenerator.retroGen(random, coords.xCoord, coords.zCoord, world);
}
if (Natura.pulseManager.isPulseLoaded(NaturaNether.PulseId))
{
this.netherTreesGenerator.retroGen(random, coords.xCoord, coords.zCoord, world);
this.netherBerryBushesGenerator.retroGen(random, coords.xCoord, coords.zCoord, world);
this.glowshroomGenerator.retroGen(random, coords.xCoord, coords.zCoord, world);
this.vineGenerator.retroGen(random, coords.xCoord, coords.zCoord, world);
this.netherMineableGenerator.retroGen(random, coords.xCoord, coords.zCoord, world);
}
}
}
}
@SubscribeEvent
public void chunkSaveEventHandler(ChunkDataEvent.Save event)
{
NBTTagCompound tag = new NBTTagCompound();
if (Config.doRetrogen)
{
tag.setBoolean("retrogen", true);
}
event.getData().setTag(NaturaWorld.PulseId, tag);
}
@SubscribeEvent
public void chunkLoadEventHandler(ChunkDataEvent.Load event)
{
if (Config.doRetrogen)
{
NBTTagCompound tag = (NBTTagCompound) event.getData().getTag(NaturaWorld.PulseId);
if (tag == null || !tag.hasKey("retrogen"))
{
ChunkCoords coords = new ChunkCoords(event.getChunk());
this.chunkRegenList.put(coords.dimension, coords);
}
}
}
private static class ChunkCoords
{
public final int dimension;
public final int xCoord;
public final int zCoord;
public ChunkCoords(Chunk chunk)
{
this.dimension = chunk.getWorld().provider.getDimension();
this.xCoord = chunk.x;
this.zCoord = chunk.z;
}
}
}