Jump to content

Recommended Posts

Posted

Hi ! I'm new to modding and java (i'm actually learning). I made a penguin entity following a tutorial on youtube about it. My entity won't spawn and I out of idea.

 

Here the error. It say that I have no attributes but I gave him. So I don't understand.

  Reveal hidden contents

You can see my code on my github

Github

 

Thanks for your help !

Posted (edited)

First you should never just copy/paste from a tutorial. You should try to understand what it is doing at each step.

Otherwise you will never be able to fix the inevitable bugs or correct the tutorial code when it is wrong. 🙂 

 

You have at least 2 errors (both are related to misunderstandings in events/registration)

You can read about events (along with other things) on this wiki: https://forge.gemwire.uk/wiki/Main_Page

It is important you know how this works, it is fundamental to writing forge mods.

 

1) You are missing the subscriber definition on your ModEventBusEvents class which means the attributes are never added to your entity

https://github.com/Overtekk/Pingoo/blob/4b91d22a1d2851b432f38a861623c90f538a9dbe/src/main/java/net/overtek/pingoo/event/ModEventBusEvents.java#L8

@Mod.EventBusSubscriber(modid = Pingoo.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEventBusEvents {

 

2) You should be registering your entity renderer in the EntityRenderersEvent.RegisterRenderers

the code here is never invoked and it is not the correct way to do it

https://github.com/Overtekk/Pingoo/blob/4b91d22a1d2851b432f38a861623c90f538a9dbe/src/main/java/net/overtek/pingoo/Pingoo.java#L46

 

It should be something like - untested code - don't just copy/paste without confirming I am correct 🙂

    @Mod.EventBusSubscriber(modid = Pingoo.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
    public class ClientModEventBusEvents {
        @SubscribeEvent 
        public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
            event.registerEntityRenderer(ModEntityTypes.PENGUIN.get(), PenguinRenderer::new);
        }
    }

NOTE: The Dist.CLIENT, this is a separate class for mod registration events that are only applicable to the client, e.g. graphics like your renderer

Edited by warjort
  • Thanks 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

i find the second 

	@Mod.EventBusSubscriber(modid = baseMmod.MOD_ID,  bus = Mod.EventBusSubscriber.Bus.FORGE )
public class modevents {
    
    @SubscribeEvent
    public static void on_toss(ItemTossEvent event) {
        
        Entity entity = event.getEntity();
        World warudo = entity.level;
        if (entity instanceof ItemEntity) {
            ItemEntity item_e = (ItemEntity)entity;
            ItemStack itemstack = item_e.getItem();
	            System.out.println("\n ItemTossEvent "  + itemstack.getItem().getRegistryName()  +  "\n");    
            
            if (itemstack.getItem() == MItems.INGOT_IRON_RED_HOT.get()) {
                //item_e.kill();
                
                //MItemEntity drop = new MItemEntity(warudo, (double)(pos.getX() + 0.5F) , (double)(pos.getY() + 1.0F)  , (double)(pos.getZ() + 0.5F) , itemstack );
                //warudo.addFreshEntity(drop);
            }
        }
	}
	



but the first one no idea

  • Thanks 1
Posted (edited)
  On 8/1/2022 at 12:00 PM, perromercenary00 said:

but the first one no idea

Expand  

It's literally what he said.
Where you added this line:

e.put(ModEntityTypes.YOUR_ENTITY.get(), EntityClass.setAttributes());

 

You need to add a @Mod.EventBusSubsriber

 

Like this:


@Mod.EventBusSubscriber(modid = baseMmod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEventBusEvents {

@SubscribeEvent

   public static void entityAttributeEvent(EntityAttributeCreationEvent event) {
   event.put(ModEntityTypes.PENGUIN.get(), PenguinEntity.setAttributes());
   }
}

 

 

If you don't add a @Mod.EventBusSubscriber your mod won't call this class

Edited by Zanckor
  • Thanks 1
Posted
  On 7/31/2022 at 11:32 PM, warjort said:

First you should never just copy/paste from a tutorial. You should try to understand what it is doing at each step.

Otherwise you will never be able to fix the inevitable bugs or correct the tutorial code when it is wrong. 🙂 

 

You have at least 2 errors (both are related to misunderstandings in events/registration)

You can read about events (along with other things) on this wiki: https://forge.gemwire.uk/wiki/Main_Page

It is important you know how this works, it is fundamental to writing forge mods.

 

1) You are missing the subscriber definition on your ModEventBusEvents class which means the attributes are never added to your entity

https://github.com/Overtekk/Pingoo/blob/4b91d22a1d2851b432f38a861623c90f538a9dbe/src/main/java/net/overtek/pingoo/event/ModEventBusEvents.java#L8

@Mod.EventBusSubscriber(modid = Pingoo.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEventBusEvents {

 

2) You should be registering your entity renderer in the EntityRenderersEvent.RegisterRenderers

the code here is never invoked and it is not the correct way to do it

https://github.com/Overtekk/Pingoo/blob/4b91d22a1d2851b432f38a861623c90f538a9dbe/src/main/java/net/overtek/pingoo/Pingoo.java#L46

 

It should be something like - untested code - don't just copy/paste without confirming I am correct 🙂

    @Mod.EventBusSubscriber(modid = Pingoo.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
    public class ClientModEventBusEvents {
        @SubscribeEvent 
        public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
            event.registerEntityRenderer(ModEntityTypes.PENGUIN.get(), PenguinRenderer::new);
        }
    }

NOTE: The Dist.CLIENT, this is a separate class for mod registration events that are only applicable to the client, e.g. graphics like your renderer

Expand  

I know but I learn java and I have no clue of what I need to do. But now I understand a bit better even if it still a bit difficult.

1)
Thanks for the answer, it works fine now. I just need to change the size, sounds, attributes and goal now. I understand a bit what was missing.
The game was crashing but it was because of the rendering who was missing.

 

2)
I didn't know that and I have do that and I create the folder and the class and now it works perfectly. Thanks you!

I have still a lot of things to learn.

 

  On 8/1/2022 at 1:55 PM, Zanckor said:

It's literally what he said.
Where you added this line:

e.put(ModEntityTypes.YOUR_ENTITY.get(), EntityClass.setAttributes());

 

You need to add a @Mod.EventBusSubsriber

 

Like this:


@Mod.EventBusSubscriber(modid = baseMmod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEventBusEvents {

@SubscribeEvent

   public static void entityAttributeEvent(EntityAttributeCreationEvent event) {
   event.put(ModEntityTypes.PENGUIN.get(), PenguinEntity.setAttributes());
   }
}

 

 

If you don't add a @Mod.EventBusSubscriber your mod won't call this class

Expand  

 

Thanks to you and perromercenary00 too. This is what was missing along with EntityRenderersEvent.RegisterRenderers.

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.