@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")); } }
@SubscribeEvent public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { // Server-side - called whenever a player logs in // I couldn't find a way to detect if the client has TerrainControl, // so for now the configs are sent anyway. // Get the config if (!(event.player instanceof EntityPlayerMP)) { return; } EntityPlayerMP player = (EntityPlayerMP) event.player; LocalWorld worldTC = worldLoader.getWorld(player.getEntityWorld()); if (worldTC == null) { // World not loaded return; } ConfigProvider configs = worldTC.getConfigs(); // Serialize it ByteBuf nettyBuffer = Unpooled.buffer(); PacketBuffer mojangBuffer = new PacketBuffer(nettyBuffer); DataOutput stream = new ByteBufOutputStream(nettyBuffer); try { stream.writeInt(PluginStandardValues.ProtocolVersion); ConfigToNetworkSender.send(configs, stream); } catch (IOException e) { TerrainControl.printStackTrace(LogMarker.FATAL, e); } // Make the packet SPacketCustomPayload packet = new SPacketCustomPayload(PluginStandardValues.ChannelName, mojangBuffer); // Send the packet player.connection.sendPacket(packet); }
@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")); } }
/** * handle timeouts etc * * @param maximumDurationInNS - the maximum amount of time to spend generating selections for * clients. 0 = don't generate any. */ public void tick(long maximumDurationInNS) { for (MultipartOneAtATimeReceiver receiver : playerMOATreceivers.values()) { receiver.onTick(); } for (MultipartOneAtATimeSender sender : playerMOATsenders.values()) { sender.onTick(); } if (maximumDurationInNS == 0) return; boolean foundSuitable = false; CommandQueueEntry currentCommand; do { currentCommand = commandQueue.peekFirst(); if (currentCommand == null) return; if (currentCommand.entityPlayerMP.get() == null) { commandQueue.removeFirst(); } else { foundSuitable = true; } } while (!foundSuitable); EntityPlayerMP entityPlayerMP = currentCommand.entityPlayerMP.get(); World playerWorld = entityPlayerMP.getEntityWorld(); Packet250ServerSelectionGeneration commandPacket = currentCommand.commandPacket; if (!currentCommand.hasStarted) { BlockVoxelMultiSelector blockVoxelMultiSelector = new BlockVoxelMultiSelector(); playerBlockVoxelMultiSelectors.put(entityPlayerMP, blockVoxelMultiSelector); playerCommandStatus.put(entityPlayerMP, CommandStatus.EXECUTING); currentCommand.blockVoxelMultiSelector = blockVoxelMultiSelector; switch (commandPacket.getCommand()) { case ALL_IN_BOX: { blockVoxelMultiSelector.selectAllInBoxStart( playerWorld, commandPacket.getCorner1(), commandPacket.getCorner2()); break; } case UNBOUND_FILL: { blockVoxelMultiSelector.selectUnboundFillStart( playerWorld, commandPacket.getFillAlgorithmSettings()); break; } case BOUND_FILL: { blockVoxelMultiSelector.selectBoundFillStart( playerWorld, commandPacket.getFillAlgorithmSettings(), commandPacket.getCorner1(), commandPacket.getCorner2()); break; } default: { ErrorLog.defaultLog() .severe("Invalid command in ServerVoxelSelections: " + commandPacket.getCommand()); break; } } currentCommand.hasStarted = true; } else { BlockVoxelMultiSelector blockVoxelMultiSelector = currentCommand.blockVoxelMultiSelector; float progress = blockVoxelMultiSelector.continueSelectionGeneration(playerWorld, maximumDurationInNS); if (progress < 0) { // finished BlockPos origin = blockVoxelMultiSelector.getWorldOrigin(); VoxelSelectionWithOrigin newSelection = new VoxelSelectionWithOrigin( origin.getX(), origin.getY(), origin.getZ(), blockVoxelMultiSelector.getSelection()); // System.out.println("New selection origin: [" + newSelection.getWxOrigin() // + ", " + newSelection.getWyOrigin() // + ", " + newSelection.getWzOrigin()+"]"); playerSelections.put(entityPlayerMP, newSelection); playerBlockVoxelMultiSelectors.remove(entityPlayerMP); playerCommandStatus.put(entityPlayerMP, CommandStatus.COMPLETED); MultipartOneAtATimeSender sender = playerMOATsenders.get(entityPlayerMP); if (sender != null) { SelectionPacket selectionPacket = SelectionPacket.createSenderPacket(blockVoxelMultiSelector, Side.SERVER); SenderLinkage newLinkage = new SenderLinkage(entityPlayerMP, selectionPacket.getUniqueID()); playerSenderLinkages.put(entityPlayerMP, newLinkage); // System.out.println("send new Multipart Selection from server to client, ID = " // + selectionPacket.getUniqueID()); // todo remove sender.sendMultipartPacket(newLinkage, selectionPacket); } assert (commandQueue.peekFirst() == currentCommand); commandQueue.removeFirst(); } } }