summaryrefslogtreecommitdiff
path: root/ihl/enviroment/LightHandler.java
diff options
context:
space:
mode:
authorFoghrye4 <foghrye4@gmail.com>2017-04-14 07:58:16 +0300
committerFoghrye4 <foghrye4@gmail.com>2017-04-14 07:58:16 +0300
commitaa42aedecd2d2842351088085e8fd9d69ec79565 (patch)
tree94c888b3d362868f427980dd37765f9bb166dba9 /ihl/enviroment/LightHandler.java
parentfb29b09822057ae7b1b913993dc1fa3a67345eec (diff)
Colourful lights
Diffstat (limited to 'ihl/enviroment/LightHandler.java')
-rw-r--r--ihl/enviroment/LightHandler.java76
1 files changed, 54 insertions, 22 deletions
diff --git a/ihl/enviroment/LightHandler.java b/ihl/enviroment/LightHandler.java
index c89ffb7..31a921e 100644
--- a/ihl/enviroment/LightHandler.java
+++ b/ihl/enviroment/LightHandler.java
@@ -7,7 +7,9 @@ import java.util.Set;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ihl.IHLMod;
+import ihl.utils.IHLMathUtils;
import net.minecraft.block.Block;
+import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
@@ -41,27 +43,28 @@ public class LightHandler {
((l >>> lightBitsPerDimension) & bitmask) - maxLightRadius, (l & bitmask) - maxLightRadius };
}
- public LightSource calculateOmniLightSource(World world, int sourceX, int sourceY, int sourceZ, int power, int red,
- int green, int blue) {
+ public LightSource calculateLightSource(World world, int sourceX, int sourceY, int sourceZ, int power, int red,
+ int green, int blue, double[] ds) {
LightSource lightSource = new LightSource(sourceX, sourceY, sourceZ, red, green, blue, power);
int[] borders = { sourceX, sourceY, sourceZ, sourceX, sourceY, sourceZ };
int[] evSource = { sourceX, sourceY, sourceZ };
int[] lightSourceXYZ = { sourceX, sourceY, sourceZ };
for (int i = 0; i < directionMasks.length; i++) {
int[] directionMask = directionMasks[i];
- this.litBlocksAndGetDescendants(world, evSource, lightSourceXYZ, lightSource.illuminatedBlocks, 0, power,
- directionMask, borders);
+ this.litBlocksAndGetDescendants(world, evSource, lightSourceXYZ, lightSource.illuminatedBlocks, 0, power>>1,
+ directionMask, borders, ds);
}
lightSource.setBorders(borders[0], borders[1], borders[2], borders[3], borders[4], borders[5]);
return lightSource;
}
private void litBlocksAndGetDescendants(World world, int[] evSource, int[] lightSource, BitSet illuminatedBlocksSet,
- int ev, int power, int[] directionMask, int[] borders) {
- power = this.getNewPower(world, ev, evSource, lightSource, power, directionMask, illuminatedBlocksSet, borders);
- power = (power<<4)/17 - 1;
+ int ev, int power, int[] directionMask, int[] borders, double[] ds) {
+ power = this.getNewPower(world, ev, evSource, lightSource, power, directionMask, illuminatedBlocksSet, borders,
+ ds);
+ power--;
if (power > 1) {
- if (vectors[ev][0] == 0) {
+ if (vectors[ev].length == 0) {
int[] xyz = IHLMod.explosionHandler.decodeXYZ(ev);
int xb = xyz[0] >> bits - 1;
int yb = xyz[1] >> bits - 1;
@@ -78,13 +81,11 @@ public class LightHandler {
evSource[1] + yb * halfValue * directionMask[1],
evSource[2] + zb * halfValue * directionMask[2] };
litBlocksAndGetDescendants(world, nextEVSource, lightSource, illuminatedBlocksSet, ev2, power,
- directionMask, borders);
+ directionMask, borders, ds);
} else {
for (int d1 : this.vectors[ev]) {
- if (d1 != 0) {
litBlocksAndGetDescendants(world, evSource, lightSource, illuminatedBlocksSet, d1, power,
- directionMask, borders);
- }
+ directionMask, borders, ds);
}
}
}
@@ -92,7 +93,7 @@ public class LightHandler {
}
private int getNewPower(World world, int ev, int[] evSource, int[] lightSource, int power, int[] directionMask,
- BitSet illuminatedBlocksSet, int[] borders) {
+ BitSet illuminatedBlocksSet, int[] borders, double[] ds) {
int power1 = power;
int[] xyz = IHLMod.explosionHandler.decodeXYZ(ev);
int absX = xyz[0] * directionMask[0] + evSource[0];
@@ -111,24 +112,55 @@ public class LightHandler {
} else if (absZ > borders[5]) {
borders[5] = absZ;
}
- Block block = world.getBlock(absX, absY, absZ);
- if (block.equals(Blocks.air) || block.isAir(world, absX, absY, absZ)) {
- return power;
- }
- power1 *= world.getBlockLightOpacity(absX, absY, absZ) / 16;
+ power1 = power1 * (255 - world.getBlockLightOpacity(absX, absY, absZ)) / 255;
int lightBitAddress = this.encodeXYZ(absX - lightSource[0], absY - lightSource[1], absZ - lightSource[2]);
illuminatedBlocksSet.set(lightBitAddress);
+ if (ds != null) {
+ float dx = (float) (absX - ds[0]);
+ float dy = (float) (absY - ds[1]);
+ float dz = (float) (absZ - ds[2]);
+ float sqd = dx * dx + dy * dy + dz * dz;
+ float d = IHLMathUtils.sqrt(sqd);
+ float dx1 = (float) (ds[3] * d);
+ float dy1 = (float) (ds[4] * d);
+ float dz1 = (float) (ds[5] * d);
+ float ddx = dx - dx1;
+ float ddy = dy - dy1;
+ float ddz = dz - dz1;
+ float sqr = ddx * ddx + ddy * ddy + ddz * ddz;
+ float sqrmax = (float) ds[6] * sqd + 4f;
+ if (sqr > sqrmax) {
+ return 0;
+ }
+ }
return power1;
}
public void addLightSource(LightSource lightSource) {
- System.out.println("Adding light source. Borders:");
- System.out.println("from " + lightSource.fromX + ";" + lightSource.fromY + ";" + lightSource.fromZ);
- System.out.println("to " + lightSource.toX + ";" + lightSource.toY + ";" + lightSource.toZ);
+/* IHLMod.log.info("Added light source at area from "+lightSource.fromX+";"+lightSource.fromY+";"+lightSource.fromZ+
+ " to "+lightSource.toX+";"+lightSource.toY+";"+lightSource.toZ);*/
this.lightSources.add(lightSource);
+ Minecraft.getMinecraft().theWorld.markBlockRangeForRenderUpdate(
+ lightSource.fromX,
+ lightSource.fromY,
+ lightSource.fromZ,
+ lightSource.toX,
+ lightSource.toY,
+ lightSource.toZ);
}
public void removeLightSource(LightSource lightSource) {
- this.lightSources.remove(lightSource);
+ if(!this.lightSources.remove(lightSource)){
+ throw new IllegalArgumentException("Requested light source is not presented.");
+ }
+/* IHLMod.log.info("Removing light source at area from "+lightSource.fromX+";"+lightSource.fromY+";"+lightSource.fromZ+
+ " to "+lightSource.toX+";"+lightSource.toY+";"+lightSource.toZ);*/
+ Minecraft.getMinecraft().theWorld.markBlockRangeForRenderUpdate(
+ lightSource.fromX,
+ lightSource.fromY,
+ lightSource.fromZ,
+ lightSource.toX,
+ lightSource.toY,
+ lightSource.toZ);
}
}