MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针。
如果在编辑的过程中遇到了什么问题,可以去讨论板提问。
为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证。
MCBBS Wiki GitHub群组已上线!
您可以在回声洞中发表吐槽!
服务器状态监控。点击进入
本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>
FancyMenu Wiki/自定义Visibility Requirements:修订间差异
(创建页面,内容为“== 关于 == 通过在拓展模组中调用 FancyMenu API,即可自定义Visibility Requirements用于布局中的元素。 重要:Visibility RequirementsAPI只在FancyMenu v2.6.3+有效。 == 准备开发环境 == 请参阅 准备工作区。 == 添加Visibility Requirements == Visibility Requirements使用<code>VisibilityRequirement</code>类。 你需要为每一个VisibilityRequirement Requirements 创建一个子…”) |
|||
| (未显示1个用户的4个中间版本) | |||
| 第14行: | 第14行: | ||
=== 不同类型的Requirements === | === 不同类型的Requirements === | ||
VisibilityRequirements可以用于两种不同的模式。 | VisibilityRequirements可以用于两种不同的模式。 | ||
第一种是不使用任何值来检查是否满足 Requirements ,第二种是使用一个值。 | 第一种是不使用任何值来检查是否满足 Requirements ,第二种是使用一个值。 | ||
如果 Requirements 使用值,那么用户在给一个元素设置 Requirements 时就需要输入这个值。 | 如果 Requirements 使用值,那么用户在给一个元素设置 Requirements 时就需要输入这个值。 | ||
=== 不使用值来创建 Requirements === | === 不使用值来创建 Requirements === | ||
创建一个<code>VisibilityRequirement</code>的新子类并取一个合适的名字。 | |||
接下来我会将我的示例类命名为<code>ExampleVisibilityRequirement</code>。 | |||
同时有一些特殊的点需要特别留意一下。 | 同时有一些特殊的点需要特别留意一下。 | ||
构造方法(Constructor) | ==== 构造方法(Constructor) ==== | ||
在构造方法中给你的 Requirements 定义唯一标识符。 | 在构造方法中给你的 Requirements 定义唯一标识符。 | ||
<syntaxhighlight lang="java"> | |||
public ExampleVisibilityRequirement() { | public ExampleVisibilityRequirement() { | ||
//The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier! | //The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier! | ||
| 第27行: | 第32行: | ||
super("example_requirement_no_value"); | super("example_requirement_no_value"); | ||
} | } | ||
</syntaxhighlight> | |||
==== hasValue() ==== | |||
这个方法用于返回 Requirements 是否需要值。 | |||
因为我们不想给这个 Requirements 使用值,所以返回<code>false</code>。 | |||
<syntaxhighlight lang="java"> | |||
@Override | @Override | ||
public boolean hasValue() { | public boolean hasValue() { | ||
| 第38行: | 第44行: | ||
return false; | return false; | ||
} | } | ||
</syntaxhighlight> | |||
==== isRequirementMet() ==== | |||
这是你的 Requirements 的最重要的方法。 | |||
这里用于返回是否满足在此要求中检查的条件。 | 这里用于返回是否满足在此要求中检查的条件。 | ||
这个方法以 Requirements 的值为参数,但因为这个 Requirements 没有值,所以参数为空。 | 这个方法以 Requirements 的值为参数,但因为这个 Requirements 没有值,所以参数为空。 | ||
<syntaxhighlight lang="java"> | |||
//Here you return if the requirement is met (using the given requirement value if the requirement has one). | //Here you return if the requirement is met (using the given requirement value if the requirement has one). | ||
//在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值) | //在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值) | ||
| 第56行: | 第64行: | ||
} | } | ||
</syntaxhighlight> | |||
==== getDisplayName() ==== | |||
这个方法返回 Requirements 的显示名。 | |||
这个显示名会在布局编辑器的Visibility Requirements选项显示。 | 这个显示名会在布局编辑器的Visibility Requirements选项显示。 | ||
<syntaxhighlight lang="java"> | |||
//This is the display name of the requirement. | //This is the display name of the requirement. | ||
//这个是 Requirements 的显示名。 | //这个是 Requirements 的显示名。 | ||
| 第69行: | 第78行: | ||
return "Example Requirement [No Value]"; | return "Example Requirement [No Value]"; | ||
} | } | ||
</syntaxhighlight> | |||
==== getDescription() ==== | |||
返回 Requirements 的描述。 | |||
当把鼠标悬停在切换 Requirements 按钮上时,该描述会作为工具提示显示。 | 当把鼠标悬停在切换 Requirements 按钮上时,该描述会作为工具提示显示。 | ||
<syntaxhighlight lang="java"> | |||
//This is the description of the requirement. | //This is the description of the requirement. | ||
//这里是 Requirements 的描述 | //这里是 Requirements 的描述 | ||
| 第84行: | 第94行: | ||
return l; | return l; | ||
} | } | ||
</syntaxhighlight> | |||
==== getValueDisplayName() ==== | |||
这个方法返回值的显示名。 | |||
因为咱的 Requirements 不用值,返回空即可。 | 因为咱的 Requirements 不用值,返回空即可。 | ||
<syntaxhighlight lang="java"> | |||
//Since this requirement has no value, just return NULL here. | //Since this requirement has no value, just return NULL here. | ||
//因为 Requirements 没有值,只需要在这里返回null。 | //因为 Requirements 没有值,只需要在这里返回null。 | ||
| 第95行: | 第106行: | ||
return null; | return null; | ||
} | } | ||
</syntaxhighlight> | |||
==== getValuePreset() ==== | |||
返回自动设置到值输入文本字段的内容。 | |||
这个 Requirements 没有值输入字段,所以我们返回<code>null</code>。 | |||
<syntaxhighlight lang="java"> | |||
这个 Requirements | |||
//No value, so just return NULL. | //No value, so just return NULL. | ||
//没有值,返回null。 | //没有值,返回null。 | ||
| 第106行: | 第118行: | ||
return null; | return null; | ||
} | } | ||
</syntaxhighlight> | |||
==== getValueInputFieldFilter() ==== | |||
该方法返回一个字符过滤器,该过滤器用来检查用户可以在数值输入文本字段中允许输入的字符。 | |||
没值,回null。 | |||
<syntaxhighlight lang="java"> | |||
//You know the drill. No value = return NULL. | //You know the drill. No value = return NULL. | ||
//没值 = 返回null(毁灭吧,我累了 *发动地鸣) | //没值 = 返回null(毁灭吧,我累了 *发动地鸣) | ||
| 第117行: | 第130行: | ||
return null; | return null; | ||
} | } | ||
</syntaxhighlight> | |||
==== 完整示例 ==== | |||
这个是完整的VisibilityRequirement样例。 | 这个是完整的VisibilityRequirement样例。 | ||
<syntaxhighlight lang="java"> | |||
package de.keksuccino.fancymenu.api.visibilityrequirements.example; | package de.keksuccino.fancymenu.api.visibilityrequirements.example; | ||
| 第200行: | 第214行: | ||
} | } | ||
</syntaxhighlight> | |||
==== 注册Visibility Requirement ==== | |||
到这你几乎完成了。(译者:我也是 *冰箱里拿一瓶啤酒) | |||
现在你只需要在游戏加载时将你的<code>VisibilityRequirement</code>注册到<code>VisibilityRequirementRegistry</code>。 | |||
<syntaxhighlight lang="java"> | |||
package de.keksuccino.fancymenu; | package de.keksuccino.fancymenu; | ||
| 第226行: | 第241行: | ||
} | } | ||
</syntaxhighlight> | |||
=== 创建带值的Requirement === | === 创建带值的Requirement === | ||
创建<code>VisibilityRequirement</code>的新子类并取一个合适的名字。 | 创建<code>VisibilityRequirement</code>的新子类并取一个合适的名字。 | ||
接下来我将我的演示类命名为<code>ExampleVisibilityRequirementWithValue</code> | 接下来我将我的演示类命名为<code>ExampleVisibilityRequirementWithValue</code>。 | ||
有一些重要的点需要留意。 | |||
构造函数(Constructor) | ==== 构造函数(Constructor) ==== | ||
构造函数用标识符独一无二 | 构造函数用标识符独一无二 | ||
<syntaxhighlight lang="java"> | |||
public ExampleVisibilityRequirementWithValue() { | public ExampleVisibilityRequirementWithValue() { | ||
//The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier! | //The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier! | ||
| 第242行: | 第258行: | ||
super("example_requirement_with_value"); | super("example_requirement_with_value"); | ||
} | } | ||
</syntaxhighlight> | |||
==== hasValue() ==== | |||
这个方法用于返回 Requirements 是否需要值。 | |||
因为我们想给这个 Requirements 使用值,所以返回true。 | 因为我们想给这个 Requirements 使用值,所以返回true。 | ||
<syntaxhighlight lang="java"> | |||
@Override | @Override | ||
public boolean hasValue() { | public boolean hasValue() { | ||
| 第253行: | 第270行: | ||
return true; | return true; | ||
} | } | ||
</syntaxhighlight> | |||
isRequirementMet() | ==== isRequirementMet() ==== | ||
这是你的 Requirements 的最重要的方法。 | 这是你的 Requirements 的最重要的方法。 | ||
这里用于返回是否满足在此要求中检查的条件。 | 这里用于返回是否满足在此要求中检查的条件。 | ||
这个方法有 Requirements 的值作为参数,所以你可以使用它检查是否满足 Requirements 。 | 这个方法有 Requirements 的值作为参数,所以你可以使用它检查是否满足 Requirements 。 | ||
<syntaxhighlight lang="java"> | |||
//Here you return if the requirement is met (using the given requirement value if the requirement has one). | //Here you return if the requirement is met (using the given requirement value if the requirement has one). | ||
//在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值) | //在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值) | ||
| 第276行: | 第296行: | ||
} | } | ||
</syntaxhighlight> | |||
getDisplayName() | ==== getDisplayName() ==== | ||
此方法返回 Requirements 显示名。 | 此方法返回 Requirements 显示名。 | ||
这个显示名会在布局编辑器的Visibility Requirements选项显示。 | 这个显示名会在布局编辑器的Visibility Requirements选项显示。 | ||
<syntaxhighlight lang="java"> | |||
//This is the display name of the requirement. | //This is the display name of the requirement. | ||
//这个是 Requirements 的显示名。 | //这个是 Requirements 的显示名。 | ||
| 第289行: | 第311行: | ||
return "Example Requirement [With Value]"; | return "Example Requirement [With Value]"; | ||
} | } | ||
</syntaxhighlight> | |||
getDescription() | ==== getDescription() ==== | ||
返回 Requirements 的描述。 | 返回 Requirements 的描述。 | ||
当把鼠标悬停在切换 Requirements 按钮上时,该描述会作为工具提示显示。 | 当把鼠标悬停在切换 Requirements 按钮上时,该描述会作为工具提示显示。 | ||
<syntaxhighlight lang="java"> | |||
//This is the description of the requirement. | //This is the description of the requirement. | ||
//这里是 Requirements 的描述 | //这里是 Requirements 的描述 | ||
| 第304行: | 第328行: | ||
return l; | return l; | ||
} | } | ||
</syntaxhighlight> | |||
==== getValueDisplayName() ==== | |||
getValueDisplayName() | |||
这个方法返回值的显示名。 | 这个方法返回值的显示名。 | ||
<syntaxhighlight lang="java"> | |||
//This is the display name of the VALUE of the requirement. | //This is the display name of the VALUE of the requirement. | ||
//这是 Requirements 的值的显示名。 | //这是 Requirements 的值的显示名。 | ||
| 第316行: | 第340行: | ||
return "Example Value Name"; | return "Example Value Name"; | ||
} | } | ||
</syntaxhighlight> | |||
==== getValuePreset() ==== | |||
如果没有真实的值,则返回自动设置到输入文本字段的内容。 | |||
最好给用户展示真实值的样例。 | 最好给用户展示真实值的样例。 | ||
<syntaxhighlight lang="java"> | |||
//This is the content that will be automatically set to the value input field when there is no value already. | //This is the content that will be automatically set to the value input field when there is no value already. | ||
//在已经没有值的情况下将自动设置到值输入栏的内容。 | //在已经没有值的情况下将自动设置到值输入栏的内容。 | ||
| 第327行: | 第352行: | ||
return "cool value preset"; | return "cool value preset"; | ||
} | } | ||
</syntaxhighlight> | |||
==== getValueInputFieldFilter() ==== | |||
该方法返回一个字符过滤器,该过滤器被用来检查用户可以在数值输入文本字段中允许输入的字符。 | |||
如果你想允许所有字符,那直接返回<code>null</code>。 | |||
<syntaxhighlight lang="java"> | |||
//The character filter of the value input field. Return NULL if you want to allow all characters. | //The character filter of the value input field. Return NULL if you want to allow all characters. | ||
//值输入字段字符过滤器,返回null允许所有字符。 | //值输入字段字符过滤器,返回null允许所有字符。 | ||
| 第340行: | 第366行: | ||
return null; | return null; | ||
} | } | ||
</syntaxhighlight> | |||
====完整示例==== | |||
这是完整的VisibilityRequirement示例。 | |||
<syntaxhighlight lang="java"> | |||
package de.keksuccino.fancymenu.api.visibilityrequirements.example; | package de.keksuccino.fancymenu.api.visibilityrequirements.example; | ||
| 第432行: | 第459行: | ||
} | } | ||
</syntaxhighlight> | |||
==== 注册Visibility Requirement ==== | |||
你弟任务!完成啦!啊哈哈哈哈哈哈哈哈哈哈哈哈! | |||
<code>VisibilityRequirement</code>:<code>VisibilityRequirementRegistry</code>先生,Java陛下,我们在天堂(游戏加载)见! | |||
<syntaxhighlight lang="java"> | |||
package de.keksuccino.fancymenu; | package de.keksuccino.fancymenu; | ||
| 第458行: | 第486行: | ||
} | } | ||
</syntaxhighlight> | |||
[[分类:FancyMenu]] | |||
2022年12月24日 (六) 16:52的最新版本
关于
通过在拓展模组中调用 FancyMenu API,即可自定义Visibility Requirements用于布局中的元素。
重要:Visibility RequirementsAPI只在FancyMenu v2.6.3+有效。
准备开发环境
请参阅 准备工作区。
添加Visibility Requirements
Visibility Requirements使用VisibilityRequirement类。
你需要为每一个VisibilityRequirement Requirements 创建一个子类。
每个VisibilityRequirement都应该在模组初始化时注册到VisibilityRequirementRegistry。
不同类型的Requirements
VisibilityRequirements可以用于两种不同的模式。
第一种是不使用任何值来检查是否满足 Requirements ,第二种是使用一个值。
如果 Requirements 使用值,那么用户在给一个元素设置 Requirements 时就需要输入这个值。
不使用值来创建 Requirements
创建一个VisibilityRequirement的新子类并取一个合适的名字。
接下来我会将我的示例类命名为ExampleVisibilityRequirement。
同时有一些特殊的点需要特别留意一下。
构造方法(Constructor)
在构造方法中给你的 Requirements 定义唯一标识符。
public ExampleVisibilityRequirement() {
//The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier!
//标识符独一无二,别想着用同一个标识符注册多个 Requirements 。
super("example_requirement_no_value");
}
hasValue()
这个方法用于返回 Requirements 是否需要值。
因为我们不想给这个 Requirements 使用值,所以返回false。
@Override
public boolean hasValue() {
//We don't need a value in this requirement, so we return false here.
//我们不想给这个 Requirements 使用值,返回false。
return false;
}
isRequirementMet()
这是你的 Requirements 的最重要的方法。
这里用于返回是否满足在此要求中检查的条件。
这个方法以 Requirements 的值为参数,但因为这个 Requirements 没有值,所以参数为空。
//Here you return if the requirement is met (using the given requirement value if the requirement has one).
//在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值)
//We don't use a value in this example, so the parameter will be NULL and we can ignore it.
//在这个样例中我们不使用值,所以参数为空,忽略即可。
@Override
public boolean isRequirementMet(@Nullable String value) {
//In this example, we just check if the window is in fullscreen mode and if it is, then we return true.
//在这个样例中我们只需要检查窗口是否处在全屏模式,如果是则返回true。
return Minecraft.getInstance().options.fullscreen;
}
getDisplayName()
这个方法返回 Requirements 的显示名。
这个显示名会在布局编辑器的Visibility Requirements选项显示。
//This is the display name of the requirement.
//这个是 Requirements 的显示名。
//You don't have much space for the display name, so try to choose a short one.
//显示名写得简短一些,因为太长会显示出错。
@Override
public String getDisplayName() {
return "Example Requirement [No Value]";
}
getDescription()
返回 Requirements 的描述。
当把鼠标悬停在切换 Requirements 按钮上时,该描述会作为工具提示显示。
//This is the description of the requirement.
//这里是 Requirements 的描述
@Override
public List<String> getDescription() {
List<String> l = new ArrayList<>();
l.add("This is an example requirement");
l.add("without a value.");
l.add("It checks if the window is in fullscreen.");
return l;
}
getValueDisplayName()
这个方法返回值的显示名。
因为咱的 Requirements 不用值,返回空即可。
//Since this requirement has no value, just return NULL here.
//因为 Requirements 没有值,只需要在这里返回null。
@Override
public String getValueDisplayName() {
return null;
}
getValuePreset()
返回自动设置到值输入文本字段的内容。
这个 Requirements 没有值输入字段,所以我们返回null。
//No value, so just return NULL.
//没有值,返回null。
@Override
public String getValuePreset() {
return null;
}
getValueInputFieldFilter()
该方法返回一个字符过滤器,该过滤器用来检查用户可以在数值输入文本字段中允许输入的字符。
没值,回null。
//You know the drill. No value = return NULL.
//没值 = 返回null(毁灭吧,我累了 *发动地鸣)
@Override
public CharacterFilter getValueInputFieldFilter() {
return null;
}
完整示例
这个是完整的VisibilityRequirement样例。
package de.keksuccino.fancymenu.api.visibilityrequirements.example;
import de.keksuccino.fancymenu.api.visibilityrequirements.VisibilityRequirement;
import de.keksuccino.konkrete.input.CharacterFilter;
import net.minecraft.client.Minecraft;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class ExampleVisibilityRequirement extends VisibilityRequirement {
public ExampleVisibilityRequirement() {
//The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier!
//标识符独一无二,别想着用同一个标识符注册多个 Requirements 。
super("example_requirement_no_value");
}
@Override
public boolean hasValue() {
//We don't need a value in this requirement, so we return false here.
//我们不想给这个 Requirements 使用值,返回false。
return false;
}
//Here you return if the requirement is met (using the given requirement value if the requirement has one).
//在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值)
//We don't use a value in this example, so the parameter will be NULL and we can ignore it.
//在这个样例中我们不使用值,所以参数为空,忽略即可。
@Override
public boolean isRequirementMet(@Nullable String value) {
//In this example, we just check if the window is in fullscreen mode and if it is, then we return true.
//在这个样例中我们只需要检查窗口是否处在全屏模式,如果是则返回true。
return Minecraft.getInstance().options.fullscreen;
}
//This is the display name of the requirement.
//这个是 Requirements 的显示名。
//You don't have much space for the display name, so try to choose a short one.
//显示名写得简短一些,因为太长会显示出错。
@Override
public String getDisplayName() {
return "Example Requirement [No Value]";
}
//This is the description of the requirement.
//这里是 Requirements 的描述
@Override
public List<String> getDescription() {
List<String> l = new ArrayList<>();
l.add("This is an example requirement");
l.add("without a value.");
l.add("It checks if the window is in fullscreen.");
return l;
}
//Since this requirement has no value, just return NULL here.
//因为 Requirements 没有值,只需要在这里返回null。
@Override
public String getValueDisplayName() {
return null;
}
//No value, so just return NULL.
//没有值,返回null。
@Override
public String getValuePreset() {
return null;
}
//You know the drill. No value = return NULL.
//没 null
@Override
public CharacterFilter getValueInputFieldFilter() {
return null;
}
}
注册Visibility Requirement
到这你几乎完成了。(译者:我也是 *冰箱里拿一瓶啤酒)
现在你只需要在游戏加载时将你的VisibilityRequirement注册到VisibilityRequirementRegistry。
package de.keksuccino.fancymenu;
import net.minecraftforge.fml.common.Mod;
import de.keksuccino.fancymenu.api.visibilityrequirements.VisibilityRequirementRegistry;
@Mod("modid")
public class ExampleModMainClass {
public ExampleModMainClass() {
try {
//Register your VisibilityRequirement to the VisibilityRequirementRegistry at mod init.
//在模组初始化时把VisibilityRequirement注册到VisibilityRequirementRegistry。
VisibilityRequirementRegistry.registerRequirement(new ExampleVisibilityRequirement());
} catch (Exception e) {
e.printStackTrace();
}
}
}
创建带值的Requirement
创建VisibilityRequirement的新子类并取一个合适的名字。
接下来我将我的演示类命名为ExampleVisibilityRequirementWithValue。
有一些重要的点需要留意。
构造函数(Constructor)
构造函数用标识符独一无二
public ExampleVisibilityRequirementWithValue() {
//The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier!
//标识符独一无二,别想着用同一个标识符注册多个 Requirements 。
super("example_requirement_with_value");
}
hasValue()
这个方法用于返回 Requirements 是否需要值。
因为我们想给这个 Requirements 使用值,所以返回true。
@Override
public boolean hasValue() {
//This requirement needs a value, so we return true here.
// Requirements 需要值,返回true。
return true;
}
isRequirementMet()
这是你的 Requirements 的最重要的方法。
这里用于返回是否满足在此要求中检查的条件。
这个方法有 Requirements 的值作为参数,所以你可以使用它检查是否满足 Requirements 。
//Here you return if the requirement is met (using the given requirement value if the requirement has one).
//在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值)
//Since this requirement has a value, the value parameter will be the value of a requirement in a layout.
//因为 Requirements 有值,所以这个参数也绘世布局中 Requirements 的值。
@Override
public boolean isRequirementMet(@Nullable String value) {
//This requirement has a value that can be any string, but the requirement will only be met if the value is "show_me".
//此 Requirements 的值可以是任何字符串,但只有当值为“show_me”时才会满足 Requirements 。
//We return true if the value is "show_me".
if (value != null) {
return value.equalsIgnoreCase("show_me");
}
return false;
}
getDisplayName()
此方法返回 Requirements 显示名。
这个显示名会在布局编辑器的Visibility Requirements选项显示。
//This is the display name of the requirement.
//这个是 Requirements 的显示名。
//You don't have much space for the display name, so try to choose a short one.
//显示名写得简短一些,因为太长会显示出错。
@Override
public String getDisplayName() {
return "Example Requirement [With Value]";
}
getDescription()
返回 Requirements 的描述。
当把鼠标悬停在切换 Requirements 按钮上时,该描述会作为工具提示显示。
//This is the description of the requirement.
//这里是 Requirements 的描述
@Override
public List<String> getDescription() {
List<String> l = new ArrayList<>();
l.add("This is an example requirement");
l.add("with a value.");
l.add("It checks if the value is 'show_me'.");
return l;
}
getValueDisplayName()
这个方法返回值的显示名。
//This is the display name of the VALUE of the requirement.
//这是 Requirements 的值的显示名。
//You don't have much space for the display name, so try to choose a short one.
//短短的进村,太长的不要!
@Override
public String getValueDisplayName() {
return "Example Value Name";
}
getValuePreset()
如果没有真实的值,则返回自动设置到输入文本字段的内容。
最好给用户展示真实值的样例。
//This is the content that will be automatically set to the value input field when there is no value already.
//在已经没有值的情况下将自动设置到值输入栏的内容。
@Override
public String getValuePreset() {
return "cool value preset";
}
getValueInputFieldFilter()
该方法返回一个字符过滤器,该过滤器被用来检查用户可以在数值输入文本字段中允许输入的字符。
如果你想允许所有字符,那直接返回null。
//The character filter of the value input field. Return NULL if you want to allow all characters.
//值输入字段字符过滤器,返回null允许所有字符。
//Can be used to only allow numbers in the input field, etc.
//输入字段可以只允许数字等。
@Override
public CharacterFilter getValueInputFieldFilter() {
return null;
}
完整示例
这是完整的VisibilityRequirement示例。
package de.keksuccino.fancymenu.api.visibilityrequirements.example;
import de.keksuccino.fancymenu.api.visibilityrequirements.VisibilityRequirement;
import de.keksuccino.konkrete.input.CharacterFilter;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class ExampleVisibilityRequirementWithValue extends VisibilityRequirement {
public ExampleVisibilityRequirementWithValue() {
//The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier!
//标识符独一无二,别想着用同一个标识符注册多个 Requirements 。
super("example_requirement_with_value");
}
@Override
public boolean hasValue() {
//This requirement needs a value, so we return true here.
//这个 Requirements 需要值,所以我们在这里返回true。
return true;
}
//Here you return if the requirement is met (using the given requirement value if the requirement has one).
//在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值)
//Since this requirement has a value, the value parameter will be the value of a requirement in a layout.
//因为 Requirements 有值,所以这个参数也绘世布局中 Requirements 的值。
@Override
public boolean isRequirementMet(@Nullable String value) {
//This requirement has a value that can be any string, but the requirement will only be met if the value is "show_me".
//此 Requirements 的值可以是任何字符串,但只有当值为“show_me”时才会满足 Requirements 。
//We return true if the value is "show_me".
//如果值是"show_me"则返回true。
if (value != null) {
return value.equalsIgnoreCase("show_me");
}
return false;
}
//This is the display name of the requirement.
//这个是 Requirements 的显示名。
//You don't have much space for the display name, so try to choose a short one.
//显示名写得简短一些,因为太长会显示出错。
@Override
public String getDisplayName() {
return "Example Requirement [With Value]";
}
//This is the description of the requirement.
//这里是 Requirements 的描述
@Override
public List<String> getDescription() {
List<String> l = new ArrayList<>();
l.add("This is an example requirement");
l.add("with a value.");
l.add("It checks if the value is 'show_me'.");
return l;
}
//This is the display name of the VALUE of the requirement.
//这是 Requirements 的值的显示名。
//You don't have much space for the display name, so try to choose a short one.
//显示名短短的进村,太长的不要!
@Override
public String getValueDisplayName() {
return "Example Value Name";
}
//This is the content that will be automatically set to the value input field when there is no value already.
//在已经没有值的情况下将自动设置到值输入栏的内容。
@Override
public String getValuePreset() {
return "cool value preset";
}
//The character filter of the value input field. Return NULL if you want to allow all characters.
//值输入字段字符过滤器,返回null允许所有字符。
//Can be used to only allow numbers in the input field, etc.
//输入字段可以只允许数字等。
@Override
public CharacterFilter getValueInputFieldFilter() {
return null;
}
}
注册Visibility Requirement
你弟任务!完成啦!啊哈哈哈哈哈哈哈哈哈哈哈哈!
VisibilityRequirement:VisibilityRequirementRegistry先生,Java陛下,我们在天堂(游戏加载)见!
package de.keksuccino.fancymenu;
import net.minecraftforge.fml.common.Mod;
import de.keksuccino.fancymenu.api.visibilityrequirements.VisibilityRequirementRegistry;
@Mod("modid")
public class ExampleModMainClass {
public ExampleModMainClass() {
try {
//Register your VisibilityRequirement to the VisibilityRequirementRegistry at mod init.
//在模组初始化时注册VisibilityRequirement到VisibilityRequirementRegistry。
VisibilityRequirementRegistry.registerRequirement(new ExampleVisibilityRequirementWithValue());
} catch (Exception e) {
e.printStackTrace();
}
}
}