提供: Minecraft Modding Wiki
移動先: 案内検索
(ページを作成)
 
42行目: 42行目:
 
     }
 
     }
  
 +
    protected void genSampleOre(World world, int worldX, int worldZ, int size, WorldGenerator generator, int minY, int maxY, Random rand) {
 +
        int l;
  
 +
        if (maxY < minY) {
 +
            l = minY;
 +
            minY = maxY;
 +
            maxY = l;
 +
        } else if (maxY == minY) {
 +
            if (minY < 255) {
 +
                ++maxY;
 +
            } else {
 +
                --minY;
 +
            }
 +
        }
 +
 +
        for (l = 0; l < size; ++l) {
 +
            int X = worldX + rnd.nextInt(16);
 +
            int Y = rnd.nextInt(maxY - minY) + minY;
 +
            int Z = worldZ + rnd.nextInt(16);
 +
 +
            generator.generate(world, rnd, X, Y, Z)
 +
        }
 +
    }
 
}
 
}
  
52行目: 74行目:
 
</source>
 
</source>
  
'''※編集途中です。このソースでは動きません。'''
+
'''※編集途中'''(SampleOre.java)'''です。このソースでは動きません。'''

2021年9月15日 (水) 11:40時点における版

この記事は"Minecraft Forge Universal 10.12.0.xxx~"を前提MODとしています。

Wood pickaxe.png
初心者向けのチュートリアルです。
C world.png
Worldに関係のあるチュートリアルです。


鉱石の生成

鉱石(ブロック)を自然生成します。 ブロックの追加は1.7のブロック追加を参照してください。

ソースコード

  • SampleOreGen.java
/*パッケージ、インポートは省略*/
@Mod(modid = SampleOreGen.MOD_ID, name = SampleOreGen.MOD_NAME, version = SampleOreGen.MOD_VERSION)
public class SampleOreGen {
    /*modid*/
    public static final String MOD_ID = "sampleoregen";
    /*modのバージョン*/
    public static final String MOD_VERSION = "1.0.0";
    /*modの名前*/
    public static final String MOD_NAME = "Sample Ore Gen";

    public static Block sample_ore;

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        sample_block = new SampleOre();

        GameRegistry.registerBlock(sample_ore, "sample_ore");
    }

    @EventHandler
    public void init(FMLInitializationEvent event) {
        MinecraftForge.ORE_GEN_BUS.register(this);
    }

    @SubscribeEvent
    public void generateOrePre(OreGenEvent.Pre event) {
        WorldGenerater sampleOreGen = new WorldGenMinable(SampleOreGen.sample_ore, 9);
        if (TerrainGen.generateOre(event.world, event.rand, sampleOreGen, event.worldX, event.worldZ, OreGenEvent.GenerateMinable.EventType.CUSTOM)) {
            genSampleOre(event.world, event.worldX, event.worldZ, 20, sampleOreGen, 0, 96, event.rand);
        }
    }

    protected void genSampleOre(World world, int worldX, int worldZ, int size, WorldGenerator generator, int minY, int maxY, Random rand) {
        int l;

        if (maxY < minY) {
            l = minY;
            minY = maxY;
            maxY = l;
        } else if (maxY == minY) {
            if (minY < 255) {
                ++maxY;
            } else {
                --minY;
            }
        }

        for (l = 0; l < size; ++l) {
            int X = worldX + rnd.nextInt(16);
            int Y = rnd.nextInt(maxY - minY) + minY;
            int Z = worldZ + rnd.nextInt(16);

            generator.generate(world, rnd, X, Y, Z)
        }
    }
}
  • SampleOre.java

※編集途中(SampleOre.java)です。このソースでは動きません。