Search in sources :

Example 1 with RegistryObject

use of net.minecraftforge.fml.RegistryObject in project Structurize by ldtteam.

the class IBlockCollection method create.

/**
 * Constructs and registers each block in the collection
 * See interface comments for the preferred content.
 * @param registrar the DeferredRegistry instance to apply the block to
 * @param itemRegistrar the DeferredRegistry instance to apply the item to
 * @param group the item group (or creative tab) to place this block in
 * @param creationListener gets fired for each block being registered with specific block type, used for client rendering register
 * @param types a selection of each block type that is part of the collection
 * @return each registered block in the collection
 */
default List<RegistryObject<Block>> create(DeferredRegister<Block> registrar, DeferredRegister<Item> itemRegistrar, ItemGroup group, BiConsumer<BlockType, RegistryObject<Block>> creationListener, BlockType... types) {
    List<RegistryObject<Block>> results = new LinkedList<>();
    for (BlockType type : types) {
        // J9+ has incompatibilities with J8-compiled default interfaces that use lambda generated suppliers.
        // Do not replace the anonymous suppliers below with a lambda.
        RegistryObject<Block> block = registrar.register(type.withSuffix(getName(), getPluralName()), new Supplier<Block>() {

            @Override
            public Block get() {
                return type.constructor.apply(getProperties());
            }
        });
        itemRegistrar.register(type.withSuffix(getName(), getPluralName()), new Supplier<Item>() {

            @Override
            public Item get() {
                return new BlockItem(block.get(), new Item.Properties().tab(group));
            }
        });
        creationListener.accept(type, block);
        results.add(block);
    }
    return results;
}
Also used : Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) RegistryObject(net.minecraftforge.fml.RegistryObject) BlockItem(net.minecraft.item.BlockItem) LinkedList(java.util.LinkedList)

Example 2 with RegistryObject

use of net.minecraftforge.fml.RegistryObject in project ResourcefulBees by Resourceful-Bees.

the class RegistryHandler method registerBee.

private static void registerBee(String name, float sizeModifier) {
    final RegistryObject<EntityType<? extends CustomBeeEntity>> customBeeEntity = ENTITY_TYPES.register(name + "_bee", () -> EntityType.Builder.<ResourcefulBee>of((type, world) -> new ResourcefulBee(type, world, name), ModConstants.BEE_MOB_CATEGORY).sized(0.7F * sizeModifier, 0.6F * sizeModifier).build(name + "_bee"));
    ModItems.ITEMS.register(name + "_bee_spawn_egg", () -> new BeeSpawnEggItem(customBeeEntity, 0xffcc33, 0x303030, name, new Item.Properties().tab(ItemGroupResourcefulBees.RESOURCEFUL_BEES)));
    ModEntities.getModBees().put(name, customBeeEntity);
}
Also used : EntityType(net.minecraft.world.entity.EntityType) JsonObject(com.google.gson.JsonObject) Config(com.teamresourceful.resourcefulbees.config.Config) ShearsDispenserBehavior(com.teamresourceful.resourcefulbees.item.dispenser.ShearsDispenserBehavior) Items(net.minecraft.world.item.Items) RegistryObject(net.minecraftforge.fml.RegistryObject) HoneycombType(com.teamresourceful.resourcefulbees.lib.enums.HoneycombType) EntityType(net.minecraft.world.entity.EntityType) CustomBeeEntity(com.teamresourceful.resourcefulbees.entity.passive.CustomBeeEntity) Item(net.minecraft.world.item.Item) HashMap(java.util.HashMap) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) IEventBus(net.minecraftforge.eventbus.api.IEventBus) ForgeFlowingFluid(net.minecraftforge.fluids.ForgeFlowingFluid) JsonOps(com.mojang.serialization.JsonOps) FMLJavaModLoadingContext(net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext) DispenserBlockInvoker(com.teamresourceful.resourcefulbees.mixin.DispenserBlockInvoker) CustomHoneyFluid(com.teamresourceful.resourcefulbees.fluids.CustomHoneyFluid) EntityAttributeCreationEvent(net.minecraftforge.event.entity.EntityAttributeCreationEvent) HoneycombData(com.teamresourceful.resourcefulbees.api.beedata.HoneycombData) HoneyBottleData(com.teamresourceful.resourcefulbees.api.honeydata.HoneyBottleData) MobCategory(net.minecraft.world.entity.MobCategory) Map(java.util.Map) CustomHoneyBottleItem(com.teamresourceful.resourcefulbees.item.CustomHoneyBottleItem) ResourcefulBee(com.teamresourceful.resourcefulbees.entity.passive.ResourcefulBee) SoundEvents(net.minecraft.sounds.SoundEvents) BlockBehaviour(net.minecraft.world.level.block.state.BlockBehaviour) CustomHoneyFluidBlock(com.teamresourceful.resourcefulbees.block.CustomHoneyFluidBlock) ScraperDispenserBehavior(com.teamresourceful.resourcefulbees.item.dispenser.ScraperDispenserBehavior) CustomHoneyBlock(com.teamresourceful.resourcefulbees.block.CustomHoneyBlock) HoneyFluidAttributes(com.teamresourceful.resourcefulbees.fluids.HoneyFluidAttributes) BlockItem(net.minecraft.world.item.BlockItem) HoneycombBlock(com.teamresourceful.resourcefulbees.block.HoneycombBlock) DeferredRegister(net.minecraftforge.registries.DeferredRegister) Material(net.minecraft.world.level.material.Material) Blocks(net.minecraft.world.level.block.Blocks) DispenserBlock(net.minecraft.world.level.block.DispenserBlock) FlowingFluid(net.minecraft.world.level.material.FlowingFluid) CustomHoneyBucketItem(com.teamresourceful.resourcefulbees.item.CustomHoneyBucketItem) BeeSpawnEggItem(com.teamresourceful.resourcefulbees.item.BeeSpawnEggItem) ResourcefulBees(com.teamresourceful.resourcefulbees.ResourcefulBees) Block(net.minecraft.world.level.block.Block) ItemStack(net.minecraft.world.item.ItemStack) HoneycombItem(com.teamresourceful.resourcefulbees.item.HoneycombItem) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) ModConstants(com.teamresourceful.resourcefulbees.lib.constants.ModConstants) BeeSpawnEggItem(com.teamresourceful.resourcefulbees.item.BeeSpawnEggItem) Item(net.minecraft.world.item.Item) CustomHoneyBottleItem(com.teamresourceful.resourcefulbees.item.CustomHoneyBottleItem) BlockItem(net.minecraft.world.item.BlockItem) CustomHoneyBucketItem(com.teamresourceful.resourcefulbees.item.CustomHoneyBucketItem) BeeSpawnEggItem(com.teamresourceful.resourcefulbees.item.BeeSpawnEggItem) HoneycombItem(com.teamresourceful.resourcefulbees.item.HoneycombItem) CustomBeeEntity(com.teamresourceful.resourcefulbees.entity.passive.CustomBeeEntity) ResourcefulBee(com.teamresourceful.resourcefulbees.entity.passive.ResourcefulBee)

