Jump to content

[1.8]advice need for the Packet Handling what i want canbe achived whit this?


Recommended Posts

Posted

well

first i have like 3 months in this is moding

i been struglking in the monecraft code and i think im getting mad,

 

but what i need to solve now is the thing of sending packages and later catchit again tha anyway i gonna if not for this maiby for later but.

i reead this http://www.minecraftforge.net/wiki/Packet_Handling but its old and the imports needit just are not in the same place and probably now are named diferent cuz eclipse dont find suitable candidates

 

What are the replace import for this ?

 

import net.minecraft.network.INetworkManager;

import net.minecraft.network.packet.Packet250CustomPayload;

import cpw.mods.fml.common.network.IPacketHandler;

import cpw.mods.fml.common.network.Player;

 

solvig this i could advance whit this guide but

 

 

What i wanna Do?

 

I have this weapon a colt1911 that took me days adding spinning things and stuff

i have a KeyBindings and set a custom keybind to key.MULTIPLY

i wanna do wen i hit the key.MULTIPLY and the item in hand is the colt1911 it trigers the animation of steve taken out the bullets clip from the gun  leting the gun whithout clip in the hand of steve

 

someone tell me time ago  i need packages to du such thing but now i before read the packages tutorial idont get how to use this for thath

 

bether explain it bether i dont speak english to well so here o go

the colt1911 is a class alredy exist has 3d model, funtional bullets that does damage, I alredy add animations for shoting and change the bulletclip wen empty and all thats works

and alredy hass an item colt1911_bulletclip, 3d model and stuf 

 

wen i hit key.MULTIPLY it must triger the take out clip animation in the gun in hand and must, this is the part troublesome, add an  ItemStack whith one  colt1911_bulletclip  to inventory

 

in order to add an item whithout trouble in inventory it must be done first in remote and the in the local world

but  KeyBindings just execute code in the remote world and i need to execute the  too in the local

 

playerIn1.inventory.setInventorySlotContents(firstEmptySlot , modMercenarioItems.colt1911_bulletclip,1,0);

 

is this achivable via this methods ??

 

 

 

Posted

alredy have reading

 

no errors market in eclipse but crash the game on start up,

i have to fix this code changin the code to adapit to mi needs

 

 

in mi main class preinit i have

Mercenary.class

 
    //declaro el network 
    public static SimpleNetworkWrapper network;
    
    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    Configuration config = new Configuration(event.getSuggestedConfigurationFile());	
    MercenaryModBlocks.init();
    MercenaryModItems.init();
    MercenaryModRecipes.init();
    
    //KeyInputHandler
    FMLCommonHandler.instance().bus().register(new mercenarymod.utilidades.KeyInputHandler());
    mercenarymod.utilidades.KeyBindings.init();


    //send packages 
    network=NetworkRegistry.INSTANCE.newSimpleChannel("canalM00");
    network.registerMessage(Handler.class, mensajeMercenario.class, 0, Side.SERVER);
    
// Sending packets:
//Mercenary.network.sendToServer(new MyMessage("foobar"));
//Mercenary.network.sendTo(new SomeMessage(), somePlayer);

    }

 

Handler.java

package  mercenarymod;

import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public abstract  class Handler implements IMessageHandler<mensajeMercenario, IMessage> {
  
    @Override
    public IMessage onMessage(mensajeMercenario message, MessageContext ctx) {
    	
    	System.out.println(String.format("Received %s from %s", message, ctx.getServerHandler().playerEntity.getDisplayName()));
        return null; // no response in this case
    }

}

 

mensajeMercenario.java

 
package mercenarymod;

import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class mensajeMercenario implements IMessage {
   
    private String text;

    public mensajeMercenario() { }

    public mensajeMercenario(String text) {
        this.setText(text);
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        setText(ByteBufUtils.readUTF8String(buf)); // this class is very useful in general for writing more complex objects
    }

    @Override
    public void toBytes(ByteBuf buf) {
        ByteBufUtils.writeUTF8String(buf, getText());
    }

public String getText() {
	return text;
}

public void setText(String text) {
	this.text = text;
}

    
}

/*
// Sending packets:
Mercenary.network.sendToServer(new MyMessage("foobar"));
Mercenary.network.sendTo(new SomeMessage(), somePlayer);

*/

 

 

it breaks at start up  whith error

17:35:14] [Client thread/ERROR] [FML]: Caught exception from modmercenario

