Skip to content

Commit 9ced0df

Browse files
fix: Y transfer for WorldEntityTracker
1 parent 1a70e17 commit 9ced0df

4 files changed

Lines changed: 26 additions & 13 deletions

File tree

src/main/java/cam72cam/mod/event/CommonEvents.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import net.minecraft.entity.player.EntityPlayer;
77
import net.minecraft.item.crafting.IRecipe;
88
import net.minecraft.util.math.BlockPos;
9-
import net.minecraft.util.math.MathHelper;
109
import net.minecraftforge.event.RegistryEvent;
1110
import net.minecraftforge.event.entity.EntityEvent;
1211
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
@@ -122,9 +121,9 @@ public static void onEntityTransfer(EntityEvent.EnteringChunk event) {
122121
ModdedEntity modded = (ModdedEntity) event.getEntity();
123122
cam72cam.mod.world.World.get(modded.world).tracker
124123
.move(modded,
125-
//Warp Y coordinate to chunk pos here for 1.16 and below
126-
ChunkPos.asLong(event.getOldChunkX(), MathHelper.floor(modded.posY/16d), event.getOldChunkZ()),
127-
ChunkPos.asLong(event.getNewChunkX(), MathHelper.floor(modded.posY/16d), event.getNewChunkZ()));
124+
//Don't calculate Y in 1.16- as no corresponding event posted
125+
ChunkPos.asLong(event.getOldChunkX(), 0, event.getOldChunkZ()),
126+
ChunkPos.asLong(event.getNewChunkX(), 0, event.getNewChunkZ()));
128127
}
129128
}
130129
}

