Jump to content

Recommended Posts

Posted

Hello!

I'm trying to render a new layer on the player model, which we be scaled differently based on a value stored in the player capabilities.
I got the rendering to work, the capability too, but now i'm trying to retrieve the value from the capability to modify on the fly the scaling.
However, the capability always return the base value (0.0) when I try to view the player model in the inventory, or using F5, and of course it doesn't work in multiplayer too.

What could be the problem?
I've attached a screenshot to show the chain of events I'm logging into the player chat.

This is my Event Handler
 

Spoiler

@Mod.EventBusSubscriber
public class HyperEventHandler {

  private final PSizeModifier pSizeModifier = new PSizeModifier();
  private IPSize pSize = null;

  @SubscribeEvent
  public void onPlayerLogsIn(PlayerLoggedInEvent event)
  {
    EntityPlayer player = event.player;
    if(player instanceof EntityPlayerMP)
    {
      pSize = player.getCapability(PSizeProvider.SIZE_CAPABILITY, null);

      IMessage msgSize = new SizeSyncPacket.SizeSyncMessage(pSize.getSize(), 0.0F, player.getEntityId());
      HyperPackets.net.sendToAll(msgSize);
      player.sendMessage(new TextComponentString("Size : " + pSize.getSize()));
    }
  }

  @SubscribeEvent
  public void onPlayerUpdate(LivingUpdateEvent event)
  {
    if(event.getEntity() instanceof EntityPlayer)
    {
      EntityPlayer player = (EntityPlayer) event.getEntity();

      if(!player.world.isRemote)
      {
        pSizeModifier.onPlayerUpdate(player);

        IMessage msgSize = new SizeSyncPacket.SizeSyncMessage(pSize.getSize(), 0.0F, player.getEntityId());
        HyperPackets.net.sendToAll(msgSize);
      }
    }
  }

  @SubscribeEvent
  public void clonePlayer(PlayerEvent.Clone event) {

    final IPSize original = PSizeProvider.getPHandler(event.getOriginal());
    final IPSize clone = PSizeProvider.getPHandler(event.getEntity());
    clone.set(original.getSize());
  }

  private static boolean layerAdded = false;

  @SubscribeEvent
  public void onPlayerRender(Pre event)
  {
    EntityPlayer player = (EntityPlayer) event.getEntity();
    if(!layerAdded)
    {
      Minecraft.getMinecraft().getRenderManager().getSkinMap().get("default").addLayer(new LayerCube(event.getRenderer()));
      Minecraft.getMinecraft().getRenderManager().getSkinMap().get("slim").addLayer(new LayerCube(event.getRenderer()));
      layerAdded = true;
    }
    if(event.getEntity() instanceof EntityPlayer)
    {
      IPSize pSize = event.getEntityPlayer().getCapability(PSizeProvider.SIZE_CAPABILITY, null);

      player.sendMessage(new TextComponentString(player.getDisplayNameString() + " : " + pSize.getSize()));
    }
  }

}

 

The SizeSyncPacket class
 

Spoiler

public class SizeSyncPacket implements IMessageHandler<SizeSyncMessage, IMessage> {

  public SizeSyncPacket(){}

  @Override
  public IMessage onMessage(SizeSyncMessage message, MessageContext ctx) {

    if(ctx.side.isClient())
    {
      float pSize = message.pSize;
      float bSize = message.bSize;

      //Attempt to synchronise capability using the Entity ID
      Minecraft.getMinecraft().addScheduledTask(() -> {
       Entity player = Minecraft.getMinecraft().world.getEntityByID(message.entityID);
       if(player == null)
         return;
       IPSize ppSize = player.getCapability(PSizeProvider.SIZE_CAPABILITY, null);	//TODO: Rename this with a clearer name
       if(ppSize != null)
         ppSize.set(pSize);
       });
    }

    return null;
  }

  public static class SizeSyncMessage implements IMessage
  {