java.lang.RuntimeException: java.lang.InstantiationException

at com.google.common.base.Throwables.propagate(Throwables.java:160) ~[guava-17.0.jar:?]

[17:35:00] [main/INFO] [GradleStart]: Extra: []
[17:35:01] [main/INFO] [GradleStart]: Running with arguments: [--userProperties, {}, --accessToken, {REDACTED}, --assetIndex, 1.8, --assetsDir, /home/tenchi/.gradle/caches/minecraft/assets, --version, 1.8, --tweakClass, net.minecraftforge.fml.common.launcher.FMLTweaker, --tweakClass, net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker]
[17:35:01] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker
[17:35:01] [main/INFO] [LaunchWrapper]: Using primary tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker
[17:35:01] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker
[17:35:01] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLTweaker
[17:35:01] [main/INFO] [FML]: Forge Mod Loader version 8.0.12.1261 for Minecraft 1.8 loading
[17:35:01] [main/INFO] [FML]: Java is Java HotSpot(TM) 64-Bit Server VM, version 1.7.0_71, running on Linux:amd64:3.2.0-4-amd64, installed at /opt/oracle/jre1.7.0_71
[17:35:01] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation
[17:35:01] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker
[17:35:01] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.fml.relauncher.FMLCorePlugin
[17:35:01] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.classloading.FMLForgePlugin
[17:35:01] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[17:35:01] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLDeobfTweaker
[17:35:01] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[17:35:01] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[17:35:01] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper
[17:35:01] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work!
[17:35:02] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing
[17:35:02] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper
[17:35:02] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLDeobfTweaker
[17:35:03] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.TerminalTweaker
[17:35:03] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.TerminalTweaker
[17:35:03] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main}
[17:35:04] [Client thread/INFO]: Setting user: Player411
[17:35:08] [Client thread/INFO]: LWJGL Version: 2.9.1
[17:35:09] [Client thread/INFO] [MinecraftForge]: Attempting early MinecraftForge initialization
[17:35:09] [Client thread/INFO] [FML]: MinecraftForge v11.14.0.1261 Initialized
[17:35:09] [Client thread/INFO] [FML]: Replaced 215 ore recipies
[17:35:09] [Client thread/INFO] [MinecraftForge]: Completed early MinecraftForge initialization
[17:35:09] [Client thread/INFO] [FML]: Searching /home/tenchi/Modding/forge-1.8-11.14.0.1261-1.8-src/eclipse/mods for mods
[17:35:09] [Client thread/INFO] [modmercenario]: Mod modmercenario is missing the required element 'name'. Substituting modmercenario
[17:35:13] [Client thread/INFO] [FML]: Forge Mod Loader has identified 5 mods to load
[17:35:13] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, examplemod, modmercenario] at CLIENT
[17:35:13] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, examplemod, modmercenario] at SERVER
[17:35:14] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:Example Mod, FMLFileResourcePack:modmercenario
[17:35:14] [Client thread/INFO] [FML]: Processing ObjectHolder annotations
[17:35:14] [Client thread/INFO] [FML]: Found 384 ObjectHolder annotations
[17:35:14] [Client thread/INFO] [FML]: Configured a dormant chunk cache size of 0
[17:35:14] [Client thread/INFO] [FML]: Applying holder lookups
[17:35:14] [Client thread/INFO] [FML]: Holder lookups applied
[17:35:14] [Client thread/ERROR] [FML]: Fatal errors were detected during the transition from PREINITIALIZATION to INITIALIZATION. Loading cannot continue
[17:35:14] [Client thread/ERROR] [FML]: 
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized
FML{8.0.12.1261} [Forge Mod Loader] (forgeSrc-1.8-11.14.0.1261-1.8.jar) Unloaded->Constructed->Pre-initialized
Forge{11.14.0.1261} [Minecraft Forge] (forgeSrc-1.8-11.14.0.1261-1.8.jar) Unloaded->Constructed->Pre-initialized
examplemod{1.0} [Example Mod] (bin) Unloaded->Constructed->Pre-initialized
modmercenario{1.1} [modmercenario] (bin) Unloaded->Constructed->Errored
[17:35:14] [Client thread/ERROR] [FML]: The following problems were captured during this phase
[17:35:14] [Client thread/ERROR] [FML]: Caught exception from modmercenario
java.lang.RuntimeException: java.lang.InstantiationException
at com.google.common.base.Throwables.propagate(Throwables.java:160) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:116) ~[forgeSrc-1.8-11.14.0.1261-1.8.jar:?]
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:106) ~[forgeSrc-1.8-11.14.0.1261-1.8.jar:?]
at mercenarymod.Mercenary.preInit(Mercenary.java:60) ~[bin/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_71]
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:515) ~[forgeSrc-1.8-11.14.0.1261-1.8.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_71]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[forgeSrc-1.8-11.14.0.1261-1.8.jar:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[forgeSrc-1.8-11.14.0.1261-1.8.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_71]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118) [LoadController.class:?]
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:513) [Loader.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:235) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:413) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:325) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_71]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]
at GradleStart.main(GradleStart.java:45) [start/:?]
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_71]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_71]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_71]
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:113) ~[forgeSrc-1.8-11.14.0.1261-1.8.jar:?]
... 41 more
[17:35:14] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:568]: ---- Minecraft Crash Report ----
// I'm sorry, Dave.

