Posted May 17, 20187 yr Edit: use >> 4 >> 4 or /16 for getting chunk? I have read that >>4 is more optimized yet it fails on negative numbers I am confused since vanilla uses >>4 when it's negative???? I need it for teleporting entities now because of a vanilla bug with the entities not being added to chunks when teleporting if the chunk isn't loaded(never) or not being added to next tick /** *supports teleporting entities from location to location in the same dimension doesn't support actual cross dimensional teleport */ public static void doTeleport(Entity e, double x, double y, double z,float yaw, float pitch) { int chunkOldX = (int)e.posX >> 4; int chunkOldZ = (int)e.posZ >> 4; int chunkX = (int)x >> 4; int chunkZ = (int)z >> 4; //remove from old chunk if(chunkOldX != chunkX || chunkOldZ != chunkZ) { Chunk chunkOld = e.world.getChunkFromChunkCoords(chunkOldX,chunkOldZ); chunkOld.removeEntity(e); } if (e instanceof EntityPlayerMP) { Set<SPacketPlayerPosLook.EnumFlags> set = EnumSet.<SPacketPlayerPosLook.EnumFlags>noneOf(SPacketPlayerPosLook.EnumFlags.class); e.dismountRidingEntity(); e.setLocationAndAngles(x, y, z, e.rotationYaw, e.rotationPitch); ((EntityPlayerMP)e).connection.setPlayerLocation(x, y, z, yaw, pitch, set); } else { float f2 = (float)MathHelper.wrapDegrees(yaw); float f3 = (float)MathHelper.wrapDegrees(pitch); f3 = MathHelper.clamp(f3, -90.0F, 90.0F); e.setLocationAndAngles(x, y, z, f2, f3); } if (!(e instanceof EntityLivingBase) || !((EntityLivingBase)e).isElytraFlying()) { e.motionY = 0.0D; e.onGround = true; } //vanilla hotfix add entity to the new chunk if not already added Chunk chunk = e.world.getChunkFromChunkCoords(chunkX,chunkZ); if(!containsEntity(chunk.getEntityLists(),e)) chunk.addEntity(e); } public static boolean containsEntity(ClassInheritanceMultiMap<Entity>[] list,Entity e) { for(int i=0;i<list.length;i++) { ClassInheritanceMultiMap map = list[i]; Iterator<Entity> it = map.iterator(); while(it.hasNext()) { Entity e2 = it.next(); if(e == e2) return true; } } return false; } Edited May 17, 20187 yr by jredfox
May 17, 20187 yr >> 4 Because of negative coordinates. 15 >> 4 = 0 ✓ 15 / 16 = 0 ✓ -15 >> 4 = -1 ✓ -15 / 16 = 0 ✗ Edited May 17, 20187 yr by Draco18s 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.
May 17, 20187 yr Author 8 minutes ago, Draco18s said: >> 4 Because of negative coordinates. 15 >> 4 = 0 ✓ 15 / 16 = 0 ✓ -15 >> 4 = -1 ✓ -15 / 16 = 0 ✗ ok so >>4 or use math helper then? Edited May 17, 20187 yr by jredfox
May 17, 20187 yr WTF? Edited May 17, 20187 yr by Draco18s 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.
May 17, 20187 yr Author 2 hours ago, Draco18s said: WTF? so your saying it's proper to do division then ? why is there an x there then as if that failed?
May 17, 20187 yr 8 hours ago, jredfox said: so your saying it's proper to do division then ? why is there an x there then as if that failed? Jesus Christ, you're as dumb as a post. No, only use >> 4, as I already said twice. The X is there because it failed to produce the correct result, therefore it is wrong and should not be used. 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.
May 17, 20187 yr JRedFox was agreeing with you. I'm not sure why you said WTF. You said use bit shifting and he said "okay I'll use bit shifting" then you said "WTF". Check out my tutorials here: http://jabelarminecraft.blogspot.com/
May 17, 20187 yr 37 minutes ago, jabelar said: JRedFox was agreeing with you. I'm not sure why you said WTF. You said use bit shifting and he said "okay I'll use bit shifting" then you said "WTF". The post was edited. I can't view the edit history, but I'm almost certain he said "division" when I made my reply. I've slept since then. He also has "or MathHelper" in there, and MathHelper does not contain a "BlockToChunk" method (there is exactly one instance of >>4 in it: smallestEncompassingPowerOfTwo), so also wrong. Edited May 17, 20187 yr by Draco18s 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.
May 17, 20187 yr 8 hours ago, Draco18s said: The post was edited. Okay, makes sense. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.