Posted May 25, 20196 yr 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)y @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 May 25, 20196 yr by Oscarita25
May 25, 20196 yr Author 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)y does anyone know how i would do this
May 25, 20196 yr 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.
May 25, 20196 yr Author 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?
May 25, 20196 yr The handler is the one I am interested in, although the best case scenario is all of them.
May 25, 20196 yr Author Here the Github repo so you can browse trough: (figured that this would be faster than copy pasting code)Github BNHA ModLayer classModel ID Message Server Model ID Message Client Hope that helps also if i do the Packets wrong tell me how to do them right because i am quite sure i am doing them quite wierd and not very optimized...
May 25, 20196 yr Author 19 minutes ago, V0idWa1k3r said: The handler is the one I am interested in, although the best case scenario is all of them. which handler are you actually refering to?
May 25, 20196 yr 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?
May 25, 20196 yr Author 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
May 25, 20196 yr 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...() ?
May 26, 20196 yr Author so @V0idWa1k3r i did pretty much fix the proxy and the items(i think) and am now stuck on the packets :0 so now at this point i am wondering how should i do it correctly because i used my packets as request and reply :0
May 26, 20196 yr 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.
May 26, 20196 yr Author 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 (just saying i am on basic level of item registering because i pretty much avoid making items at all) Edited May 26, 20196 yr by Oscarita25
May 26, 20196 yr 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.
May 26, 20196 yr Author 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?
May 26, 20196 yr Instantinating means creating a new instance. So when you write new Thing(,,,) you are instantinating Thing.
May 26, 20196 yr Author 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
May 26, 20196 yr Author 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?
May 26, 20196 yr You don't have to write the value = part, but sure. Just make sure the domain of your mod is provided somehow, either in said value or in the annotation on the class itself https://mcforge.readthedocs.io/en/latest/concepts/registries/#injecting-registry-values-into-fields
May 26, 20196 yr Author then 1 last question can i use the object holder to register the model to or do i have to that differently?
May 26, 20196 yr 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(...))
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.