Jump to content

Recommended Posts

Posted (edited)

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
Posted
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

Posted
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.

Posted

i am making the a new Renderer because i just use the parrot as placeholder i will replace it with a model of my own

and you mean like the Packet class of where i am syncing the caps?

Posted
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?

 

 

Posted
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

Posted
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...() ?

 

 

Posted

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.

Posted (edited)

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
Posted

No, you have changed NOTHING. Putting your stuff in an array doesn't change the fact that it is still created in a static initalizer.

Instantinate your stuff in the appropriate registry event as I've already said. Not anywhere else.

Posted
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?

Posted
Just now, V0idWa1k3r said:

Instantinating means creating a new instance.

So when you write new Thing(,,,) you are instantinating Thing.

sorry i meant how would i get the instance of it then 

Posted
1 minute ago, V0idWa1k3r said:

Use the ObjectHolder annotation

    @GameRegistry.ObjectHolder(value = "ua_sports_chestplate")
    public static final Item UA_SPORTS_CHEST = null;

 

like this?

Posted

It would be easiest to do with a one-line stream

Pseudo-code:

ForgeRegistries.ITEMS.valueCollection().stream().filter(i -> i.getRegistryName().getDomain().equals(MYMODID)).foreach(i -> ModelRegistry.setCustomModelResourceLocation(...))

  • Like 1

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

    • Hello, I have this same problem. Did you manage to find a solution? Any help would be appreciated. Thanks.
    • log: https://mclo.gs/QJg3wYX as stated in the title, my game freezes upon loading into the server after i used a far-away waystone in it. The modpack i'm using is better minecraft V18. Issue only comes up in this specific server, singleplayer and other servers are A-okay. i've already experimented with removing possible culprits like modernfix and various others to no effect. i've also attempted a full reinstall of the modpack profile. Issue occurs shortly after the 'cancel' button dissapears on the 'loading world' section of the loading screen.   thanks in advance.
    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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