Jump to content

[Solved] RenderLayer not rendering on multiplayer


Oscarita25

Recommended Posts

Okay i created a RenderLayer it works 100% in SinglePlayer

but it doesn't in multiplayer for other Players 

i think its because i use capabilities .. or at least i use them wrong for this :0

so the RenderLayer is shown if (int)capability x of Player is equal to (int)

 

@SideOnly(Side.CLIENT)
public class LayerEntityOnPlayerBack implements LayerRenderer<EntityLivingBase>{

    private final RenderManager renderManager;
    protected RenderLivingBase <? extends EntityLivingBase > Renderer;
    private ModelBase Model = new ModelParrot();
    private ResourceLocation Resource = RenderParrot.PARROT_TEXTURES[2];

    public LayerEntityOnPlayerBack(RenderManager rendermanager)
    {
        this.renderManager = rendermanager;
    }

    public void doRenderLayer(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale)
    {
    	IModelID model = entitylivingbaseIn.getCapability(ModelProvider.MODEL_CAP, null);
    	BNHA.NETWORK.sendToServer(new MessageRequestModel());
    	
    	    	
        if (model.getModelID() == Reference.tail)
        {
            GlStateManager.enableRescaleNormal();
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

            	if(Renderer == null) 
            	Renderer = new RenderParrot(this.renderManager);
            	
            	Renderer.bindTexture(Resource);
            	
            	
                GlStateManager.pushMatrix();
                float f = entitylivingbaseIn.isSneaking() ? -1.3F : -1.5F;
                GlStateManager.translate(0.0F, f, 0.0F);
                
                ageInTicks = 0.0F;

                Model.setLivingAnimations(entitylivingbaseIn, limbSwing, limbSwingAmount, partialTicks);
                Model.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entitylivingbaseIn);
                Model.render(entitylivingbaseIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
                GlStateManager.popMatrix();
            

            GlStateManager.disableRescaleNormal();
        }
  }

    public boolean shouldCombineTextures()
    {
        return false;
    }
}

 

Edited by Oscarita25
Link to comment
Share on other sites

1 hour ago, Oscarita25 said:

Okay i created a RenderLayer it works 100% in SinglePlayer

but it doesn't in multiplayer for other Players 

 i think its because i use capabilities .. or at least i use them wrong for this :0

so the RenderLayer is shown if (int)capability x of Player is equal to (int)

 

does anyone know how i would do this :P

Link to comment
Share on other sites

7 hours ago, Oscarita25 said:

BNHA.NETWORK.sendToServer(new MessageRequestModel());

Good dear lord. 

You do understand that you are sending a packet to a server EACH FRAME with this code, right?

Do not ever do that. That is probably the worst thing you could do.

In addition a request packet is an indication of a bad design. The server knows exactly who needs the data and when to send it. Don't request packets from the client.

In addition your approach wouldn't work anyway because packets are handled by a different thread, meanung your rendering code just moves onwards without receiving the data from the server.

 

7 hours ago, Oscarita25 said:

if(Renderer == null) Renderer = new RenderParrot(this.renderManager);

But why do this if you can just get the existing renderer for the parrot?

 

I don't think yu need to normalize the normal vectors here, so enable/disableRescaleNormal is not needed.

 

How are you syncing the capability to the players involved? Show that bit of your code.

Link to comment
Share on other sites

Quote

public static CommonProxy proxy;

A CommonProxy makes no sense. Proxies exist to separate sided-only code, if your code is common then it goes anywhere else but your proxy.

 

Quote

serverSide = Reference.COMMON_PROXY_CLASS

This makes even less sense. A server proxy contains either NOOP implementations for client-only things or code that would crash the client. Your common proxy can't be your server proxy.

 

Why do you have multiple methods both subscribing to the same FMLLifecycle event? Why not use just one method?

 

https://github.com/Oscarita25/BNHA/blob/master/src/main/java/com/oscar/data/packets/MessageEXP.java#L36

https://github.com/Oscarita25/BNHA/blob/master/src/main/java/com/oscar/data/packets/MessageLEVEL.java#L36

https://github.com/Oscarita25/BNHA/blob/master/src/main/java/com/oscar/data/packets/MessageModel.java#L36

https://github.com/Oscarita25/BNHA/blob/master/src/main/java/com/oscar/data/packets/MessageNEXP.java#L36

https://github.com/Oscarita25/BNHA/blob/master/src/main/java/com/oscar/data/packets/MessageQuirkID.java#L36

You can't do this, your handler is common, but this is client-only code. This will crash the server. You must use a proxy.

 

Quote

public class MessageRequest...

Just no. Get rid of all of your request messages. First of all the server knows when to send the data, so send it from the server when needed, don't ask the client. Second of all the client can and WILL abuse these request messages. Finally this is just extra network IO that wastes time.

 

https://github.com/Oscarita25/BNHA/blob/master/src/main/java/com/oscar/data/packets/MessageRequestActivate.java#L64

Since you have no safety checks and just blindly trust the client a malicious client can easily abuse this packet to do whatever it wants, like cover the entire world in these entities, one per block.

 