src/main/java/cam72cam/mod/mixin/feat/large_entity_collision/MixinVanillaWorld.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public void injectEntitySearch0(Entity entityIn, AxisAlignedBB aabb, Predicate<?
3030
CallbackInfoReturnable<List<Entity>> cir) {
3131
List<Entity> result = cir.getReturnValue();
3232
cam72cam.mod.world.World world = cam72cam.mod.world.World.get((World) (Object) this);
33+
//We don't handle Y coordinate in 1.16-
3334
Set<Long> collection = world.tracker.queryPotentialPackedChunkPos(
34-
ChunkPos.asLong(new Vec3d((aabb.minX + aabb.maxX) / 2, (aabb.minY + aabb.maxY) / 2, (aabb.minZ + aabb.maxZ) / 2)));
35+
ChunkPos.asLongExcludeY(new Vec3d((aabb.minX + aabb.maxX) / 2, (aabb.minY + aabb.maxY) / 2, (aabb.minZ + aabb.maxZ) / 2)));
3536
if (!collection.isEmpty()) {
3637
for (long packed : collection) {
3738
int x = ChunkPos.x(packed);
@@ -60,8 +61,9 @@ public void injectEntitySearch1(Class<? extends Entity> clazz, AxisAlignedBB aab
6061

6162
List<Entity> result = cir.getReturnValue();
6263
cam72cam.mod.world.World world = cam72cam.mod.world.World.get((World) (Object) this);
64+
//We don't handle Y coordinate in 1.16-
6365
Set<Long> collection = world.tracker.queryPotentialPackedChunkPos(
64-
ChunkPos.asLong(new Vec3d((aabb.minX + aabb.maxX) / 2, (aabb.minY + aabb.maxY) / 2, (aabb.minZ + aabb.maxZ) / 2)));
66+
ChunkPos.asLongExcludeY(new Vec3d((aabb.minX + aabb.maxX) / 2, (aabb.minY + aabb.maxY) / 2, (aabb.minZ + aabb.maxZ) / 2)));
6567
if (!collection.isEmpty()) {
6668
for (long packed : collection) {
6769
int x = ChunkPos.x(packed);

src/main/java/cam72cam/mod/world/ChunkPos.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,19 @@ public static long asLong(int x, int y, int z) {
4040
return i;
4141
}
4242

43+
//For 1.16- It turned out processing Y will take much more unnecessary effort...
44+
public static long asLongExcludeY(BlockPos pos) {
45+
return asLong(new BlockPos(pos.getX(), 0, pos.getZ()));
46+
}
47+
4348
public static long asLong(BlockPos pos) {
4449
return asLong(MathHelper.floor(pos.getX()/16d), MathHelper.floor(pos.getY()/16d), MathHelper.floor(pos.getZ()/16d));
4550
}
4651

52+
public static long asLongExcludeY(Vec3d pos) {
53+
return asLong(new Vec3d(pos.x, 0, pos.z));
54+
}
55+
4756
public static long asLong(Vec3d pos) {
4857
return asLong(MathHelper.floor(pos.x/16d), MathHelper.floor(pos.y/16d), MathHelper.floor(pos.z/16d));
4958
}

src/main/java/cam72cam/mod/world/WorldEntityTracker.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class WorldEntityTracker {
3232
public WorldEntityTracker() {}
3333

3434
public void join(ModdedEntity entity) {
35-
long chunk = ChunkPos.asLong(entity.getPosition());
35+
long chunk = ChunkPos.asLongExcludeY(entity.getPosition());
3636
int x = ChunkPos.x(chunk);
3737
int y = ChunkPos.y(chunk);
3838
int z = ChunkPos.z(chunk);
@@ -46,9 +46,11 @@ public void join(ModdedEntity entity) {
4646

4747
for (int i = x - HORIZONTAL_SEARCH_RADIUS_CHUNKS; i <= x + HORIZONTAL_SEARCH_RADIUS_CHUNKS; i++) {
4848
for (int j = z - HORIZONTAL_SEARCH_RADIUS_CHUNKS; j <= z + HORIZONTAL_SEARCH_RADIUS_CHUNKS; j++) {
49-
for (int k = y - VERTICAL_SEARCH_RADIUS_CHUNKS; k <= y + VERTICAL_SEARCH_RADIUS_CHUNKS; k++) {
49+
// for (int k = y - VERTICAL_SEARCH_RADIUS_CHUNKS; k <= y + VERTICAL_SEARCH_RADIUS_CHUNKS; k++) {
50+
//Handle Y below 1.17 is likely to cause more bug
51+
int k = 0;
5052
scanningRange.put(chunk, ChunkPos.asLong(i, k, j));
51-
}
53+
// }
5254
}
5355
}
5456
}
@@ -59,7 +61,7 @@ public void join(ModdedEntity entity) {
5961
}
6062

6163
public void leave(ModdedEntity entity) {
62-
long chunk = ChunkPos.asLong(entity.getPosition());
64+
long chunk = ChunkPos.asLongExcludeY(entity.getPosition());
6365

6466
lock.writeLock().lock();
6567
try {
@@ -97,7 +99,7 @@ public void move(ModdedEntity entity, long oldSection, long newSection) {
9799
}
98100
}
99101

100-
long chunk = ChunkPos.asLong(entity.getPosition());
102+
long chunk = ChunkPos.asLongExcludeY(entity.getPosition());
101103
int x = ChunkPos.x(chunk);
102104
int y = ChunkPos.y(chunk);
103105
int z = ChunkPos.z(chunk);
@@ -109,9 +111,10 @@ public void move(ModdedEntity entity, long oldSection, long newSection) {
109111

110112
for (int i = x - HORIZONTAL_SEARCH_RADIUS_CHUNKS; i <= x + HORIZONTAL_SEARCH_RADIUS_CHUNKS; i++) {
111113
for (int j = z - HORIZONTAL_SEARCH_RADIUS_CHUNKS; j <= z + HORIZONTAL_SEARCH_RADIUS_CHUNKS; j++) {
112-
for (int k = y - VERTICAL_SEARCH_RADIUS_CHUNKS; k <= y + VERTICAL_SEARCH_RADIUS_CHUNKS; k++) {
114+
// for (int k = y - VERTICAL_SEARCH_RADIUS_CHUNKS; k <= y + VERTICAL_SEARCH_RADIUS_CHUNKS; k++) {
115+
int k = 0;
113116
scanningRange.put(newSection, ChunkPos.asLong(i, k, j));
114-
}
117+
// }
115118
}
116119
}
117120
}

0 commit comments

Comments
 (0)