Skip to content

Commit

Permalink
Merge pull request #24 from elix-x/master
Browse files Browse the repository at this point in the history
1.3 - Updated to 1.10.2, general improvements
  • Loading branch information
gecgooden authored Jul 17, 2016
2 parents c2c8de3 + 0548ae6 commit 46c0d3a
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 171 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ Mod to pre-generate chunks. This is only required on the server.
This mod adds the following command to Minecraft:

```
/chunkgen <x> <y> <height> <width> [dimension]
/chunkgen <zone|radius|stop>
/chunkgen zone <x> <z> <xSize> <zSize> [dimension] [logToChat]
/chunkgen radius <x> <z> <radius> [dimension] [logToChat]
/chunkgen top>
```

where `x` and `y` are the origin chunk coordinates, height and width describe a rectangle centered at x,y of chunks to generate and dimension is the dimension ID to generate the chunks in.
Using either `zone` or `radius`, you can set shape of chunk generation.

All arguments should be whole numbers, however `x` and `y` may also be `~` which represents the players current position.
When using `zone`, `x` and `z` define origin of rectangular zone and `xSize` and `zSize`, it's size.
When using `radius`, `x` and `z` define center of circular zone and `radius` it's radius.
`x` and `z` are chunk coordinates (integers), absolute (ex: `45`) or relative (ex: `~5`). `xSize`, `ySize` and `radius` are in chunks (integers).

`dimension` is an optional argument.
`dimension` is an optional argument, which can be used to specify dimension to generate chunks in (integer). Can be also replaced with `~` to define dimension you're currently in.

`logToChat`, if `true` will print coordinates of each generated chunk to chat (boolean).

