Jump to content

[SOLVED] [1.14.2] Register Entities and Rendering


TheUnnamed

Recommended Posts

Is this a valid way to register entities? Be it entities extending classes such as ProjectileItemEntity or MonsterEntity class.

The reason I ask is because while the mob entity is registring and showing in game just fine, the throwable entity is not, and is completely invisible in game when spawned (even when I don't register entity rendering with the RenderingRegistry class - this would in turn render it as a white box which is not happening).

    public static EntityType<?> ENT_MOB = null;
    public static EntityType<EntityModProjectile> ENT_PROJECTILE = null;

        static
        {
			ENT_MOB = registerEntityAndEgg(event.getRegistry(), EntityType.Builder.create(EntityModMob::new, EntityClassification.MONSTER).size(0.6F, 1.95F), 0xdcdcdc, 0xe21a1a, "ent_mob");
			ENT_PROJECTILE = registerEntity(EntityType.Builder.<EntityModProjectile>create(EntityModProjectile::new, EntityClassification.MISC).size(0.25F, 0.25F).setTrackingRange(64).setUpdateInterval(20).setShouldReceiveVelocityUpdates(false), "ent_projectile");
		}

        @SubscribeEvent
        public static void registerItems(final RegistryEvent.Register<EntityType<?>> event)
        {
			event.getRegistry().registerAll(ENT_MOB, ENT_PROJECTILE);
		}

        public static <T extends Entity> EntityType<T> registerEntity(EntityType.Builder builder, String name)
        {
            EntityType<T> type = (EntityType<T>) builder.build(Main.MODID + '.' + name).setRegistryName(name);
            return type;
        }

 

And this is how I register entity rendering:

RenderingRegistry.registerEntityRenderingHandler(EntityModMob.class, renderManager -> new RenderModMob(renderManager));
RenderingRegistry.registerEntityRenderingHandler(EntityModProjectile.class, renderManager -> new SpriteRenderer<EntityModProjectile>(renderManager, Minecraft.getInstance().getItemRenderer()));

 

EntityModProjectile class:

public class EntityModProjectile extends ProjectileItemEntity
{
    public EntityModProjectile(EntityType<? extends EntityModProjectile> entityTypeIn, World worldIn)
    {
        super(entityTypeIn, worldIn);
    }

    public EntityModProjectile(World worldIn, LivingEntity throwerIn)
    {
        super(ModEntityType.ENT_PROJECTILE, throwerIn, worldIn);
    }

    public EntityModProjectile(World worldIn, double x, double y, double z)
    {
        super(ModEntityType.ENT_PROJECTILE, x, y, z, worldIn);
    }

    @Override
    protected Item func_213885_i()
    {
        return ModItems.MOD_PROJECTILE;
    }
}

 

Edited by TheUnnamed
Link to comment
Share on other sites

You need to avoid putting static fields in your registry events.

Build the EntityTypes in the RegisterAll parameter list.

 

If you need to cross-reference between your EntityTypes and renderers, use ObjectHolders 

 

Here's a snippet from my [simple] mod where create my Events for 1 block (and its BlockItem), 1 Item and a custom [Mob] Entity

    //Mod Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(modid=ChickenMod.MODID, bus=Mod.EventBusSubscriber.Bus.MOD)
    @ObjectHolder(ChickenMod.MODID)
    public static class RegistryEvents {
    	
    	public static final Block test_block=null;
    	public static final Item test_item=null;
    	public static final EntityType<EntityProtoChicken> protochicken=null;
    	
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
    			blockRegistryEvent.getRegistry().registerAll(
    					new Block(Block.Properties.create(Material.IRON)).setRegistryName(ChickenMod.MODID,"test_block")); 
        }
        
        @SubscribeEvent
        public static void onItemsRegistry(final RegistryEvent.Register<Item> itemRegistryEvent) {
        	itemRegistryEvent.getRegistry().registerAll(
        			(Item)new BlockItem(test_block,new Item.Properties().group(ITEMTAB)).setRegistryName(test_block.getRegistryName()),
        			new Item(new Item.Properties().group(ITEMTAB)).setRegistryName(ChickenMod.MODID,"test_item")
        			);
        }
        
    	//Register Entities
    	@SubscribeEvent
    	public static void onEntitiesRegistry(final RegistryEvent.Register<EntityType<?>> entityRegistryEvent) {	
    		entityRegistryEvent.getRegistry().registerAll(		    	
    		    EntityType.Builder.create(EntityProtoChicken::new,EntityClassification.MISC)
    		    	.setShouldReceiveVelocityUpdates(true).setTrackingRange(24).setUpdateInterval(60)
    		    	.build("protochicken").setRegistryName(MODID, "protochicken")
    			);	
    	}

 

...and this is where I register the renderer:

    private void doClientStuff(final FMLClientSetupEvent event) {
        // do something that can only be done on the client
                RenderingRegistry.registerEntityRenderingHandler(EntityProtoChicken.class,RenderProtoChicken :: new);
    }

 

YMMV

/p

Edited by PhilipChonacky
Link to comment
Share on other sites

Thank you for your input PhilipChonacky.

I've done exactly as you've suggested, but the issue still persists, the entity I'm summoning with the /summon command is still invisible.

 

It says the entity has been registered in the console, so I'm not quite sure what could be the problem.

Keep in mind that this only occurs with entities that are created with SSpawnObjectPacket and not SSpawnMobPacket in the IPacket<?> createSpawnPacket() method it seems, because mob entities register and render just fine in-game, as previously stated.

Link to comment
Share on other sites

I think something may be missing in the forge registry/spawn code. I have an entity that is mountable and I get a [minecraft/ClientPlayNetHandler]: Received passengers for unknown entity warning in the console. The entity is not visible and cannot be controlled. So you're not the only one experiencing this type of issue. 

Link to comment
Share on other sites

  • 2 weeks later...

I'm having exactly the same problem now. My Mobs are showing up great but my projectiles do not show up on the client at all, anything spawned via SSpawnMobPacket is great but SSpawnObjectPacket is not showing.

I use an EntityFactory object rather than the entity constructors and that also isn't being called by SSpawnObjectPacket on the client.

Link to comment
Share on other sites

I solved it. Here's how I did it:

 

When I set the EntityType variable for my named variable "ENT_PROJECTILE" and build, I use the setCustomClientFactory method, so it would look exactly like this:

ENT_PROJECTILE = registerEntity(EntityType.Builder.<EntityModProjectile>create(EntityClassification.MISC).setCustomClientFactory(EntityModProjectile::new).size(0.25F, 0.25F), "ent_projectile");

 

Inside of my EntityModProjectile class I extended the ProjectileItemEntity class, overrided the createSpawnPacket method and returned getEntitySpawningPacket from NetworkHooks class. Like this:

    @Override
    public IPacket<?> createSpawnPacket()
    {
        return NetworkHooks.getEntitySpawningPacket(this);
    }

 

I then created another constructor inside of the EntityModProjectile class, like this:

    public EntityModProjectile(FMLPlayMessages.SpawnEntity packet, World worldIn)
    {
        super(ModEntityType.ENT_PROJECTILE, worldIn);
    }

 

  • Like 1
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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