Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.10.2][SOLVED] Saving player data


lukas2005
 Share

Recommended Posts

now my PlayerDataMessage looks like this:

package pl.minepack.gym.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
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 pl.minepack.gym.Reference;
import pl.minepack.gym.capabilities.IPlayerData;
import pl.minepack.gym.capabilities.ModCapabilities;
import pl.minepack.minelib.utils.utils;

public class PlayerDataMessage implements IMessage {
private int Strength = 0;
private EntityPlayer p;

  // A default constructor is always required
  public PlayerDataMessage(){}


  public PlayerDataMessage(int Strength, EntityPlayer p) {
    this.Strength = Strength;
    this.p = p;
  }

  @Override 
  public void toBytes(ByteBuf buf) {
	  
    buf.writeInt(Strength);
    
  }

  @Override 
  public void fromBytes(ByteBuf buf) {
	  
    // Reads the int back from the buf. Note that if you have multiple values, you must read in the same order you wrote.
	  Strength = buf.readInt();
  }

// The params of the IMessageHandler are <REQ, REPLY>
// This means that the first param is the packet you are receiving, and the second is the packet you are returning.
// The returned packet can be used as a "response" from a sent packet.
public static class PlayerDataMessageHandler implements IMessageHandler<PlayerDataMessage, IMessage> {
  // Do note that the default constructor is required, but implicitly defined in this case

  @Override 
  public IMessage onMessage(PlayerDataMessage message, MessageContext ctx) {
	EntityPlayer p = message.p;
    IPlayerData d = p.getCapability(ModCapabilities.PLAYER_DATA_CAP, null);
    int Strength = message.Strength;
	d.setStrength(Strength);
	utils.Println(d.getStrength() + " : " + p.getName().toString(), Reference.NAME);
    
    // No response packet
    return null;
  }
  
}
  
  
}

so it do't uses these server methods and the error is the same

Link to comment
Share on other sites

  • Replies 72
  • Created
  • Last Reply

Top Posters In This Topic

PlayerDataMessage:

package pl.minepack.gym.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
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 pl.minepack.gym.Reference;
import pl.minepack.gym.capabilities.IPlayerData;
import pl.minepack.gym.capabilities.ModCapabilities;
import pl.minepack.minelib.utils.utils;

public class PlayerDataMessage implements IMessage {
private int Strength = 0;

  // A default constructor is always required
  public PlayerDataMessage(){}


  public PlayerDataMessage(int Strength) {
    this.Strength = Strength;
  }

  @Override 
  public void toBytes(ByteBuf buf) {
	  
    buf.writeInt(Strength);
    
  }

  @Override 
  public void fromBytes(ByteBuf buf) {
	  
    // Reads the int back from the buf. Note that if you have multiple values, you must read in the same order you wrote.
	  Strength = buf.readInt();
  }

// The params of the IMessageHandler are <REQ, REPLY>
// This means that the first param is the packet you are receiving, and the second is the packet you are returning.
// The returned packet can be used as a "response" from a sent packet.
public static class PlayerDataMessageHandler implements IMessageHandler<PlayerDataMessage, IMessage> {
  // Do note that the default constructor is required, but implicitly defined in this case

  @Override 
  public IMessage onMessage(PlayerDataMessage message, MessageContext ctx) {
	EntityPlayer p = utils.getPlayerInstance(ctx);
    IPlayerData d = p.getCapability(ModCapabilities.PLAYER_DATA_CAP, null);
    int Strength = message.Strength;
	d.setStrength(Strength);
	utils.Println(d.getStrength() + " : " + p.getName().toString(), Reference.NAME);
    
    // No response packet
    return null;
  }
  
}
  
  
}

 

utils#getPlayerInstance():

	public static EntityPlayer getPlayerInstance(MessageContext ctx) {

	return (ctx.side.isClient() ? Minecraft.getMinecraft().thePlayer : ctx.getServerHandler().playerEntity);

}

 

EDIT:

For some reason this code stopped working:

log:

 

2016-09-21 20:40:08,665 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream

2016-09-21 20:40:08,668 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream

[20:40:08] [main/INFO] [GradleStart]: username: lukas2005.38@gmail.com

[20:40:08] [main/INFO] [GradleStart]: Extra: []

