真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Minecraft1.19.2Forge模組開發(fā)05.礦石生成-創(chuàng)新互聯(lián)

我們本次嘗試在主世界生成模組中自定義的礦石 1.由于1.19的版本出現(xiàn)了深板巖層的礦石,我們要在BlockInit類中聲明一個礦石的兩種巖層形態(tài):

BlockInit.java

創(chuàng)新互聯(lián)是專業(yè)的木壘哈薩克網(wǎng)站建設(shè)公司,木壘哈薩克接單;提供成都網(wǎng)站制作、成都網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行木壘哈薩克網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
package com.joy187.re8joymod.init;

import com.joy187.re8joymod.Main;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.StainedGlassBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.util.function.Function;
import java.util.function.Supplier;

public class BlockInit {public static DeferredRegisterBLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Main.MOD_ID);
    public static final DeferredRegisterITEMS = ItemInit.ITEMS;

    //普通礦石,UniformInt.of(a,b)意思是該礦石挖掘后獎勵多少經(jīng)驗,范圍在[a,b]
    public static final RegistryObjectFANTOM_ORE = registerBlock("fantom_ore",
            () ->new DropExperienceBlock(BlockBehaviour.Properties.of(Material.STONE)
                    .strength(5f).requiresCorrectToolForDrops(), UniformInt.of(3, 10)), Main.TUTORIAL_TAB);
    
    //深板巖礦石
    public static final RegistryObjectDEEPSLATE_FANTOM_ORE = registerBlock("deepslate_fantom_ore",
            () ->new Block(BlockBehaviour.Properties.of(Material.STONE)
                    .strength(7f).requiresCorrectToolForDrops()), Main.TUTORIAL_TAB);


    private staticRegistryObjectregisterBlock(final String name,
                                                                     final Supplierblock) {return BLOCKS.register(name, block);
    }

    private staticRegistryObjectregister(final String name, final Supplierblock,
                                                                Function, Supplier>item) {RegistryObjectobj = registerBlock(name, block);
        ITEMS.register(name, item.apply(obj));
        return obj;
    }

    private staticRegistryObjectregisterBlock(String name, Supplierblock, CreativeModeTab tab) {RegistryObjecttoReturn = BLOCKS.register(name, block);
        registerBlockItem(name, toReturn, tab);
        return toReturn;
    }

    private staticRegistryObjectregisterBlockItem(String name, RegistryObjectblock,
                                                                            CreativeModeTab tab) {return ItemInit.ITEMS.register(name, () ->new BlockItem(block.get(),
                new Item.Properties().tab(tab)));
    }

    private staticRegistryObjectregisterBlockWithoutBlockItem(String name, Supplierblock) {return BLOCKS.register(name, block);
    }

    public static SuppliercreateStainedGlassFromColor(DyeColor color) {return () ->new StainedGlassBlock(color, BlockBehaviour.Properties.of(Material.GLASS, color).strength(0.3F)
                .sound(SoundType.GLASS).noOcclusion().isValidSpawn(BlockInit::never).isRedstoneConductor(BlockInit::never).isSuffocating(BlockInit::never).isViewBlocking(BlockInit::never));
    }

    public static boolean always(BlockState state, BlockGetter reader, BlockPos pos) {return true;
    }

    public static boolean never(BlockState state, BlockGetter reader, BlockPos pos) {return false;
    }

    public static boolean always(BlockState state, BlockGetter reader, BlockPos pos, EntityTypeentityType) {return true;
    }

    public static boolean never(BlockState state, BlockGetter reader, BlockPos pos, EntityTypeentityType) {return false;
    }
}
之后參考Minecraft 1.19.2 Forge模組開發(fā) 02.物品欄+方塊+物品將兩個方塊制作出來。 2.準備好了方塊,下一步就是定義其生成的內(nèi)容了。在Java包中新建一個world包->world包中新建一個feature包->feature包中分別新建三個類ModConfiguredFeatures,ModOrePlacement,ModPlacedFeatures

crr.jpg

首先是我們的礦石擺放類:

ModOrePlacement.java

package com.joy187.re8joymod.world.feature;

import net.minecraft.world.level.levelgen.placement.*;

import java.util.List;

public class ModOrePlacement {//默認礦石擺放
    public static ListorePlacement(PlacementModifier p_195347_, PlacementModifier p_195348_) {return List.of(p_195347_, InSquarePlacement.spread(), p_195348_, BiomeFilter.biome());
    }
    
