From 35864315b9c8bed0fe05759df6bc07c2acc708aa Mon Sep 17 00:00:00 2001 From: Adubbz Date: Tue, 7 Apr 2015 15:46:06 +1000 Subject: [PATCH] Added /bop stripchunk for testing ore generation and other underground stuff --- .../common/command/BOPCommand.java | 85 ++++++++++++++++++- .../assets/biomesoplenty/lang/en_US.lang | 3 +- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/main/java/biomesoplenty/common/command/BOPCommand.java b/src/main/java/biomesoplenty/common/command/BOPCommand.java index 962b58d22..adf22e193 100644 --- a/src/main/java/biomesoplenty/common/command/BOPCommand.java +++ b/src/main/java/biomesoplenty/common/command/BOPCommand.java @@ -10,15 +10,20 @@ package biomesoplenty.common.command; import java.util.List; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; 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.init.Blocks; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import biomesoplenty.common.util.biome.BiomeUtils; import com.google.common.collect.Lists; @@ -64,6 +69,10 @@ public class BOPCommand extends CommandBase { teleportFoundBiome(sender, args); } + else if ("stripchunk".equals(args[0])) + { + stripChunk(sender, args); + } } private void getBiomeName(ICommandSender sender, String[] args) throws CommandException @@ -107,12 +116,86 @@ public class BOPCommand extends CommandBase } } + private void stripChunk(ICommandSender sender, String[] args) throws CommandException + { + if (args.length < 5) + { + throw new WrongUsageException("commands.biomesoplenty.stripchunk.usage"); + } + + int radius = parseInt(args[1]); + String mode = args[2]; + boolean blacklist; + + if (mode.equals("include")) blacklist = false; + else if (mode.equals("exclude")) blacklist = true; + else + { + throw new WrongUsageException("commands.biomesoplenty.stripchunk.usage"); + } + + List stateList = Lists.newArrayList(); + + for (int i = 0; i < (args.length - 3) / 2; i++) + { + Block block = getBlockByText(sender, args[i * 2 + 3]); + int metadata = parseInt(args[i * 2 + 3 + 1]); + + stateList.add(block.getStateFromMeta(metadata)); + } + + BlockPos playerPos = sender.getPosition(); + World world = sender.getEntityWorld(); + + int playerChunkX = playerPos.getX() >> 4; + int playerChunkZ = playerPos.getZ() >> 4; + + for (int chunkX = -radius; chunkX < radius; chunkX++) + { + for (int chunkZ = -radius; chunkZ < radius; chunkZ++) + { + Chunk chunk = world.getChunkFromChunkCoords(playerChunkX + chunkX, (playerChunkZ + chunkZ)); + + for (ExtendedBlockStorage blockStorage : chunk.getBlockStorageArray()) + { + if (blockStorage != null) + { + for (int x = 0; x < 16; x++) + { + for (int y = 0; y < 16; y++) + { + for (int z = 0; z < 16; z++) + { + BlockPos pos = new BlockPos(chunk.xPosition * 16 + x, blockStorage.getYLocation() + y, chunk.zPosition * 16 + z); + IBlockState state = blockStorage.get(x, y, z); + + if (((!blacklist && stateList.contains(state)) || (blacklist && !stateList.contains(state))) && pos.getY() > 0) + { + blockStorage.set(x, y, z, Blocks.air.getDefaultState()); + world.markBlockForUpdate(pos); + world.notifyNeighborsRespectDebug(pos, Blocks.air); + } + } + } + } + } + } + + chunk.generateSkylightMap(); + } + } + } + @Override public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { if (args.length == 1) { - return getListOfStringsMatchingLastWord(args, "biomename", "tpbiome"); + return getListOfStringsMatchingLastWord(args, "biomename", "tpbiome", "stripchunk"); + } + else if (args.length == 3) + { + return getListOfStringsMatchingLastWord(args, "include", "exclude"); } return null; diff --git a/src/main/resources/assets/biomesoplenty/lang/en_US.lang b/src/main/resources/assets/biomesoplenty/lang/en_US.lang index cea6aa178..416c03341 100644 --- a/src/main/resources/assets/biomesoplenty/lang/en_US.lang +++ b/src/main/resources/assets/biomesoplenty/lang/en_US.lang @@ -1,9 +1,10 @@ -commands.biomesoplenty.usage=/biomesoplenty [args] +commands.biomesoplenty.usage=/biomesoplenty [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! +commands.biomesoplenty.stripchunk.usage=/biomesoplenty stripchunk [radius] [block] [metadata] generator.BIOMESOP=Biomes O' Plenty generator.BIOMESOP.info=Notice: Biomes O' Plenty 1.8 is in a very early state