summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java')
-rw-r--r--src/main/java/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java
new file mode 100644
index 0000000..b16ce31
--- /dev/null
+++ b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityBlockShadow.java
@@ -0,0 +1,88 @@
+package darkknight.jewelrycraft.tileentity;
+
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.network.NetworkManager;
+import net.minecraft.network.Packet;
+import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
+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()
+ {
+ metadata = -1;
+ }
+
+ /**
+ * @param nbt
+ */
+ @Override
+ public void writeToNBT(NBTTagCompound nbt)
+ {
+ super.writeToNBT(nbt);
+ nbt.setInteger("metadata", metadata);
+ }
+
+ /**
+ * @param nbt
+ */
+ @Override
+ public void readFromNBT(NBTTagCompound nbt)
+ {
+ super.readFromNBT(nbt);
+ 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(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));
+ }
+
+ /**
+ * @return
+ */
+ @Override
+ public Packet getDescriptionPacket()
+ {
+ NBTTagCompound nbttagcompound = new NBTTagCompound();
+ writeToNBT(nbttagcompound);
+ return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound);
+ }
+
+ /**
+ * @param net
+ * @param packet
+ */
+ @Override
+ public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
+ {
+ readFromNBT(packet.func_148857_g());
+ worldObj.func_147479_m(xCoord, yCoord, zCoord);
+ }
+}