    private float pSize;
    private float bSize;
    private int entityID;

    public SizeSyncMessage(float pSize, float bSize, int entityID)
    {
      this.pSize = pSize;
      this.bSize = bSize;
      this.entityID = entityID;
    }


    @Override
    public void fromBytes(ByteBuf buf) {
      this.pSize = buf.readFloat();
      this.bSize = buf.readFloat();
    }

    @Override
    public void toBytes(ByteBuf buf) {
      buf.writeFloat(pSize);
      buf.writeFloat(bSize);
    }
  }


}

 


If you think the problem might be elsewhere than these 2 classes, please feel free to tell me!

MC.png

Posted

Your packet does not have a 0-parameter constructor. The game should vomit an error when your packet is sent.

  • Like 1

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.

Posted

Well, somehow it doesn't, I forgot to put it, sorry
 

Spoiler

...
public static class SizeSyncMessage implements IMessage
  {

    private float pSize;
    private float bSize;
    private int entityID;

    public SizeSyncMessage() {}

    public SizeSyncMessage(float pSize, float bSize, int entityID)
    {
      this.pSize = pSize;
      this.bSize = bSize;
      this.entityID = entityID;
    }
...

 

 

Posted
  • Where should I move the RenderPlayerEvent?
  • Changed, in my case, is it better to use START or END ?
    Spoiler
    
     @SubscribeEvent
      public void onPlayerUpdate(PlayerTickEvent event)
      {
        if(event.phase == Phase.START) {
          EntityPlayer player = event.player;
          if (!player.world.isRemote) {
            pSizeModifier.onPlayerUpdate(player);
    
            IMessage msgSize = new SizeSyncPacket.SizeSyncMessage(pSize.getSize(), 0.0F, player.getEntityId());
            HyperPackets.net.sendToAllTracking(msgSize, player);
            HyperPackets.net.sendTo(msgSize, (EntityPlayerMP) player);
          }
        }
      }

     

  • Removed the check
  • How can I check if the value has changed? Should I simply store it temporarily and then send it if the temp value is different than the current value?
  • Applied everything, is this correct?
    Spoiler
    
      @SubscribeEvent
      public void onPlayerLogsIn(PlayerLoggedInEvent event)
      {
        EntityPlayer player = event.player;
        pSize = player.getCapability(PSizeProvider.SIZE_CAPABILITY, null);
    
        IMessage msgSize = new SizeSyncPacket.SizeSyncMessage(pSize.getSize(), 0.0F, player.getEntityId());
        HyperPackets.net.sendToAll(msgSize);
        HyperPackets.net.sendTo(msgSize, (EntityPlayerMP) player);
        player.sendMessage(new TextComponentString("Size : " + pSize.getSize()));
      }
    
      @SubscribeEvent
      public void onPlayerRespawn(PlayerRespawnEvent event)
      {
        EntityPlayer player = event.player;
        pSize = player.getCapability(PSizeProvider.SIZE_CAPABILITY, null);
    
        IMessage msgSize = new SizeSyncPacket.SizeSyncMessage(pSize.getSize(), 0.0F, player.getEntityId());
        HyperPackets.net.sendTo(msgSize, (EntityPlayerMP) player);
      }
    
      @SubscribeEvent
      public void onPlayerChangedDimension(PlayerChangedDimensionEvent event)
      {
        EntityPlayer player = event.player;
        pSize = player.getCapability(PSizeProvider.SIZE_CAPABILITY, null);
    
        IMessage msgSize = new SizeSyncPacket.SizeSyncMessage(pSize.getSize(), 0.0F, player.getEntityId());
        HyperPackets.net.sendTo(msgSize, (EntityPlayerMP) player);
      }
    
      @SubscribeEvent
      public void onTrackingStart(PlayerEvent.StartTracking event)
      {
        if(!(event.getTarget() instanceof EntityPlayer))
          return;
        EntityPlayer target = (EntityPlayer) event.getTarget();
        pSize = target.getCapability(PSizeProvider.SIZE_CAPABILITY, null);
    
        IMessage msgSize = new SizeSyncPacket.SizeSyncMessage(pSize.getSize(), 0.0F, target.getEntityId());
        HyperPackets.net.sendTo(msgSize, (EntityPlayerMP) event.getEntityPlayer());
      }
    
      @SubscribeEvent
      public void onPlayerUpdate(PlayerTickEvent event)
      {
        if(event.phase == Phase.START) {
          EntityPlayer player = event.player;
          if (!player.world.isRemote) {
            pSizeModifier.onPlayerUpdate(player);
            //TODO: Send update when data changes
            IMessage msgSize = new SizeSyncPacket.SizeSyncMessage(pSize.getSize(), 0.0F, player.getEntityId());
            HyperPackets.net.sendToAllTracking(msgSize, player);
            HyperPackets.net.sendTo(msgSize, (EntityPlayerMP) player);
          }
        }
      }

     

     

Posted (edited)
  • Okay, moved all rendering to a separate class
    Spoiler
    
    @Mod.EventBusSubscriber(value = {Side.CLIENT})
    public class HyperClientEventHandler {
    
      @SubscribeEvent
      public void onHandRender(RenderHandEvent event)
      {
        //TODO: Fill this up
      }
      private static boolean layerAdded = false;
    
      @SubscribeEvent
      public void onPlayerRender(Pre event)
      {
        EntityPlayer player = (EntityPlayer) event.getEntity();
        if(!layerAdded)
        {
          Minecraft.getMinecraft().getRenderManager().getSkinMap().get("default").addLayer(new LayerBalls(event.getRenderer()));
          Minecraft.getMinecraft().getRenderManager().getSkinMap().get("slim").addLayer(new LayerBalls(event.getRenderer()));
          layerAdded = true;
        }
        if(event.getEntity() instanceof EntityPlayer)
        {
          IPSize pSize = event.getEntityPlayer().getCapability(PSizeProvider.SIZE_CAPABILITY, null);
    
          player.sendMessage(new TextComponentString(player.getDisplayNameString() + " : " + pSize.getSize()));
        }
      }
    
    }

     

  • So I just need to remove onPlayerUpdate of my code, alright
  • Sending the packet each time the setter is called
    Spoiler
    
      private void sendUpdate(EntityPlayer player)
      {
        IMessage msgSize = new SizeSyncPacket.SizeSyncMessage(getSize(), 0.0F, player.getEntityId());
        HyperPackets.net.sendToAllTracking(msgSize, player);
        HyperPackets.net.sendTo(msgSize, (EntityPlayerMP) player);
      }
    
      @Override
      public void set(float size, EntityPlayer player) {
        this.size = size;
        sendUpdate(player);
      }
    
      //Same thing for the other corresponding methods

     

  • EDIT : Okay, the problem is, by doing it like this it break my readNBT method of my storage class, since i'm calling instance.set(), and now it need an EntityPlayer to be passed, I don't see an obvious way to specify it tho
     
  • Removed sendToAll()

Sorry about the copy pasting, bad habit of mine. Moved every similar packet related things into a private sendUpdateMessage() method.

Edited by WORMSTweaker
Capability Storage broken
Posted

Okay, now the problem is, by passing EntityPlayer in my setters it break my readNBT() method of my storage class, since i'm calling instance.set(), and now it need an EntityPlayer to be passed
I do not see an obvious way to specify it tho, simply using Minecraft.getMinecraft().player doesn't work and simply result in a NullPointerException

Spoiler

@Override
public void readNBT(Capability<IPSize> capability, IPSize instance, EnumFacing side, NBTBase nbt) {
  if(nbt instanceof NBTTagCompound)
  {
    NBTTagCompound compound = (NBTTagCompound) nbt;

    if (compound.hasKey("PSize"))
    {
      instance.set(compound.getFloat("PSize"), EntityPlayer); //Now need EntityPlayer
    }
  }
}

 

Posted

Hmm. I'm having trouble understanding what you want me to do then...
Right now, my AttachCapabilitiesEvent looks like this

Spoiler

  private static final ResourceLocation PSIZE_CAP = new ResourceLocation(Hyper.MOD_ID, "PSize");

  @SubscribeEvent
  public void attachCapability(AttachCapabilitiesEvent<Entity> event)
  {
    if(!(event.getObject() instanceof EntityPlayer)) return;
    event.addCapability(PSIZE_CAP, new PSizeProvider());
  }

 

My PSizeProvider class looks like this
 

Spoiler

public class PSizeProvider implements ICapabilitySerializable<NBTBase> {

  @CapabilityInject(IPSize.class)
  public static final Capability<IPSize> SIZE_CAPABILITY = null;

  private IPSize instance = SIZE_CAPABILITY.getDefaultInstance();

  @Override
  public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
    return capability == SIZE_CAPABILITY;
  }

  @Override
  public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
    return capability == SIZE_CAPABILITY ? SIZE_CAPABILITY.<T> cast(this.instance) : null;
  }

  @Override
  public NBTBase serializeNBT() {
    return SIZE_CAPABILITY.getStorage().writeNBT(SIZE_CAPABILITY, this.instance, null);
  }

  @Override
  public void deserializeNBT(NBTBase nbt) {
    SIZE_CAPABILITY.getStorage().readNBT(SIZE_CAPABILITY, this.instance, null, nbt);
  }

  public static IPSize getPHandler(Entity entity)
  {
    if(entity.hasCapability(SIZE_CAPABILITY, null))
      return entity.getCapability(SIZE_CAPABILITY, null);
    return null;
  }

}

 