[20:40:08] [main/INFO] [GradleStart]: Password found, attempting login

[20:40:08] [main/INFO]: Logging in with username & password

[20:40:09] [main/INFO] [GradleStart]: Login Succesful!

[20:40:09] [main/INFO] [GradleStart]: Running with arguments: [--userProperties, [{"name":"preferredLanguage","value":"en"},{"name":"twitch_access_token","value":"09emc4rwc7gr6saqfv8d33k7jxhi69"}], --assetsDir, C:/Users/Łukasz/.gradle/caches/minecraft/assets, --assetIndex, 1.10, --userType, mojang, --accessToken{REDACTED}, --version, 1.10.2, --uuid, e149942f201f48db9f25b34056b86aa9, --username, lukas20056, --tweakClass, net.minecraftforge.fml.common.launcher.FMLTweaker, --tweakClass, net.minecraftforge.gradle.tweakers.CoremodTweaker]

[20:40:09] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker

[20:40:09] [main/INFO] [LaunchWrapper]: Using primary tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker

[20:40:09] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.tweakers.CoremodTweaker

[20:40:09] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLTweaker

[20:40:09] [main/INFO] [FML]: Forge Mod Loader version 12.18.1.2042 for Minecraft 1.10.2 loading

[20:40:09] [main/INFO] [FML]: Java is Java HotSpot 64-Bit Server VM, version 1.8.0_102, running on Windows 10:amd64:10.0, installed at C:\Program Files\Java\jre1.8.0_102

[20:40:09] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation

[20:40:09] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.CoremodTweaker

[20:40:09] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.fml.relauncher.FMLCorePlugin

[20:40:09] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.classloading.FMLForgePlugin

[20:40:09] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker

[20:40:09] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLDeobfTweaker

[20:40:09] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.tweakers.AccessTransformerTweaker

[20:40:09] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker

[20:40:10] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker

[20:40:10] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper

[20:40:10] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work!

[20:40:13] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing

[20:40:13] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper

[20:40:13] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLDeobfTweaker

[20:40:15] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.AccessTransformerTweaker

2016-09-21 20:40:15,676 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream

2016-09-21 20:40:15,757 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream

2016-09-21 20:40:15,759 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream

[20:40:15] [main/INFO] [GradleStart]: Remapping AccessTransformer rules...

[20:40:15] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.TerminalTweaker

[20:40:15] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.TerminalTweaker

[20:40:15] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main}

[20:40:18] [Client thread/INFO]: Setting user: lukas20056

[20:40:26] [Client thread/WARN]: Skipping bad option: lastServer:

[20:40:26] [Client thread/INFO]: LWJGL Version: 2.9.4

[20:40:29] [Client thread/INFO] [sTDOUT]: [net.minecraftforge.fml.client.SplashProgress:start:221]: ---- Minecraft Crash Report ----

// I'm sorry, Dave.

 

Time: 21.09.16 20:40

Description: Loading screen debug info

 

This is just a prompt for computer specs to be printed. THIS IS NOT A ERROR

 

 

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

---------------------------------------------------------------------------------------

 

-- System Details --

Details:

Minecraft Version: 1.10.2

Operating System: Windows 10 (amd64) version 10.0

Java Version: 1.8.0_102, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 748733912 bytes (714 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML:

Loaded coremods (and transformers):

GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 369.09' Renderer: 'GeForce GTX 750 Ti/PCIe/SSE2'

[20:40:29] [Client thread/INFO] [FML]: MinecraftForge v12.18.1.2042 Initialized

[20:40:29] [Client thread/INFO] [FML]: Replaced 233 ore recipes

[20:40:30] [Client thread/INFO] [FML]: Found 0 mods from the command line. Injecting into mod discoverer

[20:40:30] [Client thread/INFO] [FML]: Searching D:\Programy\Deweloping\Projekty\eclipse\Java\Mod Making\Gym-Mod\run\mods for mods

[20:40:32] [Client thread/WARN] [FML]: ****************************************

[20:40:32] [Client thread/WARN] [FML]: * The modid Baubles is not the same as it's lowercase version. Lowercasing will be enforced in 1.11

[20:40:32] [Client thread/WARN] [FML]: *  at net.minecraftforge.fml.common.FMLModContainer.sanityCheckModId(FMLModContainer.java:141)

[20:40:32] [Client thread/WARN] [FML]: *  at net.minecraftforge.fml.common.FMLModContainer.<init>(FMLModContainer.java:126)

[20:40:32] [Client thread/WARN] [FML]: *  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

[20:40:32] [Client thread/WARN] [FML]: *  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

[20:40:32] [Client thread/WARN] [FML]: *  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

[20:40:32] [Client thread/WARN] [FML]: *  at java.lang.reflect.Constructor.newInstance(Unknown Source)...

[20:40:32] [Client thread/WARN] [FML]: ****************************************

[20:40:32] [Client thread/INFO] [FML]: Forge Mod Loader has identified 6 mods to load

[20:40:32] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, gym, minelib, Baubles] at CLIENT

