Jump to content

PlayerRenderer registering


bigMojitos

Recommended Posts

Hi I'm having trouble figuring out how to register a created PlayerRenderer I Currently have this:

    private final IntRender test = new IntRender(question goes here, false);

but I dont know where to get my games instance for the first parameter which is ; EntityRendererProvider.Context . Any help would be appreciated!

Link to comment
Share on other sites

9 hours ago, Luis_ST said:

EntityRenderers must be registered in EntityRenderersEvent.RegisterRenderers.

How do I register it if its not a custom Entity but instead a Player. When ever I put this in:

Quote

@SubscribeEvent public void entRenderEvent(EntityRenderersEvent.RegisterRenderers ev)

{

ev.registerEntityRenderer(EntityType.PLAYER , IntRender::new);

}

IntelliJ tells me both parameters are wrong and invalid. For reference my 'IntRender' class is an extension of the PlayerRenderer.

Link to comment
Share on other sites

5 minutes ago, ChampionAsh5357 said:

What is the purpose of the custom player renderer? Are you trying to rerender the player from scratch, or are you just adding something on top of the original model?

I want to create new animations for the players arms that can be seen in third person. As for the actual animations I'm still deciding which method to use; rotating the arms with the renderer or creating some new model and animations in blender. I will most likely use the latter but I've read online and was told in discord that for both options having a custom PlayerRenderer would be viable and useful but if you have any other ideas let me know please!

Edited by bigMojitos
Link to comment
Share on other sites

The correct way to replace player rendering is by using `RenderPlayerEvent$Pre` and canceling the render before rendering the wanted model yourself. If using the regular player model and just changing the model animations, then you should be fine. If using a custom player model, there are some additional difficulties when it comes to layers since you may have to reinitialize them to supply your own player model for the correct rendering location.

Link to comment
Share on other sites

4 minutes ago, ChampionAsh5357 said:

The correct way to replace player rendering is by using `RenderPlayerEvent$Pre` and canceling the render before rendering the wanted model yourself. If using the regular player model and just changing the model animations, then you should be fine. If using a custom player model, there are some additional difficulties when it comes to layers since you may have to reinitialize them to supply your own player model for the correct rendering location.

public class ClientBus {


    @SubscribeEvent
   public void playerRender(RenderPlayerEvent.Pre ev){
       print("Event has fired"); //not firing
   }


   @SubscribeEvent
    public void clientBustTest(InputEvent.Key ev){
        if(ev.getKey() == InputConstants.KEY_C) print("Test event has fired");
   }

}

So here's my client bus and all its events. The KeyEvent is firing perfectly but the RenderPlayerEvent, both .pre and .post, do not fire at all, at least to my knowledge. If you could help and point out my issues with this I'd really appreciate it.

Here's my Mod Class where I register this event bus:

    public Inceptor()
    {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        // Register the commonSetup method for modloading
        modEventBus.addListener(this::commonSetup);

        // Register the Deferred Register to the mod event bus so blocks get registered
        BLOCKS.register(modEventBus);
        // Register the Deferred Register to the mod event bus so items get registered
        ITEMS.register(modEventBus);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);

       MinecraftForge.EVENT_BUS.register(new ClientBus());

    }
Link to comment
Share on other sites

21 minutes ago, Luis_ST said:

I would highly recommend to use the @EventBusSubscriber annotation to register EventHandlers. See:
eventhandler.png

Which one would it be? I just tried the First one, same result, and the second one was my previous set up. Would it be either of the two bottom ones?

Link to comment
Share on other sites

18 minutes ago, Luis_ST said:

The first one is the way to go, did you add the static keyword to the EventHandler methods?

Please post the full updated EventHandler class.

package me.wdh.inceptor.client;

import com.google.common.eventbus.Subscribe;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.world.entity.EntityType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import static me.wdh.inceptor.Inceptor.print;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class ClientBus {


    @SubscribeEvent
   public static void playerRender(RenderPlayerEvent.Pre ev){
       print("Event has fired"); //not firing
   }


   @SubscribeEvent
    public static void clientBustTest(InputEvent.Key ev){
        if(ev.getKey() == InputConstants.KEY_C) print("Test event has fired");
   }

}

I also tried moving the whole ClientBus Class into the Mod Class so I could make it static but it still had the same output.

Edited by bigMojitos
Link to comment
Share on other sites

10 minutes ago, ChampionAsh5357 said:

You need to set the `modid` field to your mod id in the `@EventBusSubscriber` annotation.