Time: 6/01/15 05:35 PM
Description: Initializing game

java.lang.RuntimeException: java.lang.InstantiationException
at com.google.common.base.Throwables.propagate(Throwables.java:160)
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:116)
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:106)
at mercenarymod.Mercenary.preInit(Mercenary.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:515)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:513)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:235)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:413)
at net.minecraft.client.Minecraft.run(Minecraft.java:325)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)
at GradleStart.main(GradleStart.java:45)
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:113)
... 41 more


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at com.google.common.base.Throwables.propagate(Throwables.java:160)
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:116)
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:106)
at mercenarymod.Mercenary.preInit(Mercenary.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:515)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:513)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:235)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:413)

-- Initialization --
Details:
Stacktrace:
at net.minecraft.client.Minecraft.run(Minecraft.java:325)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)
at GradleStart.main(GradleStart.java:45)

-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Linux (amd64) version 3.2.0-4-amd64
Java Version: 1.7.0_71, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 878426176 bytes (837 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.10 FML v8.0.12.1261 Minecraft Forge 11.14.0.1261 5 mods loaded, 5 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized
FML{8.0.12.1261} [Forge Mod Loader] (forgeSrc-1.8-11.14.0.1261-1.8.jar) Unloaded->Constructed->Pre-initialized
Forge{11.14.0.1261} [Minecraft Forge] (forgeSrc-1.8-11.14.0.1261-1.8.jar) Unloaded->Constructed->Pre-initialized
examplemod{1.0} [Example Mod] (bin) Unloaded->Constructed->Pre-initialized
modmercenario{1.1} [modmercenario] (bin) Unloaded->Constructed->Errored
Launched Version: 1.8
LWJGL: 2.9.1
OpenGL: GeForce GT 520/PCIe/SSE2 GL version 4.2.0 NVIDIA 304.117, NVIDIA Corporation
GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

Using VBOs: No
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: Español (México)
Profiler Position: N/A (disabled)
[17:35:14] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:568]: #@!@# Game crashed! Crash report saved to: #@!@# /home/tenchi/Modding/forge-1.8-11.14.0.1261-1.8-src/eclipse/./crash-reports/crash-2015-01-06_17.35.14-client.txt

 

jumm

nop idont get whats is wrong

 

 

Posted

eclipse make a handler.class method abstrack and i dint notice it

 

ñaa just fix that and get  a new one

 

 

wen try to send the message it break the world

 



