Using Notch's block lighting functions now.

Also removed some debug messages
This commit is contained in:
TomyLobo 2011-10-24 23:42:04 +02:00
parent a0461aeb2c
commit a1fb1fd4e4

View File

@ -22,9 +22,6 @@ package com.sk89q.worldedit.bukkit;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace; import org.bukkit.block.Furnace;
@ -46,7 +43,6 @@ import org.bukkit.entity.Wolf;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.TreeType; import org.bukkit.TreeType;
@ -753,23 +749,15 @@ public class BukkitWorld extends LocalWorld {
Object notchChunk = World_getChunkFromChunkCoords.invoke(notchWorld, chunkX, chunkZ); Object notchChunk = World_getChunkFromChunkCoords.invoke(notchWorld, chunkX, chunkZ);
long t = System.currentTimeMillis(); // Fix skylight
final byte[] blocks = (byte[])Chunk_blocks.get(notchChunk); final byte[] blocks = (byte[])Chunk_blocks.get(notchChunk);
int length = blocks.length; int length = blocks.length;
Chunk_skylightMap.set(notchChunk, NibbleArray_ctor.newInstance(length, 7)); 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); Chunk_generateSkylightMap.invoke(notchChunk);
System.out.println("Took "+(System.currentTimeMillis()-t)+"ms to restore skylighting."); // Fix blocklight
t = System.currentTimeMillis();
Chunk_blocklightMap.set(notchChunk, NibbleArray_ctor.newInstance(length, 7)); Chunk_blocklightMap.set(notchChunk, NibbleArray_ctor.newInstance(length, 7));
Chunk chunk = world.getChunkAt(chunkX, chunkZ);
List<BlockState> lightEmitters = new ArrayList<BlockState>();
for (int x = 0; x < chunkSizeX; ++x) { for (int x = 0; x < chunkSizeX; ++x) {
boolean xBorder = x == 0 || x == chunkSizeX - 1; boolean xBorder = x == 0 || x == chunkSizeX - 1;
@ -778,35 +766,17 @@ public class BukkitWorld extends LocalWorld {
for (int y = 0; y < chunkSizeY; ++y) { for (int y = 0; y < chunkSizeY; ++y) {
final int index = y + z * chunkSizeY + x * chunkSizeY * chunkSizeZ; final int index = y + z * chunkSizeY + x * chunkSizeY * chunkSizeZ;
byte blockID = blocks[index]; byte blockID = blocks[index];
if (!BlockType.emitsLight(blockID)) { if (BlockType.emitsLight(blockID)) {
if (xBorder || zBorder && BlockType.isTranslucent(blockID)) { Chunk_relightBlock.invoke(notchChunk, x, y, z);
lightEmitters.add(chunk.getBlock(x, y, z).getState()); }
if (blockID == 20) { else {
blocks[index] = 0; if ((xBorder || zBorder) && BlockType.isTranslucent(blockID)) {
} Chunk_relightBlock.invoke(notchChunk, x, y, z);
else { }
blocks[index] = 20;
}
}
continue;
} }
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) { catch (Exception e) {
@ -820,6 +790,7 @@ public class BukkitWorld extends LocalWorld {
private static Method CraftWorld_getHandle; private static Method CraftWorld_getHandle;
private static Method World_getChunkFromChunkCoords; private static Method World_getChunkFromChunkCoords;
private static Method Chunk_generateSkylightMap; private static Method Chunk_generateSkylightMap;
private static Method Chunk_relightBlock;
private static Field Chunk_blocks; private static Field Chunk_blocks;
private static Field Chunk_skylightMap; private static Field Chunk_skylightMap;
private static Field Chunk_blocklightMap; 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); 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_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_blocks = Class.forName("net.minecraft.server.Chunk").getField("b");
Chunk_skylightMap = Class.forName("net.minecraft.server.Chunk").getField("h"); Chunk_skylightMap = Class.forName("net.minecraft.server.Chunk").getField("h");
@ -842,6 +815,7 @@ public class BukkitWorld extends LocalWorld {
fastLightingAvailable = true; fastLightingAvailable = true;
} }
catch (Throwable e) { catch (Throwable e) {
e.printStackTrace();
} }
} }
} }