[20:40:32] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, gym, minelib, Baubles] at SERVER

[20:40:33] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:Gym Mod, FMLFileResourcePack:Mine Lib, FMLFileResourcePack:Baubles

[20:40:34] [Client thread/INFO] [FML]: Processing ObjectHolder annotations

[20:40:34] [Client thread/INFO] [FML]: Found 423 ObjectHolder annotations

[20:40:34] [Client thread/INFO] [FML]: Identifying ItemStackHolder annotations

[20:40:34] [Client thread/INFO] [FML]: Found 0 ItemStackHolder annotations

[20:40:34] [Client thread/INFO] [FML]: Configured a dormant chunk cache size of 0

[20:40:34] [Client thread/INFO] [sTDOUT]: [pl.minepack.minelib.utils.utils:Println:58]: [Gym Mod] Pre Init

[20:40:34] [Forge Version Check/INFO] [ForgeVersionCheck]: [Forge] Starting version check at http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json

[20:40:34] [Client thread/INFO] [sTDOUT]: [pl.minepack.minelib.utils.utils:Println:58]: [Mine Lib] Pre Init

[20:40:34] [Client thread/INFO] [FML]: Applying holder lookups

[20:40:34] [Client thread/INFO] [FML]: Holder lookups applied

[20:40:34] [Client thread/INFO] [FML]: Injecting itemstacks

[20:40:34] [Client thread/INFO] [FML]: Itemstack injection complete

[20:40:34] [Forge Version Check/INFO] [ForgeVersionCheck]: [Forge] Found status: OUTDATED Target: 12.18.1.2092

[20:40:40] [sound Library Loader/INFO]: Starting up SoundSystem...

[20:40:41] [Thread-8/INFO]: Initializing LWJGL OpenAL

[20:40:41] [Thread-8/INFO]: (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)

[20:40:41] [Thread-8/INFO]: OpenAL initialized.

[20:40:41] [sound Library Loader/INFO]: Sound engine started

[20:40:52] [Client thread/INFO] [FML]: Max texture size: 16384

[20:40:52] [Client thread/INFO]: Created: 16x16 textures-atlas

[20:40:55] [Client thread/INFO] [sTDOUT]: [pl.minepack.minelib.utils.utils:Println:58]: [Gym Mod] Init

[20:40:55] [Client thread/INFO] [sTDOUT]: [pl.minepack.minelib.utils.utils:Println:58]: [Mine Lib] Init

[20:40:55] [Client thread/INFO] [FML]: Injecting itemstacks

[20:40:55] [Client thread/INFO] [FML]: Itemstack injection complete

[20:40:55] [Client thread/INFO] [sTDOUT]: [pl.minepack.minelib.utils.utils:Println:58]: [Gym Mod] Post Init

[20:40:55] [Client thread/INFO] [sTDOUT]: [pl.minepack.minelib.utils.utils:Println:58]: [Mine Lib] Post Init

[20:40:55] [Client thread/INFO] [FML]: Forge Mod Loader has successfully loaded 6 mods

[20:40:55] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:Gym Mod, FMLFileResourcePack:Mine Lib, FMLFileResourcePack:Baubles

[20:41:01] [Client thread/INFO]: SoundSystem shutting down...

[20:41:01] [Client thread/WARN]: Author: Paul Lamb, www.paulscode.com

[20:41:01] [sound Library Loader/INFO]: Starting up SoundSystem...

[20:41:02] [Thread-10/INFO]: Initializing LWJGL OpenAL

