为什么 Minecraft 中的 setLightLevel 函数没有正常工作?

huangapple go评论84阅读模式
英文:

Why is setLightLevel for Minecraft not working correctly?

问题

所以我开始为我的Minecraft模组开发修改。其中一个方块应该是更强大版本的萤石。以下是脚本:

import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;

public class FeralFlareBlock extends BlockBase
{

	public FeralFlareBlock(String name, Material material) 
	{
		super(name, material);
		
		setSoundType(SoundType.GLASS);
		setHardness(0.3F);
		setResistance(0.3F);
		setHarvestLevel("pickaxe", 1);
		setLightLevel(100.0F);
		setLightOpacity(1);
		
	}
	
}

有一个 setLightLevel 函数,我将其设置为100,即使萤石的亮度是15,理论上这应该更加强大。但实际上并不是。不知道我做错了什么,请帮忙。谢谢

英文:

So i started developing my mod for minectraft. One of the block it adds should be more powerfull version of glowstone. So this is the script:

import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;

public class FeralFlareBlock extends BlockBase
{

	public FeralFlareBlock(String name, Material material) 
	{
		super(name, material);
		
		setSoundType(SoundType.GLASS);
		setHardness(0.3F);
		setResistance(0.3F);
		setHarvestLevel("pickaxe", 1);
		setLightLevel(100.0F);
		setLightOpacity(1);
		
	}
	
}

There is the setLightLevel function, i have it set to 100 even tho glowstone is 15 so theoretically this should be more powerfull. It isn't. Don't know what im doing wrong, please help me. Thx

答案1

得分: 2

解释

setLightLevel 方法接受介于 0.0(最暗)和 1.0(最亮)之间的值。

因此,值为 100.0F 是无效的。

另请参阅我在搜索您的问题时找到的一些讨论:[1.11] 当方块放置在世界中时,setLightLevel 不会产生光亮

> Item#setLightLevel 方法接受一个浮点数,范围在 0.0F 到 1.0F 之间,而不是从 0 到 15。如果您想要最大的光亮级别,您应该使用 1.0F。

作为参考,这是一个链接到 某个 javadoc:Block#setLightLevel


> 我将其设置为 100,即使荧石的亮度是 15,所以从理论上讲这应该更强大。但事实并非如此。

Minecraft 中的最亮光亮级别为 15(通过值 1.0 使用 setLightLevel 获得)。您无法使任何东西比这更亮。Minecraft 不支持更高的亮度值。


将 0-15 转换为方法

您可以通过简单的数学计算轻松地将 Minecraft 的光亮级别(0 到 15)转换为此方法:

// 接受介于 0 和 15 之间(包括两者)的值,并转换为介于 0 到 1.0 之间的值。
private static double translateLightLevelToFloat(int lightLevel) {
    if (ligthLevel < 0 || lightLevel > 15) {
        throw new IllegalArgumentException("光亮级别必须在 0 到 15 之间(包括两者)");
    }

    return lightLevel / 15.0;
}
英文:

Explanation

The setLightLevel method does take values between 0.0 (darkest) and 1.0 (brightest).

So a value of 100.0F is invalid.

Also see some thread I found when searching for your issue: [1.11] setLightLevel not producing light when block is placed in world:

> Item#setLightLevel takes a float between 0.0F and 1.0F, instead of going from 0 to 15. If you want to have the max light level, you use 1.0F.

For reference, here is a link to a javadoc: Block#setLightLevel.


> I have it set to 100 even tho glowstone is 15 so theoretically this should be more powerfull. It isn't.

The brightest light level in Minecraft is 15 (received by a value of 1.0 with setLightLevel). You can not make anything brighter than this. Minecraft does not support brighter values.


Translate from 0-15

You can easily convert minecrafts light levels (0 to 15) to this method with simple math:

// Takes values between 0 and 15 (both inclusive) and converts to 0 to 1.0.
private static double translateLightLevelToFloat(int lightLevel) {
    if (ligthLevel < 0 || lightLevel > 15) {
        throw new IllegalArgumentException("Light level must be between 0 and 15 (both inclusive)");
    }

    return lightLevel / 15.0;
}

答案2

得分: -1

最大光亮级别为15。因此,它不会比萤石更亮。

https://minecraft.gamepedia.com/Light

有16个光亮级别,由整数从0(最低)到15(最高)指定。

英文:

The maximum lightlevel is 15. So it cannot get lighter than glowstone.

https://minecraft.gamepedia.com/Light

> There are 16 light
> levels, which are specified by an integer from 0 (the minimum) to 15
> (the maximum).

huangapple
  • 本文由 发表于 2020年5月5日 16:39:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/61609084.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定