Retro gen, enable in ores.json config file, disable once ran
This commit is contained in:
parent
3d082d8b82
commit
dc1ff4754c
4 changed files with 93 additions and 0 deletions
|
@ -40,6 +40,7 @@ import techreborn.packets.PacketAesu;
|
|||
import techreborn.packets.PacketIdsu;
|
||||
import techreborn.proxies.CommonProxy;
|
||||
import techreborn.tiles.idsu.IDSUManager;
|
||||
import techreborn.world.TechRebornRetroGen;
|
||||
import techreborn.world.TechRebornWorldGen;
|
||||
|
||||
@Mod(modid = ModInfo.MOD_ID, name = ModInfo.MOD_NAME, version = ModInfo.MOD_VERSION, dependencies = ModInfo.MOD_DEPENDENCUIES, guiFactory = ModInfo.GUI_FACTORY_CLASS, acceptedMinecraftVersions = "[1.8.8,1.8.9]")
|
||||
|
@ -131,6 +132,7 @@ public class Core {
|
|||
MinecraftForge.EVENT_BUS.register(new MultiblockServerTickHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new TRTickHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new OreUnifier());
|
||||
MinecraftForge.EVENT_BUS.register(worldGen.retroGen);
|
||||
if (config.scrapboxDispenser) {
|
||||
BlockDispenser.dispenseBehaviorRegistry.putObject(ModItems.scrapBox, new BehaviorDispenseScrapbox());
|
||||
}
|
||||
|
|
85
src/main/java/techreborn/world/TechRebornRetroGen.java
Normal file
85
src/main/java/techreborn/world/TechRebornRetroGen.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package techreborn.world;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.ChunkDataEvent;
|
||||
import reborncore.common.misc.ChunkCoord;
|
||||
import techreborn.Core;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Based off https://github.com/SteamNSteel/SteamNSteel
|
||||
*/
|
||||
public class TechRebornRetroGen {
|
||||
private static final String RETROGEN_TAG = "techrebonr:retogen";
|
||||
private static final Set<ChunkCoord> completedChunks = Sets.newHashSet();
|
||||
private final Deque<ChunkCoord> chunksToRetroGen = new ArrayDeque<ChunkCoord>(64);
|
||||
|
||||
private boolean isChunkEligibleForRetroGen(ChunkDataEvent.Load event) {
|
||||
return Core.worldGen.config.retroGenOres && event.world.provider.getDimensionId() == 0
|
||||
&& event.getData().getString(RETROGEN_TAG).isEmpty();
|
||||
}
|
||||
|
||||
public void markChunk(ChunkCoord coord) {
|
||||
completedChunks.add(coord);
|
||||
}
|
||||
|
||||
private boolean isTickEligibleForRetroGen(TickEvent.WorldTickEvent event) {
|
||||
return event.phase == TickEvent.Phase.END || event.side == Side.SERVER;
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldTick(TickEvent.WorldTickEvent event) {
|
||||
if (isTickEligibleForRetroGen(event)) {
|
||||
if (!chunksToRetroGen.isEmpty()) {
|
||||
final ChunkCoord coord = chunksToRetroGen.pollFirst();
|
||||
Core.logHelper.info("Regenerating ore in " + coord + '.');
|
||||
final World world = event.world;
|
||||
if (world.getChunkProvider().chunkExists(coord.getX(), coord.getZ())) {
|
||||
final long seed = world.getSeed();
|
||||
final Random rng = new Random(seed);
|
||||
final long xSeed = rng.nextLong() >> 2 + 1L;
|
||||
final long zSeed = rng.nextLong() >> 2 + 1L;
|
||||
final long chunkSeed = (xSeed * coord.getX() + zSeed * coord.getZ()) * seed;
|
||||
rng.setSeed(chunkSeed);
|
||||
Core.worldGen.generate(rng, coord.getX() << 4, coord.getZ() << 4, world, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onChunkLoad(ChunkDataEvent.Load event) {
|
||||
if (isChunkEligibleForRetroGen(event)) {
|
||||
final ChunkCoord coord = ChunkCoord.of(event);
|
||||
Core.logHelper.info("Queueing retro ore gen for " + coord + '.');
|
||||
chunksToRetroGen.addLast(coord);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onChunkSave(ChunkDataEvent.Save event) {
|
||||
final ChunkCoord coord = ChunkCoord.of(event);
|
||||
if (completedChunks.contains(coord)) {
|
||||
event.getData().setString(RETROGEN_TAG, "X");
|
||||
completedChunks.remove(coord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("chunksToRetroGen", chunksToRetroGen)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -6,10 +6,12 @@ import com.google.gson.reflect.TypeToken;
|
|||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraft.world.gen.feature.WorldGenMinable;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import net.minecraftforge.fml.common.IWorldGenerator;
|
||||
import reborncore.common.misc.ChunkCoord;
|
||||
import techreborn.Core;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.world.config.OreConfig;
|
||||
|
@ -60,6 +62,7 @@ public class TechRebornWorldGen implements IWorldGenerator {
|
|||
public File configFile;
|
||||
public static RubberTreeGenerator treeGenerator = new RubberTreeGenerator();
|
||||
public boolean jsonInvalid = false;
|
||||
public final TechRebornRetroGen retroGen = new TechRebornRetroGen();
|
||||
|
||||
public void load() {
|
||||
init();
|
||||
|
@ -192,6 +195,7 @@ public class TechRebornWorldGen implements IWorldGenerator {
|
|||
}
|
||||
|
||||
}
|
||||
retroGen.markChunk(ChunkCoord.of(chunkX, chunkZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ public class WorldGenConfig {
|
|||
|
||||
public boolean generateOres = true;
|
||||
|
||||
public boolean retroGenOres = false;
|
||||
|
||||
public List<OreConfig> overworldOres;
|
||||
|
||||
public List<OreConfig> neatherOres;
|
||||
|
|
Loading…
Reference in a new issue