simple-tech

Minecraft: Better than Adventure! mod that adds simple blocks to automate tasks
git clone git://memoryshards.xyz/simple-tech.git
Log | Files | Refs | README | LICENSE

TileEntityLightSensor.java (1666B)


      1 package ambos.simpletech.block.entity;
      2 
      3 import ambos.simpletech.SimpleTech;
      4 import ambos.simpletech.block.BlockLightSensor;
      5 import net.minecraft.core.block.Block;
      6 import net.minecraft.core.block.entity.TileEntity;
      7 
      8 public class TileEntityLightSensor extends TileEntity {
      9     @Override
     10     public void tick() {
     11         // If the world object is valid...
     12         if (worldObj != null && !worldObj.isClientSide) {
     13             Block block = getBlockType();
     14             // If it's a light sensor...
     15             if (block instanceof BlockLightSensor) {
     16                 BlockLightSensor lightSensor = ((BlockLightSensor) block);
     17                 boolean isDay = worldObj.isDaytime();
     18                 boolean isPowered = SimpleTech.getRedstoneFromMetadata(
     19                         worldObj.getBlockMetadata(x, y, z),
     20                         BlockLightSensor.redstoneOffset) > 0;
     21                 boolean isInverted = lightSensor.isInverted(worldObj, x, y, z);
     22                 if (isInverted) {
     23                     // Daytime mode.
     24                     if (isDay && !isPowered)
     25                         // Sends redstone value.
     26                         lightSensor.updateSensor(worldObj, x, y, z, true);
     27                     if (!isDay && isPowered)
     28                         lightSensor.updateSensor(worldObj, x, y, z, false);
     29                 } else {
     30                     // Nighttime mode.
     31                     if (isDay && isPowered)
     32                         lightSensor.updateSensor(worldObj, x, y, z, false);
     33                     if (!isDay && !isPowered)
     34                         lightSensor.updateSensor(worldObj, x, y, z, true);
     35                 }
     36             }
     37         }
     38     }
     39 }