summaryrefslogtreecommitdiff
path: root/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java
diff options
context:
space:
mode:
authorOnyxDarkKnight <sor1n.iliutza16@gmail.com>2014-04-14 12:03:51 +0300
committerOnyxDarkKnight <sor1n.iliutza16@gmail.com>2014-04-14 12:03:51 +0300
commit4ea6a1052438ef1d8d42057d2a71755383166227 (patch)
tree94def1bf66c59583d8e8aa7e3d1117a6f5b56b62 /eclipse/Jewelrycraft/common/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java
parent1a692ab45df3d88a6cc247cc9f4c0a41c7715264 (diff)
More updating
Diffstat (limited to 'eclipse/Jewelrycraft/common/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java')
-rw-r--r--eclipse/Jewelrycraft/common/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java
new file mode 100644
index 0000000..28f4daa
--- /dev/null
+++ b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java
@@ -0,0 +1,57 @@
+package darkknight.jewelrycraft.tileentity;
+
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.MathHelper;
+import net.minecraft.world.EnumSkyBlock;
+
+public class TileEntityBlockShadow extends TileEntity
+{
+ public int metadata;
+
+ public TileEntityBlockShadow()
+ {
+ this.metadata = -1;
+ }
+
+ @Override
+ public void writeToNBT(NBTTagCompound nbt)
+ {
+ super.writeToNBT(nbt);
+ nbt.setInteger("metadata", metadata);
+ }
+
+ @Override
+ public void readFromNBT(NBTTagCompound nbt)
+ {
+ super.readFromNBT(nbt);
+ this.metadata = nbt.getInteger("metadata");
+ }
+
+ @Override
+ public void updateEntity()
+ {
+ super.updateEntity();
+ int blockLight, realLight;
+ int lightValue = worldObj.getSavedLightValue(EnumSkyBlock.Sky, xCoord, yCoord, zCoord) - worldObj.skylightSubtracted;
+ float sunPosAngle = worldObj.getCelestialAngleRadians(1.0F);
+
+ if (sunPosAngle < (float)Math.PI) sunPosAngle += (0.0F - sunPosAngle) * 0.2F;
+ else sunPosAngle += (((float)Math.PI * 2F) - sunPosAngle) * 0.2F;
+
+ lightValue = Math.round((float)lightValue * MathHelper.cos(sunPosAngle));
+
+ if (lightValue < 0) lightValue = 0;
+ if (lightValue > 15) lightValue = 15;
+
+ blockLight = worldObj.getChunkFromBlockCoords(xCoord, zCoord).getSavedLightValue(EnumSkyBlock.Block, xCoord & 15, yCoord, zCoord & 15);
+ realLight = worldObj.getChunkFromBlockCoords(xCoord, zCoord).getBlockLightValue(xCoord & 15, yCoord, zCoord & 15, 0);
+
+ if((blockLight == 0 && worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord)) || (lightValue >= blockLight)) metadata = 15 - lightValue;
+ else if(!worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord)) metadata = 15 - realLight;
+ else if(lightValue < blockLight) metadata = 15 - blockLight;
+
+ worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 2);
+ worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
+ }
+}