NyaaCat / Yasui

Control entity resource consumption by dropping AI computing. Mobは安い。
MIT License
29 stars 7 forks source link

[WIP] V2 Code Refactoring #4

Open phoenixlzx opened 5 years ago

phoenixlzx commented 5 years ago

Features

Design

The plugin should be modular. It has 3 major parts:

Commands

Command Permission Description
/yasui status yasui.command.status Shows current server overall status with some statistics.
/yasui chunks [world] yasui.command.chunks Shows top-N chunks that consuming most of the tick time. If [world] is supplied, shows data for that specific world. Otherwise use the world which the executor is in.
/yasui counter <entity\|redstone> [world] yasui.command.counter Shows top-N entity or redstone counter data that consuming most of the tick time. entity lists LivingEntity and All Other categories, while redstone lists Redstone and Physics categories.
/yasui operation <engage\|release> <operation> [world\|all] yasui.command.operation Manually engage or release operation to a specific world, or the world which player is in, or all worlds.
/yasui reset yasui.command.reset Reset Yasui's counters and statistics. This will not reload the configurations and operation status.
/yasui reload yasui.command.reload Reload the plugin and configuration, check and update all the settings/operations/rule definitions as well as reset all counters.

Configuration example

config.yml

language: en_US
enable: true  # global switch
scan_interval_tick: 600
broadcast: CHAT # CHAT | SUBTITLE | ACTIONBAR | ADMIN_CHAT | NONE
top_listing: 10
modules: # Comment out any of the below will disable all its operations.
- entity_ai_suppressor
- entity_culler
- redstone_suppressor
- random_tick_speed
- command_executor

Operation files are placed under operations/ directory, with operation name as the file name, and module name as root variable name in the file, along with its parameters.

Operation names use hyphens, while feature module names use underscores.

# Suppress entity AI on engage, or restore them on release.
entity_ai_suppressor:
  method: NO_TARGETING # NO_TARGETING | NO_AI | NERFING
  exclude: # entities won't be suppressed, typically used with mob farms that take adv of entity anger
    type:
    - PIG_ZOMBIE
    - ENDERMAN
    tagged: false  # has custom name or tag
    tamed: false  # has owner
# Cull mobs and disable new mob spawns on engage, enable new mob spawns on release.
entity_culler:
  excluded:
    type:
    - DOLPHIN
    - SNOWMAN
    tagged: true
    tamed: true
  per_chunk_limit: 12
  per_region_limit: 30
# Suppress redstone currents on engage, lift cancellation on release.
# Note: Yasui should always set NewCurrent = OldCurrent to keep consistency of redstone mechanics.
redstone_suppressor:
  event_thresholds:
    count_per_chunk: 12000 # 12000 events in 'scan_interval_tick'
    count_piston_per_chunk: 120 #  120 piston events in 'scan_interval_tick'
  supress_chunk_region: 1 # redstone in nearby 3x3 chunks will be supressed
# Decrease random tick speed by 1 on engage, increase by 1 on release.
random_tick_speed:
  min: 1
  max: 3
# Execute command on engage or release.
command_executor:
  engage: 'essentials:killall entities all'
  release: '' # empty string will not do anything

Rule files are placed under rules/ directory.

enabled: true
operations: 
- 'suppress-entity-ai'
worlds:
- world
- world_nether
- world_the_end
engage:
  condition: tps_1m < 18.0 && world_living_entities > 2000
  message: '&b[YASUI] &c[ENGAGED] &6Entity AI Suppressed'
release:
  condition: tps_1m > 19.5
  message: '&b[YASUI] &a[RELEASED] &6Entity AI Recovered'
enabled: true
operations: 
- 'adjust-random-tick-speed'
worlds:
- world
- world_nether
- world_the_end
engage:
  condition: tps_5m < 17.0
  message: '&b[YASUI] &c[ENGAGED] &6Random Tick Speed: &d{world_random_tick_speed}'
release:
  condition: tps_5m > 19.0
  message: '&b[YASUI] &c[RELEASED] &6Random Tick Speed: &d{world_random_tick_speed}'
enabled: true
operations: 
- 'suppress-redstone'
worlds:
- world
- world_nether
- world_the_end
engage:
  condition: tps_5m < 15.0
  message: '&b[YASUI] &c[ENGAGED] &6Redstone Suppressed'
release:
  condition: tps_5m > 19.0
  message: '&b[YASUI] &c[RELEASED] &6Redstone Recovered'
enabled: true
operations: 
- 'cull-entity'
worlds:
- world
- world_nether
- world_the_end
engage:
  condition: tps_5m < 17.0 && world_entity > 2000
  message: '&b[YASUI] &c[ENGAGED] &6EntityLimit Engaged'
release:
  condition: tps_5m > 19.0
  message: '&b[YASUI] &c[RELEASED] &6EntityLimit Released'
phoenixlzx commented 5 years ago

问题:

phoenixlzx commented 5 years ago

新需求: region

region/region-name.yml

enabled: true
region:
  minChunkX: 7
  minChunkZ: 11
  maxChunkX: 10
  maxChunkZ: 16
bypass:
  - cull-entity  # rule names
  - suppress-redstone
phoenixlzx commented 5 years ago

New config option - broadcast messages destination

broadcast:
  type: CHAT
  log_console: true
  permission: yasui.command.status

Only players with yasui.command.status permission will receive the broadcast message.

update - Entity Culler (paper)

Mobcap implementation (paper)

API reference:

Module mobcap

Operation operations/mobcap.yml

If engaged, new mob will not naturally spawn when:

new mob will not spawn for most of the reasons (except custom/plugin) when:

Note:

mobcap:
  global:
    soft: 1600
    hard: 2400
    types:
    - VILLAGER: 100
    - PILLAGER: 100
    - PIG_ZOMBIE: 200
  chunk:
    default: 32
    types:
    - VILLAGER: 4
    - PILLAGER: 4
    - CHICKEN: 8

Rule rule/mobcap.yml

enabled: false
operations: 
- 'mobcap'
worlds:
- world
- world_nether
- world_the_end
engage:
  condition: tps_5m < 17.0 && world_living_entities > 1500
  message: '&b[YASUI] &c[ENGAGED] &6Mob spawn limited'
release:
  condition: tps_5m > 19.5
  message: '&b[YASUI] &c[RELEASED] &6Mob spawn lifted'

Dynamic View Distance (Paper)

API reference

Module adjust-view-distance

Operation operation/adjust-view-distance.yml

Reduce player view distance by 1 on engage, and increase by 1 on release, to the minimum or maximum value.

adjust-view-distance:
  min: 6
  max: 10

Rule rule/adjust-view-distance.yml

enabled: false
operations: 
- 'adjust-view-distance'
worlds:
- world
- world_nether
- world_the_end
engage:
  condition: tps_5m < 16.0 && world_chunks > 5000
  message: '&b[YASUI] &c[ENGAGED] &6View Distance &d{world_view_distance}'
release:
  condition: tps_5m > 19.0
  message: '&b[YASUI] &c[RELEASED] &6View Distance &d{world_view_distance}'