Skip to content

Commit

Permalink
Merge pull request #11 from Baughn/master
Browse files Browse the repository at this point in the history
Misc. extra features
  • Loading branch information
gecgooden committed Sep 14, 2015
2 parents f419ae9 + 4dd0e6f commit 14ad7a7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 48 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/gecgooden/chunkgen/ChunkGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.gecgooden.chunkgen.util.Utilities;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void serverLoad(FMLServerStartingEvent event)
{
event.registerServerCommand(new ChunkGenCommand());
if(Reference.x != null && Reference.z != null && Reference.height != null && Reference.width != null && Reference.height > 0 && Reference.width > 0) {
Utilities.generateChunks(Reference.x, Reference.z, Reference.width, Reference.height, 0);
Utilities.queueChunkGeneration(event.getServer(), Reference.x, Reference.z, Reference.height, Reference.width, 0);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
package com.gecgooden.chunkgen.commands;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

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

import net.minecraft.client.Minecraft;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkProviderServer;

public class ChunkGenCommand implements ICommand
{
Expand Down Expand Up @@ -104,14 +98,7 @@ else if(astring[0].equalsIgnoreCase("stop")) {
dimensionID = Integer.parseInt(astring[4]);
}

for(int i = (x - width/2); i < (x + width/2); i++) {
for(int j = (z - height/2); j < (z + height/2); j++) {
if(Reference.toGenerate == null) {
Reference.toGenerate = new LinkedList<ChunkPosition>();
}
Reference.toGenerate.add(new ChunkPosition(i, j, dimensionID, icommandsender));
}
}
Utilities.queueChunkGeneration(icommandsender, x, z, height, width, dimensionID);
Reference.startingSize = Reference.toGenerate.size();
} catch (NumberFormatException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ private static void loadConfiguration() {
Reference.z = configuration.get(Configuration.CATEGORY_GENERAL, "z", 0, "Z starting value").getInt();
Reference.height = configuration.get(Configuration.CATEGORY_GENERAL, "height", 0, "Height starting value").getInt();
Reference.width = configuration.get(Configuration.CATEGORY_GENERAL, "width", 0, "Width starting value").getInt();
Reference.numChunksPerTick = configuration.get(Configuration.CATEGORY_GENERAL, "numChunksPerTick", 1, "Number of chunks loaded per tick").getInt();
Reference.tickDelay = configuration.get(Configuration.CATEGORY_GENERAL, "tickDelay", 40, "Number of ticks inbetween percentage updates").getInt();
Reference.pauseForPlayers = configuration.get(Configuration.CATEGORY_GENERAL, "pauseForPlayers", true, "Pause chunk generation when players are logged on").getBoolean();
Reference.numChunksPerTick = configuration.get(Configuration.CATEGORY_GENERAL, "numChunksPerTick", 1.0, "Number of chunks loaded per tick").getDouble();
Reference.updateDelay = configuration.get(Configuration.CATEGORY_GENERAL, "updateDelay", 40, "Number of chunks inbetween percentage updates").getInt();

if(configuration.hasChanged()) {
configuration.save();
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/com/gecgooden/chunkgen/handlers/TickHandler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.gecgooden.chunkgen.handlers;

import java.text.DecimalFormat;

import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
Expand All @@ -12,26 +10,33 @@

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraft.world.World;

public class TickHandler {

private int tickCounter = 0;

private double chunkQueue = 0;
private int chunksGenerated = 0;

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
// Note that this only works on dedicated servers.
final World world = MinecraftServer.getServer().getEntityWorld();
if (Reference.pauseForPlayers && world.playerEntities.size() > 0) return;

if(Reference.toGenerate != null && !Reference.toGenerate.isEmpty()) {
tickCounter++;
for(int i = 0; i < Reference.numChunksPerTick; i++) {
chunkQueue += Reference.numChunksPerTick;
while (chunkQueue > 1) {
chunkQueue--;
chunksGenerated++;
ChunkPosition cp = Reference.toGenerate.poll();
if(cp != null) {
Utilities.generateChunk(cp.getX(), cp.getZ(), cp.getDimensionID());
float completedPercentage = 1 - (float)Reference.toGenerate.size()/(float)Reference.startingSize;
if(tickCounter == Reference.tickDelay) {
if(chunksGenerated % Reference.updateDelay == 0) {
Reference.logger.info("percentage: " + completedPercentage);
tickCounter = 0;
ChatComponentTranslation chatTranslation = new ChatComponentTranslation("");
MinecraftServer.getServer().addChatMessage(chatTranslation);

cp.getICommandSender().addChatMessage(new ChatComponentText("Chunkgen: " + (int)(completedPercentage * 100) + "% completed"));
}
if(Reference.toGenerate.peek() == null) {
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/com/gecgooden/chunkgen/reference/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
import com.gecgooden.chunkgen.util.ChunkPosition;

public class Reference {
public static Integer x;
public static Integer z;
public static Integer height;
public static Integer width;
public static Integer numChunksPerTick;

public static final String MOD_ID = "chunkgen";
public static Integer x;
public static Integer z;
public static Integer height;
public static Integer width;
public static double numChunksPerTick;
public static boolean pauseForPlayers;

public static final String MOD_ID = "chunkgen";
public static final String VERSION = "1.7.10-1.2.2";
public static final String GUI_FACTORY = "com.gecgooden.chunkgen.client.gui.GuiFactory";

public static Queue<ChunkPosition> toGenerate;
public static int startingSize;
public static int tickDelay;
public static int updateDelay;

public static DecimalFormat decimalFormat;

public static Logger logger;
}
40 changes: 30 additions & 10 deletions src/main/java/com/gecgooden/chunkgen/util/Utilities.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package com.gecgooden.chunkgen.util;

import java.util.ArrayList;
import java.util.List;

import com.gecgooden.chunkgen.reference.Reference;

import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.chunk.storage.RegionFileCache;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraftforge.common.DimensionManager;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


public class Utilities {
Expand Down Expand Up @@ -57,4 +53,28 @@ public static void generateChunk(int x, int z, int dimensionID) {
Reference.logger.info("Loaded Chunk at " + x + " " + z + " " + dimensionID);
}
}

public static void queueChunkGeneration(ICommandSender icommandsender, int x0, int z0, int height, int width, int dimensionID) {
int x = 0, z = 0, dx = 0, dy = -1;
int t = Math.max(height, width);
int maxI = t * t;

if (Reference.toGenerate == null) {
Reference.toGenerate = new LinkedList<ChunkPosition>();
}

for (int i = 0; i < maxI; i++) {
if ((-width / 2 <= x) && (x <= width / 2) && (-height / 2 <= z) && (z <= height / 2)) {
Reference.toGenerate.add(new ChunkPosition(x + x0, z + z0, dimensionID, icommandsender));
}

if ((x == z) || ((x < 0) && (x == -z)) || ((x > 0) && (x == 1 - z))) {
t = dx;
dx = -dy;
dy = t;
}
x += dx;
z += dy;
}
}
}

0 comments on commit 14ad7a7

Please sign in to comment.