@Override public void processCommand(ICommandSender sender, String[] params) { MinecraftServer server = MinecraftServer.getServer(); EntityPlayerMP player = getCommandSenderAsPlayer(sender); WorldServer world = server.worldServerForDimension(player.getEntityWorld().provider.dimensionId); if (!TFCOptions.enableDebugMode) { TFC_Core.sendInfoMessage(player, new ChatComponentText("Debug Mode Required")); return; } if (params.length == 0) { TFC_Core.sendInfoMessage(player, new ChatComponentText("Stripping Chunk")); Chunk chunk = world.getChunkFromBlockCoords((int) player.posX, (int) player.posZ); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 256; y++) { Block id = chunk.getBlock(x, y, z); if (id != TFCBlocks.Ore && id != TFCBlocks.Ore2 && id != TFCBlocks.Ore3 && id != Blocks.bedrock) world.setBlock( x + (chunk.xPosition * 16), y, z + (chunk.zPosition * 16), Blocks.air, 0, 2); } } } TFC_Core.sendInfoMessage(player, new ChatComponentText("Stripping Chunk Complete")); } else if (params.length == 1) { TFC_Core.sendInfoMessage( player, new ChatComponentText( "Stripping Chunks Within a Radius of " + Integer.parseInt(params[0]))); int radius = Integer.parseInt(params[0]); for (int i = -radius; i <= radius; i++) { for (int k = -radius; k <= radius; k++) { Chunk chunk = world.getChunkFromBlockCoords( (int) player.posX + (i * 16), (int) player.posZ + (k * 16)); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 256; y++) { Block id = chunk.getBlock(x, y, z); if (id != TFCBlocks.Ore && id != TFCBlocks.Ore2 && id != TFCBlocks.Ore3 && id != Blocks.bedrock) world.setBlock( x + (chunk.xPosition * 16), y, z + (chunk.zPosition * 16), Blocks.air, 0, 2); } } } } } TFC_Core.sendInfoMessage(player, new ChatComponentText("Stripping Chunk Complete")); } }
@Override public void processCommand(ICommandSender sender, String[] params) { EntityPlayerMP player = getCommandSenderAsPlayer(sender); if (!TFCOptions.enableDebugMode) { TFC_Core.sendInfoMessage(player, new ChatComponentText("Debug Mode Required")); return; } MinecraftServer server = MinecraftServer.getServer(); WorldServer world = server.worldServerForDimension(player.getEntityWorld().provider.dimensionId); if (params.length == 0) { TFC_Core.sendInfoMessage(player, new ChatComponentText("Stripping Chunk")); Chunk chunk = world.getChunkFromBlockCoords((int) player.posX, (int) player.posZ); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 256; y++) { Block id = chunk.getBlock(x, y, z); if (id != Blocks.air && id != TFCBlocks.ore && id != TFCBlocks.ore2 && id != TFCBlocks.ore3 && id != Blocks.bedrock) { if (TFC_Core.isGround( id)) // Automatically replace ground blocks to help with performance { world.setBlock( x + (chunk.xPosition * 16), y, z + (chunk.zPosition * 16), Blocks.air, 0, 2); } else { Boolean isOre = false; Iterator iter = WorldGenOre.oreList.values().iterator(); while (iter.hasNext()) { OreSpawnData osd = (OreSpawnData) iter.next(); if (osd != null && id == osd.block) { isOre = true; break; } } if (!isOre) { world.setBlock( x + (chunk.xPosition * 16), y, z + (chunk.zPosition * 16), Blocks.air, 0, 2); } } } } } } TFC_Core.sendInfoMessage(player, new ChatComponentText("Stripping Chunk Complete")); } else if (params.length == 1) { TFC_Core.sendInfoMessage( player, new ChatComponentText( "Stripping Chunks Within a Radius of " + Integer.parseInt(params[0]))); int radius = Integer.parseInt(params[0]); for (int i = -radius; i <= radius; i++) { for (int k = -radius; k <= radius; k++) { Chunk chunk = world.getChunkFromBlockCoords((int) player.posX + i * 16, (int) player.posZ + k * 16); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 256; y++) { Block id = chunk.getBlock(x, y, z); if (id != Blocks.air && id != TFCBlocks.ore && id != TFCBlocks.ore2 && id != TFCBlocks.ore3 && id != Blocks.bedrock) { if (TFC_Core.isGround( id)) // Automatically replace ground blocks to help with performance { world.setBlock( x + (chunk.xPosition * 16), y, z + (chunk.zPosition * 16), Blocks.air, 0, 2); } else { Boolean isOre = false; Iterator iter = WorldGenOre.oreList.values().iterator(); while (iter.hasNext()) { OreSpawnData osd = (OreSpawnData) iter.next(); if (osd != null && id == osd.block) { isOre = true; break; } } if (!isOre) { world.setBlock( x + (chunk.xPosition * 16), y, z + (chunk.zPosition * 16), Blocks.air, 0, 2); } } } } } } } } TFC_Core.sendInfoMessage(player, new ChatComponentText("Stripping Chunk Complete")); } }
@SubscribeEvent public void onWorldTick(WorldTickEvent event) { if (event.phase == Phase.START) { final WorldServer world = (WorldServer) event.world; CopyOnWriteArrayList<ScheduledBlockChange> changeList = TickHandlerServer.scheduledBlockChanges.get(world.provider.dimensionId); if (changeList != null && !changeList.isEmpty()) { int blockCount = 0; int blockCountMax = Math.max(this.MAX_BLOCKS_PER_TICK, changeList.size() / 4); List<ScheduledBlockChange> newList = new ArrayList<ScheduledBlockChange>(Math.max(0, changeList.size() - blockCountMax)); for (ScheduledBlockChange change : changeList) { if (++blockCount > blockCountMax) { newList.add(change); } else { if (change != null) { BlockVec3 changePosition = change.getChangePosition(); Block block = world.getBlock(changePosition.x, changePosition.y, changePosition.z); // Only replace blocks of type BlockAir or fire - this is to prevent accidents where // other mods have moved blocks if (changePosition != null && (block instanceof BlockAir || block == Blocks.fire)) { world.setBlock( changePosition.x, changePosition.y, changePosition.z, change.getChangeID(), change.getChangeMeta(), change.getChangeUpdateFlag()); } } } } changeList.clear(); TickHandlerServer.scheduledBlockChanges.remove(world.provider.dimensionId); if (newList.size() > 0) TickHandlerServer.scheduledBlockChanges.put( world.provider.dimensionId, new CopyOnWriteArrayList<ScheduledBlockChange>(newList)); } CopyOnWriteArrayList<BlockVec3> torchList = TickHandlerServer.scheduledTorchUpdates.get(world.provider.dimensionId); if (torchList != null && !torchList.isEmpty()) { for (BlockVec3 torch : torchList) { if (torch != null) { Block b = world.getBlock(torch.x, torch.y, torch.z); if (b instanceof BlockUnlitTorch) { world.scheduleBlockUpdateWithPriority( torch.x, torch.y, torch.z, b, 2 + world.rand.nextInt(30), 0); } } } torchList.clear(); TickHandlerServer.scheduledTorchUpdates.remove(world.provider.dimensionId); } if (world.provider instanceof IOrbitDimension) { final Object[] entityList = world.loadedEntityList.toArray(); for (final Object o : entityList) { if (o instanceof Entity) { final Entity e = (Entity) o; if (e.worldObj.provider instanceof IOrbitDimension) { final IOrbitDimension dimension = (IOrbitDimension) e.worldObj.provider; if (e.posY <= dimension.getYCoordToTeleportToPlanet()) { final Integer dim = WorldUtil.getProviderForName(dimension.getPlanetToOrbit()).dimensionId; WorldUtil.transferEntityToDimension(e, dim, world, false, null); } } } } } } else if (event.phase == Phase.END) { final WorldServer world = (WorldServer) event.world; List<BlockVec3> edgesList = TickHandlerServer.edgeChecks.get(world.provider.dimensionId); final HashSet<BlockVec3> checkedThisTick = new HashSet(); if (edgesList != null && !edgesList.isEmpty()) { List<BlockVec3> edgesListCopy = new ArrayList(); edgesListCopy.addAll(edgesList); for (BlockVec3 edgeBlock : edgesListCopy) { if (edgeBlock != null && !checkedThisTick.contains(edgeBlock)) { if (TickHandlerServer.scheduledForChange(world.provider.dimensionId, edgeBlock)) { continue; } ThreadFindSeal done = new ThreadFindSeal(world, edgeBlock, 2000, new ArrayList<TileEntityOxygenSealer>()); checkedThisTick.addAll(done.checked); } } TickHandlerServer.edgeChecks.remove(world.provider.dimensionId); } } }
@SubscribeEvent public void onWorldTick(WorldTickEvent event) { if (event.phase == Phase.START) { final WorldServer world = (WorldServer) event.world; CopyOnWriteArrayList<ScheduledBlockChange> changeList = TickHandlerServer.scheduledBlockChanges.get(world.provider.dimensionId); if (changeList != null && !changeList.isEmpty()) { for (ScheduledBlockChange change : changeList) { if (change != null) { BlockVec3 changePosition = change.getChangePosition(); if (changePosition != null) { world.setBlock( changePosition.x, changePosition.y, changePosition.z, change.getChangeID(), change.getChangeMeta(), 2); } } } changeList.clear(); TickHandlerServer.scheduledBlockChanges.remove(world.provider.dimensionId); } CopyOnWriteArrayList<BlockVec3> torchList = TickHandlerServer.scheduledTorchUpdates.get(world.provider.dimensionId); if (torchList != null && !torchList.isEmpty()) { for (BlockVec3 torch : torchList) { if (torch != null) { if (world.getBlock(torch.x, torch.y, torch.z) == GCBlocks.unlitTorch) { world.scheduleBlockUpdateWithPriority( torch.x, torch.y, torch.z, GCBlocks.unlitTorch, 2 + world.rand.nextInt(30), 0); } else if (world.getBlock(torch.x, torch.y, torch.z) == GCBlocks.unlitTorchLit) { world.scheduleBlockUpdateWithPriority( torch.x, torch.y, torch.z, GCBlocks.unlitTorchLit, 2 + world.rand.nextInt(30), 0); } } } torchList.clear(); TickHandlerServer.scheduledTorchUpdates.remove(world.provider.dimensionId); } if (world.provider instanceof IOrbitDimension) { final Object[] entityList = world.loadedEntityList.toArray(); for (final Object o : entityList) { if (o instanceof Entity) { final Entity e = (Entity) o; if (e.worldObj.provider instanceof IOrbitDimension) { final IOrbitDimension dimension = (IOrbitDimension) e.worldObj.provider; if (e.posY <= dimension.getYCoordToTeleportToPlanet()) { final Integer dim = WorldUtil.getProviderForName(dimension.getPlanetToOrbit()).dimensionId; WorldUtil.transferEntityToDimension(e, dim, world, false, null); } } } } } } else if (event.phase == Phase.END) { final WorldServer world = (WorldServer) event.world; List<BlockVec3> edgesList = TickHandlerServer.edgeChecks.get(world.provider.dimensionId); final HashSet<BlockVec3> checkedThisTick = new HashSet(); if (edgesList != null && !edgesList.isEmpty()) { List<BlockVec3> edgesListCopy = new ArrayList(); edgesListCopy.addAll(edgesList); for (BlockVec3 edgeBlock : edgesListCopy) { if (edgeBlock != null && !checkedThisTick.contains(edgeBlock)) { if (TickHandlerServer.scheduledForChange(world.provider.dimensionId, edgeBlock)) { continue; } ThreadFindSeal done = new ThreadFindSeal(world, edgeBlock, 2000, new ArrayList<TileEntityOxygenSealer>()); checkedThisTick.addAll(done.checked); } } TickHandlerServer.edgeChecks.remove(world.provider.dimensionId); } } }