[17:56:56] [Netty Server IO #1/ERROR] [FML]: FMLIndexedMessageCodec exception caught
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: mercenarymod.mensajeMercenario
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:4.0.15.Final]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:4.0.15.Final]
at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:79) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:136) [NetworkManager.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:414) [NetworkManager.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103) [simpleChannelInboundHandler.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleServerSideCustomPacket(NetworkDispatcher.java:377) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:215) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:47) [NetworkDispatcher.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103) [simpleChannelInboundHandler.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:4.0.15.Final]
at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:312) [LocalChannel.class:4.0.15.Final]
at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:44) [LocalChannel.class:4.0.15.Final]
at io.netty.channel.local.LocalChannel$6.run(LocalChannel.java:298) [LocalChannel$6.class:4.0.15.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354) [singleThreadEventExecutor.class:4.0.15.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353) [NioEventLoop.class:4.0.15.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) [singleThreadEventExecutor$2.class:4.0.15.Final]
at java.lang.Thread.run(Unknown Source) [?:1.7.0_71]
Caused by: java.lang.InstantiationException: mercenarymod.mensajeMercenario
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_71]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:79) ~[FMLIndexedMessageToMessageCodec.class:?]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:21) ~[FMLIndexedMessageToMessageCodec.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.15.Final]
... 25 more
[17:56:56] [Netty Server IO #1/ERROR] [FML]: SimpleChannelHandlerWrapper exception
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: mercenarymod.mensajeMercenario
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:4.0.15.Final]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:4.0.15.Final]
at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:79) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:136) [NetworkManager.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:414) [NetworkManager.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103) [simpleChannelInboundHandler.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleServerSideCustomPacket(NetworkDispatcher.java:377) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:215) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:47) [NetworkDispatcher.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103) [simpleChannelInboundHandler.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:4.0.15.Final]
at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:312) [LocalChannel.class:4.0.15.Final]
at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:44) [LocalChannel.class:4.0.15.Final]
at io.netty.channel.local.LocalChannel$6.run(LocalChannel.java:298) [LocalChannel$6.class:4.0.15.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354) [singleThreadEventExecutor.class:4.0.15.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353) [NioEventLoop.class:4.0.15.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) [singleThreadEventExecutor$2.class:4.0.15.Final]
at java.lang.Thread.run(Unknown Source) [?:1.7.0_71]
Caused by: java.lang.InstantiationException: mercenarymod.mensajeMercenario
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_71]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:79) ~[FMLIndexedMessageToMessageCodec.class:?]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:21) ~[FMLIndexedMessageToMessageCodec.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.15.Final]
... 25 more
[17:56:56] [Netty Server IO #1/ERROR] [FML]: There was a critical exception handling a packet on channel canalM00
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: mercenarymod.mensajeMercenario
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:4.0.15.Final]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:4.0.15.Final]
at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:79) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:136) [NetworkManager.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:414) [NetworkManager.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103) [simpleChannelInboundHandler.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleServerSideCustomPacket(NetworkDispatcher.java:377) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:215) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:47) [NetworkDispatcher.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103) [simpleChannelInboundHandler.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:4.0.15.Final]
at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:312) [LocalChannel.class:4.0.15.Final]
at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:44) [LocalChannel.class:4.0.15.Final]
at io.netty.channel.local.LocalChannel$6.run(LocalChannel.java:298) [LocalChannel$6.class:4.0.15.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354) [singleThreadEventExecutor.class:4.0.15.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353) [NioEventLoop.class:4.0.15.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) [singleThreadEventExecutor$2.class:4.0.15.Final]
at java.lang.Thread.run(Unknown Source) [?:1.7.0_71]
Caused by: java.lang.InstantiationException: mercenarymod.mensajeMercenario
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_71]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:79) ~[FMLIndexedMessageToMessageCodec.class:?]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:21) ~[FMLIndexedMessageToMessageCodec.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.15.Final]
... 25 more
[17:56:56] [server thread/INFO]: Player267 lost connection: TextComponent{text='A fatal error has occured, this 

Posted

Double check that there is no abstract methods. It seems like there is problem to construct new instance of mercenarymod.mensajeMercenario

Posted

i check and no abstracks remain.

 

eclipse says no errors but

reading again the guides they say  in the old ways you must define the chanel in the sending code , i dont see thath here

 

the game crash wen try to send this from a testItem

 

public ItemStack onItemRightClick(ItemStack cargador, World worldIn, EntityPlayer playerIn)

  {

   

    if (!worldIn.isRemote){

    Mercenary.network.sendToServer(new mensajeMercenario("foobar"));

    }

   

    return cargador;

  } 

 

 

ñaa i can realize whats wrong

 

someone can show me a code whith a working package system whith the preinit part  the clasess and example of sending and reciving

Posted

ya

alredy founded a gramatical error and fixit

The part to send messages to server is working but send mesages to local world demand i use a stance of EntityPlayerMP, and it happens that is diferent than  EntityPlayerMC  and cannot cast it from player using trics like

EntityPlayerMP player =(EntityPlayerMP) playerIn;

 

anyway i think that is a server thing an no work unless i have a server runing

 

thiis my working Mesage code i put the clases in a folder named mensajes to avoid disorder in the main folder 

 

main class Mercenary.java  preiniti

public static SimpleNetworkWrapper network;
    
   
    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    Configuration config = new Configuration(event.getSuggestedConfigurationFile());	
    MercenaryModBlocks.init();
    MercenaryModItems.init();
    MercenaryModRecipes.init();

    //KeyInputHandler
    FMLCommonHandler.instance().bus().register(new mercenarymod.utilidades.KeyInputHandler());
    mercenarymod.utilidades.KeyBindings.init();

    //enviar paquetes 
    network=NetworkRegistry.INSTANCE.newSimpleChannel("canalM00");
    network.registerMessage(mensajeMercenarioalServidor.Handler0.class, mensajeMercenarioalServidor.class, 0, Side.SERVER);
    network.registerMessage(mensajeMercenarioalMundoLocal.Handler1.class, mensajeMercenarioalMundoLocal.class, 1, Side.CLIENT);
    

   

mensajeMercenarioalServidor.java

package mercenarymod.mensajes;

import io.netty.buffer.ByteBuf;
import mercenarymod.Mercenary;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;


public class mensajeMercenarioalServidor implements IMessage {
   

private static String texto0;

public mensajeMercenarioalServidor(){;}
    

    public mensajeMercenarioalServidor(String text) {
        //this.setText(text);
    	texto0=text;
    	//System.out.println("Aqui en el mensaje al servidor");
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        setText(ByteBufUtils.readUTF8String(buf)); // this class is very useful in general for writing more complex objects
    }

    @Override
    public void toBytes(ByteBuf buf) {
        ByteBufUtils.writeUTF8String(buf, getText());
    }

public String getText() {
	return texto0;
}

public void setText(String text) {
	this.texto0 = text;
}

    
//Mercenary.network.sendToServer(new mensajeMercenarioalServidor("es remoto este mundo"));


public static class Handler0 implements IMessageHandler<mensajeMercenarioalServidor, IMessage> {


    @Override
    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();
    	return null; // no response in this case
    }




}

}

 

