net.minecraft.world.LightType Java Examples

The following examples show how to use net.minecraft.world.LightType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpawningSphereCommand.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    LiteralArgumentBuilder command = Commands.literal(COMMAND)
            .then(Commands.literal(ArgumentNames.SET)
                    .then(Commands.argument(ArgumentNames.POS, Arguments.point())
                            .executes(SpawningSphereCommand::setSphere))
                    .executes(SpawningSphereCommand::setSphere))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        boolean cleared = SpawningSphereProvider.clear();

                        String format = cleared ? "bbor.commands.spawningSphere.cleared" : "bbor.commands.spawningSphere.notSet";
                        CommandHelper.feedback(context, format);
                        return 0;
                    }))
            .then(Commands.literal(CALCULATE_SPAWNABLE)
                    .executes(context -> {
                        if (!SpawningSphereProvider.hasSpawningSphereInDimension(Player.getDimensionId())) {
                            CommandHelper.feedback(context, "bbor.commands.spawningSphere.notSet");
                            return 0;
                        }

                        Counts counts = new Counts();
                        World world = Minecraft.getInstance().world;
                        SpawningSphereProvider.calculateSpawnableSpacesCount(pos -> {
                            counts.spawnable++;
                            if (world.getLightFor(LightType.SKY, pos) > 7)
                                counts.nightSpawnable++;
                        });
                        SpawningSphereProvider.setSpawnableSpacesCount(counts.spawnable);

                        CommandHelper.feedback(context, "bbor.commands.spawningSphere.calculated",
                                String.format("%,d", counts.spawnable),
                                String.format("%,d", counts.nightSpawnable));
                        return 0;
                    }));
    commandDispatcher.register(command);
}
 
Example #2
Source File: SpawnableBlocksHelper.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
static boolean isSpawnable(World world, BlockPos pos, BlockState spawnBlockState, BlockState upperBlockState) {
    VoxelShape collisionShape = upperBlockState.getCollisionShape(world, pos);
    boolean isNether = world.dimension.isNether();
    return spawnBlockState.canEntitySpawn(world, pos.down(), isNether ? EntityType.ZOMBIE_PIGMAN : entityType) &&
            !Block.doesSideFillSquare(collisionShape, Direction.UP) &&
            !upperBlockState.canProvidePower() &&
            !upperBlockState.isIn(BlockTags.RAILS) &&
            collisionShape.getEnd(Direction.Axis.Y) <= 0 &&
            upperBlockState.getFluidState().isEmpty() &&
            (isNether || world.getLightFor(LightType.BLOCK, pos) <= 7);
}
 
Example #3
Source File: MobSpawnEspHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private void scan()
{
	int minX = chunk.getPos().getStartX();
	int minY = 0;
	int minZ = chunk.getPos().getStartZ();
	int maxX = chunk.getPos().getEndX();
	int maxY = 255;
	int maxZ = chunk.getPos().getEndZ();
	
	ClientWorld world = MC.world;
	ArrayList<BlockPos> blocks = new ArrayList<>();
	
	for(int x = minX; x <= maxX; x++)
		for(int y = minY; y <= maxY; y++)
			for(int z = minZ; z <= maxZ; z++)
			{
				BlockPos pos = new BlockPos(x, y, z);
				BlockState state = world.getBlockState(pos);
				
				if(state.getMaterial().blocksMovement())
					continue;
				if(!state.getFluidState().isEmpty())
					continue;
				
				BlockState stateDown = world.getBlockState(pos.down());
				if(!stateDown.allowsSpawning(world, pos.down(),
					EntityType.ZOMBIE))
					continue;
				
				blocks.add(pos);
			}
		
	if(Thread.interrupted())
		return;
	
	red.addAll(blocks.stream()
		.filter(pos -> world.getLightLevel(LightType.BLOCK, pos) < 8)
		.filter(pos -> world.getLightLevel(LightType.SKY, pos) < 8)
		.collect(Collectors.toList()));
	
	if(Thread.interrupted())
		return;
	
	yellow.addAll(blocks.stream().filter(pos -> !red.contains(pos))
		.filter(pos -> world.getLightLevel(LightType.BLOCK, pos) < 8)
		.collect(Collectors.toList()));
	doneScanning = true;
}
 
