private void serverTick(boolean doEffects) { World entityWorld = MinecraftServer.getServer().getEntityWorld(); RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(entityWorld); if (!dimensionManager.getDimensions().isEmpty()) { DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(entityWorld); for (Map.Entry<Integer, DimensionDescriptor> entry : dimensionManager.getDimensions().entrySet()) { Integer id = entry.getKey(); // If there is an activity probe we only drain power if the dimension is loaded (a player is // there or a chunkloader) DimensionInformation information = dimensionManager.getDimensionInformation(id); WorldServer world = DimensionManager.getWorld(id); // Power handling. if (world != null || information.getProbeCounter() == 0) { handlePower(doEffects, dimensionStorage, entry, id, information); } // Special effect handling. if (world != null && !world.playerEntities.isEmpty()) { handleRandomEffects(world, information); } } dimensionStorage.save(entityWorld); } }
private void handleLowPower(Integer id, int power, boolean doEffects) { if (power <= 0) { // We ran out of power! WorldServer world = DimensionManager.getWorld(id); if (world != null) { List<EntityPlayer> players = new ArrayList<EntityPlayer>(world.playerEntities); if (DimletConfiguration.dimensionDifficulty >= 1) { for (EntityPlayer player : players) { if (!RfToolsDimensionManager.checkValidPhasedFieldGenerator(player, true)) { player.attackEntityFrom(new DamageSourcePowerLow("powerLow"), 1000000.0f); } else { if (doEffects && DimletConfiguration.phasedFieldGeneratorDebuf) { player.addPotionEffect( new PotionEffect(Potion.moveSlowdown.getId(), EFFECTS_MAX * MAXTICKS, 4, true)); player.addPotionEffect( new PotionEffect(Potion.digSlowdown.getId(), EFFECTS_MAX * MAXTICKS, 2, true)); player.addPotionEffect( new PotionEffect(Potion.hunger.getId(), EFFECTS_MAX * MAXTICKS, 2, true)); } } } } else { Random random = new Random(); for (EntityPlayer player : players) { if (!RfToolsDimensionManager.checkValidPhasedFieldGenerator(player, true)) { WorldServer worldServerForDimension = MinecraftServer.getServer() .worldServerForDimension(DimletConfiguration.spawnDimension); int x = random.nextInt(2000) - 1000; int z = random.nextInt(2000) - 1000; int y = worldServerForDimension.getTopSolidOrLiquidBlock(x, z); if (y == -1) { y = 63; } TeleportationTools.teleportToDimension( player, DimletConfiguration.spawnDimension, x, y, z); } else { if (doEffects) { player.addPotionEffect( new PotionEffect(Potion.moveSlowdown.getId(), EFFECTS_MAX * MAXTICKS, 4, true)); player.addPotionEffect( new PotionEffect(Potion.digSlowdown.getId(), EFFECTS_MAX * MAXTICKS, 4, true)); player.addPotionEffect( new PotionEffect(Potion.hunger.getId(), EFFECTS_MAX * MAXTICKS, 2, true)); } } } } } } }