Jump to content

can you make EntityType RegistryObject


PlainPlaying

Recommended Posts

I am trying to make a spawn egg that spawns the wither, I am using a custom ModSpawnEggItem class:
 

package com.plainplaying.test.items;

import io.netty.handler.codec.http2.Http2FrameLogger;
import net.minecraft.block.DispenserBlock;
import net.minecraft.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ModSpawnEggItem extends SpawnEggItem {
    protected static final List<ModSpawnEggItem> UNADDED_EGGS = new ArrayList<>();
    private final Lazy<? extends EntityType<?>> entityTypeSupplier;
    public ModSpawnEggItem(final RegistryObject<? extends EntityType<?>> entityTypeSupplier, int primaryColorIn, int secondaryColorIn, Properties builder) {
        super(null, primaryColorIn, secondaryColorIn, builder);
        this.entityTypeSupplier = Lazy.of(entityTypeSupplier::get);
        UNADDED_EGGS.add(this);
    }

    public static void initSpawnEggs(){
        final Map<EntityType<?>, SpawnEggItem> EGGS = ObfuscationReflectionHelper.getPrivateValue(SpawnEggItem.class, null, "field_195987_b");
        DefaultDispenseItemBehavior dispenseBehavior = new DefaultDispenseItemBehavior() {
            @Override
            protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
                Direction direction = source.getBlockState().get(DispenserBlock.FACING);
                EntityType<?> type = ((SpawnEggItem) stack.getItem()).getType(stack.getTag());
                if (direction == Direction.WEST){
                    type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(-1,0,0), SpawnReason.DISPENSER,direction!= Direction.UP, false);
                }
                else if (direction == Direction.EAST){
                    type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(1,0,0), SpawnReason.DISPENSER,direction!= Direction.UP, false);
                }
                else if (direction == Direction.NORTH){
                    type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(0,0,-1), SpawnReason.DISPENSER,direction!= Direction.UP, false);
                }
                else if (direction == Direction.SOUTH){
                    type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(0,0,1), SpawnReason.DISPENSER,true, false);
                }
                else if (direction == Direction.DOWN){
                    type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(0,-1,0), SpawnReason.DISPENSER,true, false);
                }else{
                    type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(0,1,0), SpawnReason.DISPENSER,true, false);
                }
                stack.shrink(1);
                return stack;
            }
        };

        for (final SpawnEggItem spawnEgg : UNADDED_EGGS){
            EGGS.put(spawnEgg.getType(null), spawnEgg);
            DispenserBlock.registerDispenseBehavior(spawnEgg, dispenseBehavior);
        }
        UNADDED_EGGS.clear();
    }

    @Override
    public EntityType<?> getType(CompoundNBT nbt) {
        return this.entityTypeSupplier.get();
    }
}

I am creating the spawn egg like this:
 

public static final RegistryObject<SpawnEggItem> WITHER_SPAWN_EGG = ITEMS.register("wither_spawn_egg",
            () -> new ModSpawnEggItem(EntityType.WITHER, 0xF1BF7B, 0x705128,new Item.Properties().group(TestMod.TAB)));

and I get an error saying that I need an RegistryObject instead of EntityType, and I understand why, but I don't know how to fix. I want it to work with registry object, so i though maybe I can use .get() on the registry object, but I don't know how to make ModSpawnEggItem be compatible with EntityType, Can somone help me?

Link to comment
Share on other sites

I personally would juggle the code so that it takes in an entity type instead as I don't think it's possible to access the wither's registry object as it were (I could be wrong though). If you want to have other instances of a class take in a registry object, you could always use .get() when calling the constructor or even have an overloaded constructer that takes in a registry object and calls .get() on it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Add the full crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here
    • [10:43:34] [Datafixer Bootstrap/INFO]: 237 Datafixer optimizations took 430 milliseconds [10:43:38] [Render thread/INFO]: Environment: Environment[sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD] [10:43:38] [Render thread/INFO]: Setting user: InfexionX [10:43:38] [Render thread/INFO]: Backend library: LWJGL version 3.3.3+5 [10:43:39] [Render thread/INFO]: Reloading ResourceManager: vanilla [10:43:39] [Worker-Main-7/INFO]: Found unifont_all_no_pua-15.1.05.hex, loading [10:43:39] [Worker-Main-3/INFO]: Found unifont_jp_patch-15.1.05.hex, loading [10:43:40] [Render thread/WARN]: Missing sound for event: minecraft:block.spawner.fall [10:43:40] [Render thread/INFO]: OpenAL initialized on device OpenAL Soft on Headphones (High Definition Audio Device) [10:43:40] [Render thread/INFO]: Sound engine started [10:43:40] [Render thread/INFO]: Created: 1024x512x4 minecraft:textures/atlas/blocks.png-atlas [10:43:40] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/signs.png-atlas [10:43:40] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/banner_patterns.png-atlas [10:43:40] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/shield_patterns.png-atlas [10:43:40] [Render thread/INFO]: Created: 1024x1024x4 minecraft:textures/atlas/armor_trims.png-atlas [10:43:40] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/chest.png-atlas [10:43:40] [Render thread/INFO]: Created: 128x64x4 minecraft:textures/atlas/decorated_pot.png-atlas [10:43:40] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/shulker_boxes.png-atlas [10:43:40] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/beds.png-atlas [10:43:40] [Render thread/INFO]: Created: 64x64x0 minecraft:textures/atlas/map_decorations.png-atlas [10:43:40] [Render thread/INFO]: Created: 512x256x0 minecraft:textures/atlas/particles.png-atlas [10:43:40] [Render thread/INFO]: Created: 512x256x0 minecraft:textures/atlas/paintings.png-atlas [10:43:40] [Render thread/INFO]: Created: 256x128x0 minecraft:textures/atlas/mob_effects.png-atlas [10:43:40] [Render thread/INFO]: Created: 1024x512x0 minecraft:textures/atlas/gui.png-atlas [10:44:16] [Render thread/INFO]: Stopping!
    • ive added theoneprobe, crashed. i removed ascended quark and it works. make it make sense.    thank you, TileEntity and please know i only had the courage to post here for help because i kept seeing how useful you are to everyone else so i am super glad you were the one to help me. thanks a lot!
    • Yes - looks like arsmagicalegacy requires this mod Or it is an issue with ascended_quark
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.