Example #4
Source File: BlockInfo.java    From fabric-carpet with MIT License 4 votes vote down vote up
public static List<BaseText> blockInfo(BlockPos pos, World world)
{
    BlockState state = world.getBlockState(pos);
    Material material = state.getMaterial();
    Block block = state.getBlock();
    String metastring = "";
    for (net.minecraft.state.property.Property<?> iproperty : state.getProperties())
    {
        metastring += ", "+iproperty.getName() + '='+state.get(iproperty);
    }
    List<BaseText> lst = new ArrayList<>();
    lst.add(Messenger.s(""));
    lst.add(Messenger.s("====================================="));
    lst.add(Messenger.s(String.format("Block info for %s%s (id %d%s):",Registry.BLOCK.getId(block),metastring, Registry.BLOCK.getRawId(block), metastring )));
    lst.add(Messenger.s(String.format(" - Material: %s", materialName.get(material))));
    lst.add(Messenger.s(String.format(" - Map colour: %s", mapColourName.get(state.getTopMaterialColor(world, pos)))));
    lst.add(Messenger.s(String.format(" - Sound type: %s", soundName.get(block.getSoundGroup(state)))));
    lst.add(Messenger.s(""));
    //lst.add(Messenger.s(String.format(" - Full block: %s", block.isShapeFullCube()))); //  isFullCube() )));
    lst.add(Messenger.s(String.format(" - Normal cube: %s", state.isSimpleFullBlock(world, pos)))); //isNormalCube())));
    lst.add(Messenger.s(String.format(" - Is liquid: %s", material.isLiquid())));
    lst.add(Messenger.s(""));
    lst.add(Messenger.s(String.format(" - Light in: %d, above: %d",
            Math.max(world.getLightLevel(LightType.BLOCK, pos),world.getLightLevel(LightType.SKY, pos)) ,
            Math.max(world.getLightLevel(LightType.BLOCK, pos.up()),world.getLightLevel(LightType.SKY, pos.up())))));
    lst.add(Messenger.s(String.format(" - Brightness in: %.2f, above: %.2f", world.getBrightness(pos), world.getBrightness(pos.up()))));
    lst.add(Messenger.s(String.format(" - Is opaque: %s", material.isSolid() )));
    //lst.add(Messenger.s(String.format(" - Light opacity: %d", state.getOpacity(world,pos))));
    lst.add(Messenger.s(String.format(" - Blocks light: %s", state.getMaterial().blocksLight())));
    //lst.add(Messenger.s(String.format(" - Emitted light: %d", state.getLightValue())));
    //lst.add(Messenger.s(String.format(" - Picks neighbour light value: %s", state.useNeighborBrightness(world, pos))));
    lst.add(Messenger.s(""));
    lst.add(Messenger.s(String.format(" - Causes suffocation: %s", state.canSuffocate(world, pos))));
    lst.add(Messenger.s(String.format(" - Blocks movement on land: %s", !state.canPlaceAtSide(world,pos, BlockPlacementEnvironment.LAND))));
    lst.add(Messenger.s(String.format(" - Blocks movement in air: %s", !state.canPlaceAtSide(world,pos, BlockPlacementEnvironment.AIR))));
    lst.add(Messenger.s(String.format(" - Blocks movement in liquids: %s", !state.canPlaceAtSide(world,pos, BlockPlacementEnvironment.WATER))));
    lst.add(Messenger.s(String.format(" - Can burn: %s", material.isBurnable())));
    lst.add(Messenger.s(String.format(" - Requires a tool: %s", !material.isReplaceable()))); //?maybe
    lst.add(Messenger.s(String.format(" - Hardness: %.2f", state.getHardness(world, pos))));
    lst.add(Messenger.s(String.format(" - Blast resistance: %.2f", block.getBlastResistance())));
    lst.add(Messenger.s(String.format(" - Ticks randomly: %s", block.hasRandomTicks(state))));
    lst.add(Messenger.s(""));
    lst.add(Messenger.s(String.format(" - Can provide power: %s", state.emitsRedstonePower())));
    lst.add(Messenger.s(String.format(" - Strong power level: %d", world.getReceivedStrongRedstonePower(pos))));
    lst.add(Messenger.s(String.format(" - Redstone power level: %d", world.getReceivedRedstonePower(pos))));
    lst.add(Messenger.s(""));
    lst.add(wander_chances(pos.up(), world));

    return lst;
}