Added commands for teleporting to a biome of a given id, and finding the biome associated with an id
This commit is contained in:
parent
d569d3862b
commit
c4c5e0553a
4 changed files with 208 additions and 3 deletions
120
src/main/java/biomesoplenty/common/command/BOPCommand.java
Normal file
120
src/main/java/biomesoplenty/common/command/BOPCommand.java
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright 2015, the Biomes O' Plenty Team
|
||||||
|
*
|
||||||
|
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||||
|
*
|
||||||
|
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package biomesoplenty.common.command;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.command.CommandBase;
|
||||||
|
import net.minecraft.command.CommandException;
|
||||||
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.command.WrongUsageException;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.util.ChatComponentTranslation;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
|
import biomesoplenty.common.util.biome.BiomeUtils;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
public class BOPCommand extends CommandBase
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getCommandName()
|
||||||
|
{
|
||||||
|
return "biomesoplenty";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List getCommandAliases()
|
||||||
|
{
|
||||||
|
return Lists.newArrayList("bop", "biomesop");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandUsage(ICommandSender sender)
|
||||||
|
{
|
||||||
|
return "commands.biomesoplenty.usage";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRequiredPermissionLevel()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
||||||
|
{
|
||||||
|
if (args.length < 1)
|
||||||
|
{
|
||||||
|
throw new WrongUsageException("commands.biomesoplenty.usage");
|
||||||
|
}
|
||||||
|
else if ("biomename".equals(args[0]))
|
||||||
|
{
|
||||||
|
getBiomeName(sender, args);
|
||||||
|
}
|
||||||
|
else if ("tpbiome".equals(args[0]))
|
||||||
|
{
|
||||||
|
teleportFoundBiome(sender, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getBiomeName(ICommandSender sender, String[] args) throws CommandException
|
||||||
|
{
|
||||||
|
if (args.length < 2)
|
||||||
|
{
|
||||||
|
throw new WrongUsageException("commands.biomesoplenty.biomename.usage");
|
||||||
|
}
|
||||||
|
|
||||||
|
int biomeId = parseInt(args[1], 0, 255);
|
||||||
|
BiomeGenBase biome = BiomeGenBase.getBiome(biomeId);
|
||||||
|
|
||||||
|
sender.addChatMessage(new ChatComponentTranslation("commands.biomesoplenty.biomename.success", biomeId, biome == null ? "Undefined" : biome.biomeName));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void teleportFoundBiome(ICommandSender sender, String[] args) throws CommandException
|
||||||
|
{
|
||||||
|
if (args.length < 2)
|
||||||
|
{
|
||||||
|
throw new WrongUsageException("commands.biomesoplenty.tpbiome.usage");
|
||||||
|
}
|
||||||
|
|
||||||
|
int biomeId = parseInt(args[1], 0, 255);
|
||||||
|
BiomeGenBase biome = BiomeGenBase.getBiome(biomeId);
|
||||||
|
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
|
||||||
|
World world = player.worldObj;
|
||||||
|
BlockPos closestBiomePos = biome == null ? null : BiomeUtils.findBiome(world, biome, player.getPosition());
|
||||||
|
|
||||||
|
if (closestBiomePos != null)
|
||||||
|
{
|
||||||
|
double x = (double)closestBiomePos.getX();
|
||||||
|
double y = (double)world.getTopSolidOrLiquidBlock(closestBiomePos).getY();
|
||||||
|
double z = (double)closestBiomePos.getZ();
|
||||||
|
|
||||||
|
player.playerNetServerHandler.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch);
|
||||||
|
sender.addChatMessage(new ChatComponentTranslation("commands.biomesoplenty.tpbiome.success", player.getCommandSenderName(), biome.biomeName, x, y, z));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.addChatMessage(new ChatComponentTranslation("commands.biomesoplenty.tpbiome.error", biome == null ? "Undefined" : biome.biomeName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
||||||
|
{
|
||||||
|
if (args.length == 1)
|
||||||
|
{
|
||||||
|
return getListOfStringsMatchingLastWord(args, "biomename", "tpbiome");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright 2015, the Biomes O' Plenty Team
|
||||||
|
*
|
||||||
|
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||||
|
*
|
||||||
|
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package biomesoplenty.common.util.biome;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
|
import net.minecraft.world.biome.WorldChunkManager;
|
||||||
|
|
||||||
|
public class BiomeUtils
|
||||||
|
{
|
||||||
|
public static BlockPos findBiome(World world, BiomeGenBase biome, BlockPos startPos)
|
||||||
|
{
|
||||||
|
int radius = 256;
|
||||||
|
WorldChunkManager chunkManager = world.getWorldChunkManager();
|
||||||
|
BlockPos pos1 = null;
|
||||||
|
BlockPos pos2 = null;
|
||||||
|
|
||||||
|
for (int x = -10; x <= 10; x++)
|
||||||
|
{
|
||||||
|
for (int z = -10; z <= 10; z++)
|
||||||
|
{
|
||||||
|
if (pos1 == null)
|
||||||
|
{
|
||||||
|
BlockPos foundPos = chunkManager.findBiomePosition(startPos.getX() + (x * 512), startPos.getZ() + (z * 512), 256, Arrays.asList(biome), world.rand);
|
||||||
|
|
||||||
|
if (foundPos != null && world.getBiomeGenForCoords(foundPos) == biome)
|
||||||
|
{
|
||||||
|
pos1 = foundPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos2 == null)
|
||||||
|
{
|
||||||
|
BlockPos foundPos = chunkManager.findBiomePosition(startPos.getX() + (x * 512), startPos.getZ() + (-z * 512), 256, Arrays.asList(biome), world.rand);
|
||||||
|
|
||||||
|
if (foundPos != null && world.getBiomeGenForCoords(foundPos) == biome)
|
||||||
|
{
|
||||||
|
pos2 = foundPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos1 != null && pos2 != null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos1 != null && pos2 != null)
|
||||||
|
{
|
||||||
|
if (startPos.distanceSq(pos1) < startPos.distanceSq(pos2)) return pos1;
|
||||||
|
else return pos2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (pos1 != null) return pos1;
|
||||||
|
else return pos2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,9 +10,6 @@ package biomesoplenty.core;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||||
import net.minecraftforge.fml.common.Mod.Instance;
|
import net.minecraftforge.fml.common.Mod.Instance;
|
||||||
|
@ -20,6 +17,12 @@ import net.minecraftforge.fml.common.SidedProxy;
|
||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
|
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import biomesoplenty.common.command.BOPCommand;
|
||||||
import biomesoplenty.common.init.ModBiomes;
|
import biomesoplenty.common.init.ModBiomes;
|
||||||
import biomesoplenty.common.init.ModBlocks;
|
import biomesoplenty.common.init.ModBlocks;
|
||||||
import biomesoplenty.common.init.ModConfiguration;
|
import biomesoplenty.common.init.ModConfiguration;
|
||||||
|
@ -70,6 +73,12 @@ public class BiomesOPlenty
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void serverStarting(FMLServerStartingEvent event)
|
||||||
|
{
|
||||||
|
event.registerServerCommand(new BOPCommand());
|
||||||
|
}
|
||||||
|
|
||||||
public File getConfigDirectory()
|
public File getConfigDirectory()
|
||||||
{
|
{
|
||||||
return configDirectory;
|
return configDirectory;
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
commands.biomesoplenty.usage=/biomesoplenty <tpbiome> [args]
|
||||||
|
commands.biomesoplenty.biomename.usage=/biomesoplenty biomename [biomeId]
|
||||||
|
commands.biomesoplenty.biomename.success=Biome ID %s is associated with %s
|
||||||
|
commands.biomesoplenty.tpbiome.usage=/biomesoplenty tpbiome [biomeId]
|
||||||
|
commands.biomesoplenty.tpbiome.success=Teleported %s to biome %s at (%s, %s, %s)
|
||||||
|
commands.biomesoplenty.tpbiome.error=Couldn't find biome %s!
|
||||||
|
|
||||||
generator.BIOMESOP=Biomes O' Plenty
|
generator.BIOMESOP=Biomes O' Plenty
|
||||||
generator.BIOMESOP.info=Notice: Biomes O' Plenty 1.8 is in a very early state
|
generator.BIOMESOP.info=Notice: Biomes O' Plenty 1.8 is in a very early state
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue