Jump to content

[1.15.2] Cannot use my registered entity types


Triphion

Recommended Posts

I have registered my entities using Deferred registries and it has been working fine until I tried to create a boss-summoning item. I have tried to use vanilla entities instead of my own entities and they work. But apparently, my own entities are being registered AFTER I register my items and blocks, but this should not be the case since I register my entities BEFORE my items and blocks. 

The error message states:

Quote

Encountered and error during the load_registries event phase. 

Registry Object not present. 

Which to me states that it cannot grab the entity since it hasn't been registered yet. 

		instance = this;
		
		final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
		
		modBus.addListener(this::commonSetup);
		modBus.addListener(this::clientSetup);
		
		EtauricEntities.ENTITIES.register(modBus);
		
		EtauricItems.ITEMS.register(modBus);
		EtauricBlocks.BLOCKS.register(modBus);
		
		EtauricBiomes.BIOMES.register(modBus);
		
		MinecraftForge.EVENT_BUS.register(this);

This is my Main Class. 

	public static final RegistryObject<Item> TERROR_FEEDER = ITEMS.register("terror_feeder", () -> new BossItem(new BossItem.BossProperties().setBoss(EtauricEntities.CHUPNUT.get()).setTooltip("A food source for a special water beast...")));

And this is the Item i'm trying to get to work. 

public class BossItem extends Item
{
	private final String tooltip;
	private final EntityType<? extends LivingEntity> boss;
	
	public BossItem(BossItem.BossProperties properties) 
	{
		super(properties.group(ItemGroup.MISC).maxStackSize(1));
		this.boss = properties.boss;
		this.tooltip = properties.toolTip;
	}
	
	@Override
	public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) 
	{
		if (this.tooltip != null) 
		{
			tooltip.add(new StringTextComponent("\u00A7e" + this.tooltip + "\u00A7e"));
		}
		
		tooltip.add(new StringTextComponent("\u00A76" + "Use this to summon " + this.boss.getName() + "\u00A76"));
	}
	
	public static class BossProperties extends Item.Properties
	{
		private String toolTip;
		private EntityType<? extends LivingEntity> boss;
		
		public BossItem.BossProperties setBoss(EntityType<? extends LivingEntity> boss) 
		{
			this.boss = boss;
			
			return this;
		}
		
		public BossItem.BossProperties setTooltip(String toolTip)
		{
			this.toolTip = toolTip;
			
			return this;
		}
	}
}

And lastly, this is the BossItem class. 

Edited by Triphion
Link to comment
Share on other sites

2 minutes ago, Triphion said:

EtauricEntities.ENTITIES.register(modBus);

EtauricItems.ITEMS.register(modBus);

EtauricBlocks.BLOCKS.register(modBus);

This is not actually registering stuff, so the order does not matter. This is registering the DeferredRegisters to the event bus, so that it can register your RegistryObjects at the correct time.

The only guarantee at this time for registration is that blocks are always first, items second, everything else in an assumed random order afterwards.

 

I have not tried doing anything like you are yet, but I would imagine that it will involve the use of a supplier to provide your entity type.

Link to comment
Share on other sites

Why doesn't this work? 

	public static final RegistryObject<Item> TERROR_FEEDER = ITEMS.register("terror_feeder", () -> new BossItem(new BossItem.BossProperties().setBoss(EtauricEntities.CHUPNUT).setTooltip("A food source for a special water beast...")));

It won't work unless i specifically say that the <?> entity is an entity chupnut...

		public BossItem.BossProperties setBoss(RegistryObject<EntityType<? extends LivingEntity>> boss) 
		{
			this.boss = boss.get();
			
			return this;
		}

I assume that this is what you meant by that?

47 minutes ago, diesieben07 said:

Store the RegistryObject (or just a Supplier, which RegistryObject implements) instead of the direct EntityType.

Edited by Triphion
Link to comment
Share on other sites

4 minutes ago, diesieben07 said:

Which errors? Where exactly?

Quote

The method setBoss(EntityType<? extends LivingEntity>) in the type BossItem.BossProperties is not applicable for the arguments (RegistryObject<EntityType<ChupnutEntity>>)

Quote

The method setBoss(RegistryObject<EntityType<? extends LivingEntity>>) in the type BossItem.BossProperties is not applicable for the arguments (RegistryObject<EntityType<ChupnutEntity>>)

On the setBoss method. 

And then it gives me 3 "quick fixes" that all involves I change either the chupnut to livingentity or that the method parameter be changed to chupnutentity. 

Edited by Triphion
Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

Generics are invariant by default. So if you want a RegistryObject<something> you need to pass exactly a RegistryObject<something>, not e.g. a RegistryObject<subclass of something>.

If you want to allow subclasses, you need to use RegistryObject<? extends something>. In your case: RegistryObject<? extends EntityType<? extends LivingEntity>>.

 

Yes, Java generics suck. Use Kotlin if it really bothers you.

