Posted May 16, 201510 yr So I have several tile entities that push players around and affect their motion in general, and through testing I found that they would not affect anyone but the person who placed the block on a server, so I made a new packet and had it perform the movement alteration in the onMessage. The problem is, when a player touches the AOE, it crashes on a NPE in the packet's onMessage, specifically on the first line of setting the entities' motion, and as far as I can see, this shouldn't happen, so I'm just confused here. [14:50:51] [server thread/ERROR] [FML]: There was a critical exception handling a packet on channel arcaneartificing java.lang.NullPointerException at izzyaxel.arcaneartificing.main.messages.MessageMovePlayers$MovePlayerHandler.onMessage(MessageMovePlayers.java:54) ~[MessageMovePlayers$MovePlayerHandler.class:?] at izzyaxel.arcaneartificing.main.messages.MessageMovePlayers$MovePlayerHandler.onMessage(MessageMovePlayers.java:47) ~[MessageMovePlayers$MovePlayerHandler.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] Main Packet TE Pusher 1 TE Pusher 2 TE Float 1 TE Float 2 PS, how would I do packets to update clients for lighting changes, and to see rendering being done in a TESR?
May 18, 201510 yr Author So, how would I get a valid ID? I just tried changing the list to EntityPlayer, moved getting the ID to outside the isRemote check, and iterating through all loaded entities and comparing the sent ID to each one, but it's always invalid.
May 18, 201510 yr Author How else would I tell it which players to move? The reason I'm trying to send this packet is because in SMP, only the person who placed the block is affected by it until the other players relog. The same thing happens with the TESR rendering and lighting updates from two of my other tile entities, I'm tackling this one first because it's the one I knew how to handle.
May 19, 201510 yr I am kinda trying to figure out what is the problem. So I have several tile entities that push players around and affect their motion in general, and through testing I found that they would not affect anyone but the person who placed the block on a server. How else would I tell it which players to move? The reason I'm trying to send this packet is because in SMP, only the person who placed the block is affected by it until the other players relog. I don't really see what stops you from performing pushes. If your TileEntity is setup correctly then it should be the same for all players - no matter if reloged or not. That fact measn that you can push on both server and client (more smooth effect). Forgive me for not understanding problem here ;c 1.7.10 is no longer supported by forge, you are on your own.
May 19, 201510 yr Author When I tried placing some of the blocks that push players in my test server, the other players were not getting pushed by them, but I was, they had to relog to have the block/TE affect them. I assumed this was due to client-server syncing issues, so I tried to have the tile entity send a packet to the server and move the player from there, which is where the NPE occurred.
May 19, 201510 yr Author Ok I just realized something from further testing. How do you sync tile entities between the server and all clients? The same thing happens with all 3 tile entities, when the block is turned on by one player it works for them, but it needs to be interfaced with by the other players to affect them, for instance one of the blocks pushes players on a horizontal axis, you right click on a side to change the output to that side and right click on the top or bottom to turn it on/off, so when one player places it down and turns it on while a second player is inside the area of effect, it's turned on for player 1, and affects them, but off for player 2, and doesn't affect them, despite showing the "on" particles for both. If player 2 right clicks the top, it'll turn on the effect for them, but the particles will turn off for everybody. So it is client-server desync, but not the way I thought it was originally.
May 19, 201510 yr Author Ok, well what's wrong with how I'm doing it now? Also wrapping the contents of onBlockActivated with !isRemote makes it not push anyone, but the particles show up and it turns on and off properly. Horizontal Pusher Block public class BlockGravityEngineHP extends BlockContainer { public BlockGravityEngineHP() { super(Material.piston); this.setBlockName("gravityEngineHP"); this.setStepSound(Block.soundTypePiston); this.setHardness(1.0F); this.setResistance(5.0F); this.setBlockTextureName(Reference.MODID + ":" + getUnlocalizedName().substring(5)); this.setHarvestLevel("pickaxe", 1); } @Override public TileEntity createNewTileEntity(World world, int id) { return new TEGravityEngineHP(); } @Override public void onBlockExploded(World world, int x, int y, int z, Explosion explosion) { world.setBlockToAir(x, y, z); world.removeTileEntity(x, y, z); onBlockDestroyedByExplosion(world, x, y, z, explosion); } @Override public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) { world.setBlockToAir(x, y, z); world.removeTileEntity(x, y, z); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if(!world.isRemote) { TEGravityEngineHP grav = (TEGravityEngineHP)world.getTileEntity(x, y, z); if(!player.isSneaking()) { grav.switchSides(side); return true; } else { switch(side) { case 2: grav.switchSides(3); break; case 3: grav.switchSides(2); break; case 4: grav.switchSides(5); break; case 5: grav.switchSides(4); break; default: break; } return true; } } return false; } } Horizontal Pusher TE public class TEGravityEngineHP extends TileEntity { int side = 0; boolean on = false; public TEGravityEngineHP() { super(); } public void setOn(int side) { switch(side) { case 0: switchSides(0); break; case 1: switchSides(1); break; } } public void switchSides(int sideHit) { switch(sideHit) { case 0: on = !on; if(worldObj.getBlock(this.xCoord, this.yCoord + 1, this.zCoord) instanceof BlockGravityEngineHP) { ((TEGravityEngineHP)worldObj.getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord)).setOn(0); } break; case 1: on = !on; if(worldObj.getBlock(this.xCoord, this.yCoord - 1, this.zCoord) instanceof BlockGravityEngineHP) { ((TEGravityEngineHP)worldObj.getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord)).setOn(1); } break; case 2: side = 2; break; case 3: side = 0; break; case 4: side = 1; break; case 5: side = 3; break; default: break; } } @Override public void updateEntity() { if(on) { byte xB = 0; byte zB = 0; switch(side) { case 0: zB = 1; break; case 1: xB = -1; break; case 2: zB = -1; break; case 3: xB = 1; break; default: break; } if(!worldObj.isRemote) { Random rand = this.worldObj.rand; double mult = 0.0305610; double timeX = xB * (mult * gravityEngineHRange); double timeZ = zB * (mult * gravityEngineHRange); double x = this.xCoord + 0.5 + (zB * (((rand.nextInt(3) - 1) * rand.nextFloat()) / 2)); double y = this.yCoord - 1.0 + (((rand.nextInt(3) - 1) * rand.nextFloat()) / 2); double z = this.zCoord + 0.5 + (xB * (((rand.nextInt(3) - 1) * rand.nextFloat()) / 2)); if(rand.nextInt(100) % 2 == 0) { ArcaneArtificing.snw.sendToAllAround(new MessageDoParticles(Reference.LightChargeFX, x, y, z, timeX, 0, timeZ, 5, 50), new NetworkRegistry.TargetPoint(this.worldObj.provider.dimensionId, this.xCoord, this.yCoord, this.zCoord, 256)); } } float minX = xB == -1 ? gravityEngineHRange : 0; float minZ = zB == -1 ? gravityEngineHRange : 0; float maxX = xB == 1 ? gravityEngineHRange : 1; float maxZ = zB == 1 ? gravityEngineHRange : 1; List<Entity> entities = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(this.xCoord - minX, this.yCoord, this.zCoord - minZ, this.xCoord + maxX, this.yCoord + 1, this.zCoord + maxZ)); for(Entity ent : entities) { double motx = 0, moty = 0, motz = 0; if(xB != 0) motx = xB == -1 ? -0.4 : 0.4; if(zB != 0) motz = zB == -1 ? -0.4 : 0.4; ent.motionX = motx; ent.motionZ = motz; ent.motionY = moty; } } } @Override public boolean canUpdate() { return true; } @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); side = tag.getInteger("Side"); on = tag.getBoolean("On"); } @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); tag.setInteger("Side", side); tag.setBoolean("On", on); } @Override public Packet getDescriptionPacket() { NBTTagCompound tag = new NBTTagCompound(); tag.setInteger("Side", side); tag.setBoolean("On", on); this.writeToNBT(tag); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, this.getBlockMetadata(), tag); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { this.readFromNBT(packet.func_148857_g()); } }
May 19, 201510 yr Author Yep, and it's got the correct values. Edit: It also does affect animals, but EntityItems jump around, like the client is only syncing once every 5 seconds. It's only players that have the full sync issue.
May 20, 201510 yr Author Ok I got it working on server, but the effect is very jerky and you drop out of the AoE quickly, not at all what I wanted for the pushers, they're supposed to keep you on the same Y level the entire time by setting the player's motionY to 0 every tick, and of course all of them need to have smooth motion. Main Packet H Pusher Block H Pusher TE
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.