Jump to content

[1.15.1] How to register a EntityType with the DeferredRegister


Recommended Posts

Posted (edited)
  On 1/31/2020 at 11:25 AM, DragonITA said:

Does the first parameter, the entity parameter, have to be or all three parameters?

Expand  

You should pass in null as the entity type as you’re going to override the getType method to return your one

  On 1/31/2020 at 11:25 AM, DragonITA said:

I still have not understood how to override the function.

Expand  

Just override “getType” like any other method. You can use an anonymous subclass if you want.

 

The only issue that I’ve found with this is that the spawn egg textures don’t get generated for your egg. I’m looking into this.

Edited by Cadiboo
  • Thanks 1

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

  • 1 month later...
Posted (edited)

If you still have problems with your SparnEgg, try this:

public class SupplierSpawnEggItem extends SpawnEggItem
{
    private RegistryObject<?> supplier;
    
    public SupplierSpawnEggItem(EntityType<?> typeIn, RegistryObject<?> supplierIn, int primaryColorIn, int secondaryColorIn, Properties builder)
    {
        super(typeIn, primaryColorIn, secondaryColorIn, builder);
        supplier = supplierIn;
    }
    
    @Override
    public EntityType<?> getType(CompoundNBT p_208076_1_)
    {
        return (EntityType<?>) supplier.get();
    }
}

This custom SpawnEgg-class works fine for me.

Textures and colors work too.

Edited by Drachenbauer
Posted (edited)

@DrachenbauerOk, for placing a entity you need a spawnegg. Cadiboo has make a method to create, register and use Spawnegggs but that are registered with the deferredregister. But the Problem with the DeferredRegister is that when you are trying to place the entity then the game crash and it say you that the RegistryObject was not found (RegistryObject = Your entity). This was caused because the egg was registered before the entity, so when you use the egg you spawn null and it cause a crash. Now the other part of the code is to make that when you use the Spawnegg, that you are sure that the entity was before registered, so that when you spawn it it not cause a game crash.

Edited by DragonITA

New in Modding? == Still learning!

Posted (edited)

My much slimmer code, that i posted above, can do that too.

 

Ad cadiboo´s version:

is there something about using spawneggs in a redstone-dispenser?

 

I just wonder, about this part:

        public static void initUnaddedEggs() {
		final Map<EntityType<?>, SpawnEggItem> EGGS = ObfuscationReflectionHelper.getPrivateValue(SpawnEggItem.class, null, "field_195987_b");
		DefaultDispenseItemBehavior defaultDispenseItemBehavior = new DefaultDispenseItemBehavior() {
			public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
				Direction direction = source.getBlockState().get(DispenserBlock.FACING);
				EntityType<?> entitytype = ((SpawnEggItem) stack.getItem()).getType(stack.getTag());
				entitytype.spawn(source.getWorld(), stack, null, source.getBlockPos().offset(direction), SpawnReason.DISPENSER, direction != Direction.UP, false);
				stack.shrink(1);
				return stack;
			}
		};
		for (final SpawnEggItem egg : UNADDED_EGGS) {
			EGGS.put(egg.getType(null), egg);
			DispenserBlock.registerDispenseBehavior(egg, defaultDispenseItemBehavior);
			// ItemColors for each spawn egg don't need to be registered because this method is called before ItemColors is created
		}
		UNADDED_EGGS.clear();
	}

 

I tested to put my egg into the dispenser, but only the egg came out.

 

But this happens with all my mod-ones, also the ones, that still are registered the old way, too...

 

Edit:

Now i got the new one to work in a dispenser.

Now i know, this method makes it able to spawn the entity out of the disbenser.

 

And for the two constructors:

When do you get an Entity type in a NonNullSupplier?

With DeferredRegister, you put them always into a RegistryObject.

 

And instead of using this thing called "Lazy", you also can put them into separate fields and use a boolean to choose one in the getType method.

The boolean is set to true in one constructor and false in the other.

 

Another question:

Why do the creators of minecraft never change the order of register entity and item?

 

Edit:

Now i modifyed the constructors a bit:

I removed the EntityType parameters from the constructor-headers and pass directly "null" to the superconstructor.

So i could remove the "null" from my registry lines for the eggs.

Edited by Drachenbauer

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Sorry for the late response, but the game opened and I made a world but it's stuck at 0% Here's the latest.log https://mclo.gs/peEb1R8 I disabled The Factory Must Grow and soulsweapons
    • Hey everyone! Two of my friends downloaded this modpack and are having an issue with the blocks loading in correctly. Grass looks like bamboo, waystones look like two barrels stacked on eachother, and wheat looks like water and stairs. What is this problem? How can we fix it? Neither of my other friends or myself had this issue. 
    • I removed Yung's cave biome mod and It wasnt in one of those biomes however the log file said the same line (([25Apr2025 21:20:15.500] [Flywheel Task Executor #5/WARN] [Embeddium-MixinTaintDetector/]: Mod(s) [oculus] are modifying Embeddium class me.jellysquid.mods.sodium.client.render.vertex.serializers.VertexSerializerRegistryImpl, which may cause instability.))
    • Note: i had a couple of ideas, but i just don't know how to execute them. The main idea was to make the new block (let's exemplify with a mixer) be essentially a clone of the mechanical mixer (different texture tho) that would have a different recipe type (instead of mixing, advanced_mixing) and i would copy all the create mod recipes and edit the processing time while also adding the tier dependent ones.
    • Hi! Before everything, thank you for even reading. I'm coming here in need of help making a few aspects for a create mod addon. It's an addon that aims to add almost the full periodic table with realistic ways of obtaining all the elements and capability of almost full automation. For what purpose? A techy armor and to go to the moon and rocky planets of the solar system. It'll have 3 different tiers of machines (mixer, millstone, crushing wheels): basic (just the normal create mod machines but renamed), advanced (25% faster and has recipes only possible for this tier and above) end elite (75% faster than basic and recipes only available for this tier). The problem is, I'm not a coder. I know less than the basics. I know how to do everything else but these machine tiers and i need some help if you can.
  • Topics

×
×
  • Create New...

Important Information

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