Skip to content

Commit

Permalink
Support MC 1.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RubixDev committed Aug 2, 2022
1 parent 12f577c commit 78aec69
Show file tree
Hide file tree
Showing 17 changed files with 352 additions and 251 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

![Icon](https://raw.githubusercontent.com/RubixDev/CarpetGamerules/main/src/main/resources/assets/carpetgamerules/icon.png)

An extension Mod for [gnembon's Carpet Mod](https://github.com/gnembon/fabric-carpet) that adds all vanilla gamerules to the carpet settings.
An extension for [gnembon's Carpet Mod](https://github.com/gnembon/fabric-carpet) that adds all vanilla gamerules to the carpet settings.

## Related Mods and Tools

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

./update_version.py
./generate_readmes.py
./gen_md.py
./gradlew build
105 changes: 76 additions & 29 deletions generate_readmes.py → gen_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@
with open('pyconfig.json', 'r') as config_file:
SETTINGS: dict[str, any] = json.load(config_file)

with open(SETTINGS['languageFile'], 'r') as lang_file:
# Remove lines with comments
contents: str = re.compile(
r'^\s*//.*$', re.MULTILINE).sub('', lang_file.read())
descriptions_raw: dict[str, any] = json.loads(contents)
# DESCRIPTIONS has following structure:
# { "ruleName": { "desc": "...", "extra": ["...", "..."] } }
DESCRIPTIONS: dict[str, dict] = {}
for k, v in descriptions_raw.items():
rule_name = re.compile(
r'carpet\.rule\.(\w+)\.(?:desc|extra\.\d+)').search(k).group(1)
if rule_name not in DESCRIPTIONS.keys():
DESCRIPTIONS[rule_name] = {
'desc': '',
'extra': [],
}
if k.endswith('.desc'):
DESCRIPTIONS[rule_name]['desc'] = v
elif re.compile(r'\.extra\.\d+$').search(k):
index = int(k.split('.')[-1])
while len(DESCRIPTIONS[rule_name]['extra']) <= index:
DESCRIPTIONS[rule_name]['extra'].append('')
DESCRIPTIONS[rule_name]['extra'][index] = v
else:
print(f'\x1b[1;33mWarning: unknown key {k} in language file\x1b[0m')


class Rule:
type: str
Expand All @@ -22,7 +48,8 @@ class Rule:

def __repr__(self):
nl: str = '\n'
options: list[str] = ['true', 'false'] if self.type == 'boolean' else self.options
options: list[str] = [
'true', 'false'] if self.type == 'boolean' else self.options
if 'COMMAND' in self.categories:
options: list[str] = ['true', 'false', 'ops']

Expand Down Expand Up @@ -50,44 +77,49 @@ def read_rules() -> list[Rule]:
with open(SETTINGS['carpetSettingsClass'], 'r') as settings_file:
print('Reading settings file\n')
settings_string = settings_file.read()
raw_rules: list[str] = [i.split(';')[0] for i in settings_string.split('@Rule')[1:]]
raw_rules: list[str] = [i.split(';')[0] for i in re.compile(
'^[^/\n]*[^/\n]*@Rule', re.MULTILINE).split(settings_string)[1:]]

rules: list[Rule] = []
for raw_rule in raw_rules:
rule: Rule = Rule()
field: list[str] = raw_rule.split('\n')[-1].split('public static ')[-1].split(' ')
field: list[str] = raw_rule.split(
'\n')[-1].split('public static ')[-1].split(' ')
rule.type = field[0]
rule.name = field[1]
print(f'Parsing rule {rule.name}')
rule.value = field[3].replace('"', '')

attr_dict: dict[str: str] = { match.group(1): match.group(2) for match in re.finditer(r'(name|desc|extra|options|category|strict|appSource|validate) = ([\s\S]+?)(?=,\n?\s*?\w+?\s?=\s?|\n?\s*?\)\n)', raw_rule) }

rule.desc = attr_dict['desc'][1:-1]
if 'extra' in attr_dict.keys():
if (attr_dict['extra'][0] == '{'):
rule.extra = [
re.sub(r'([^\\]|^)"', r'\1|||||', extra)
.split('|||||')[1].split('|||||')[0]
.replace('\\"', '"')
for extra in re.sub(r'",\s|",\n', '"|||||', attr_dict['extra'][1:-1]).split('|||||')
]
else:
rule.extra = [attr_dict['extra'][1:-1]]
attr_dict: dict[str: str] = {
match.group(1): match.group(2) for match in re.finditer(
r'(options|categories|strict|appSource|validators|conditions) = ([\s\S]+?)(?=,\n?\s*?\w+?\s?=\s?|\n?\s*?\)\n)',
raw_rule
)
}

rule.desc = DESCRIPTIONS[rule.name]['desc']
rule.extra = DESCRIPTIONS[rule.name]['extra']
if 'options' in attr_dict.keys():
rule.options = [re.sub(r'\s|\n', '', option)[1:-1] for option in re.compile(r',\s|,\n').split(attr_dict['options'][1:-1])]
rule.strict = not ('strict' in attr_dict.keys()) or attr_dict['strict'] == 'true'
rule.categories = [category for category in attr_dict['category'][1:-1].replace(' ', '').split(',')]
rule.options = [re.sub(r'\s|\n', '', option)[
1:-1] for option in re.compile(r',\s|,\n').split(attr_dict['options'][1:-1])]
rule.strict = not ('strict' in attr_dict.keys()
) or attr_dict['strict'] == 'true'
rule.categories = [
category for category in attr_dict['categories'][1:-1].replace(' ', '').split(',')]
main_category: str = SETTINGS['mainCategory']
if main_category not in rule.categories:
print(f'\033[1;31m{main_category} category is missing in {rule.name}!\033[22m Exiting...\033[0m')
print(
f'\033[1;31m{main_category} category is missing in {rule.name}!\033[22m Exiting...\033[0m')
return []
if 'validate' in attr_dict.keys():
validator: str = attr_dict['validate'].replace('.class', '')
rule.restriction = settings_string.split(f'class {validator} extends')[1].split('"')[1]
found_additional: list[str] = settings_string.split(f'// {rule.name}Additional: ')
if 'validators' in attr_dict.keys():
validator: str = attr_dict['validators'].replace('.class', '')
rule.restriction = settings_string.split(
f'class {validator} extends')[1].split('"')[1]
found_additional: list[str] = settings_string.split(
f'// {rule.name}Additional: ')
if len(found_additional) > 1:
rule.additional = re.sub(r'\n\s+?//\s?', ' ', found_additional[1].split(':::')[0])
rule.additional = re.sub(
r'\n\s+?//\s?', ' ', found_additional[1].split(':::')[0])

rules.append(rule)
print(f'Successfully parsed {rule.name}')
Expand All @@ -101,11 +133,13 @@ def write_files(rules: list[Rule]):
out: str = header_file.read()

print('Listing all categories')
all_categories: list[str] = list(set([item for sublist in [rule.categories for rule in rules] for item in sublist]))
all_categories: list[str] = [category for category in all_categories if category.upper() != SETTINGS['mainCategory']]
all_categories: list[str] = list(set(
[item for sublist in [rule.categories for rule in rules] for item in sublist]))
all_categories = [category for category in all_categories if category.upper(
) != SETTINGS['mainCategory']]
all_categories.sort()

out += f'## Lists of Categories\n'
out += '## Lists of Categories\n'
for category in all_categories:
out += f'- [`{category}`](markdown/{category}_Category.md)\n'
out += '\n'
Expand All @@ -121,7 +155,8 @@ def write_files(rules: list[Rule]):

for category in all_categories:
print(f'Listing rules in {category} category')
rules_in_category: list[Rule] = [rule for rule in rules if category in rule.categories]
rules_in_category: list[Rule] = [
rule for rule in rules if category in rule.categories]
rules_in_category.sort(key=lambda e: e.name)
out: str = f'# List of Rules in the {category} Category\n\n' \
f'For a list of all implemented Rules go [here](../README.md)\n'
Expand All @@ -132,6 +167,7 @@ def write_files(rules: list[Rule]):
category_readme.write(out[:-1])

curseforge_list(rules)
modrinth_list(rules)


def list_rules(rules: list[Rule], rule_headline: str) -> str:
Expand All @@ -157,6 +193,17 @@ def curseforge_list(rules: list[Rule]):
curse_file.write(out)


def modrinth_list(rules: list[Rule]):
with open(SETTINGS['modrinthHeader'], 'r') as header_file:
out: str = header_file.read()
out += f'Count: {len(rules)}\n'
for rule in rules:
out += f'- {rule.name}\n'
with open('markdown/modrinth.md', 'w') as modrinth_file:
print('\nWriting modrinth.md')
modrinth_file.write(out)


if __name__ == '__main__':
write_files(read_rules())
print('\nDone!')
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.19
yarn_mappings=1.19+build.4
minecraft_version=1.19.1
yarn_mappings=1.19.1+build.5
loader_version=0.14.8
# check available versions on maven for the given minecraft version you are using: https://masa.dy.fi/maven/carpet/fabric-carpet/
carpet_core_version=1.4.79+v220607
carpet_core_version=1.4.83+v220727

# Mod Properties
mod_version = 1.2.1
mod_version = 1.2.2
maven_group = de.rubixdev.carpetgamerules
archives_base_name = carpetgamerules

Expand Down
2 changes: 1 addition & 1 deletion markdown/CurseForge-header.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Carpet Gamerules

Extension Mod for [gnembon's Carpet Mod](https://github.com/gnembon/fabric-carpet) that adds all vanilla gamerules to the carpet settings
Extension Mod for [gnembon's Carpet Mod](https://www.curseforge.com/minecraft/mc-mods/carpet) that adds all vanilla gamerules to the carpet settings

**Visit the [GitHub page](https://github.com/RubixDev/CarpetGamerules) for a more detailed explanation.**

Expand Down
7 changes: 7 additions & 0 deletions markdown/Modrinth-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Carpet Gamerules

Extension for [gnembon's Carpet Mod](https://github.com/gnembon/fabric-carpet) that adds all vanilla gamerules to the carpet settings

**Visit the [GitHub page](https://github.com/RubixDev/CarpetGamerules) for a more detailed explanation.**

## List of Gamerules
2 changes: 1 addition & 1 deletion markdown/README-header.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

![Icon](https://raw.githubusercontent.com/RubixDev/CarpetGamerules/main/src/main/resources/assets/carpetgamerules/icon.png)

An extension Mod for [gnembon's Carpet Mod](https://github.com/gnembon/fabric-carpet) that adds all vanilla gamerules to the carpet settings.
An extension for [gnembon's Carpet Mod](https://github.com/gnembon/fabric-carpet) that adds all vanilla gamerules to the carpet settings.

## Related Mods and Tools

Expand Down
2 changes: 1 addition & 1 deletion markdown/curseforge.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Carpet Gamerules

Extension Mod for [gnembon's Carpet Mod](https://github.com/gnembon/fabric-carpet) that adds all vanilla gamerules to the carpet settings
Extension Mod for [gnembon's Carpet Mod](https://www.curseforge.com/minecraft/mc-mods/carpet) that adds all vanilla gamerules to the carpet settings

**Visit the [GitHub page](https://github.com/RubixDev/CarpetGamerules) for a more detailed explanation.**

Expand Down
44 changes: 44 additions & 0 deletions markdown/modrinth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Carpet Gamerules

Extension for [gnembon's Carpet Mod](https://github.com/gnembon/fabric-carpet) that adds all vanilla gamerules to the carpet settings

**Visit the [GitHub page](https://github.com/RubixDev/CarpetGamerules) for a more detailed explanation.**

## List of Gamerules
Count: 36
- announceAdvancements
- commandBlockOutput
- disableElytraMovementCheck
- disableRaids
- doDaylightCycle
- doEntityDrops
- doFireTick
- doImmediateRespawn
- doInsomnia
- doLimitedCrafting
- doMobLoot
- doMobSpawning
- doPatrolSpawning
- doTileDrops
- doTraderSpawning
- doWardenSpawning
- doWeatherCycle
- drowningDamage
- fallDamage
- fireDamage
- forgiveDeadPlayers
- freezeDamage
- keepInventory
- logAdminCommands
- maxCommandChainLength
- maxEntityCramming
- mobGriefing
- naturalRegeneration
- playersSleepingPercentage
- randomTickSpeed
- reducedDebugInfo
- sendCommandFeedback
- showDeathMessages
- spawnRadius
- spectatorsGenerateChunks
- universalAnger
4 changes: 3 additions & 1 deletion pyconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"mainClass": "src/main/java/de/rubixdev/carpetgamerules/CarpetGamerulesServer.java",
"carpetSettingsClass": "src/main/java/de/rubixdev/carpetgamerules/CarpetGamerulesSettings.java",
"languageFile": "src/main/resources/assets/carpetgamerules/lang/en_us.json5",
"mainCategory": "GAMERULE",
"readmeHeader": "markdown/README-header.md",
"curseForgeHeader": "markdown/CurseForge-header.md"
"curseForgeHeader": "markdown/CurseForge-header.md",
"modrinthHeader": "markdown/Modrinth-header.md"
}
Loading

0 comments on commit 78aec69

Please sign in to comment.