@Mod.EventBusSubscriber(modid = "incp",bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class ClientBus {...

Just tried it nothing changed, same output as before. Do you want me to pastebin it?

Link to comment
Share on other sites

3 minutes ago, bigMojitos said:

Just tried it nothing changed, same output as before. Do you want me to pastebin it?

Sure, though looking at your code again, it may be whatever custom printer you are using is at fault. Try putting a breakpoint in one of the events and attempt to execute it (going into third person or pressing a key).

Link to comment
Share on other sites

10 minutes ago, Luis_ST said:

Did you checked if the EventHandler works using the debugger?
If not put a breakpoint in the EventHandler, start the game and join a world.

To check if it worked I just put a static print to chat method down in the InputEvent.Key and used it with the same EventHandler and it did manage to work. Let me know if the debugger can give me more insight than that but yea I'm confused. Im making a new Mod right now just to test this event to see if its something internal, as in my computer.

Edited by bigMojitos
Link to comment
Share on other sites

2 minutes ago, bigMojitos said:

Let me know if the debugger can give me more insight than that but yea I'm confused.

The debugger is the way to go to debug stuff, it should be obviously since it's called debugger.

Use it and you can make 100% sure if the EventHandler is called or not.

Link to comment
Share on other sites

 

package com.example.examplemod;

import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.apache.logging.log4j.LogManager;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(ExampleMod.MODID)
public class ExampleMod
{
    // Define mod id in a common place for everything to reference
    public static final String MODID = "examplemod";
    // Directly reference a slf4j logger
    private static final Logger LOGGER = LogUtils.getLogger();
    // Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
    // Create a Deferred Register to hold Items which will all be registered under the "examplemod" namespace
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);

    // Creates a new Block with the id "examplemod:example_block", combining the namespace and path
    public static final RegistryObject<Block> EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of(Material.STONE)));
    // Creates a new BlockItem with the id "examplemod:example_block", combining the namespace and path
    public static final RegistryObject<Item> EXAMPLE_BLOCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_BUILDING_BLOCKS)));

    public ExampleMod()
    {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        // Register the commonSetup method for modloading
        modEventBus.addListener(this::commonSetup);

        // Register the Deferred Register to the mod event bus so blocks get registered
        BLOCKS.register(modEventBus);
        // Register the Deferred Register to the mod event bus so items get registered
        ITEMS.register(modEventBus);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
        MinecraftForge.EVENT_BUS.register(new ClientBus());

    }

    private void commonSetup(final FMLCommonSetupEvent event)
    {
        // Some common setup code
        LOGGER.info("HELLO FROM COMMON SETUP");
        LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT));
    }

    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(ServerStartingEvent event)
    {
        // Do something when the server starts
        LOGGER.info("HELLO from server starting");
    }

    // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
    @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
    public static class ClientModEvents
    {
        @SubscribeEvent
        public static void onClientSetup(FMLClientSetupEvent event)
        {
            // Some client setup code
            LOGGER.info("HELLO FROM CLIENT SETUP");
            LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
        }
    }

    // Add this field to your main class

// You can use it from anywhere:
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
    public static class ClientVan {

        public static void print(String r){
            if(Minecraft.getInstance().player != null) {
                Player p = Minecraft.getInstance().player;
                p.sendSystemMessage(Component.nullToEmpty(r));
            }

        }


        @SubscribeEvent
        public static void playerRender(RenderPlayerEvent.Pre ev){
            print(" CV Event has fired"); //not firing
        }


        @SubscribeEvent
        public static void clientBustTest(InputEvent.@NotNull Key ev){
            if(ev.getKey() == InputConstants.KEY_C) print( " CV Test event has fired");
        }

    }

}

I just created a new mod added my EventBus class to the Mod class and got the same results(KeyEvent is firing while RenderPlayerEvent is not). I ran it through the debugger and put the breakpoint at right below the declaration of the KeyEvent and I got these results : https://imgur.com/gallery/oOUNTYI . Any thing I'm noticeably doing wrong here to cause the issue? I also want to thank you rq for being so responsive and helpful

Edited by bigMojitos
Link to comment
Share on other sites

3 minutes ago, bigMojitos said:

I just created a new mod added my EventBus class to the Mod class and got the same results(KeyEvent is firing while RenderPlayerEvent is not).

How are you testing whether the event is firing? Are you just opening the game, or are you going into third person so the player renderer is actually called?

Link to comment
Share on other sites

14 minutes ago, ChampionAsh5357 said:

How are you testing whether the event is firing? Are you just opening the game, or are you going into third person so the player renderer is actually called?

Dude. Holy shit. I did not know that was how you had to problem completely fixed. Thank you so much!

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.