Skip to content

Commit

Permalink
Merge pull request #45 from jchung01/network-fixes
Browse files Browse the repository at this point in the history
Fix biome change rendering client-side and BiomeArrayMessage handling
  • Loading branch information
ACGaming authored Apr 3, 2024
2 parents 51b5641 + 864f61f commit 2ba37eb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ public class MixinCommandSetBiome {

@Redirect(method = "execute", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;setBiomeArray([B)V"))
private void reid$setBiomeArray(Chunk instance, byte[] biomeArray,
@Local BlockPos coord, @Local World world, @Local(ordinal = 4) int x,
@Local(ordinal = 5) int z, @Share("intBiomeArray") LocalRef<int[]> intBiomeArray) {
@Local BlockPos coord, @Local World world, @Local(ordinal = 4) int chunkX,
@Local(ordinal = 5) int chunkZ, @Share("intBiomeArray") LocalRef<int[]> intBiomeArray) {
// Method calls markDirty()
((INewChunk) world.getChunk(x, z)).setIntBiomeArray(Arrays.copyOf(intBiomeArray.get(), intBiomeArray.get().length));
MessageManager.sendClientsBiomeArray(world, new BlockPos(x, coord.getY(), z), Arrays.copyOf(intBiomeArray.get(), intBiomeArray.get().length));
int posX = chunkX << 4;
int posZ = chunkZ << 4;
((INewChunk) world.getChunk(chunkX, chunkZ)).setIntBiomeArray(Arrays.copyOf(intBiomeArray.get(), intBiomeArray.get().length));
MessageManager.sendClientsBiomeArray(world, new BlockPos(posX, coord.getY(), posZ), Arrays.copyOf(intBiomeArray.get(), intBiomeArray.get().length));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public IMessage onMessage(BiomeArrayMessage message, MessageContext ctx) {
WorldClient world = Minecraft.getMinecraft().world;
Chunk chunk = world.getChunk(message.chunkX, message.chunkZ);
((INewChunk) chunk).setIntBiomeArray(message.biomeArray);
world.markBlockRangeForRenderUpdate(new BlockPos(chunk.getPos().getXStart(), 0, chunk.getPos().getZStart()), new BlockPos(chunk.getPos().getXEnd(), 0, chunk.getPos().getZEnd()));
world.markBlockRangeForRenderUpdate(new BlockPos(chunk.getPos().getXStart(), 0, chunk.getPos().getZStart()), new BlockPos(chunk.getPos().getXEnd(), world.getHeight(), chunk.getPos().getZEnd()));
});
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public IMessage onMessage(BiomeChangeMessage message, MessageContext ctx) {
WorldClient world = Minecraft.getMinecraft().world;
Chunk chunk = world.getChunk(new BlockPos(message.x, 0, message.z));
((INewChunk) chunk).getIntBiomeArray()[(message.z & 15) << 4 | message.x & 15] = message.biomeId;
world.markBlockRangeForRenderUpdate(new BlockPos(message.x, 0, message.z), new BlockPos(message.x, 0, message.z));
world.markBlockRangeForRenderUpdate(new BlockPos(message.x, 0, message.z), new BlockPos(message.x, world.getHeight(), message.z));
});
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/dimdev/jeid/network/MessageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void sendClientsBiomeChange(World world, BlockPos pos, int biomeId

public static void sendClientsBiomeArray(World world, BlockPos pos, int[] biomeArr) {
MessageManager.CHANNEL.sendToAllTracking(
new BiomeArrayMessage(pos.getX(), pos.getZ(), biomeArr),
new BiomeArrayMessage(pos.getX() >> 4, pos.getZ() >> 4, biomeArr), // Expects chunkX/Z
new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 0.0D) // Range ignored
);
}
Expand Down

0 comments on commit 2ba37eb

Please sign in to comment.