```
/chunkgen stop
Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ buildscript {
}
apply plugin: 'net.minecraftforge.gradle.forge'

sourceCompatibility = 1.7
targetCompatibility = 1.7

/*
// for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot
plugins {
Expand All @@ -25,7 +28,7 @@ group= "com.gecgooden.chunkgen" // http://maven.apache.org/guides/mini/guide-nam
archivesBaseName = "chunkgen"

minecraft {
version = "1.9.4-12.17.0.1976"
version = "1.10.2-12.18.1.2014"
runDir = "run"

// the mappings can be changed at any time, and must be in the following format.
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/com/gecgooden/chunkgen/ChunkGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@
import java.text.DecimalFormat;
import java.util.Map;

@Mod(modid = Reference.MOD_ID, version = Reference.VERSION, guiFactory=Reference.GUI_FACTORY)
@Mod(modid = Reference.MOD_ID, version = Reference.VERSION, guiFactory=Reference.GUI_FACTORY, acceptableRemoteVersions = "*")
public class ChunkGen
{
/**
* Makes the mod server side only
* @param map
* @param side
* @return Always true.
*/
@NetworkCheckHandler
public boolean networkCheckHandler(Map<String, String> map, Side side) {
return true;
}

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
Expand All @@ -48,7 +38,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.queueChunkGeneration(event.getServer(), Reference.skipChunks, Reference.x, Reference.z, Reference.height, Reference.width, 0);
Utilities.queueChunkGeneration(event.getServer(), Reference.skipChunks, Reference.x, Reference.z, Reference.height, Reference.width, 0, false);
}
}
}
142 changes: 47 additions & 95 deletions src/main/java/com/gecgooden/chunkgen/commands/ChunkGenCommand.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
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.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

public class ChunkGenCommand implements ICommand
public class ChunkGenCommand extends CommandBase
{
private List aliases;
public ChunkGenCommand()
{
this.aliases = new ArrayList();
this.aliases.add("chunkgen");

}

@Override
Expand All @@ -33,104 +27,62 @@ public String getCommandName()
@Override
public String getCommandUsage(ICommandSender icommandsender)
{
return "chunkgen <x> <y> <height> <width> [dimension]";
}

@Override
public List getCommandAliases()
{
return this.aliases;
return "commands.chunkgen.usage";
}

@Override
public void execute(MinecraftServer server, ICommandSender icommandsender, String[] astring) throws CommandException {
if(!icommandsender.canCommandSenderUseCommand(getRequiredPermissionLevel(), this.getCommandName()) && !server.isSinglePlayer()) {
TextComponentTranslation chatTranslation = new TextComponentTranslation("commands.generic.permission", new Object[0]);
server.addChatMessage(chatTranslation);
icommandsender.addChatMessage(new TextComponentString(chatTranslation.getUnformattedComponentText()));
if(astring.length == 0 || astring[0].equalsIgnoreCase("help")) {
notifyCommandListener(icommandsender, this, "commands.chunkgen.usage");
} else {
int playerX = 0;
int playerY = 0;
int playerZ = 0;
if(!icommandsender.getName().equalsIgnoreCase("Rcon")) {
EntityPlayer ep = server.worldServerForDimension(0).getPlayerEntityByName(icommandsender.getName());
BlockPos blockPos = icommandsender.getPosition();
playerX = blockPos.getX();
playerY = blockPos.getY();
playerZ = blockPos.getZ();
}
if(astring.length == 0 || astring[0].equalsIgnoreCase("help")) {
TextComponentTranslation chatTranslation = new TextComponentTranslation(getCommandUsage(icommandsender), new Object[0]);
server.addChatMessage(chatTranslation);
icommandsender.addChatMessage(new TextComponentString(chatTranslation.getUnformattedComponentText()));
}
else if(astring[0].equalsIgnoreCase("stop")) {
Reference.toGenerate.clear();
TextComponentTranslation chatTranslation = new TextComponentTranslation("commands.stopped");
server.addChatMessage(chatTranslation);
icommandsender.addChatMessage(new TextComponentString(chatTranslation.getUnformattedComponentText()));
} else {
try {
int x = 0;
int z = 0;
if(astring[0].equalsIgnoreCase("~")) {
x = playerX/16;
} else {
x = Integer.parseInt(astring[0]);
switch (astring[0]) {
case "zone":
if(astring.length == 1){
notifyCommandListener(icommandsender, this, "commands.chunkgen.usage.zone");
} else {
int x = (int) parseCoordinate(icommandsender.getPosition().getX() >> 4, astring[1], false).getResult();
int z = (int) parseCoordinate(icommandsender.getPosition().getZ() >> 4, astring[2], false).getResult();
int height = parseInt(astring[3]);
int width = parseInt(astring[4]);
int dimensionID = icommandsender.getEntityWorld().provider.getDimension();
boolean logToChat = false;
if(astring.length > 5 && !"~".equals(astring[5])) {
dimensionID = parseInt(astring[5]);
}
if(astring[1].equalsIgnoreCase("~")) {
z = playerZ/16;
} else {
z = Integer.parseInt(astring[1]);
if(astring.length > 6){
logToChat = parseBoolean(astring[6]);
}
int height = Integer.parseInt(astring[2]);
int width = Integer.parseInt(astring[3]);
notifyCommandListener(icommandsender, this, "commands.chunkgen.enqueued", Utilities.queueChunkGeneration(icommandsender, 0, x, z, height, width, dimensionID, logToChat));
}
break;
case "radius":
if(astring.length == 1){
notifyCommandListener(icommandsender, this, "commands.chunkgen.usage.radius");
} else {
int x = (int) parseCoordinate(icommandsender.getPosition().getX() >> 4, astring[1], false).getResult();
int z = (int) parseCoordinate(icommandsender.getPosition().getZ() >> 4, astring[2], false).getResult();
int radius = parseInt(astring[3]);
int dimensionID = icommandsender.getEntityWorld().provider.getDimension();
if(astring.length == 5) {
dimensionID = Integer.parseInt(astring[4]);
boolean logToChat = false;
if(astring.length > 4 && !"~".equals(astring[4])) {
dimensionID = parseInt(astring[4]);
}
Utilities.queueChunkGeneration(icommandsender, 0, x, z, height, width, dimensionID);
} catch (NumberFormatException e) {
e.printStackTrace();
TextComponentTranslation chatTranslation = new TextComponentTranslation("commands.numberFormatException");
server.addChatMessage(chatTranslation);
icommandsender.addChatMessage(new TextComponentString(chatTranslation.getUnformattedComponentText()));
} catch (Exception e) {
e.printStackTrace();
TextComponentTranslation chatTranslation = new TextComponentTranslation("commands.failed");
server.addChatMessage(chatTranslation);
icommandsender.addChatMessage(new TextComponentString(chatTranslation.getUnformattedComponentText()));
if(astring.length > 5){
logToChat = parseBoolean(astring[5]);
}
notifyCommandListener(icommandsender, this, "commands.chunkgen.enqueued", Utilities.queueChunkGeneration(icommandsender, 0, x, z, radius, dimensionID, logToChat));
}
break;
case "stop":
Reference.toGenerate.clear();
break;
}
}
}

@Override
public boolean checkPermission(MinecraftServer minecraftServer, ICommandSender iCommandSender) {
return true;
}

@Override
public List<String> getTabCompletionOptions(MinecraftServer minecraftServer, ICommandSender iCommandSender, String[] strings, @Nullable BlockPos blockPos) {
return null;
}

/**
* Return the required permission level for this command.
*/
public int getRequiredPermissionLevel()
{
return 4;
}

@Override
public boolean isUsernameIndex(String[] astring, int i)
{
return false;
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args,BlockPos pos) {
return args.length == 1 ? getListOfStringsMatchingLastWord(args, "zone", "radius", "stop") : null;
}

@Override
public int compareTo(ICommand o) {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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.pauseForPlayers = configuration.get(Configuration.CATEGORY_GENERAL, "pauseForPlayers", true, "Pause chunk generation when players are logged on").getBoolean();
Reference.pauseForPlayers = configuration.get(Configuration.CATEGORY_GENERAL, "pauseForPlayers", false, "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();
Reference.skipChunks = getSkipChunks().getInt();
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/com/gecgooden/chunkgen/handlers/TickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.gecgooden.chunkgen.reference.Reference;
import com.gecgooden.chunkgen.util.ChunkPosition;
import com.gecgooden.chunkgen.util.Utilities;

import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
Expand All @@ -18,12 +20,11 @@ public class TickHandler {

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {

final MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
final World world = server.getEntityWorld();
if (Reference.pauseForPlayers && world.playerEntities.size() > 0) return;

if(Reference.toGenerate != null && !Reference.toGenerate.isEmpty()) {
if(!Reference.toGenerate.isEmpty()) {
chunkQueue += Reference.numChunksPerTick;
while (chunkQueue > 1) {
chunkQueue--;
Expand All @@ -33,16 +34,16 @@ public void onServerTick(TickEvent.ServerTickEvent event) {
Utilities.generateChunk(server, cp.getX(), cp.getZ(), cp.getDimensionID());
if(chunksGenerated % Reference.updateDelay == 0) {
float completedPercentage = 1 - (float)Reference.toGenerate.size()/(float)Reference.startingSize;
Reference.logger.info("percentage: " + completedPercentage);
TextComponentString chatTranslation = new TextComponentString("");
server.addChatMessage(chatTranslation);

cp.getICommandSender().addChatMessage(new TextComponentString("Chunkgen: " + (int)(completedPercentage * 100) + "% completed"));
Reference.logger.info(String.format("Generattion %s%% completed", completedPercentage));
cp.getICommandSender().addChatMessage(new TextComponentTranslation("chunkgen.progress", completedPercentage * 100));

ConfigurationHandler.UpdateSkipChunks();
}
if(cp.logToChat()){
cp.getICommandSender().addChatMessage(new TextComponentTranslation("chunkgen.genat", cp.getX(), cp.getZ(), DimensionManager.getProviderType(cp.getDimensionID()) != null ? DimensionManager.getProviderType(cp.getDimensionID()).getName() : cp.getDimensionID()));
}
if(Reference.toGenerate.peek() == null) {
TextComponentTranslation chatTranslation = new TextComponentTranslation("commands.successful");
TextComponentTranslation chatTranslation = new TextComponentTranslation("chunkgen.success");
server.addChatMessage(chatTranslation);
cp.getICommandSender().addChatMessage(new TextComponentString(chatTranslation.getUnformattedComponentText()));
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/gecgooden/chunkgen/reference/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.logging.log4j.Logger;

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

public class Reference {
Expand All @@ -15,10 +16,10 @@ public class Reference {
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 VERSION = "1.3";
public static final String GUI_FACTORY = "com.gecgooden.chunkgen.client.gui.GuiFactory";

public static Queue<ChunkPosition> toGenerate;
public static Queue<ChunkPosition> toGenerate = new LinkedList<ChunkPosition>();
public static int startingSize;
public static int updateDelay;

Expand Down
31 changes: 20 additions & 11 deletions src/main/java/com/gecgooden/chunkgen/util/ChunkPosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,36 @@ public class ChunkPosition {
private int z;
private int dimensionID;
private ICommandSender iCommandSender;

public ChunkPosition(int x, int z, int dimensionID, ICommandSender icommandsender) {
super();
private boolean logToChat;

public ChunkPosition(int x, int z, int dimensionID, ICommandSender icommandsender, boolean logToChat) {
this.x = x;
this.z = z;
this.dimensionID = dimensionID;
iCommandSender = icommandsender;
this.iCommandSender = icommandsender;
this.logToChat = logToChat;
}

public int getX() {
return x;
}

public void setX(int x) {
this.x = x;
}

public int getZ() {
return z;
}

public void setZ(int z) {
this.z = z;
}

public int getDimensionID() {
return dimensionID;
}

public void setDimensionID(int dimensionID) {
this.dimensionID = dimensionID;
}
Expand All @@ -48,5 +49,13 @@ public ICommandSender getICommandSender() {
public void setICommandSender(ICommandSender iCommandSender) {
this.iCommandSender = iCommandSender;
}


public boolean logToChat() {
return logToChat;
}

public void setLogToChat(boolean logToChat) {
this.logToChat = logToChat;
}

}
Loading

0 comments on commit 46c0d3a

Please sign in to comment.