Posted January 8, 201510 yr well good nigths i been create a keybind class and works now i wanna use that keybind to do something i set the key.MULTIPLY i want to put in mi inventory an item when this key is pressed but not know how to achive this, i think i must use packages so alredy have a funtional package handler and do this keybind.MULTIPLY > gearbox.class > packageToserver.class > executeCustonClassThatputTheitemInInventory. in efect i hit multiply and have the item created in inventory but just in the local world so it behaves wrong and can disapear i any moment or is there but dont works . these are just conjuteras whit code and has become long am clumsy like to put here the classes involved soo i gona leave it as a simple question for now how you would do for at pressing particular key on the keyboard will spawn a particular item in inventory
January 8, 201510 yr Author the troube is that the code end being execute in the local world only but there is like seven clases involving sending from one to other but this is the one launchiing the package to execute remotly and execute the code localy to the keybind trigers this in the gearbox class public static void liberar0() { Mercenary.network.sendToServer(new mensajeMercenarioalServidor("liberar"));//execute in server mercenarymod.mensajes.ejecutar.esto("liberar"); //execute here localy liberar=true; } the server handler0 catch the message and do this public IMessage onMessage(mensajeMercenarioalServidor message, MessageContext ctx) { //System.out.println(String.format("Received %s from %s", message, ctx.getServerHandler().playerEntity.getDisplayName())); System.out.println("### Mensaje en el Servidor="+texto0); //pruebaDeMundos.prueba(); ejecutar.esto(texto0); //execute this aparently in the server world } ihave this in console , and i assume it means the server is geting the message [21:32:32] [Netty Server IO #1/INFO] [sTDOUT]: [mercenarymod.mensajes.mensajeMercenarioalServidor$Handler0:onMessage:65]: ### Mensaje en el Servidor=liberar [21:32:32] [Netty Server IO #1/INFO]: [CHAT] §3mundo=true lastly the ejecutar class have this public static void esto(String comando){ Minecraft mc = Minecraft.getMinecraft(); EntityPlayer playerIn= mc.thePlayer; World mundo=playerIn.getEntityWorld(); chat.chatda(playerIn, "mundo="+mundo.isRemote); ItemStack objetoprueba = new ItemStack(MercenaryModItems.camaEl,1,0); playerIn.inventory.setInventorySlotContents(8, objetoprueba); } } the chat.chatda(playerIn, "mundo="+mundo.isRemote); apears 2 times in the screen and say two times mundo=true that means the code is executed two times but just local world , i get the item in inventory but behaves wrong becose is not synced whit server
January 8, 201510 yr Author well now i have something and is working but im afraid to crash a server because i have done keybind > gearbox > sendtoservercomad > sendToLocalcomand i wann reduce the need of code in the event of trigering the accion put in my invetory so in gearbox now i just execute gearbox.java public static void liberar0() { System.out.println("\n\n\n=============liberar=true;============"); //just to mark whent it start this code in the console Mercenary.network.sendToServer(new mensajeMercenarioalServidor("liberar")); liberar=true; } notece i just send the packge to server im not executing the class ejecutar.java from here in the Server handler i do this i execute ejecutar.esto() and resend the mesage from here to the local world System.out.println("Mensaje en el Servidor="+texto0); EntityPlayer playerIn=ctx.getServerHandler().playerEntity; //method taken from diesieben07 EntityPlayerMP playerMp=(EntityPlayerMP)playerIn; World mundo=playerIn.getEntityWorld(); chat.chatda(playerIn, "in server mundo="+mundo.isRemote); ejecutar.esto(texto0,playerIn); Mercenary.network.sendTo(new mensajeMercenarioalMundoLocal("texto0"),playerMp); in the ClientHandler ido this and here is mi fear gets a craddle @Override public IMessage onMessage(mensajeMercenarioalMundoLocal message, MessageContext ctx) { System.out.println("MensajeLocal="+texto1); Minecraft mc = Minecraft.getMinecraft(); EntityPlayer playerIn= mc.thePlayer; //EntityPlayer playerIn=ctx.getServerHandler().playerEntity; //EntityPlayerMP playerMp=(EntityPlayerMP)playerIn; World mundo=playerIn.getEntityWorld(); chat.chatda(playerIn, "in local mundo="+mundo.isRemote); ejecutar.esto(texto1,playerIn); return null; // no response in this case } a have ended using Minecraft mc = Minecraft.getMinecraft(); to get the user but alredy told me that this could crash the server but here is no server here is the client so is teoricaly safe is this true or i have to find other way to get server , idont wanna include playerIn.getUnlocalizatedName in the mesage coz i read there is a limit of 16 characters and i gonna use thath to make this code do a lot of diferent things EntityPlayer playerIn=ctx.getServerHandler().playerEntity; dont works here and dont find equivalent EntityPlayer playerIn=ctx.getClientHandler().playerEntity; for this code, is working rigth no crash no errors on player screen i have in local mundo=true ejecutar mundo=true in server mundo=false ejecutar mundo=false in console i have =============liberar=true;============ [06:23:47] [Netty Server IO #1/INFO] [sTDOUT]: [mercenarymod.mensajes.mensajeMercenarioalServidor$Handler0:onMessage:65]: Mensaje en el Servidor=liberar [06:23:47] [Netty Local Client IO #0/INFO] [sTDOUT]: [mercenarymod.mensajes.mensajeMercenarioalMundoLocal$Handler1:onMessage:66]: MensajeLocal=texto0 [06:23:47] [Netty Local Client IO #0/INFO]: [CHAT] §3in local mundo=true [06:23:47] [Netty Local Client IO #0/INFO]: [CHAT] §3ejecutar mundo=true [06:23:47] [Client thread/INFO]: [CHAT] §3in server mundo=false [06:23:47] [Client thread/INFO]: [CHAT] §3ejecutar mundo=false the items gets to the player inventory whithout weirdness ineed to find i guide to mount a server whith mods for minecraft 1.8 and another pc whit videoCard to make tests to the code
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.