mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 04:00:30 +00:00
Add dimension parameter to commands.getBlockInfo{,s}
Closes #130. Worth noting it doesn't add an additional argument to getBlockPosition - want to leave that off for now.
This commit is contained in:
parent
d3563a3854
commit
18d66bd727
@ -18,9 +18,13 @@ import net.minecraft.command.Commands;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -193,16 +197,18 @@ public class CommandAPI implements ILuaAPI
|
||||
* @param maxX The end x coordinate of the range to query.
|
||||
* @param maxY The end y coordinate of the range to query.
|
||||
* @param maxZ The end z coordinate of the range to query.
|
||||
* @param dimension The dimension to query (e.g. "minecraft:overworld"). Defaults to the current dimension.
|
||||
* @return A list of information about each block.
|
||||
* @throws LuaException If the coordinates are not within the world.
|
||||
* @throws LuaException If trying to get information about more than 4096 blocks.
|
||||
* @cc.since 1.76
|
||||
* @cc.changed 1.99 Added {@code dimension} argument.
|
||||
*/
|
||||
@LuaFunction( mainThread = true )
|
||||
public final List<Map<?, ?>> getBlockInfos( int minX, int minY, int minZ, int maxX, int maxY, int maxZ ) throws LuaException
|
||||
public final List<Map<?, ?>> getBlockInfos( int minX, int minY, int minZ, int maxX, int maxY, int maxZ, Optional<String> dimension ) throws LuaException
|
||||
{
|
||||
// Get the details of the block
|
||||
World world = computer.getLevel();
|
||||
World world = getLevel( dimension );
|
||||
BlockPos min = new BlockPos(
|
||||
Math.min( minX, maxX ),
|
||||
Math.min( minY, maxY ),
|
||||
@ -247,23 +253,35 @@ public class CommandAPI implements ILuaAPI
|
||||
* @param x The x position of the block to query.
|
||||
* @param y The y position of the block to query.
|
||||
* @param z The z position of the block to query.
|
||||
* @param dimension The dimension to query (e.g. "minecraft:overworld"). Defaults to the current dimension.
|
||||
* @return The given block's information.
|
||||
* @throws LuaException If the coordinates are not within the world, or are not currently loaded.
|
||||
* @cc.changed 1.76 Added block state info to return value
|
||||
* @cc.changed 1.99 Added {@code dimension} argument.
|
||||
*/
|
||||
@LuaFunction( mainThread = true )
|
||||
public final Map<?, ?> getBlockInfo( int x, int y, int z ) throws LuaException
|
||||
public final Map<?, ?> getBlockInfo( int x, int y, int z, Optional<String> dimension ) throws LuaException
|
||||
{
|
||||
// Get the details of the block
|
||||
World world = computer.getLevel();
|
||||
World world = getLevel( dimension );
|
||||
BlockPos position = new BlockPos( x, y, z );
|
||||
if( World.isInWorldBounds( position ) )
|
||||
{
|
||||
if( !World.isInWorldBounds( position ) ) throw new LuaException( "Co-ordinates out of range" );
|
||||
return getBlockInfo( world, position );
|
||||
}
|
||||
else
|
||||
|
||||
@Nonnull
|
||||
private World getLevel( @Nonnull Optional<String> id ) throws LuaException
|
||||
{
|
||||
throw new LuaException( "Co-ordinates out of range" );
|
||||
}
|
||||
World currentWorld = computer.getLevel();
|
||||
if( currentWorld == null ) throw new LuaException( "No world exists" );
|
||||
|
||||
if( !id.isPresent() ) return currentWorld;
|
||||
|
||||
ResourceLocation dimensionId = ResourceLocation.tryParse( id.get() );
|
||||
if( dimensionId == null ) throw new LuaException( "Invalid dimension name" );
|
||||
|
||||
World world = currentWorld.getServer().getLevel( RegistryKey.create( Registry.DIMENSION_REGISTRY, dimensionId ) );
|
||||
if( world == null ) throw new LuaException( "Unknown dimension" );
|
||||
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user