From a1fb1fd4e4e0bea0a54b69b8971c5b85158bc203 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Mon, 24 Oct 2011 23:42:04 +0200 Subject: [PATCH] Using Notch's block lighting functions now. Also removed some debug messages --- .../sk89q/worldedit/bukkit/BukkitWorld.java | 52 +++++-------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index fdb8a0c35..4b23a5334 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -22,9 +22,6 @@ package com.sk89q.worldedit.bukkit; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.Furnace; @@ -46,7 +43,6 @@ import org.bukkit.entity.Wolf; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.Bukkit; -import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.TreeType; @@ -753,23 +749,15 @@ public class BukkitWorld extends LocalWorld { Object notchChunk = World_getChunkFromChunkCoords.invoke(notchWorld, chunkX, chunkZ); - long t = System.currentTimeMillis(); + // Fix skylight final byte[] blocks = (byte[])Chunk_blocks.get(notchChunk); int length = blocks.length; Chunk_skylightMap.set(notchChunk, NibbleArray_ctor.newInstance(length, 7)); - System.out.println("Took "+(System.currentTimeMillis()-t)+"ms to remove skylighting."); - t = System.currentTimeMillis(); - Chunk_generateSkylightMap.invoke(notchChunk); - System.out.println("Took "+(System.currentTimeMillis()-t)+"ms to restore skylighting."); - t = System.currentTimeMillis(); - + // Fix blocklight Chunk_blocklightMap.set(notchChunk, NibbleArray_ctor.newInstance(length, 7)); - Chunk chunk = world.getChunkAt(chunkX, chunkZ); - - List lightEmitters = new ArrayList(); for (int x = 0; x < chunkSizeX; ++x) { boolean xBorder = x == 0 || x == chunkSizeX - 1; @@ -778,35 +766,17 @@ public class BukkitWorld extends LocalWorld { for (int y = 0; y < chunkSizeY; ++y) { final int index = y + z * chunkSizeY + x * chunkSizeY * chunkSizeZ; byte blockID = blocks[index]; - if (!BlockType.emitsLight(blockID)) { - if (xBorder || zBorder && BlockType.isTranslucent(blockID)) { - lightEmitters.add(chunk.getBlock(x, y, z).getState()); - if (blockID == 20) { - blocks[index] = 0; - } - else { - blocks[index] = 20; - } - - } - continue; + if (BlockType.emitsLight(blockID)) { + Chunk_relightBlock.invoke(notchChunk, x, y, z); + } + else { + if ((xBorder || zBorder) && BlockType.isTranslucent(blockID)) { + Chunk_relightBlock.invoke(notchChunk, x, y, z); + } } - - lightEmitters.add(chunk.getBlock(x, y, z).getState()); - - blocks[index] = 0; } } } - - System.out.println("Took "+(System.currentTimeMillis()-t)+"ms to remove blocklighting."); - t = System.currentTimeMillis(); - - for (BlockState lightEmitter : lightEmitters) { - lightEmitter.update(true); - } - - System.out.println("Took "+(System.currentTimeMillis()-t)+"ms to restore blocklighting."); } } catch (Exception e) { @@ -820,6 +790,7 @@ public class BukkitWorld extends LocalWorld { private static Method CraftWorld_getHandle; private static Method World_getChunkFromChunkCoords; private static Method Chunk_generateSkylightMap; + private static Method Chunk_relightBlock; private static Field Chunk_blocks; private static Field Chunk_skylightMap; private static Field Chunk_blocklightMap; @@ -833,6 +804,8 @@ public class BukkitWorld extends LocalWorld { World_getChunkFromChunkCoords = Class.forName("net.minecraft.server.World").getMethod("getChunkAt", int.class, int.class); Chunk_generateSkylightMap = Class.forName("net.minecraft.server.Chunk").getMethod("initLighting"); + Chunk_relightBlock = Class.forName("net.minecraft.server.Chunk").getDeclaredMethod("g", int.class, int.class, int.class); + Chunk_relightBlock.setAccessible(true); Chunk_blocks = Class.forName("net.minecraft.server.Chunk").getField("b"); Chunk_skylightMap = Class.forName("net.minecraft.server.Chunk").getField("h"); @@ -842,6 +815,7 @@ public class BukkitWorld extends LocalWorld { fastLightingAvailable = true; } catch (Throwable e) { + e.printStackTrace(); } } }