2014-04-04 22:03:18 +00:00
/ *
* WorldEdit , a Minecraft world manipulation toolkit
* Copyright ( C ) sk89q < http : //www.sk89q.com>
* Copyright ( C ) WorldEdit team and contributors
*
* This program is free software : you can redistribute it and / or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE . See the GNU Lesser General Public License
* for more details .
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
2014-04-03 02:08:50 +00:00
package com.sk89q.worldedit.command ;
2012-03-17 15:35:29 +00:00
2014-07-17 07:21:13 +00:00
import com.sk89q.worldedit.EditSession ;
import com.sk89q.worldedit.LocalSession ;
import com.sk89q.worldedit.WorldEdit ;
import com.sk89q.worldedit.WorldEditException ;
2019-04-14 08:30:40 +00:00
import com.sk89q.worldedit.command.util.CommandPermissions ;
2019-04-17 06:02:23 +00:00
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator ;
import com.sk89q.worldedit.command.util.Logging ;
2019-05-27 22:26:20 +00:00
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder ;
2014-06-28 01:04:34 +00:00
import com.sk89q.worldedit.entity.Player ;
2019-05-27 22:26:20 +00:00
import com.sk89q.worldedit.extension.platform.Actor ;
2018-06-19 00:53:15 +00:00
import com.sk89q.worldedit.extension.platform.Capability ;
2014-07-17 07:21:13 +00:00
import com.sk89q.worldedit.function.FlatRegionFunction ;
import com.sk89q.worldedit.function.FlatRegionMaskingFilter ;
import com.sk89q.worldedit.function.biome.BiomeReplace ;
2014-06-28 02:55:38 +00:00
import com.sk89q.worldedit.function.mask.Mask ;
2014-07-17 07:21:13 +00:00
import com.sk89q.worldedit.function.mask.Mask2D ;
import com.sk89q.worldedit.function.operation.Operations ;
import com.sk89q.worldedit.function.visitor.FlatRegionVisitor ;
2018-10-14 10:40:53 +00:00
import com.sk89q.worldedit.math.BlockVector2 ;
import com.sk89q.worldedit.math.BlockVector3 ;
2014-07-17 07:21:13 +00:00
import com.sk89q.worldedit.regions.CuboidRegion ;
2012-03-17 15:35:29 +00:00
import com.sk89q.worldedit.regions.FlatRegion ;
import com.sk89q.worldedit.regions.Region ;
2014-07-17 07:21:13 +00:00
import com.sk89q.worldedit.regions.Regions ;
2018-06-16 05:29:48 +00:00
import com.sk89q.worldedit.util.Location ;
2019-04-27 11:57:25 +00:00
import com.sk89q.worldedit.util.formatting.component.PaginationBox ;
2014-04-05 09:59:38 +00:00
import com.sk89q.worldedit.world.World ;
2014-07-17 07:21:13 +00:00
import com.sk89q.worldedit.world.biome.BiomeData ;
2019-02-16 07:27:00 +00:00
import com.sk89q.worldedit.world.biome.BiomeType ;
2014-07-17 07:21:13 +00:00
import com.sk89q.worldedit.world.registry.BiomeRegistry ;
2019-04-14 08:30:40 +00:00
import org.enginehub.piston.annotation.Command ;
import org.enginehub.piston.annotation.CommandContainer ;
import org.enginehub.piston.annotation.param.Arg ;
2019-05-27 22:26:20 +00:00
import org.enginehub.piston.annotation.param.ArgFlag ;
2019-04-14 08:30:40 +00:00
import org.enginehub.piston.annotation.param.Switch ;
2014-04-05 09:59:38 +00:00
import java.util.HashSet ;
import java.util.Set ;
2019-04-27 11:57:25 +00:00
import java.util.stream.Collectors ;
2019-04-15 08:25:19 +00:00
2019-04-30 05:40:32 +00:00
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION ;
2014-06-28 01:04:34 +00:00
/ * *
* Implements biome - related commands such as " /biomelist " .
* /
2019-04-17 06:02:23 +00:00
@CommandContainer ( superTypes = CommandPermissionsConditionGenerator . Registration . class )
2012-03-17 15:35:29 +00:00
public class BiomeCommands {
2014-06-28 01:04:34 +00:00
/ * *
* Create a new instance .
* /
2019-04-14 08:30:40 +00:00
public BiomeCommands ( ) {
2012-03-17 15:35:29 +00:00
}
@Command (
2019-04-14 08:30:40 +00:00
name = " biomelist " ,
aliases = { " biomels " } ,
desc = " Gets all biomes available. "
2012-03-17 15:35:29 +00:00
)
@CommandPermissions ( " worldedit.biome.list " )
2019-05-27 22:26:20 +00:00
public void biomeList ( Actor actor ,
@ArgFlag ( name = 'p' , desc = " Page number. " , def = " 1 " )
int page ) {
WorldEditAsyncCommandBuilder . createAndSendMessage ( actor , ( ) - > {
BiomeRegistry biomeRegistry = WorldEdit . getInstance ( ) . getPlatformManager ( )
. queryCapability ( Capability . GAME_HOOKS ) . getRegistries ( ) . getBiomeRegistry ( ) ;
2019-04-27 11:57:25 +00:00
2019-05-27 22:26:20 +00:00
PaginationBox paginationBox = PaginationBox . fromStrings ( " Available Biomes " , " /biomelist -p %page% " ,
BiomeType . REGISTRY . values ( ) . stream ( )
. map ( biomeType - > {
String id = biomeType . getId ( ) ;
final BiomeData data = biomeRegistry . getData ( biomeType ) ;
if ( data ! = null ) {
String name = data . getName ( ) ;
return id + " ( " + name + " ) " ;
} else {
return id ;
}
} )
. collect ( Collectors . toList ( ) ) ) ;
return paginationBox . create ( page ) ;
} , null ) ;
2012-03-17 15:35:29 +00:00
}
@Command (
2019-04-14 08:30:40 +00:00
name = " biomeinfo " ,
2012-03-17 15:35:29 +00:00
desc = " Get the biome of the targeted block. " ,
2019-04-14 08:30:40 +00:00
descFooter = " By default, uses all blocks in your selection. "
2012-03-17 15:35:29 +00:00
)
@CommandPermissions ( " worldedit.biome.info " )
2019-04-14 08:30:40 +00:00
public void biomeInfo ( Player player , LocalSession session ,
2019-04-30 05:40:32 +00:00
@Switch ( name = 't' , desc = " Use the block you are looking at. " )
2019-04-15 09:03:05 +00:00
boolean useLineOfSight ,
2019-04-30 05:40:32 +00:00
@Switch ( name = 'p' , desc = " Use the block you are currently in. " )
2019-04-15 09:03:05 +00:00
boolean usePosition ) throws WorldEditException {
2018-06-19 00:53:15 +00:00
BiomeRegistry biomeRegistry = WorldEdit . getInstance ( ) . getPlatformManager ( )
. queryCapability ( Capability . GAME_HOOKS ) . getRegistries ( ) . getBiomeRegistry ( ) ;
2019-02-16 07:27:00 +00:00
Set < BiomeType > biomes = new HashSet < > ( ) ;
2014-07-17 07:21:13 +00:00
String qualifier ;
2019-04-14 08:30:40 +00:00
if ( useLineOfSight ) {
2018-06-16 05:29:48 +00:00
Location blockPosition = player . getBlockTrace ( 300 ) ;
2012-03-28 18:04:59 +00:00
if ( blockPosition = = null ) {
player . printError ( " No block in sight! " ) ;
return ;
}
2019-02-16 07:27:00 +00:00
BiomeType biome = player . getWorld ( ) . getBiome ( blockPosition . toVector ( ) . toBlockPoint ( ) . toBlockVector2 ( ) ) ;
2014-07-17 07:21:13 +00:00
biomes . add ( biome ) ;
qualifier = " at line of sight point " ;
2019-04-14 08:30:40 +00:00
} else if ( usePosition ) {
2019-02-16 07:27:00 +00:00
BiomeType biome = player . getWorld ( ) . getBiome ( player . getLocation ( ) . toVector ( ) . toBlockPoint ( ) . toBlockVector2 ( ) ) ;
2014-07-17 07:21:13 +00:00
biomes . add ( biome ) ;
qualifier = " at your position " ;
2012-03-28 18:04:59 +00:00
} else {
2014-04-05 09:59:38 +00:00
World world = player . getWorld ( ) ;
2012-03-17 15:35:29 +00:00
Region region = session . getSelection ( world ) ;
if ( region instanceof FlatRegion ) {
2018-10-14 10:40:53 +00:00
for ( BlockVector2 pt : ( ( FlatRegion ) region ) . asFlatRegion ( ) ) {
2012-03-17 15:35:29 +00:00
biomes . add ( world . getBiome ( pt ) ) ;
}
} else {
2018-10-14 10:40:53 +00:00
for ( BlockVector3 pt : region ) {
biomes . add ( world . getBiome ( pt . toBlockVector2 ( ) ) ) ;
2012-03-17 15:35:29 +00:00
}
}
2014-07-17 07:21:13 +00:00
qualifier = " in your selection " ;
}
player . print ( biomes . size ( ) ! = 1 ? " Biomes " + qualifier + " : " : " Biome " + qualifier + " : " ) ;
2019-02-16 07:27:00 +00:00
for ( BiomeType biome : biomes ) {
2014-07-17 07:21:13 +00:00
BiomeData data = biomeRegistry . getData ( biome ) ;
if ( data ! = null ) {
player . print ( " " + data . getName ( ) ) ;
} else {
player . print ( " <unknown # " + biome . getId ( ) + " > " ) ;
2012-03-17 15:35:29 +00:00
}
}
}
2012-03-21 06:40:35 +00:00
@Command (
2019-04-14 08:30:40 +00:00
name = " /setbiome " ,
2019-04-28 05:12:05 +00:00
desc = " Sets the biome of your current block or region. " ,
2019-04-14 08:30:40 +00:00
descFooter = " By default, uses all the blocks in your selection "
2012-03-21 06:40:35 +00:00
)
2019-04-15 08:25:19 +00:00
@Logging ( REGION )
2012-03-21 06:40:35 +00:00
@CommandPermissions ( " worldedit.biome.set " )
2019-04-14 08:30:40 +00:00
public void setBiome ( Player player , LocalSession session , EditSession editSession ,
2019-04-27 07:32:02 +00:00
@Arg ( desc = " Biome type. " ) BiomeType target ,
2019-04-15 09:03:05 +00:00
@Switch ( name = 'p' , desc = " Use your current position " )
boolean atPosition ) throws WorldEditException {
2014-07-17 07:21:13 +00:00
World world = player . getWorld ( ) ;
Region region ;
2013-03-28 23:53:42 +00:00
Mask mask = editSession . getMask ( ) ;
2014-07-17 07:21:13 +00:00
Mask2D mask2d = mask ! = null ? mask . toMask2D ( ) : null ;
2013-03-28 23:53:42 +00:00
2014-07-17 07:21:13 +00:00
if ( atPosition ) {
2018-10-14 10:40:53 +00:00
region = new CuboidRegion ( player . getLocation ( ) . toVector ( ) . toBlockPoint ( ) , player . getLocation ( ) . toVector ( ) . toBlockPoint ( ) ) ;
2012-03-28 18:04:59 +00:00
} else {
2014-07-17 07:21:13 +00:00
region = session . getSelection ( world ) ;
}
2012-03-21 06:40:35 +00:00
2014-07-17 07:21:13 +00:00
FlatRegionFunction replace = new BiomeReplace ( editSession , target ) ;
if ( mask2d ! = null ) {
replace = new FlatRegionMaskingFilter ( mask2d , replace ) ;
2012-03-21 06:40:35 +00:00
}
2014-07-17 07:21:13 +00:00
FlatRegionVisitor visitor = new FlatRegionVisitor ( Regions . asFlatRegion ( region ) , replace ) ;
Operations . completeLegacy ( visitor ) ;
player . print ( " Biomes were changed in " + visitor . getAffected ( ) + " columns. You may have to rejoin your game (or close and reopen your world) to see a change. " ) ;
2012-03-21 06:40:35 +00:00
}
2014-06-28 01:04:34 +00:00
2012-03-17 15:35:29 +00:00
}