mensajeMercenarioalMundoLocal.java

package mercenarymod.mensajes;

import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;


public class mensajeMercenarioalMundoLocal implements IMessage {
   
  

private static String texto1;

public mensajeMercenarioalMundoLocal(){;}
    

    public mensajeMercenarioalMundoLocal(String text) {
        //this.setText(text);
    	texto1=text;
    	//System.out.println("Aqui en el mensaje al mundo Local");
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        setText(ByteBufUtils.readUTF8String(buf)); // this class is very useful in general for writing more complex objects
    }

    @Override
    public void toBytes(ByteBuf buf) {
        ByteBufUtils.writeUTF8String(buf, getText());
    }

public String getText() {
	return texto1;
}

public void setText(String text) {
	this.texto1 = text;
}

    
//Mercenary.network.sendTo(new mensajeMercenarioalMundoLocal("Es este el mundo local"),playerMP);



public static class Handler1 implements IMessageHandler<mensajeMercenarioalMundoLocal, IMessage> {


    @Override
    public IMessage onMessage(mensajeMercenarioalMundoLocal message, MessageContext ctx) {
    	
    	//System.out.println(String.format("Received %s from %s", message, ctx.getServerHandler().playerEntity.getDisplayName()));
    	System.out.println("MensajeLocal="+texto1);
    	pruebaDeMundos.prueba();
    	
    	return null; // no response in this case
    }




}


}

 

pruebaDeMundos.java

package mercenarymod.mensajes;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;


public class pruebaDeMundos{



public pruebaDeMundos() {;}



public static void prueba(){



Minecraft mc = Minecraft.getMinecraft();
EntityPlayer playerIn= mc.thePlayer;
World worldIn=mc.theWorld;
World worldOn= playerIn.getEntityWorld();	
WorldProvider worldUn=worldOn.provider;

System.out.println("$$$$= es worldIn remoto ="+worldIn.isRemote);
//System.out.println("\n\n\nes worldIn remoto ="+worldOn.isRemote);


}



}

 

 

i been testing this using this code

 

public ItemStack onItemRightClick(ItemStack cargador, World worldIn, EntityPlayer playerIn)
  {
    	
    	
    
    	System.out.println("%%%%= es worldIn remoto ="+worldIn.isRemote);
    	Mercenary.network.sendToServer(new mensajeMercenarioalServidor("es remoto este mundo"));
    	//Mercenary.network.sendTo(new mensajeMercenarioalMundoLocal("Es este el mundo local"),???PlayerMp);
    	
    	
    return cargador;
  }

 

 