    //普通礦石擺放
    public static ListcommonOrePlacement(int p_195344_, PlacementModifier p_195345_) {return orePlacement(CountPlacement.of(p_195344_), p_195345_);
    }
    
    //稀有礦石擺放
    public static ListrareOrePlacement(int p_195350_, PlacementModifier p_195351_) {return orePlacement(RarityFilter.onAverageOnceEvery(p_195350_), p_195351_);
    }

}
其次是我們的礦石生成定義類ModPlacedFeatures

ModPlacedFeatures.java

package com.joy187.re8joymod.world.feature;

import com.joy187.re8joymod.Main;
import net.minecraft.core.Registry;
import net.minecraft.world.level.levelgen.VerticalAnchor;
import net.minecraft.world.level.levelgen.placement.*;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import static com.joy187.re8joymod.world.feature.ModOrePlacement.commonOrePlacement;

public class ModPlacedFeatures {public static final DeferredRegisterPLACED_FEATURES =
            DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, Main.MOD_ID);

    //礦石擺放
    public static final RegistryObjectFANTOM_ORE_PLACED = PLACED_FEATURES.register("fantom_ore_placed",
            () ->new PlacedFeature(ModConfiguredFeatures.FANTOM_ORES.getHolder().get(),
                    commonOrePlacement(7, //每個區(qū)塊生成多少礦石
                            HeightRangePlacement.triangle(VerticalAnchor.aboveBottom(-60), VerticalAnchor.aboveBottom(60))))); //-60,60分別指礦石生成高度范圍介于[-60,60]



    public static void register(IEventBus eventBus) {PLACED_FEATURES.register(eventBus);
    }

}
最后是礦石生成配置類ModConfiguredFeatures

ModConfiguredFeatures.java

package com.joy187.re8joymod.world.feature;

import com.google.common.base.Suppliers;
import com.joy187.re8joymod.Main;
import com.joy187.re8joymod.init.BlockInit;
import net.minecraft.core.Registry;
import net.minecraft.data.worldgen.features.OreFeatures;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.*;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import java.util.List;
import java.util.function.Supplier;


public class ModConfiguredFeatures {public static final DeferredRegister>CONFIGURED_FEATURES =
            DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, Main.MOD_ID);

    //將我們第一步的兩種礦石分別填入其中
    public static final Supplier>OVERWORLD_FANTOM_ORES = Suppliers.memoize(() ->List.of(
            OreConfiguration.target(OreFeatures.STONE_ORE_REPLACEABLES, BlockInit.FANTOM_ORE.get().defaultBlockState()), //普通巖層
            OreConfiguration.target(OreFeatures.DEEPSLATE_ORE_REPLACEABLES, BlockInit.DEEPSLATE_FANTOM_ORE.get().defaultBlockState()))); //深板巖層

    //將這種礦石生成類型進行注冊
    public static final RegistryObject>FANTOM_ORES = CONFIGURED_FEATURES.register("fantom_ore",
            () ->new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(OVERWORLD_FANTOM_ORES.get(),7)));

    public static void register(IEventBus eventBus) {CONFIGURED_FEATURES.register(eventBus);
    }

}
3.在項目主類中添加我們礦石生成配置類和礦石生成定義類的注冊事件:
public Main()
    {IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
        bus.addListener(this::commonSetup);
        bus.addListener(this::setup);
        bus.addListener(this::clientSetup);
        ItemInit.ITEMS.register(bus);
        BlockInit.BLOCKS.register(bus);
        EntityInit.ENTITY_TYPES.register(bus);
        
        //添加這兩個
        ModConfiguredFeatures.register(bus);
        ModPlacedFeatures.register(bus);

        MinecraftForge.EVENT_BUS.register(this);
    }
4.代碼部分結(jié)束,之后需要在數(shù)據(jù)包中添加礦石生成的內(nèi)容

crt.jpg

在數(shù)據(jù)包中新建forge包,forge包中新建biome_modifier包->biome_modifier包中新建礦石生成文件add_fantom_ore,在features中填入我們在ModPlacedFeatures類中定義的名稱:

add_fantom_ore.json

{"type": "forge:add_features",
  "biomes": "#minecraft:is_overworld",
  "features": "re8joymod:fantom_ore_placed",
  "step": "underground_ores"
}
5.保存所有設(shè)置,進入游戲: 我們新建一個存檔,之后查看是否能找到模組中的礦石:

ore.png

成功在深板巖層發(fā)現(xiàn)了礦石!

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧


當(dāng)前標題:Minecraft1.19.2Forge模組開發(fā)05.礦石生成-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://weahome.cn/article/cdpojs.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部