Minecraft 1.14.4 Forge Modの作成 その8 【鉱石の追加と生成】
首先
鉱石を追加し、ワールド生成時に鉱石が生成されるようにしてみます。
这次,我按照参考网站上的步骤成功地生成了矿石,但我无法理解其中的含义。
ソースコードを眺め、ある程度調べてみましたが、推測を多く含みます。
分かり次第、記事を更新していく予定です。

参考:Ore Generation – Minecraft 1.14/1.14.3(旧版本)的Modding教程
Ore Generation – Minecraft 1.14/1.14.4的Modding教程
电脑开发环境
在这里,我们将环境设置如下。
-
- Windows 10
-
- JDK 8u211
-
- Minecraft 1.14.4
-
- Minecraft Forge 1.14.4 (28.1.0)
- IntelliJ IDEA 2019.2.3
增加矿石方块
参考Minecraft 1.14.4 Forge Mod的第四部分,添加新的方块。
一种琵琶矿石

琵琶湖游船

パッケージ、クラスファイルの作成


将Logger的修饰符修改为public。
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
Config.java
源代码
请各位自行修改源代码中的BiwakoMod部分。
package jp.yuyu.biwako_mod.config;
import java.io.File;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
import jp.yuyu.biwako_mod.BiwakoMod;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber
public class Config
{
private static final ForgeConfigSpec.Builder SERVER_BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SERVER;
private static final ForgeConfigSpec.Builder CLIENT_BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec CLIENT;
static
{
OregenConfig.init(SERVER_BUILDER, CLIENT_BUILDER);
SERVER = SERVER_BUILDER.build();
CLIENT = CLIENT_BUILDER.build();
}
public static void loadConfig(ForgeConfigSpec config, String path)
{
BiwakoMod.LOGGER.info("Loading config: " + path);
final CommentedFileConfig file = CommentedFileConfig.builder(new File(path)).sync().autosave().writingMode(WritingMode.REPLACE).build();
BiwakoMod.LOGGER.info("Built config: " + path);
file.load();
BiwakoMod.LOGGER.info("Loaded config: " + path);
config.setConfig(file);
}
}
角色
在运行Client时,会在生成的run文件夹中存在一个config文件夹。在其中,有一个forge-client.toml文件。
内容是这样的。
#Client only settings, mostly things related to rendering
[client]
#Disable culling of hidden faces next to stairs and slabs. Causes extra rendering, but may fix some resource packs that exploit this vanilla mechanic.
disableStairSlabCulling = false
#Allow item rendering to detect emissive quads and draw them properly. This allows glowing blocks to look the same in item form, but incurs a very slight performance hit.
allowEmissiveItems = true
#Toggle off to make missing model text in the gui fit inside the slot.
zoomInMissingModelTextInGui = false
#Enable forge to queue all chunk updates to the Chunk Update thread.
#May increase FPS significantly, but may also cause weird rendering lag.
#Not recommended for computers without a significant number of cores available.
alwaysSetupTerrainOffThread = false
#Enable the forge block rendering pipeline - fixes the lighting of custom models.
forgeLightPipelineEnabled = true
#When enabled, forge will show any warnings that occurred during loading
showLoadWarnings = true
#Enable uploading cloud geometry to the GPU for faster rendering.
forgeCloudsEnabled = true
#When enabled, makes specific reload tasks such as language changing quicker to run.
selectiveResourceReloadEnabled = true
也许,为了处理这个配置文件,Config.java需要准备。
服务器配置在这种情况下不会被生成(?)好像。
配置定植-橡树
源代码
请各自预先更改的部分是:
-
- ForgeConfigSpec.IntValueの変数名
-
- ForgeConfigSpec.Builder.commentメソッドの引数
- ForgeConfigSpec.Builder.defineInRangeメソッドの引数
这条消息在下面有解释。
package jp.yuyu.biwako_mod.config;
import jp.yuyu.biwako_mod.BiwakoMod;
import net.minecraftforge.common.ForgeConfigSpec;
public class OregenConfig
{
public static ForgeConfigSpec.IntValue biwako_ore_chance;
public static ForgeConfigSpec.BooleanValue generate_overworld;
public static void init(ForgeConfigSpec.Builder server, ForgeConfigSpec.Builder client)
{
BiwakoMod.LOGGER.info("OregenConfig init");
server.comment("Oregen Config");
biwako_ore_chance = server
.comment("Maximum number of ore veins of the biwako ore that can spawn in one chunk.")
.defineInRange("oregen.biwako_ore_chance", 20, 1, 1000000);
generate_overworld = server
.comment("Decide if you want Biwako Mod ores to spawn in the overworld")
.define("oregen.generate_overworld", true);
}
}
解释 (jiě shì)
我认为这是为了设置矿石生成时的参数而准备的。
通过刚才创建的Config.java,我们添加了服务器配置。
在”comment”方法中,可以设置配置文件中的注释。
在”define”方法中,可以设置配置的路径和值。
在”defineInRange”方法中,可以设置配置的路径、默认值以及可取的最小值和最大值。
这个配置会以文件或其他形式存储,例如forge-client.toml,以便用户以后可以进行更改。
Minecraft启动后,在模组列表中选择模组时,可能会有一些设置,我认为这就是相应的设置,但似乎不能更改如果没有准备源代码。
琵琶湖笩运机会
当琵琶矿石生成时,可以设定其周围生成的矿石数量。
以香草矿石为例,
-
- 石炭 17
-
- 鉄鉱石 金 9
-
- ダイヤモンド レッドストーン 8
- ラピスラズリ 7
此次我設定了預設值為20,所以應該會生成像煤炭一樣大的礦脈。
此外,我設定了可接受的值範圍為1~1000000,但目前除了預設值外並沒有進行任何改變,
所以biwako_ore_chance變數總是存儲著20。
実際のワールドには、この値を最大値としたランダムな個数の鉱脈が生成されるようになっています。
生成超界
在游戏的设置中,可以选择是否在超界生成矿石。
OreGeneration
源代码
package jp.yuyu.biwako_mod.world;
import jp.yuyu.biwako_mod.BiwakoMod;
import jp.yuyu.biwako_mod.config.OregenConfig;
import jp.yuyu.biwako_mod.lists.BlockList;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.registries.ForgeRegistries;
public class OreGeneration {
public static void setupOreGeneration() {
if (OregenConfig.generate_overworld.get()) {
for (Biome biome : ForgeRegistries.BIOMES) {
biome.addFeature(
GenerationStage.Decoration.UNDERGROUND_ORES,
Biome.createDecoratedFeature(
Feature.ORE,
new OreFeatureConfig(
OreFeatureConfig.FillerBlockType.NATURAL_STONE,
BlockList.BiwakoOre.getDefaultState(),
OregenConfig.biwako_ore_chance.get()),
Placement.COUNT_RANGE,
new CountRangeConfig(10, 20, 0, 100)));
biome.addFeature(
GenerationStage.Decoration.UNDERGROUND_ORES,
Biome.createDecoratedFeature(
Feature.ORE,
new OreFeatureConfig(
OreFeatureConfig.FillerBlockType.NETHERRACK,
BlockList.BiwakoQuartzOre.getDefaultState(),
OregenConfig.biwako_ore_chance.get()),
Placement.COUNT_RANGE,
new CountRangeConfig(10, 20, 0, 100)));
}
}
}
}
说明
全部のバイオーム(Forest,River,Nezer,The End,…)を取得し、それぞれのバイオームに鉱石を生成させるようにします。
我将解释addFeature方法的功能。
- 第1引数 Decoration decorationStage
バイオームに追加する特徴のタイプ。地下の鉱石以外にも地上の建造物、地下の建造物などがある。
今回は、GenerationStage.Decoration.UNDERGROUND_ORESで地下の鉱石を追加する。
- 第2引数 ConfiguredFeature<?> featureIn
具体的な鉱石の特徴を設定する。
OreFeatureConfig.FillerBlockType.NATURAL_STONEで鉱石の周りには、
自然のブロック(石・安山岩,…)で埋め尽くされて生成されます。
その後に洞窟が生成されるから、問題ないのかな?
设置块的状态,该状态在使用BlockList.BiwakoOre.getDefaultState()生成时设置。
我们获取并设置了默认状态。
通过OregenConfig.biwako_ore_chance.get()函数,可以设置每个矿脉生成的矿石数量。
Placement.COUNT_RANGEは調査中です、よくわかっていません
CountRangeConfig(10, 20, 0, 100))で、生成される高さ、鉱脈の個数を設定している気がします。
第1引数:count,第2引数:bottomOffset,第3引数:topOffset,第4引数:maximumです。
第4引数生成されるy座標の最大値を表していることだけ分かりましたが、
それ以外の値がどう影響してくるのかは現在調査中です。
调用矿石生成方法
最后,在BiwakoMod.java的setup()方法中调用生成矿石的设置方法。
private void setup(final FMLCommonSetupEvent event) {
OreGeneration.setupOreGeneration();
LOGGER.info("HELLO FROM PREINIT");
}
启动Minecraft

我在Github上公开了项目。