/** Detect when water drains. */
  @EventHandler
  public void onBlockPhysics(BlockPhysicsEvent event) {
    if (event.isCancelled()) return;

    BlockState b = event.getBlock().getState();
    // As far as I know, these are always evaporation events.
    if (plugin.isBlockStateDetectable(b)) {
      plugin.executeSensorsAroundBlock(b, true, event);
    }
  }
  /** Detect when pistons affect water or sensor components. PISTONS MAH BOI! */
  @EventHandler
  public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    if (event.isCancelled()) return;

    // Get the block just at the end of the piston chain (that will be replaced when the chain is
    // pushed)
    Block endblock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1);
    BlockState b = endblock.getState();
    plugin.debugprint("Block at end of piston chain " + b.getType());
    if (plugin.isBlockStateAnUpdater(b)) {
      plugin.executeSensorsAroundBlock(b, true, event);
    }
  }
  /** Detect an event where water is flowing. */
  @EventHandler
  public void onBlockFromTo(BlockFromToEvent event) {
    if (event.isCancelled()) return;

    BlockState fromstate = event.getBlock().getState();
    if (plugin.isBlockStateDetectable(fromstate)) {
      plugin.executeSensorsAroundBlock(fromstate, false, event);
    }
    BlockState tostate = event.getToBlock().getState();
    if (plugin.isBlockStateDetectable(fromstate)) {
      plugin.executeSensorsAroundBlock(tostate, false, event);
    }
  }
  /**
   * When you just gotta place some 8... or replace it. Also works when you place water sensor
   * components (block or lever)
   */
  @EventHandler
  public void onBlockPlace(BlockPlaceEvent event) {
    if (event.isCancelled()) return;

    BlockState tostate = event.getBlockPlaced().getState();
    if (plugin.isBlockStateAnUpdater(tostate)) {
      plugin.executeSensorsAroundBlock(tostate, false, event);
    }
    // If we're destroying water, it's an evaporation event. Doesn't really matter with levers...
    BlockState fromstate = event.getBlockReplacedState();
    if (plugin.isBlockStateAnUpdater(fromstate)) {
      plugin.executeSensorsAroundBlock(fromstate, true, event);
    }
  }
Exemplo n.º 5
0
 @Override
 public WaterSensor build() {
   try {
     WaterSensor record = new WaterSensor();
     record.quantity =
         fieldSetFlags()[0] ? this.quantity : (java.lang.Float) defaultValue(fields()[0]);
     record.major_area_num =
         fieldSetFlags()[1]
             ? this.major_area_num
             : (java.lang.Integer) defaultValue(fields()[1]);
     record.minor_area_num =
         fieldSetFlags()[2]
             ? this.minor_area_num
             : (java.lang.Integer) defaultValue(fields()[2]);
     record.time_since_turn_on =
         fieldSetFlags()[3]
             ? this.time_since_turn_on
             : (java.lang.Integer) defaultValue(fields()[3]);
     record.unique_id =
         fieldSetFlags()[4] ? this.unique_id : (java.lang.Long) defaultValue(fields()[4]);
     record.runtime =
         fieldSetFlags()[5] ? this.runtime : (java.lang.Long) defaultValue(fields()[5]);
     record.minType =
         fieldSetFlags()[6] ? this.minType : (java.lang.CharSequence) defaultValue(fields()[6]);
     record.majType =
         fieldSetFlags()[7] ? this.majType : (java.lang.CharSequence) defaultValue(fields()[7]);
     record.item_sensed =
         fieldSetFlags()[8]
             ? this.item_sensed
             : (java.lang.CharSequence) defaultValue(fields()[8]);
     record.subject_measured =
         fieldSetFlags()[9]
             ? this.subject_measured
             : (java.lang.CharSequence) defaultValue(fields()[9]);
     record.sensor_location_name =
         fieldSetFlags()[10]
             ? this.sensor_location_name
             : (java.lang.CharSequence) defaultValue(fields()[10]);
     return record;
   } catch (Exception e) {
     throw new org.apache.avro.AvroRuntimeException(e);
   }
 }