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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have done this now but have got the error:   'food(net.minecraft.world.food.FoodProperties)' in 'net.minecraft.world.item.Item.Properties' cannot be applied to                '(net.minecraftforge.registries.RegistryObject<net.minecraft.world.item.Item>)' public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register( "lemon_juice", () -> new Item( new HoneyBottleItem.Properties().stacksTo(1).food( (new FoodProperties.Builder()) .nutrition(3) .saturationMod(0.25F) .effect(() -> new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 1500), 0.01f ) .build() ) )); The code above is from the ModFoods class, the one below from the ModItems class. public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register("lemon_juice", () -> new Item(new Item.Properties().food(ModFoods.LEMON_JUICE)));   I shall keep going between them to try and figure out the cause. I am sorry if this is too much for you to help with, though I thank you greatly for your patience and all the effort you have put in to help me.
    • I have been following these exact tutorials for quite a while, I must agree that they are amazing and easy to follow. I have registered the item in the ModFoods class, I tried to do it in ModItems (Where all the items should be registered) but got errors, I think I may need to revert this and figure it out from there. Once again, thank you for your help! 👍 Just looking back, I have noticed in your code you added ITEMS.register, which I am guessing means that they are being registered in ModFoods, I shall go through the process of trial and error to figure this out.
    • ♈+2349027025197ஜ Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join a brotherhood for protection and wealth here’s is your opportunity, but you should know there’s no ritual without repercussions but with the right guidance and support from this great temple your destiny is certain to be changed for the better and equally protected depending if you’re destined for greatness Call now for enquiry +2349027025197☎+2349027025197₩™ I want to join ILLUMINATI occult without human sacrificeGREATORLDRADO BROTHERHOOD OCCULT , Is The Club of the Riches and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In Greatorldrado BROTHERHOOD we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money Rewards once they join in order to upgrade their lifestyle.; interested viewers should contact us; on. +2349027025197 ۝ஐℰ+2349027025197 ₩Greatorldrado BROTHERHOOD OCCULT IS A SACRED FRATERNITY WITH A GRAND LODGE TEMPLE SITUATED IN G.R.A PHASE 1 PORT HARCOURT NIGERIA, OUR NUMBER ONE OBLIGATION IS TO MAKE EVERY INITIATE MEMBER HERE RICH AND FAMOUS IN OTHER RISE THE POWERS OF GUARDIANS OF AGE+. +2349027025197   SEARCHING ON HOW TO JOIN THE Greatorldrado BROTHERHOOD MONEY RITUAL OCCULT IS NOT THE PROBLEM BUT MAKE SURE YOU'VE THOUGHT ABOUT IT VERY WELL BEFORE REACHING US HERE BECAUSE NOT EVERYONE HAS THE HEART TO DO WHAT IT TAKES TO BECOME ONE OF US HERE, BUT IF YOU THINK YOU'RE SERIOUS MINDED AND READY TO RUN THE SPIRITUAL RACE OF LIFE IN OTHER TO ACQUIRE ALL YOU NEED HERE ON EARTH CONTACT SPIRITUAL GRANDMASTER NOW FOR INQUIRY +2349027025197   +2349027025197 Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join
    • Hi, I'm trying to use datagen to create json files in my own mod. This is my ModRecipeProvider class. public class ModRecipeProvider extends RecipeProvider implements IConditionBuilder { public ModRecipeProvider(PackOutput pOutput) { super(pOutput); } @Override protected void buildRecipes(Consumer<FinishedRecipe> pWriter) { ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', ModItems.COMPRESSED_DIAMOND.get()) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get(),9) .requires(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .unlockedBy(getHasName(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()), has(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get())) .save(pWriter); ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', Blocks.DIAMOND_BLOCK) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); } } When I try to run the runData client, it shows an error:  Caused by: java.lang.IllegalStateException: Duplicate recipe compressed:compressed_diamond I know that it's caused by the fact that there are two recipes for the ModItems.COMPRESSED_DIAMOND. But I need both of these recipes, because I need a way to craft ModItems.COMPRESSED_DIAMOND_BLOCK and restore 9 diamond blocks from ModItems.COMPRESSED_DIAMOND. Is there a way to solve this?
  • Topics

×
×
  • Create New...

Important Information

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