Example 3 with RegistryObject

use of net.minecraftforge.fml.RegistryObject in project trofers by ochotonida.

the class LootTables method addBlockLootTables.

private void addBlockLootTables() {
    CopyNbt.Builder copyNbtBuilder = CopyNbt.copyData(CopyNbt.Source.BLOCK_ENTITY).copy("Trophy", "BlockEntityTag.Trophy");
    for (RegistryObject<TrophyBlock> trophy : ModBlocks.TROPHIES) {
        ResourceLocation location = new ResourceLocation(Trofers.MODID, "blocks/" + trophy.getId().getPath());
        LootTable.Builder lootTable = LootTable.lootTable().withPool(LootPool.lootPool().add(ItemLootEntry.lootTableItem(trophy.get()).apply(copyNbtBuilder)));
        lootTables.add(Pair.of(() -> builder -> builder.accept(location, lootTable), LootParameterSets.BLOCK));
    }
}
Also used : LootTableProvider(net.minecraft.data.LootTableProvider) CopyNbt(net.minecraft.loot.functions.CopyNbt) RegistryObject(net.minecraftforge.fml.RegistryObject) ModBlocks(trofers.common.init.ModBlocks) VanillaLootTables(trofers.data.loottables.VanillaLootTables) net.minecraft.loot(net.minecraft.loot) Supplier(java.util.function.Supplier) Pair(com.mojang.datafixers.util.Pair) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) LootTableBuilder(trofers.data.loottables.LootTableBuilder) List(java.util.List) Map(java.util.Map) ResourceLocation(net.minecraft.util.ResourceLocation) BiConsumer(java.util.function.BiConsumer) TrophyBlock(trofers.common.block.TrophyBlock) DataGenerator(net.minecraft.data.DataGenerator) Trofers(trofers.Trofers) CopyNbt(net.minecraft.loot.functions.CopyNbt) ResourceLocation(net.minecraft.util.ResourceLocation) TrophyBlock(trofers.common.block.TrophyBlock)

Example 4 with RegistryObject

use of net.minecraftforge.fml.RegistryObject in project Wings by pau101.

the class Proxy method setup.