[20:41:02] [Thread-10/INFO]: (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)

[20:41:02] [Thread-10/INFO]: OpenAL initialized.

[20:41:02] [sound Library Loader/INFO]: Sound engine started

[20:41:09] [Client thread/INFO] [FML]: Max texture size: 16384

[20:41:09] [Client thread/INFO]: Created: 1024x512 textures-atlas

[20:41:10] [Client thread/WARN]: Skipping bad option: lastServer:

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]: +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]: The following texture errors were found.

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]: ==================================================

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]:  DOMAIN blocks/blocks/gym

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]: --------------------------------------------------

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]:  domain blocks/blocks/gym is missing 1 texture

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]:    domain blocks/blocks/gym is missing a resource manager - it is probably a side-effect of automatic texture processing

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]: -------------------------

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]:    The missing resources for domain blocks/blocks/gym are:

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]:      textures/particle/ParticleSztanga.png

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]: -------------------------

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]:    No other errors exist for domain blocks/blocks/gym

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]: ==================================================

[20:41:11] [Client thread/ERROR] [TEXTURE ERRORS]: +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

[20:41:21] [server thread/INFO]: Starting integrated minecraft server version 1.10.2

[20:41:21] [server thread/INFO]: Generating keypair

[20:41:21] [server thread/INFO] [FML]: Injecting existing block and item data into this server instance

[20:41:21] [server thread/INFO] [FML]: Applying holder lookups

[20:41:21] [server thread/INFO] [FML]: Holder lookups applied

[20:41:21] [server thread/INFO] [FML]: Loading dimension 0 (Test) (net.minecraft.server.integrated.IntegratedServer@351950a9)

[20:41:22] [server thread/INFO] [FML]: Loading dimension 1 (Test) (net.minecraft.server.integrated.IntegratedServer@351950a9)

[20:41:22] [server thread/INFO] [FML]: Loading dimension -1 (Test) (net.minecraft.server.integrated.IntegratedServer@351950a9)

[20:41:22] [server thread/INFO]: Preparing start region for level 0

[20:41:23] [server thread/INFO]: Preparing spawn area: 0%

[20:41:24] [server thread/INFO]: Preparing spawn area: 53%

[20:41:25] [server thread/INFO]: Changing view distance to 12, from 10

[20:41:27] [Netty Local Client IO #0/INFO] [FML]: Server protocol version 2

[20:41:27] [Netty Server IO #1/INFO] [FML]: Client protocol version 2

[20:41:27] [Netty Server IO #1/INFO] [FML]: Client attempting to join with 6 mods : minelib@1.0,FML@8.0.99.99,Forge@12.18.1.2042,gym@0.0.1,mcp@9.19,Baubles@1.2.1.0

[20:41:27] [Netty Local Client IO #0/INFO] [FML]: [Netty Local Client IO #0] Client side modded connection established

[20:41:27] [server thread/INFO] [FML]: [server thread] Server side modded connection established

[20:41:27] [server thread/INFO]: lukas20056[local:E:6bae02ab] logged in with entity id 207 at (72.14319974255062, 94.0, 51.63044043013551)

[20:41:27] [server thread/INFO]: lukas20056 joined the game

[20:41:27] [Netty Local Client IO #0/ERROR] [FML]: SimpleChannelHandlerWrapper exception

java.lang.NullPointerException

at pl.minepack.gym.network.PlayerDataMessage$PlayerDataMessageHandler.onMessage(PlayerDataMessage.java:53) ~[PlayerDataMessage$PlayerDataMessageHandler.class:?]

at pl.minepack.gym.network.PlayerDataMessage$PlayerDataMessageHandler.onMessage(PlayerDataMessage.java:1) ~[PlayerDataMessage$PlayerDataMessageHandler.class:?]

at net.minecraftforge.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:56) ~[simpleChannelHandlerWrapper.class:?]

at net.minecraftforge.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:36) ~[simpleChannelHandlerWrapper.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) ~[simpleChannelInboundHandler.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:4.0.23.Final]

at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [DefaultChannelPipeline.class:4.0.23.Final]

at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:4.0.23.Final]

at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:109) [FMLProxyPacket.class:?]

at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:156) [NetworkManager.class:?]