Wow. Thanks for telling me, that would have been a great pain for me to figure out by my own. Still, the registry_object is not present remains. This is my current code:

	public static final RegistryObject<Item> TERROR_FEEDER = ITEMS.register("terror_feeder", () -> new BossItem(new BossItem.BossProperties().setBoss(EtauricEntities.CHUPNUT).setTooltip("A food source for a special water beast...")));

Item register. 

public class BossItem extends Item
{
	private final String tooltip;
	private final EntityType<? extends LivingEntity> boss;
	
	public BossItem(BossItem.BossProperties properties) 
	{
		super(properties.group(ItemGroup.MISC).maxStackSize(1));
		this.boss = properties.boss;
		this.tooltip = properties.toolTip;
	}
	
	@Override
	public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) 
	{
		if (this.tooltip != null) 
		{
			tooltip.add(new StringTextComponent("\u00A7e" + this.tooltip + "\u00A7e"));
		}
		
		tooltip.add(new StringTextComponent("\u00A76" + "Use this to summon " + this.boss.getName().getString() + "\u00A76"));
	}
	
	public static class BossProperties extends Item.Properties
	{
		private String toolTip;
		private EntityType<? extends LivingEntity> boss;
		
		public BossItem.BossProperties setBoss(EntityType<? extends LivingEntity> boss) 
		{
			this.boss = boss;
			
			return this;
		}
		
		public BossItem.BossProperties setBoss(RegistryObject<? extends EntityType<? extends LivingEntity>> boss) 
		{
			this.boss = boss.get();
			
			return this;
		}
		
		public BossItem.BossProperties setTooltip(String toolTip)
		{
			this.toolTip = toolTip;
			
			return this;
		}
	}
}

The BossItem. 

Did I do it the way you told me? 

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

You are still directly using EntityType. You must use the registry object.

Oh. Well, how would i do that? The registry objects and the suppliers are really new to me so I haven't really figured out how to use them. 

	public static final RegistryObject<Item> TERROR_FEEDER = ITEMS.register("terror_feeder", () -> new BossItem(new BossItem.BossProperties().setBoss(EtauricEntities.CHUPNUT).setTooltip("A food source for a special water beast...")));
RegistryObject<EntityType<EtauricEntities.CHUPNUT>>

This is obviously wrong as i've experienced...

Link to comment
Share on other sites

38 minutes ago, diesieben07 said:

This is your issue. Store the RegistryObject here, instead of calling get immediately.

I'm sorry, I don't think I follow. If I were to store it like so:

		public BossItem.BossProperties setBoss(RegistryObject<? extends EntityType<? extends LivingEntity>> boss) 
		{
			this.boss = boss;
			
			return this;
		}

I have to remove this:

		private EntityType<? extends LivingEntity> boss;
		
		public BossItem.BossProperties setBoss(EntityType<? extends LivingEntity> boss) 
		{
			this.boss = boss;
			
			return this;
		}

And change this: 

		private EntityType<? extends LivingEntity> boss;

To this: 

		private RegistryObject<? extends EntityType<? extends LivingEntity>> boss;

And that would mean, that if I wanted to use this to spawn some other vanilla creature, it wouldn't work. 

Or am I wrong here? 

 

EDIT: It does work, but this does not support vanilla creatures. Do I have to create a second BossItem that does work with vanilla, or is there a way for both methods to coexist in the same BossItem?

Edited by Triphion
Link to comment
Share on other sites

1 hour ago, diesieben07 said:

Of course it would, you can pass in whatever RegistryObject you want here.

Oh? Then how would I pass in a vanilla creature? Since the vanilla creatures are EntityTypes, I don't know how to do that. 

Edited by Triphion
Link to comment
Share on other sites

RegistryObject.of(resourceLocation-of-entitytype, ForgeRegistries.ENTITY);

If you change it to receive a Supplier<? extends EntityType<? extends LivingEntity>> instead of having to be a RegistryObject, then you could pass in the vanilla types as () -> VANILLA_TYPE.

 

You could change your existing method to create the registry object or supplier and pass it into the other method.

Edited by Alpvax
Link to comment
Share on other sites

33 minutes ago, Alpvax said:

RegistryObject.of(resourceLocation-of-entitytype, ForgeRegistries.ENTITY);

If you change it to receive a Supplier<? extends EntityType<? extends LivingEntity>> instead of having to be a RegistryObject, then you could pass in the vanilla types as () -> VANILLA_TYPE.

 

You could change your existing method to create the registry object or supplier and pass it into the other method.

Thank you! I changed it to a Supplier instead. I'm gonna have to learn how to use these systems so that I can use them more efficiently in the future.

Case solved! 

Edited by Triphion
Link to comment
Share on other sites

14 hours ago, diesieben07 said:

If you use RegistryObject it will, that is the point of RegistryObject.

Yes, but with that approach being a supplier, I am correct in thinking that it won't? Would using the delegate fix it, or is a RegistryObject the correct approach?

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.

Announcements



×
×
  • Create New...

Important Information

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