[12:18:28] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.pruebas.itemPrueba00:onItemRightClick:70]: %%%%= es worldIn remoto =true

[12:18:28] [Netty Server IO #1/INFO] [sTDOUT]: [mercenarymod.mensajes.mensajeMercenarioalServidor$Handler0:onMessage:65]: Mensaje en el Servidor=es remoto este mundo

[12:18:28] [Netty Server IO #1/INFO] [sTDOUT]: [mercenarymod.mensajes.pruebaDeMundos:prueba:27]: $$$$= es worldIn remoto =true

[12:18:28] [server thread/INFO] [sTDOUT]: [mercenarymod.items.pruebas.itemPrueba00:onItemRightClick:70]: %%%%= es worldIn remoto =false

[12:18:28] [Netty Server IO #1/INFO] [sTDOUT]: [mercenarymod.mensajes.mensajeMercenarioalServidor$Handler0:onMessage:65]: Mensaje en el Servidor=es remoto este mundo

[12:18:28] [Netty Server IO #1/INFO] [sTDOUT]: [mercenarymod.mensajes.pruebaDeMundos:prueba:27]: $$$$= es worldIn remoto =true

Posted

 

then you're saying that whith no server I still can send packets to the local world from the "local server"  i think i need thath for wath im triying to do but. ¿how i get a instance of EntityPlayerMP. for my local player  becose the method onitemrigthclick only give EntityPlayer whithout the MP and the network.sendTo(  is demanding a playerMP

 

 

look at this if i load this whith  EntityPlayer playerIn  eclipse starts complaining

Mercenary.network.sendTo(new mensajeMercenarioalMundoLocal("Es este el mundo local"),playerIn);

 

minecraft runs but crash wen i hit rigth click whit error

 

java.util.concurrent.ExecutionException: java.lang.Error: Unresolved compilation problem:

The method sendTo(IMessage, EntityPlayerMP) in the type SimpleNetworkWrapper is not applicable for the arguments (mensajeMercenarioalMundoLocal, EntityPlayer)

 

###

if  i do

public ItemStack onItemRightClick(ItemStack cargador, World worldIn, EntityPlayer playerIn)

  {

   

        //EntityPlayerMP playerMp= (EntityPlayerMP) playerIn;

        //crash error java.lang.ClassCastException: net.minecraft.client.entity.EntityPlayerSP cannot be cast to net.minecraft.entity.player.EntityPlayerMP

 

    EntityPlayerMP playerMp=null;

   

    System.out.println("%%%%= es worldIn remoto ="+worldIn.isRemote);

    //Mercenary.network.sendToServer(new mensajeMercenarioalServidor("es remoto este mundo"));

    if (worldIn.isRemote){Mercenary.network.sendTo(new mensajeMercenarioalMundoLocal("Es este el mundo local"),playerMp);}

   

    return cargador;

  }

eclipse does not bother me but anyway dont crash but dont work it fail for the null player

 

java.lang.RuntimeException: PLAYER target expects a Player arg

 

###

is geting to long i need to know how i get an instance of EntityPlayerMP 

or maiby i have wrong the mensajeMercenarioalMundoLocal.java

or this need an extra trick to work ?

or everithing is wrong from the same start

Posted

public ItemStack onItemRightClick(ItemStack cargador, World worldIn, EntityPlayer playerIn)

  {

   

    System.out.println("%%%%= es worldIn remoto ="+worldIn.isRemote);

    Mercenary.network.sendToServer(new mensajeMercenarioalServidor("es remoto este mundo"));

    if (!worldIn.isRemote){

    EntityPlayerMP playerMp= (EntityPlayerMP) playerIn;

    Mercenary.network.sendTo(new mensajeMercenarioalMundoLocal("Es este el mundo local"),playerMp);

                                          }

   

    return cargador;

  }

 

then this must be the rigth way to send the mesage to local and server at same time

so that means

 

(world.isRemote)=true  then this is local world

 

(!world.isRemote)=true  then this is server world

   

and it means to  the bulletclip thing gonna get messy

Posted

Yeah, if you are doing client to server packets, ALWAYS send the packets. Since 1.3, singleplayer runs a server as well to support LAN worlds.

 

- Romejanic

Romejanic

 

Creator of Witch Hats, Explosive Chickens and Battlefield!

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

    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
  • Topics

×
×
  • Create New...

Important Information

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