Knowing this, how can I

26 minutes ago, diesieben07 said:

pass it from AttachCapabilitiesEvent

to my PSizeStorage class?

Posted

Okay, I've done it like this

Spoiler

  @SubscribeEvent
  public void attachCapability(AttachCapabilitiesEvent<Entity> event)
  {
    if(!(event.getObject() instanceof EntityPlayer)) return;
    event.addCapability(PSIZE_CAP, new PSizeProvider((EntityPlayer) event.getObject()));
  }

 

I've put this in the Provider

Spoiler

  public static EntityPlayer player;

  public PSizeProvider(EntityPlayer player)
  {
    this.player = player;
  }

 

And I simply access it like this
 

Spoiler

@Override
  public void set(float size) {
    this.size = size;
    sendUpdate(PSizeProvider.player);
  }

 


Doing this do raise some exception tho; so I must be doing something wrong again eh...
 

Spoiler

[16:12:17] [Server thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught
java.lang.NullPointerException: null
	at net.minecraftforge.fml.common.network.FMLOutboundHandler$OutboundTarget$4.selectNetworks(FMLOutboundHandler.java:143) ~[FMLOutboundHandler$OutboundTarget$4.class:?]
	at net.minecraftforge.fml.common.network.FMLOutboundHandler.write(FMLOutboundHandler.java:378) ~[FMLOutboundHandler.class:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:111) ~[MessageToMessageEncoder.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1032) ~[DefaultChannelPipeline.class:4.1.9.Final]
	at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:296) ~[AbstractChannel.class:4.1.9.Final]
	at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendTo(SimpleNetworkWrapper.java:250) [SimpleNetworkWrapper.class:?]
	at fr.wormstweaker.hyper.capabilities.PSize.sendUpdate(PSize.java:21) [PSize.class:?]
	at fr.wormstweaker.hyper.capabilities.PSize.set(PSize.java:27) [PSize.class:?]
	at fr.wormstweaker.hyper.capabilities.PSizeStorage.readNBT(PSizeStorage.java:34) [PSizeStorage.class:?]
	at fr.wormstweaker.hyper.capabilities.PSizeStorage.readNBT(PSizeStorage.java:14) [PSizeStorage.class:?]
	at fr.wormstweaker.hyper.capabilities.PSizeProvider.deserializeNBT(PSizeProvider.java:40) [PSizeProvider.class:?]
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.deserializeNBT(CapabilityDispatcher.java:135) [CapabilityDispatcher.class:?]
	at net.minecraft.entity.Entity.readFromNBT(Entity.java:2071) [Entity.class:?]
	at net.minecraft.server.management.PlayerList.readPlayerDataFromFile(PlayerList.java:334) [PlayerList.class:?]
	at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:126) [PlayerList.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:258) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.access$100(NetworkDispatcher.java:72) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:208) [NetworkDispatcher$1.class:?]
	at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307) [NetworkManager.class:?]
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197) [NetworkSystem.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
[16:12:17] [Server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception
java.lang.NullPointerException: null
	at net.minecraftforge.fml.common.network.FMLOutboundHandler$OutboundTarget$4.selectNetworks(FMLOutboundHandler.java:143) ~[FMLOutboundHandler$OutboundTarget$4.class:?]
	at net.minecraftforge.fml.common.network.FMLOutboundHandler.write(FMLOutboundHandler.java:378) ~[FMLOutboundHandler.class:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:111) ~[MessageToMessageEncoder.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1032) ~[DefaultChannelPipeline.class:4.1.9.Final]
	at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:296) ~[AbstractChannel.class:4.1.9.Final]
	at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendTo(SimpleNetworkWrapper.java:250) [SimpleNetworkWrapper.class:?]
	at fr.wormstweaker.hyper.capabilities.PSize.sendUpdate(PSize.java:21) [PSize.class:?]
	at fr.wormstweaker.hyper.capabilities.PSize.set(PSize.java:27) [PSize.class:?]
	at fr.wormstweaker.hyper.capabilities.PSizeStorage.readNBT(PSizeStorage.java:34) [PSizeStorage.class:?]
	at fr.wormstweaker.hyper.capabilities.PSizeStorage.readNBT(PSizeStorage.java:14) [PSizeStorage.class:?]
	at fr.wormstweaker.hyper.capabilities.PSizeProvider.deserializeNBT(PSizeProvider.java:40) [PSizeProvider.class:?]
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.deserializeNBT(CapabilityDispatcher.java:135) [CapabilityDispatcher.class:?]
	at net.minecraft.entity.Entity.readFromNBT(Entity.java:2071) [Entity.class:?]
	at net.minecraft.server.management.PlayerList.readPlayerDataFromFile(PlayerList.java:334) [PlayerList.class:?]
	at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:126) [PlayerList.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:258) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.access$100(NetworkDispatcher.java:72) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:208) [NetworkDispatcher$1.class:?]
	at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307) [NetworkManager.class:?]
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197) [NetworkSystem.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
[16:12:17] [Server thread/INFO] [minecraft/PlayerList]: Player333[local:E:c6e8a22a] logged in with entity id 352 at (-7.728049676188878, 72.0, 274.9231576576308)
[16:12:17] [Server thread/INFO] [minecraft/MinecraftServer]: Player333 joined the game
[16:12:18] [Server thread/INFO] [minecraft/IntegratedServer]: Saving and pausing game...
[16:12:18] [Server thread/INFO] [minecraft/MinecraftServer]: Saving chunks for level 'New World'/overworld
[16:12:19] [Client thread/FATAL] [minecraft/Minecraft]: Error executing task
java.util.concurrent.ExecutionException: java.lang.ClassCastException: net.minecraft.client.entity.EntityPlayerSP cannot be cast to net.minecraft.entity.player.EntityPlayerMP
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_171]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_171]
	at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?]
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1178) [Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:442) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: java.lang.ClassCastException: net.minecraft.client.entity.EntityPlayerSP cannot be cast to net.minecraft.entity.player.EntityPlayerMP
	at fr.wormstweaker.hyper.capabilities.PSize.sendUpdate(PSize.java:21) ~[PSize.class:?]
	at fr.wormstweaker.hyper.capabilities.PSize.set(PSize.java:27) ~[PSize.class:?]
	at fr.wormstweaker.hyper.packets.SizeSyncPacket.lambda$onMessage$0(SizeSyncPacket.java:40) ~[SizeSyncPacket.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_171]
	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) ~[?:1.8.0_171]
	at java.util.concurrent.FutureTask.run(FutureTask.java) ~[?:1.8.0_171]
	at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]
	... 15 more

 

 

