Fix relight and removelight (#475)

* Start work on lighting engine (does not build)

* Implement getLighting

* Setting, flushing light etc works. Getting light should be working..?

* Better queue/chunk handling

* Use correct location for lighting update

* Correct set location, remove debug

* cleanup a little

* Fix fixlight

* Apply to all versions for the numpties

* Remove lighting extent if not using

* Actually bitmask blocks when setting in chunks

* Initialise Maps and Dequeues with inital size

* format

* Documentation maybe
This commit is contained in:
dordsor21
2020-05-27 11:45:08 +01:00
committed by GitHub
parent 1ff5e7761b
commit bdc14c10c7
27 changed files with 1910 additions and 93 deletions

View File

@ -27,9 +27,11 @@ import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Caption;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.RelightMode;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
@ -139,16 +141,15 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.light.fix")
public void fixLighting(Player player) throws WorldEditException {
player.print(TextComponent.of("Temporarily not working"));
// final Location loc = player.getLocation();
// Region selection = player.getSelection();
// if (selection == null) {
// final int cx = loc.getBlockX() >> 4;
// final int cz = loc.getBlockZ() >> 4;
// selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
// }
// int count = FaweAPI.fixLighting(player.getWorld(), selection,null);
// player.print(Caption.of("fawe.info.lighting.propagate.selection" , count));
final Location loc = player.getLocation();
Region selection = player.getSelection();
if (selection == null) {
final int cx = loc.getBlockX() >> 4;
final int cz = loc.getBlockZ() >> 4;
selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
}
int count = FaweAPI.fixLighting(player.getWorld(), selection,null, RelightMode.ALL);
player.print(Caption.of("fawe.info.lighting.propagate.selection" , count));
}
// @Command(
@ -163,22 +164,21 @@ public class RegionCommands {
// player.print(TextComponent.of("Light: " + block + " | " + sky));
// }
// @Command(
// name = "/removelighting",
// desc = "Removing lighting in a selection"
// )
// @CommandPermissions("worldedit.light.remove")
// public void removeLighting(Player player) {
// player.print(TextComponent.of("Temporarily not working"));
// Region selection = player.getSelection();
// if (selection == null) {
// final int cx = player.getLocation().getBlockX() >> 4;
// final int cz = player.getLocation().getBlockZ() >> 4;
// selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
// }
// int count = FaweAPI.fixLighting(player.getWorld(), selection, null);
// player.print(Caption.of("fawe.info.updated.lighting.selection" , count));
// }
@Command(
name = "/removelighting",
desc = "Removing lighting in a selection"
)
@CommandPermissions("worldedit.light.remove")
public void removeLighting(Player player) {
Region selection = player.getSelection();
if (selection == null) {
final int cx = player.getLocation().getBlockX() >> 4;
final int cz = player.getLocation().getBlockZ() >> 4;
selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
}
int count = FaweAPI.fixLighting(player.getWorld(), selection, null, RelightMode.NONE);
player.print(Caption.of("fawe.info.updated.lighting.selection" , count));
}
@Command(
name = "/nbtinfo",

View File

@ -205,6 +205,46 @@ public class AbstractDelegateExtent implements Extent {
public boolean setBiome(BlockVector2 position, BiomeType biome) {
return extent.setBiome(position.getX(), 0, position.getZ(), biome);
}
@Override
public boolean relight(int x, int y, int z) {
return extent.relight(x, y, z);
}
@Override
public boolean relightBlock(int x, int y, int z) {
return extent.relightBlock(x, y, z);
}
@Override
public boolean relightSky(int x, int y, int z) {
return extent.relightSky(x, y, z);
}
@Override
public void setSkyLight(int x, int y, int z, int value) {
extent.setSkyLight(x, y, z, value);
}
@Override
public void setBlockLight(int x, int y, int z, int value) {
extent.setSkyLight(x, y, z, value);
}
@Override
public int getSkyLight(int x, int y, int z) {
return extent.getSkyLight(x, y, z);
}
@Override
public int getEmmittedLight(int x, int y, int z) {
return extent.getEmmittedLight(x, y, z);
}
@Override
public int getBrightness(int x, int y, int z) {
return extent.getBrightness(x, y, z);
}
@Override
public String toString() {

View File

@ -651,6 +651,18 @@ public interface Extent extends InputExtent, OutputExtent {
return count;
}
default boolean relight(int x, int y, int z) {
return false;
}
default boolean relightBlock(int x, int y, int z) {
return false;
}
default boolean relightSky(int x, int y, int z) {
return false;
}
/**
* Have an extent processed
* - Either block (Extent) processing or chunk processing

View File

@ -85,4 +85,48 @@ public interface InputExtent {
default BiomeType getBiomeType(int x, int y, int z) {
return getBiome(MutableBlockVector2.get(x, z));
}
/**
* Get the light level at the given location
*
* @param position location
* @return the light level at the location
*/
default int getEmmittedLight(MutableBlockVector3 position) {
return getEmmittedLight(position.getX(), position.getY(), position.getZ());
}
default int getEmmittedLight(int x, int y, int z) {
return 0;
}
/**
* Get the sky light level at the given location
*
* @param position location
* @return the sky light level at the location
*/
default int getSkyLight(MutableBlockVector3 position) {
return getSkyLight(position.getX(), position.getY(), position.getZ());
}
default int getSkyLight(int x, int y, int z) {
return 0;
}
default int getBrightness(MutableBlockVector3 position) {
return getBrightness(position.getX(), position.getY(), position.getZ());
}
default int getBrightness(int x, int y, int z) {
return getFullBlock(x, y, z).getMaterial().getLightValue();
}
default int getOpacity(MutableBlockVector3 position) {
return getOpacity(position.getX(), position.getY(), position.getZ());
}
default int getOpacity(int x, int y, int z) {
return getFullBlock(x, y, z).getMaterial().getLightOpacity();
}
}

View File

@ -82,6 +82,30 @@ public interface OutputExtent {
return setBiome(MutableBlockVector2.get(x, z), biome);
}
/**
* Set the light value
*
* @param position position of the block
* @param value light level to set
*/
default void setBlockLight(BlockVector3 position, int value) {
setBlockLight(position.getX(), position.getY(), position.getZ(), value);
}
default void setBlockLight(int x, int y, int z, int value) {}
/**
* Set the sky light value
*
* @param position position of the block
* @param value light level to set
*/
default void setSkyLight(BlockVector3 position, int value) {
setSkyLight(position.getX(), position.getY(), position.getZ(), value);
}
default void setSkyLight(int x, int y, int z, int value) {}
/**
* Return an {@link Operation} that should be called to tie up loose ends
* (such as to commit changes in a buffer).