at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:51) [NetworkManager.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]

at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleClientSideCustomPacket(NetworkDispatcher.java:410) [NetworkDispatcher.class:?]

at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:276) [NetworkDispatcher.class:?]

at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:73) [NetworkDispatcher.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [DefaultChannelPipeline.class:4.0.23.Final]

at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:326) [LocalChannel.class:4.0.23.Final]

at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:45) [LocalChannel.class:4.0.23.Final]

at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:312) [LocalChannel$5.class:4.0.23.Final]

at io.netty.channel.local.LocalEventLoop.run(LocalEventLoop.java:33) [LocalEventLoop.class:4.0.23.Final]

at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [singleThreadEventExecutor$2.class:4.0.23.Final]

at java.lang.Thread.run(Unknown Source) [?:1.8.0_102]

[20:41:27] [Netty Local Client IO #0/ERROR] [FML]: There was a critical exception handling a packet on channel gym

java.lang.NullPointerException

at pl.minepack.gym.network.PlayerDataMessage$PlayerDataMessageHandler.onMessage(PlayerDataMessage.java:53) ~[PlayerDataMessage$PlayerDataMessageHandler.class:?]

at pl.minepack.gym.network.PlayerDataMessage$PlayerDataMessageHandler.onMessage(PlayerDataMessage.java:1) ~[PlayerDataMessage$PlayerDataMessageHandler.class:?]

at net.minecraftforge.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:56) ~[simpleChannelHandlerWrapper.class:?]

at net.minecraftforge.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:36) ~[simpleChannelHandlerWrapper.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) ~[simpleChannelInboundHandler.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) ~[AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) ~[AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:4.0.23.Final]

at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) ~[AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) ~[AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) ~[DefaultChannelPipeline.class:4.0.23.Final]

at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:4.0.23.Final]

at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:109) [FMLProxyPacket.class:?]

at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:156) [NetworkManager.class:?]

at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:51) [NetworkManager.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]

at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleClientSideCustomPacket(NetworkDispatcher.java:410) [NetworkDispatcher.class:?]

at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:276) [NetworkDispatcher.class:?]

at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:73) [NetworkDispatcher.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [DefaultChannelPipeline.class:4.0.23.Final]

at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:326) [LocalChannel.class:4.0.23.Final]

at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:45) [LocalChannel.class:4.0.23.Final]

at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:312) [LocalChannel$5.class:4.0.23.Final]

at io.netty.channel.local.LocalEventLoop.run(LocalEventLoop.java:33) [LocalEventLoop.class:4.0.23.Final]

at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [singleThreadEventExecutor$2.class:4.0.23.Final]

at java.lang.Thread.run(Unknown Source) [?:1.8.0_102]

[20:41:27] [server thread/INFO]: lukas20056 lost connection: TextComponent{text='Disconnected', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}

[20:41:27] [server thread/INFO]: lukas20056 left the game

[20:41:27] [server thread/INFO]: Stopping singleplayer server as player logged out

[20:41:27] [server thread/INFO]: Stopping server

[20:41:27] [server thread/INFO]: Saving players

[20:41:27] [server thread/INFO]: Saving worlds

[20:41:27] [server thread/INFO]: Saving chunks for level 'Test'/Overworld

[20:41:28] [server thread/INFO]: Saving chunks for level 'Test'/Nether

[20:41:28] [server thread/INFO]: Saving chunks for level 'Test'/The End

[20:41:28] [server thread/INFO] [FML]: Unloading dimension 0

[20:41:28] [server thread/INFO] [FML]: Unloading dimension -1

[20:41:28] [server thread/INFO] [FML]: Unloading dimension 1

[20:41:28] [server thread/INFO] [FML]: Applying holder lookups

[20:41:28] [server thread/INFO] [FML]: Holder lookups applied

[20:42:56] [Client thread/INFO]: Stopping!

[20:42:56] [Client thread/INFO]: SoundSystem shutting down...

[20:42:57] [Client thread/WARN]: Author: Paul Lamb, www.paulscode.com

Java HotSpot 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release

 

 

 

EDIT 2:

It says that the IPlayerData d = p.getCapability(ModCapabilities.PLAYER_DATA_CAP, null); returned null but why?

 

Link to comment
Share on other sites