The reason for your issue is that you only ever set the capability data for the model to the main client player. If you need the model data for another player then set it in their capability instance, not in the client's player.

 

https://github.com/Oscarita25/BNHA/blob/master/src/main/java/com/oscar/init/ModItems.java#L38

Don't ever use static initializers for registry entries. Registry entries MUST be instantinated in the appropriate registy event. Using static initializers can and WILL cause issues.

 

https://github.com/Oscarita25/BNHA/blob/master/src/main/java/com/oscar/items/ItemBase.java

ItemBase is pointless, there is already an ItemBase, it's called Item. Don't abuse inheritance.

 

Quote

implements IHasModel

IHasModel is the worst thing to ever exist on this planet. It is ugly, doesn't make any sense since all items need models anyway, makes you write extra code and makes your code that much harder to manage. Don't use it and just register your models in the modelregistryevent directly.

 

https://github.com/Oscarita25/BNHA/blob/master/src/main/java/com/oscar/util/LoggingUtil.java

Any reason for this class to exist? Like at all?

 

 

Link to comment
Share on other sites

2 minutes ago, V0idWa1k3r said:

This makes even less sense. A server proxy contains either NOOP implementations for client-only things or code that would crash the client. Your common proxy can't be your server proxy.

 

What is NOOP? yeah i understand that and i wanted to change that for a while just forgot about it because .. if it works it works (i will change it later)

 

 

4 minutes ago, V0idWa1k3r said:

You can't do this, your handler is common, but this is client-only code. This will crash the server. You must use a proxy.

 

 

i actually i can because those packets are registered for client side and won't be actually executed on server side! (i tested it on server it won't cause issues)
https://github.com/Oscarita25/BNHA/blob/0d4dbc2c3f7e5f7bad430f8d129aea5594d83399/src/main/java/com/oscar/proxy/CommonProxy.java#L78
 


 

6 minutes ago, V0idWa1k3r said:

Just no. Get rid of all of your request messages. First of all the server knows when to send the data, so send it from the server when needed, don't ask the client. Second of all the client can and WILL abuse these request messages. Finally this is just extra network IO that wastes time.

 

okay i understand that this is bad code can you give a example code of how to do it much better and optimized?

 

7 minutes ago, V0idWa1k3r said:

Since you have no safety checks and just blindly trust the client a malicious client can easily abuse this packet to do whatever it wants, like cover the entire world in these entities, one per block.

 

how would i do the safety check for that? :0


 

8 minutes ago, V0idWa1k3r said:

Don't ever use static initializers for registry entries. Registry entries MUST be instantinated in the appropriate registy event. Using static initializers can and WILL cause issues.

 

should i just delete the static intializers or should do it entirely different (code example if possible)

 

 

9 minutes ago, V0idWa1k3r said:

ItemBase is pointless, there is already an ItemBase, it's called Item. Don't abuse inheritance.

 

yeah it is forgot to delete it if you just look in my code it doesn't even do anything... 

 

 

10 minutes ago, V0idWa1k3r said:

IHasModel is the worst thing to ever exist on this planet. It is ugly, doesn't make any sense since all items need models anyway, makes you write extra code and makes your code that much harder to manage. Don't use it and just register your models in the modelregistryevent directly.

 

okay will do

 

 

10 minutes ago, V0idWa1k3r said:

Any reason for this class to exist? Like at all?

 

i am logging some stuff with it.. but not that much

Link to comment
Share on other sites

5 minutes ago, Oscarita25 said:

What is NOOP?

No Operation, do nothing.

 

6 minutes ago, Oscarita25 said:

because .. if it works it works

It works for now, but it may and likely will cause issues later. Do you want to do a quick reactoring now or restructure half of your mod later?

 

7 minutes ago, Oscarita25 said:

actually i can because those packets are registered for client side and won't be actually executed on server side! (i tested it on server it won't cause issues)

This doesn't matter. It's client-only code in a common environment. Yes, vanilla JVM won't load classes before it gets to their execution without any special flags I believe. Vanilla JVM isn't the only one though, and other implementations may do different things.

Besides there are still ways to load that code on a server and cause a crash.

So no, you really can't and it will cause issues.

 

9 minutes ago, Oscarita25 said:

okay i understand that this is bad code can you give a example code of how to do it much better and optimized?

 

Just send the data from the server when the client needs it. The actual implementation would differ but as an example of your model capability you would send it to the player when they log in or when the data changes.

 

10 minutes ago, Oscarita25 said:

how would i do the safety check for that? :0

 

That would depend on your implementation. There should be a limit to these interactions anyway, like a cooldown or something. But that's up to you.

 

10 minutes ago, Oscarita25 said:

should i just delete the static intializers or should do it entirely different (code example if possible)

Delete the static initializers and just instantinate your things in the registry event. That's it. There is no example needed - do you need an example of writing new Item...() ?

 

 

Link to comment
Share on other sites

Just send them whenever the client needs them. You know when they need it.

If you have a capability you want to sync then send the packet every time the player logs in or the data changes.

