Skip to content

Commit

Permalink
Added dimension for startup chunk loading
Browse files Browse the repository at this point in the history
  • Loading branch information
gecgooden committed Mar 12, 2018
1 parent fe45020 commit bda188d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/gecgooden/chunkgen/ChunkGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public void preInit(FMLPreInitializationEvent event) {
@EventHandler
public void serverLoad(FMLServerStartingEvent event) {
event.registerServerCommand(new ChunkGenCommand());
if (Reference.x != null && Reference.z != null && Reference.depth != null && Reference.width != null && Reference.depth > 0 && Reference.width > 0) {
Reference.logger.info(String.format("Starting initial Generation with x:%d z:%d width:%d depth:%d", Reference.x, Reference.z, Reference.width, Reference.depth));
Utilities.queueChunkGeneration(event.getServer(), Reference.skipChunks, Reference.x, Reference.z, Reference.width, Reference.depth, 0, false);
if (Reference.x != null && Reference.z != null && Reference.depth != null && Reference.width != null && Reference.depth > 0 && Reference.width > 0 && Reference.dimension != null) {
Reference.logger.info(String.format("Starting initial Generation in Dimension:%d with x:%d z:%d width:%d depth:%d", Reference.dimension, Reference.x, Reference.z, Reference.width, Reference.depth));
Utilities.queueChunkGeneration(event.getServer(), Reference.x, Reference.z, Reference.width, Reference.depth, Reference.dimension, false);
}
}
}
18 changes: 8 additions & 10 deletions src/main/java/com/gecgooden/chunkgen/commands/ChunkGenCommand.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.gecgooden.chunkgen.commands;

import java.util.List;

import com.gecgooden.chunkgen.reference.Reference;
import com.gecgooden.chunkgen.util.Utilities;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;

import java.util.List;

public class ChunkGenCommand extends CommandBase {

public static final String SUB_CMD_HELP = "help";
public static final String SUB_CMD_ZONE = "zone";
public static final String SUB_CMD_RADIUS = "radius";
public static final String SUB_CMD_STOP = "stop";
private static final String SUB_CMD_HELP = "help";
private static final String SUB_CMD_ZONE = "zone";
private static final String SUB_CMD_RADIUS = "radius";
private static final String SUB_CMD_STOP = "stop";

public ChunkGenCommand() {

Expand Down Expand Up @@ -56,7 +54,7 @@ public void execute(MinecraftServer server, ICommandSender icommandsender, Strin
if (astring.length > 6) {
logToChat = parseBoolean(astring[6]);
}
notifyCommandListener(icommandsender, this, "commands.chunkgen.enqueued", Utilities.queueChunkGeneration(icommandsender, 0, x, z, width,depth, dimensionID, logToChat));
notifyCommandListener(icommandsender, this, "commands.chunkgen.enqueued", Utilities.queueChunkGeneration(icommandsender, z, width, depth, dimensionID, logToChat));
}
break;
case SUB_CMD_RADIUS:
Expand All @@ -74,7 +72,7 @@ public void execute(MinecraftServer server, ICommandSender icommandsender, Strin
if (astring.length > 5) {
logToChat = parseBoolean(astring[5]);
}
notifyCommandListener(icommandsender, this, "commands.chunkgen.enqueued", Utilities.queueChunkGeneration(icommandsender, 0, x, z, radius, dimensionID, logToChat));
notifyCommandListener(icommandsender, this, "commands.chunkgen.enqueued", Utilities.queueChunkGeneration(icommandsender, x, z, radius, dimensionID, logToChat));
}
break;
case SUB_CMD_STOP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private static void loadConfiguration() {
Reference.z = configuration.get(Configuration.CATEGORY_GENERAL, "z", 0, "Z starting value").getInt();
Reference.depth = configuration.get(Configuration.CATEGORY_GENERAL, "depth", 0, "Height starting value").getInt();
Reference.width = configuration.get(Configuration.CATEGORY_GENERAL, "width", 0, "Width starting value").getInt();
Reference.dimension = configuration.get(Configuration.CATEGORY_GENERAL, "dimension", 0, "Dimension to auto generate in").getInt();
Reference.pauseForPlayers = configuration.get(Configuration.CATEGORY_GENERAL, "pauseForPlayers", false, "Pause chunk generation when players are logged on").getBoolean();
Reference.maxChunksLoaded = configuration.get(Configuration.CATEGORY_GENERAL, "maxChunksLoaded", 3000, "Pause chunk generation if more chunks than this are in memory").getInt();
Reference.numChunksPerTick = configuration.get(Configuration.CATEGORY_GENERAL, "numChunksPerTick", 1.0, "Number of chunks loaded per tick").getDouble();
Expand All @@ -42,7 +43,7 @@ private static void loadConfiguration() {
}
}

public static void UpdateSkipChunks() {
static void updateSkipChunks() {
getSkipChunks().set(Reference.skipChunks);

configuration.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void onServerTick(TickEvent.ServerTickEvent event) {
double completedPercentage = 100 - ((double) Reference.toGenerate.size() / (double) Reference.startingSize) * 100;
if (chunksGenerated % Reference.updateDelay == 0) {
Reference.logger.info(String.format("Generation [x:%3d z:%3d][DIM:%s] %.3f%% completed", cp.getX(), cp.getZ(), getChunkDescription(cp), completedPercentage));
ConfigurationHandler.UpdateSkipChunks();
ConfigurationHandler.updateSkipChunks();
}
if (cp.logToChat()) {
cp.getICommandSender().sendMessage(new TextComponentTranslation("chunkgen.genat", cp.getX(), cp.getZ(), getChunkDescription(cp), String.format("%.3f", completedPercentage)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import java.text.DecimalFormat;
import java.util.LinkedList;
import java.util.List;

public class Reference {
public static Integer x;
public static Integer z;
public static Integer depth;
public static Integer width;
public static Integer dimension;
public static double numChunksPerTick;
public static boolean pauseForPlayers;
public static Integer maxChunksLoaded;
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/gecgooden/chunkgen/util/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.RegionFileCache;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraftforge.common.DimensionManager;

import java.security.Provider;


public class Utilities {

Expand All @@ -34,7 +31,7 @@ public static boolean generateChunk(MinecraftServer server, int x, int z, int di
return true;
}

public static int queueChunkGeneration(ICommandSender icommandsender, int skipChunks, int x, int z, int radius, int dimensionID, boolean logToChat) {
public static int queueChunkGeneration(ICommandSender icommandsender, int x, int z, int radius, int dimensionID, boolean logToChat) {
final int xmax = x + radius;
final int xmin = x - radius;
final int zmax = z + radius;
Expand All @@ -55,7 +52,7 @@ public static int queueChunkGeneration(ICommandSender icommandsender, int skipCh
return Reference.startingSize = Reference.toGenerate.size();
}

public static int queueChunkGeneration(ICommandSender icommandsender, int skipChunks, int x, int z, int xSize, int zSize, int dimensionID, boolean logToChat) {
public static int queueChunkGeneration(ICommandSender icommandsender, int x, int z, int xSize, int zSize, int dimensionID, boolean logToChat) {
final int xmax = x + xSize;
final int xmin = x - xSize;
final int zmax = z + zSize;
Expand Down

0 comments on commit bda188d

Please sign in to comment.