コード例 #1
0
    @Override
    public void tickEnd(EnumSet<TickType> type, Object... tickData) {
      if (lastWorld != FMLClientHandler.instance().getClient().theWorld
          || thePlayer != FMLClientHandler.instance().getClient().thePlayer) {
        thePlayer = FMLClientHandler.instance().getClient().thePlayer;
        if (thePlayer != null) {
          lastWorld = thePlayer.worldObj;
        } else {
          lastWorld = null;
        }
      }

      if (thePlayer != null && thePlayer.isEntityAlive() && !DynamicLights.globalLightsOff()) {
        int prevLight = lightLevel;

        ItemStack item = thePlayer.getCurrentEquippedItem();
        lightLevel = getLightFromItemStack(item);

        for (ItemStack armor : thePlayer.inventory.armorInventory) {
          lightLevel = Math.max(lightLevel, getLightFromItemStack(armor));
        }

        if (prevLight != 0 && lightLevel != prevLight) {
          lightLevel = 0;
        } else {
          if (thePlayer.isBurning()) {
            lightLevel = 15;
          } else {
            if (checkPlayerWater(thePlayer)
                && item != null
                && notWaterProofItems.retrieveValue(item.itemID, item.getItemDamage()) == 1) {
              lightLevel = 0;

              for (ItemStack armor : thePlayer.inventory.armorInventory) {
                if (armor != null
                    && notWaterProofItems.retrieveValue(armor.itemID, item.getItemDamage()) == 0) {
                  lightLevel = Math.max(lightLevel, getLightFromItemStack(armor));
                }
              }
            }
          }
        }

        if (!enabled && lightLevel > 8) {
          enableLight();
        } else if (enabled && lightLevel < 9) {
          disableLight();
        }
      }
    }
  @SubscribeEvent
  public void onTick(TickEvent.ClientTickEvent tick) {
    if (lastWorld != FMLClientHandler.instance().getClient().theWorld
        || thePlayer != FMLClientHandler.instance().getClient().thePlayer) {
      thePlayer = FMLClientHandler.instance().getClient().thePlayer;
      if (thePlayer != null) {
        lastWorld = thePlayer.worldObj;
      } else {
        lastWorld = null;
      }
    }

    if (thePlayer != null && thePlayer.isEntityAlive() && !DynamicLights.globalLightsOff()) {
      List<IMCMessage> messages = FMLInterModComms.fetchRuntimeMessages(this);
      if (messages.size() > 0) {
        // just get the last one
        IMCMessage imcMessage = messages.get(messages.size() - 1);
        if (imcMessage.key.equalsIgnoreCase("forceplayerlighton")) {
          if (!fmlOverrideEnable) {
            fmlOverrideEnable = true;
            if (!enabled) {
              lightLevel = 15;
              enableLight();
            }
          }
        } else if (imcMessage.key.equalsIgnoreCase("forceplayerlightoff")) {
          if (fmlOverrideEnable) {
            fmlOverrideEnable = false;
            if (enabled) {
              disableLight();
            }
          }
        }
      }

      if (!fmlOverrideEnable) {
        int prevLight = lightLevel;

        ItemStack item = thePlayer.getCurrentEquippedItem();
        lightLevel = itemsMap.getLightFromItemStack(item);

        for (ItemStack armor : thePlayer.inventory.armorInventory) {
          lightLevel = DynamicLights.maxLight(lightLevel, itemsMap.getLightFromItemStack(armor));
        }

        if (prevLight != 0 && lightLevel != prevLight) {
          lightLevel = 0;
        } else {
          if (thePlayer.isBurning()) {
            lightLevel = 15;
          } else {
            if (checkPlayerWater(thePlayer)
                && item != null
                && notWaterProofItems.retrieveValue(
                        GameData.getItemRegistry().getNameForObject(item.getItem()),
                        item.getItemDamage())
                    == 1) {
              lightLevel = 0;

              for (ItemStack armor : thePlayer.inventory.armorInventory) {
                if (armor != null
                    && notWaterProofItems.retrieveValue(
                            GameData.getItemRegistry().getNameForObject(armor.getItem()),
                            item.getItemDamage())
                        == 0) {
                  lightLevel =
                      DynamicLights.maxLight(lightLevel, itemsMap.getLightFromItemStack(armor));
                }
              }
            }
          }
        }

        if (!enabled && lightLevel > 0) {
          enableLight();
        } else if (enabled && lightLevel < 1) {
          disableLight();
        }
      }
    }
  }