Something something something NullPointerException something PlayerDataMessage line 53

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

IPlayerData:

package pl.minepack.gym.capabilities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import pl.minepack.gym.network.ModNetwork;
import pl.minepack.gym.network.PlayerDataMessage;
public interface IPlayerData {

	public int addStrength(int count);
	public int subStrength(int count);

	public int setStrength(int count);
	public int getStrength();

	public static class Storage implements Capability.IStorage<IPlayerData> {

		  @Override
		  public NBTBase writeNBT(Capability<IPlayerData> capability, IPlayerData instance, EnumFacing side) {
			  NBTTagCompound nbt = new NBTTagCompound();
			  
			  nbt.setInteger("Strength", instance.getStrength());
			  
			  return nbt;
		  }

			@Override
			public void readNBT(Capability<IPlayerData> capability, IPlayerData instance, EnumFacing side,
					NBTBase nbt) {

				instance.setStrength(((NBTTagCompound)nbt).getInteger("Strength"));

			}

	}

	public static class DefaultImpl implements IPlayerData {

		private int Strength = 0;

		private EntityPlayer p;

		DefaultImpl(EntityPlayer p) {

			this.p = p;

		}

		@Override
		public int addStrength(int count) {

			return setStrength(getStrength() + count);
		}

		@Override
		public int subStrength(int count) {

			return setStrength(getStrength() - count);
		}

		@Override
		public int setStrength(int count) {

			if (!p.getEntityWorld().isRemote) {

				ModNetwork.INSTANCE.sendTo(new PlayerDataMessage(count), (EntityPlayerMP) p);	

			}

			return this.Strength = count;

		}

		@Override
		public int getStrength() {

			return this.Strength;

		}  
	}

	public static class Provider implements ICapabilitySerializable {

		private EntityPlayer p;

		public Provider(EntityPlayer p) {

			this.p = p;

		}


		@Override
		public boolean hasCapability(Capability<?> capability, EnumFacing facing) {

			if (capability instanceof IPlayerData) return true;

			return false;

		}

		@Override
		public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
			return (T) new DefaultImpl(p);
		}

		@Override
		public NBTBase serializeNBT() {
			NBTBase nbt = new NBTTagCompound();



			return nbt;
		}

		@Override
		public void deserializeNBT(NBTBase nbt) {


		}



	}

}

ModCapabilities:

public class ModCapabilities {

@CapabilityInject(IPlayerData.class)
public static Capability<IPlayerData> PLAYER_DATA_CAP = null;

public static void main() {

	CapabilityManager.INSTANCE.register(IPlayerData.class, new IPlayerData.Storage(), IPlayerData.DefaultImpl.class);

}

}

 

ModNetwork:

public class ModNetwork {

public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID);

public static void main() {

	register();

}

public static void register() {

	INSTANCE.registerMessage(PlayerDataMessageHandler.class, PlayerDataMessage.class, 0, Side.CLIENT);

}

}

 

AttachCapabilityEvent:

	@SubscribeEvent
public void attachCap(AttachCapabilitiesEvent.Entity e) {
	if (e.getEntity() instanceof EntityPlayer) {
		//EntityPlayer player = (EntityPlayer) e.getEntity();

		e.addCapability(new ResourceLocation(Reference.MODID, "PlayerData"), new IPlayerData.Provider((EntityPlayer) e.getEntity()));                   

	}
}

and i think thats all stuff related to this topic

Link to comment
Share on other sites

For fucks sake, read what people tell you.

First:

if (capability instanceof IPlayerData) return true;
This won't work.

 

return (T) new DefaultImpl(); // Right here
While this will somewhat work, it is not very useful. Creating a new capability instance every time means it will not persist in any way, ever.
Link to comment
Share on other sites

For fucks sake, read what people tell you.

First:

if (capability instanceof IPlayerData) return true;
This won't work.

 

return (T) new DefaultImpl(); // Right here
While this will somewhat work, it is not very useful. Creating a new capability instance every time means it will not persist in any way, ever.

but what shloud i do in these 2 places??
Link to comment
Share on other sites

but what shloud i do in these 2 places??
See, this is something we can work with. Don't just ignore the advice you get because you don't understand it (because then people will assume you understood it and fixed the problems).

 

In

hasCapability

you have to check if it's your