protected void setup(FMLCommonSetupEvent event) {
    CapabilityManager.INSTANCE.register(Flight.class, SimpleStorage.ofVoid(), FlightDefault::new);
    CapabilityManager.INSTANCE.register(InSomniable.class, SimpleStorage.ofVoid(), InSomniable::new);
    event.enqueueWork(() -> {
        BiConsumer<IItemProvider, RegistryObject<Item>> reg = (item, obj) -> {
            BrewingRecipeRegistry.addRecipe(new PotionMix(Potions.SLOW_FALLING, Ingredient.of(item), new ItemStack(obj.get())));
            BrewingRecipeRegistry.addRecipe(new PotionMix(Potions.LONG_SLOW_FALLING, Ingredient.of(item), new ItemStack(obj.get())));
        };
        reg.accept(Items.FEATHER, WingsItems.ANGEL_WINGS_BOTTLE);
        reg.accept(Items.RED_DYE, WingsItems.PARROT_WINGS_BOTTLE);
        reg.accept(WingsItems.BAT_BLOOD_BOTTLE.get(), WingsItems.BAT_WINGS_BOTTLE);
        reg.accept(Items.BLUE_DYE, WingsItems.BLUE_BUTTERFLY_WINGS_BOTTLE);
        reg.accept(Items.LEATHER, WingsItems.DRAGON_WINGS_BOTTLE);
        reg.accept(Items.BONE, WingsItems.EVIL_WINGS_BOTTLE);
        reg.accept(Items.OXEYE_DAISY, WingsItems.FAIRY_WINGS_BOTTLE);
        reg.accept(Items.BLAZE_POWDER, WingsItems.FIRE_WINGS_BOTTLE);
        reg.accept(Items.ORANGE_DYE, WingsItems.MONARCH_BUTTERFLY_WINGS_BOTTLE);
        reg.accept(Items.SLIME_BALL, WingsItems.SLIME_WINGS_BOTTLE);
    });
}
Also used : FlightDefault(me.paulf.wings.server.flight.FlightDefault) SimpleStorage(me.paulf.wings.util.SimpleStorage) PotionMix(me.paulf.wings.server.potion.PotionMix) Ingredient(net.minecraft.item.crafting.Ingredient) RegistryObject(net.minecraftforge.fml.RegistryObject) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Item(net.minecraft.item.Item) Potions(net.minecraft.potion.Potions) CapabilityManager(net.minecraftforge.common.capabilities.CapabilityManager) Items(net.minecraft.item.Items) MessageSyncFlight(me.paulf.wings.server.net.clientbound.MessageSyncFlight) IEventBus(net.minecraftforge.eventbus.api.IEventBus) WingsItems(me.paulf.wings.server.item.WingsItems) ItemStack(net.minecraft.item.ItemStack) IItemProvider(net.minecraft.util.IItemProvider) FMLCommonSetupEvent(net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent) Flight(me.paulf.wings.server.flight.Flight) FlightDefault(me.paulf.wings.server.flight.FlightDefault) BiConsumer(java.util.function.BiConsumer) Network(me.paulf.wings.server.net.Network) BrewingRecipeRegistry(net.minecraftforge.common.brewing.BrewingRecipeRegistry) InSomniable(me.paulf.wings.server.dreamcatcher.InSomniable) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) InSomniable(me.paulf.wings.server.dreamcatcher.InSomniable) IItemProvider(net.minecraft.util.IItemProvider) RegistryObject(net.minecraftforge.fml.RegistryObject) ItemStack(net.minecraft.item.ItemStack) PotionMix(me.paulf.wings.server.potion.PotionMix)

Example 5 with RegistryObject

use of net.minecraftforge.fml.RegistryObject in project relics by SSKirillSS.

the class ItemRegistry method syncItemLists.