In case of the model capability data you would want to send it every time a player started to track another player - grab the other player and send it to the tracking player.

Link to comment
Share on other sites

also just asking bc i did this like really fast:

 

public class ModItems {
	
	

	//Materials
	public static final ItemArmor.ArmorMaterial UA_SPORTS_MAT = 
			EnumHelper.addArmorMaterial
         (Reference.MOD_ID +":ua_sports",Reference.MOD_ID +":ua_sports",15,
		 new int[]{1, 4, 5, 2},12,SoundEvents.ITEM_ARMOR_EQUIP_LEATHER,(float) 0);	
	
	public static  final ItemArmor.ArmorMaterial BAKUGO_ARMOR_MAT =
			EnumHelper.addArmorMaterial
		 (Reference.MOD_ID +":bakugo_armor",Reference.MOD_ID +":bakugo_armor",15,
		 new int[]{1, 4, 5, 2},12,SoundEvents.ITEM_ARMOR_EQUIP_LEATHER,(float) 0);
	
	public static final ItemArmor.ArmorMaterial DEKU_ARMOR_MAT =
			EnumHelper.addArmorMaterial
		 (Reference.MOD_ID +":deku_armor",Reference.MOD_ID +":deku_armor",15,
		 new int[]{1, 4, 5, 2},12,SoundEvents.ITEM_ARMOR_EQUIP_LEATHER,(float) 0);
	

	public static final Item[] ITEMS = {
			new ClothArmor("ua_sports_chestplate",UA_SPORTS_MAT,1,EntityEquipmentSlot.CHEST),
			new ClothArmor("ua_sports_leggings",UA_SPORTS_MAT,2,EntityEquipmentSlot.LEGS),
			new ClothArmor("deku_armor_chestplate",DEKU_ARMOR_MAT,1,EntityEquipmentSlot.CHEST),
			new ClothArmor("deku_armor_leggings",DEKU_ARMOR_MAT,2,EntityEquipmentSlot.LEGS),
			new ClothArmor("deku_armor_feet",DEKU_ARMOR_MAT,1,EntityEquipmentSlot.FEET),
			new ClothArmor("bakugo_armor_head",BAKUGO_ARMOR_MAT,1,EntityEquipmentSlot.HEAD),
			new ClothArmor("bakugo_armor_chestplate",BAKUGO_ARMOR_MAT,1,EntityEquipmentSlot.CHEST),
			new ClothArmor("bakugo_armor_leggings",BAKUGO_ARMOR_MAT,2,EntityEquipmentSlot.LEGS),
			new ClothArmor("bakugo_armor_feet",BAKUGO_ARMOR_MAT,1,EntityEquipmentSlot.FEET)
	};

}

 

@Mod.EventBusSubscriber(modid = Reference.MOD_ID)
public class RegistryHandler {
	
	
	@SubscribeEvent
	public static void onItemRegister(RegistryEvent.Register<Item> event) {
		event.getRegistry().registerAll(ModItems.ITEMS);
		
		LoggingUtil.BNHALogger.info("Registered Items");
	}

	@SubscribeEvent
	public static void registerModels(ModelRegistryEvent event)
	{
		
		for (Item item: ModItems.ITEMS)
		{
			ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
		}
		
		LoggingUtil.BNHALogger.info("Registered models");
	}


}

is this the right way to register it? - just asking because i am not sure :P

(just saying i am on basic level of item registering because i pretty much avoid making items at all)

Edited by Oscarita25
Link to comment
Share on other sites

11 minutes ago, V0idWa1k3r said:

Just send them whenever the client needs them. You know when they need it.

If you have a capability you want to sync then send the packet every time the player logs in or the data changes.

In case of the model capability data you would want to send it every time a player started to track another player - grab the other player and send it to the tracking player.

 

if i got it right ...
 

			new ClothArmor("ua_sports_chestplate",UA_SPORTS_MAT,1,EntityEquipmentSlot.CHEST),
			new ClothArmor("ua_sports_leggings",UA_SPORTS_MAT,2,EntityEquipmentSlot.LEGS),
			new ClothArmor("deku_armor_chestplate",DEKU_ARMOR_MAT,1,EntityEquipmentSlot.CHEST),
			new ClothArmor("deku_armor_leggings",DEKU_ARMOR_MAT,2,EntityEquipmentSlot.LEGS),
			new ClothArmor("deku_armor_feet",DEKU_ARMOR_MAT,1,EntityEquipmentSlot.FEET),
			new ClothArmor("bakugo_armor_head",BAKUGO_ARMOR_MAT,1,EntityEquipmentSlot.HEAD),
			new ClothArmor("bakugo_armor_chestplate",BAKUGO_ARMOR_MAT,1,EntityEquipmentSlot.CHEST),
			new ClothArmor("bakugo_armor_leggings",BAKUGO_ARMOR_MAT,2,EntityEquipmentSlot.LEGS),
			new ClothArmor("bakugo_armor_feet",BAKUGO_ARMOR_MAT,1,EntityEquipmentSlot.FEET)

this right into the registry?

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.

×
×
  • Create New...

Important Information

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