Capability

instance (the one you receive via

@CapabilityInject

).

Like I hinted at already, you need to create your capability implementation instance once in the constructor of the provider and store it in a field. Then in

getCapability

you just return that instance.

Link to comment
Share on other sites

now my code looks like this:

package pl.minepack.gym.capabilities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import pl.minepack.gym.network.ModNetwork;
import pl.minepack.gym.network.PlayerDataMessage;
public interface IPlayerData {

	public int addStrength(int count);
	public int subStrength(int count);

	public int setStrength(int count);
	public int getStrength();

	public static class Storage implements Capability.IStorage<IPlayerData> {

		  @Override
		  public NBTBase writeNBT(Capability<IPlayerData> capability, IPlayerData instance, EnumFacing side) {
			  NBTTagCompound nbt = new NBTTagCompound();
			  
			  nbt.setInteger("Strength", instance.getStrength());
			  
			  return nbt;
		  }

			@Override
			public void readNBT(Capability<IPlayerData> capability, IPlayerData instance, EnumFacing side,
					NBTBase nbt) {

				instance.setStrength(((NBTTagCompound)nbt).getInteger("Strength"));

			}

	}

	public static class DefaultImpl implements IPlayerData {

		private int Strength = 0;

		private EntityPlayer p;

		DefaultImpl(EntityPlayer p) {

			this.p = p;

		}

		@Override
		public int addStrength(int count) {

			return setStrength(getStrength() + count);
		}

		@Override
		public int subStrength(int count) {

			return setStrength(getStrength() - count);
		}

		@Override
		public int setStrength(int count) {

			if (!p.getEntityWorld().isRemote) {

				ModNetwork.INSTANCE.sendTo(new PlayerDataMessage(count), (EntityPlayerMP) p);	

			}

			return this.Strength = count;

		}

		@Override
		public int getStrength() {

			return this.Strength;

		}  
	}

	public static class Provider implements ICapabilitySerializable {

		private DefaultImpl Impl;

		public Provider(EntityPlayer p) {

			Impl = new DefaultImpl(p);

		}


		@Override
		public boolean hasCapability(Capability<?> capability, EnumFacing facing) {

			if (capability == ModCapabilities.PLAYER_DATA_CAP) return true;

			return false;

		}

		@Override
		public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
			return (T) Impl;
		}

		@Override
		public NBTBase serializeNBT() {
			NBTBase nbt = new NBTTagCompound();



			return nbt;
		}

		@Override
		public void deserializeNBT(NBTBase nbt) {


		}



	}

}

and it still returns null in 53 line of PlayerDataMessage:

package pl.minepack.gym.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IThreadListener;
import net.minecraft.world.WorldServer;
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 pl.minepack.gym.Reference;
import pl.minepack.gym.capabilities.IPlayerData;
import pl.minepack.gym.capabilities.ModCapabilities;
import pl.minepack.minelib.utils.utils;

public class PlayerDataMessage implements IMessage {
private int Strength = 0;

  // A default constructor is always required
  public PlayerDataMessage(){}


  public PlayerDataMessage(int Strength) {
    this.Strength = Strength;
  }

  @Override 
  public void toBytes(ByteBuf buf) {
	  
    buf.writeInt(Strength);
    
  }

  @Override 
  public void fromBytes(ByteBuf buf) {
	  
    // Reads the int back from the buf. Note that if you have multiple values, you must read in the same order you wrote.
	  Strength = buf.readInt();
  }

// The params of the IMessageHandler are <REQ, REPLY>
// This means that the first param is the packet you are receiving, and the second is the packet you are returning.
// The returned packet can be used as a "response" from a sent packet.
public static class PlayerDataMessageHandler implements IMessageHandler<PlayerDataMessage, IMessage> {
  // Do note that the default constructor is required, but implicitly defined in this case

  @Override 
  public IMessage onMessage(PlayerDataMessage message, MessageContext ctx) {
	EntityPlayer p = utils.getPlayerInstance(ctx);
    IPlayerData d = p.getCapability(ModCapabilities.PLAYER_DATA_CAP, null); //Here
	d.setStrength(message.Strength);
	utils.Println(d.getStrength() + " : " + p.getName().toString(), Reference.NAME);
    
    // No response packet
    return null;
  }
  
}
  
  
}

 