public static void syncItemLists() {
    registeredRelics = ITEMS.getEntries().stream().filter(RegistryObject::isPresent).map(RegistryObject::get).filter(item -> item instanceof RelicItem).map(item -> (RelicItem<?>) item).collect(Collectors.toList());
    registeredRunes = ITEMS.getEntries().stream().filter(RegistryObject::isPresent).map(RegistryObject::get).filter(item -> item instanceof RuneItem).map(item -> (RuneItem) item).collect(Collectors.toList());
    slotModifiers = ForgeRegistries.ITEMS.getEntries().stream().map(Map.Entry::getValue).filter(entry -> entry instanceof RelicItem).map(item -> (RelicItem<?>) item).filter(relic -> relic.getSlotModifiers(new ItemStack(relic)) != null).filter(relic -> !relic.getSlotModifiers(new ItemStack(relic)).getModifiers().isEmpty()).collect(Collectors.toList());
    attributeModifiers = ForgeRegistries.ITEMS.getEntries().stream().map(Map.Entry::getValue).filter(entry -> entry instanceof RelicItem).map(item -> (RelicItem<?>) item).filter(relic -> relic.getAttributeModifiers(new ItemStack(relic)) != null).filter(relic -> !relic.getAttributeModifiers(new ItemStack(relic)).getAttributes().isEmpty()).collect(Collectors.toList());
}
Also used : RegistryObject(net.minecraftforge.fml.RegistryObject) Getter(lombok.Getter) Item(net.minecraft.item.Item) HunterBeltItem(it.hurts.sskirillss.relics.items.relics.belt.HunterBeltItem) it.hurts.sskirillss.relics.items.relics(it.hurts.sskirillss.relics.items.relics) SquireBagItem(it.hurts.sskirillss.relics.items.relics.back.SquireBagItem) LeatherBeltItem(it.hurts.sskirillss.relics.items.relics.belt.LeatherBeltItem) ArrayList(java.util.ArrayList) FMLJavaModLoadingContext(net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext) ItemStack(net.minecraft.item.ItemStack) ElytraBoosterItem(it.hurts.sskirillss.relics.items.relics.back.ElytraBoosterItem) Reference(it.hurts.sskirillss.relics.utils.Reference) MidnightRobeItem(it.hurts.sskirillss.relics.items.relics.back.MidnightRobeItem) Map(java.util.Map) HolyLocketItem(it.hurts.sskirillss.relics.items.relics.necklace.HolyLocketItem) Mod(net.minecraftforge.fml.common.Mod) DelayRingItem(it.hurts.sskirillss.relics.items.relics.ring.DelayRingItem) BastionRingItem(it.hurts.sskirillss.relics.items.relics.ring.BastionRingItem) CamouflageRingItem(it.hurts.sskirillss.relics.items.relics.ring.CamouflageRingItem) it.hurts.sskirillss.relics.items.relics.talisman(it.hurts.sskirillss.relics.items.relics.talisman) DrownedBeltItem(it.hurts.sskirillss.relics.items.relics.belt.DrownedBeltItem) ReflectionNecklaceItem(it.hurts.sskirillss.relics.items.relics.necklace.ReflectionNecklaceItem) RageGloveItem(it.hurts.sskirillss.relics.items.relics.hands.RageGloveItem) ArrowQuiverItem(it.hurts.sskirillss.relics.items.relics.back.ArrowQuiverItem) it.hurts.sskirillss.relics.items.runes(it.hurts.sskirillss.relics.items.runes) DeferredRegister(net.minecraftforge.registries.DeferredRegister) Collectors(java.util.stream.Collectors) WoolMittenItem(it.hurts.sskirillss.relics.items.relics.hands.WoolMittenItem) List(java.util.List) FragrantFlowerItem(it.hurts.sskirillss.relics.items.relics.head.FragrantFlowerItem) it.hurts.sskirillss.relics.items(it.hurts.sskirillss.relics.items) RelicItem(it.hurts.sskirillss.relics.items.relics.base.RelicItem) JellyfishNecklaceItem(it.hurts.sskirillss.relics.items.relics.necklace.JellyfishNecklaceItem) SpiderNecklaceItem(it.hurts.sskirillss.relics.items.relics.necklace.SpiderNecklaceItem) it.hurts.sskirillss.relics.items.relics.feet(it.hurts.sskirillss.relics.items.relics.feet) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) EndersHandItem(it.hurts.sskirillss.relics.items.relics.hands.EndersHandItem) RelicItem(it.hurts.sskirillss.relics.items.relics.base.RelicItem) RegistryObject(net.minecraftforge.fml.RegistryObject) ItemStack(net.minecraft.item.ItemStack)

Aggregations

RegistryObject (net.minecraftforge.fml.RegistryObject)9 ResourceLocation (net.minecraft.util.ResourceLocation)4 Map (java.util.Map)3 Item (net.minecraft.item.Item)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BiConsumer (java.util.function.BiConsumer)2 Supplier (java.util.function.Supplier)2 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 JsonObject (com.google.gson.JsonObject)1 Pair (com.mojang.datafixers.util.Pair)1 JsonOps (com.mojang.serialization.JsonOps)1 ResourcefulBees (com.teamresourceful.resourcefulbees.ResourcefulBees)1 HoneycombData (com.teamresourceful.resourcefulbees.api.beedata.HoneycombData)1 HoneyBottleData (com.teamresourceful.resourcefulbees.api.honeydata.HoneyBottleData)1 CustomHoneyBlock (com.teamresourceful.resourcefulbees.block.CustomHoneyBlock)1 CustomHoneyFluidBlock (com.teamresourceful.resourcefulbees.block.CustomHoneyFluidBlock)1 HoneycombBlock (com.teamresourceful.resourcefulbees.block.HoneycombBlock)1 Config (com.teamresourceful.resourcefulbees.config.Config)1