Posted

I cannot access PSizeProvider.player otherwise

I suppose I misunderstood how you wanted me to store/retrieve EntityPlayer from the Provider

And yes I do understand what static means, I just didn't thought about this when I wrote this, sorry

Posted

I was away for a few days, so sorry for the late response, I think I finally understood now
So, before, my instance was created like this:
private IPSize instance = SIZE_CAPABILITY.getDefaultInstance();

This is how I've seen every capability instance being created in the examples that I found
I suppose that wasn't good, since I can't pass the player this way, so instead i'm doing this:
private IPSize instance = new PSize(player);

Where player is set trough the constructor of the Provider
 

Spoiler

  private EntityPlayer player;
  public PSizeProvider(EntityPlayer player)
  {
    this.player = player;
  }

 

This should be good (?), but again I'm not 100% sure this is correct, and what's you're expecting me to do
The constructor of PSize is simply this

Spoiler

  private EntityPlayer player;
  public PSize(EntityPlayer player)
  {
    this.player = player;
  }

 

and player is used by sendUpdate() that I detailed in earlier posts

However, I get a NullPointerException when deserializeNBT() is called, so I suppose that somehow player in the Provider isn't set correctly?...

 

Spoiler

[15:44:03] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Loading entity NBT
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:212) ~[NetworkSystem.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865) ~[MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) ~[MinecraftServer.class:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) ~[IntegratedServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
Caused by: java.lang.NullPointerException
	at fr.wormstweaker.hyper.capabilities.PSize.sendUpdate(PSize.java:18) ~[PSize.class:?]
	at fr.wormstweaker.hyper.capabilities.PSize.set(PSize.java:32) ~[PSize.class:?]
	at fr.wormstweaker.hyper.capabilities.PSizeStorage.readNBT(PSizeStorage.java:34) ~[PSizeStorage.class:?]
	at fr.wormstweaker.hyper.capabilities.PSizeStorage.readNBT(PSizeStorage.java:14) ~[PSizeStorage.class:?]
	at fr.wormstweaker.hyper.capabilities.PSizeProvider.deserializeNBT(PSizeProvider.java:45) ~[PSizeProvider.class:?]
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.deserializeNBT(CapabilityDispatcher.java:135) ~[CapabilityDispatcher.class:?]
	at net.minecraft.entity.Entity.readFromNBT(Entity.java:2071) ~[Entity.class:?]
	at net.minecraft.server.management.PlayerList.readPlayerDataFromFile(PlayerList.java:334) ~[PlayerList.class:?]
	at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:126) ~[PlayerList.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:258) ~[NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.access$100(NetworkDispatcher.java:72) ~[NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:208) ~[NetworkDispatcher$1.class:?]
	at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307) ~[NetworkManager.class:?]
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197) ~[NetworkSystem.class:?]
	... 5 more

 

 

Posted

So then, instead of callingsendUpdate() in my set() like this

Spoiler

  @Override
  public void set(float size) {
    this.size = size;
    sendUpdate();
  }

 

I should instead call it each time after I use set(), like this?
 

Spoiler

    IPSize size = player.getCapability(PSizeProvider.SIZE_CAPABILITY, null);

    size.add(1.0F);
    sendUpdate(player);

 

 

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



×
×
  • Create New...

Important Information

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