Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.4] Dealing with EntityType Shennanigans


Recommended Posts

I'm currently working on porting a mod from 1.12 to 1.16.

 

Back in 1.12, summoning entities was seemingly quite easy, where I could create my entity object, then call world.addEntity(entity), and it would take my entity object and summon it in.

 

Now it seems in the land of 1.16, that as a result of the EntityType system(?), world.addEntity(entity) seems to completely ignore the fact I've already created an instance of my entity object and tries to make a new one using the factory. Problematically for me, I'm trying to make an entity that extends AbstractFireballEntity (as I want it to act similarly to a fireball, just with different behavior on hit, and a couple cosmetic changes) which requires me to pass in a shooter to its constructor. And for the life of me, I cannot find a way to let the Factory know what my shooter is. Could anyone guide me in the right direction?

 

Link to source repo: https://github.com/hammy3502/survival-extras-2

 

Files of note: entity.PancakeProjectile, item.PancakeBow, init.ModEntities

 

Thank you so much for any help that can be provided, and apologies if the code is a mess right now, I'm hoping to clean it up once I have most of the things from my 1.12 ported over.

Link to post
Share on other sites
  • You need a separate EntityType per entity class, or the entity will not spawn the entity correctly.
  • You are incorrectly registering your EntityType. Please refer to the documentation for how to register things: https://mcforge.readthedocs.io/en/latest/concepts/registries/.
  • I cloned your repo and your Entity never spawns on the client, because the client side constructor causes a NullPointerException.
Link to post
Share on other sites

Hello, and thank you for the help!

 

I will definitely look into the incorrect registration, it looks like I'm using register() instead of registerAll() (though I should probably figure out how to use the deferred register for EntityTypes).

 

The Entity doesn't spawn on the client due to passing null in for the shooter, causing the game to fail on getting the shooter's position. What I'm stuck on is how to get a valid shooter from item.PancakeBow over to entity.PancakeProjectile. What would be the best way of going about doing this?

 

Thank you again for any help! I'll have the registration fixed as soon as I can, though I'm able to get the entity in the game (see it in /summon's TAB completion with my modid).

Edited by hammy3502
Link to post
Share on other sites
9 minutes ago, hammy3502 said:

it looks like I'm using register() instead of registerAll()

That's not relevant. The problem is that you are creating your registry objects outside the registry event and you are not using @ObjectHolder.

 

9 minutes ago, hammy3502 said:

What I'm stuck on is how to get a valid shooter from item.PancakeBow over to entity.PancakeProjectile. What would be the best way of going about doing this?

Implement IEntityAdditionalSpawnData on your entity and send the entityID of the shooter.

 

 

Link to post
Share on other sites

Hello, and thank you for the help!

 

I think I'm wrapping my mind around the functions in IEntityAdditionalSpawnData, and I know I can pass the data around from there throughout the Entity class, but I'm wondering how I can get that data into the super() constructor of the entity considering the fact that Java prevents referencing "this" until after calling super(), and super() is where it fails.

 

As for the registration stuff, I'm quite confused on. I'm listening for 

RegistryEvent.Register<EntityType<?>> event

and registering there, and looking at the Forge Docs, if I understand them correctly, @ObjectHolder looks to be for already-registered objects. I'm sure I definitely don't understand this properly, I'm just confused as to how to proceed.

 

Thank you for all the help so far!

 

EDIT: Figured out how to get ahold of the data in the constructor (I used spawnEntity.getAdditionalData())

Edited by hammy3502
Link to post
Share on other sites
12 hours ago, hammy3502 said:

As for the registration stuff, I'm quite confused on. I'm listening for 


RegistryEvent.Register<EntityType<?>> event

and registering there, and looking at the Forge Docs, if I understand them correctly, @ObjectHolder looks to be for already-registered objects. I'm sure I definitely don't understand this properly, I'm just confused as to how to proceed.

@ObjectHolder injects registry entries into fields. It is what you must use when you use the registry event manually and want to use plain fields (instead of RegistryObject). Do not create your registry entry in a static initializer and do not assign it to the fields manually.

A cleaner way to do this is to use DeferredRegister.

Link to post
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.

Guest
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

    • sorry i will talk in english. there is the debug.log of server and the client debug.log debug.log
    • Aww thanks i guess... Makes sense now.
    • I showed you that code...    it was this, and your 'complained' about the deferred register name, then went on about Objectholder (which to be fair was only there because the ONLY other example of doing this wasn't exactly knowledgeable as to what was happening or why. I'm trying to figure out why the following works, and the example wasn't exactly updated, so i had to use IDE feedback to get it to work properly, and I used setRegistryName as a way to prevent it from using my own name space....    -- To be clear i'm not sure what i did that caused it to work..  but it does Just to be clear  This is sitting where the package says it's sitting.   -mine are sitting in com.dephoegon.reclaim....   package net.minecraft; import com.dephoegon.reclaim.aid.block.sand; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.material.MaterialColor; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraftforge.common.ToolType; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.ObjectHolder; @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public class blockoverrides { public static final Block SAND = new sand(14406560, AbstractBlock.Properties.create(Material.SAND, MaterialColor.SAND) .harvestTool(ToolType.SHOVEL).harvestLevel(0) .hardnessAndResistance(0.5F).sound(SoundType.SAND) , "", "", "", true).setRegistryName("minecraft", "sand"); @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) { blockRegistryEvent.getRegistry().registerAll ( SAND ); } public static final Item SAND_ITEM = new BlockItem(SAND, new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)).setRegistryName("minecraft","sand"); @SubscribeEvent public static void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll ( SAND_ITEM ); } }  
    • From what I can .. gather, and I'm sure this is my confusion going on..        It has public Objects that are effectively the block registry calls. Wait?  Would it be possible to actually override a public object, and have it use it? ---      I'm not sure I understand,   though the only bit I can honestly gather from that is a string name key, & the block object calling a new instance of a block (sand, log, etc) with properties defined in those block classes, which are often calling abstractblocks for properties, and extending special classes (like fallingblock) which tend to fall onto blocks, then abstract blocks themselves.   perhaps I'm missing the forest for the trees (or missing the trees for the forest), but  I'm not getting how you meant that.
    • Oh hold on, I forgot about the refresh gradle option. I refreshed the project and it downloaded new jars. That's weird, the last time I opened the workspace and started the game, it was working fine. Sorry for wasting your time. 😓
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.