Link to comment
Share on other sites

i have these read/write NBT methods in my capability storage class

Indeed you do. But you never use it anywhere. Your provider is responsible for writing the capability to NBT. It can do so via the IStorage interface or not, the IStorage is just a way to communicate "hey, this is how I am saved to disk" from the capability to the provider (capability and provider don't need to be written by the same mod!).
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm trying to make a block that is slippery in one direction: its friction depends on the angle of your motion. I've got it to work perfectly for nonplayer entities, but (once again), the player poses a different issue because of siding. My testing indicates that calling getDeltaMovement is giving (0, -1, 0) on serverside when it shouldn't be, and this screws up the calculation. How can I get accurate information here? @Override public float getFriction(BlockState state, LevelReader level, BlockPos pos, @org.jetbrains.annotations.Nullable Entity entity) { if (entity == null) { return 0.7F; } //Get a unit vector in the appropriate direction Vec3 axisUnitVector = Vec3.ZERO; if (state.getValue(AXIS) == Direction.Axis.X) { axisUnitVector = new Vec3(1, 0, 0); } else if (state.getValue(AXIS) == Direction.Axis.Z) { axisUnitVector = new Vec3(0, 0, 1); } //The block can't be placed vertically //Take the dot product of that vector with a unit vector in the direction of the entity's movement //This effectively just returns the cosine of the angle between the entity's vector and the chosen axis //i.e. 0 when perpendicular, 1 when parallel, etc. Vec3 normalizedMovement = entity.getDeltaMovement().normalize(); double dotProduct = Math.abs(normalizedMovement.dot(axisUnitVector)); //Produce a string for reporting String vectorString = "(" + StringUtils.truncate(String.valueOf(normalizedMovement.x), 4) + "," + StringUtils.truncate(String.valueOf(normalizedMovement.y), 4) + "," + StringUtils.truncate(String.valueOf(normalizedMovement.z), 4) + ")"; //Friction ranges from 0.6 to 1 depending on that cosine double finalMultiplier = Mth.lerp(dotProduct, 0.6, 1); chatPrint("Friction: " + StringUtils.truncate(String.valueOf(finalMultiplier), 5) + ", dot:" + StringUtils.truncate(String.valueOf(dotProduct), 5) + ", vector:" + vectorString + (level.isClientSide() ? "clientside" : "serverside"), (Level) level); return (float) finalMultiplier; } Walking on the block in the slippery direction produces this output: [CHAT] Friction: 0.6, dot:0.0, vector:(0.0,-1.0,0.0) serverside [CHAT] Friction: 0.981, dot:0.953, vector:(-0.0,-0.3,-0.9) clientside [CHAT] Friction: 0.6, dot:0.0, vector:(0.0,-1.0,0.0) serverside [CHAT] Friction: 0.981, dot:0.952, vector:(-0.0,-0.3,-0.9) clientside [CHAT] Friction: 0.6, dot:0.0, vector:(0.0,-1.0,0.0) serverside [CHAT] Friction: 0.981, dot:0.952, vector:(-0.0,-0.3,-0.9) clientside [CHAT] Friction: 0.6, dot:0.0, vector:(0.0,-1.0,0.0) serverside [CHAT] Friction: 0.981, dot:0.952, vector:(-0.0,-0.3,-0.9) clientside [CHAT] Friction: 0.6, dot:0.0, vector:(0.0,-1.0,0.0) serverside [CHAT] Friction: 0.980, dot:0.952, vector:(-0.0,-0.3,-0.9) clientside [CHAT] Friction: 0.6, dot:0.0, vector:(0.0,-1.0,0.0) serverside [CHAT] Friction: 0.980, dot:0.952, vector:(-0.0,-0.3,-0.9) clientside [CHAT] Friction: 0.6, dot:0.0, vector:(0.0,-1.0,0.0) serverside [CHAT] Friction: 0.980, dot:0.952, vector:(-0.0,-0.3,-0.9) clientside  
    • The 1.19 optifine previews are not compatible with forge, see the release notes: https://optifine.net/changelog?f=preview_OptiFine_1.19_HD_U_H8_pre2.jar
    • deleted the folder, and still, not working.
  • Topics

×
×
  • Create New...

Important Information

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