Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.4 update #36

Merged
merged 6 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

## 0.4.6

- added UUID object to represent uuids consisting out of 4 integers
- changed TextComponent & Entity to be gson serializable, so you don't have to call toMap manually
- added arguments methods on context to generate macro commands introduced in 1.20.2
- added serializable UUID object to represent uuids consisting out of 4 integers (thanks @Globbi)
- added Random Widget
- added Return.run and Return.fail subcommands
- added arguments field for File.execute to run functions with arguments
- updated blocks, items, particles and entities to include content from 1.20.4 and 23w51b
- updated documentation links to the new minecraft wiki https://minecraft.wiki (thanks @Spongecade)
- changed TextComponent, Effect & Entity to be gson serializable, so you don't have to call toMap manually
- refactored Title widget
- fixed function tags load/tick generating with paths with `.mcfunction`
- fixed function tags load/tick generating with paths with `.mcfunction` (thanks @FlafyDev)
- fixed Storage.copyScore ignoring the scale parameter
- fixed Github testing workflows to run with Dart 3
- fixed Entity to introduce a trailing comma when given empty tags
- fixed Entity.Clone to deep copy, instead of shallow copy (thanks @CCpcalvin)
- fixed Github testing workflows to run with Dart 3 and provide Code Coverage (thanks @Globbi)

## 0.4.5

Expand Down
7 changes: 1 addition & 6 deletions example/files/load.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ class LoadFile extends Widget {

@override
Widget generate(Context context) {
return For.of([
Data.merge(Entity.All(), nbt: {
"uuid": UUID(1, 2, 3, 4),
'name': TextComponent('name'),
})
]);
return For.of([]);
}
}
9 changes: 9 additions & 0 deletions lib/src/basic/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ class Command extends RestActionAble {
}
@override
Widget generate(Context context) {
if (context.macros.isNotEmpty &&
context.macros.entries
.any((element) => _command.contains(element.key))) {
_command = '\$${context.macros.entries.where((e) => e.value != null).fold(
_command,
(command, entry) =>
command.replaceAll(entry.key, '\${${entry.value}}'),
)}';
}
return Text(_command);
}

Expand Down
31 changes: 26 additions & 5 deletions lib/src/basic/file.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:gson/gson.dart';
import 'package:objd/src/basic/widgets.dart';
import 'package:objd/src/build/build.dart';
import 'package:objd/src/utils/storage.dart';

import 'package:objd/src/wrappers/comment.dart';
import 'package:objd/src/wrappers/data.dart';

class File extends Widget {
Widget? child;
Expand All @@ -12,6 +15,7 @@
bool? isRecursive;
Comment? header;
bool inheritFolder;
Object? arguments;

/// The file class simply generates a new mcfunction file with content and a path.
///
Expand Down Expand Up @@ -46,7 +50,13 @@
this.create = true,
this.header,
this.inheritFolder = true,
this.arguments,
}) : execute = true {
assert(arguments == null ||
arguments is Map ||
arguments is Storage ||
arguments is Entity ||
arguments is Location);

Check warning on line 59 in lib/src/basic/file.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/basic/file.dart#L59

Added line #L59 was not covered by tests
path.replaceAll('.mcfunction', '');
if (path.substring(0, 1) == '/') path = path.substring(1);
}
Expand Down Expand Up @@ -86,33 +96,44 @@
String? pack,
bool create = true,
Comment? header,
Object? arguments,
}) =>
File(
File.execute(

Check warning on line 101 in lib/src/basic/file.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/basic/file.dart#L101

Added line #L101 was not covered by tests
path,
child: StraitWidget(child),
execute: true,
pack: pack,
create: create,
header: header,
);

File run({bool create = false}) => File.execute(
File run({bool create = false, Object? arguments}) => File.execute(
path,
pack: pack,
create: create,
child: child,
arguments: arguments,
);

Path fullPath([Path? p]) => inheritFolder && p != null
? p.append(path, type: 'mcfunction')
: Path.from(path, type: 'mcfunction');

@override
Widget generate(Context context) {
Command generate(Context context) {
if (isRecursive != null && isRecursive!) path = context.file;

pack ??= context.packId;
return Command('function $pack:$path');

final argString = switch (arguments) {
Map _ => ' ${gson.encode(arguments)}',
Entity e => ' with entity $e',
Block b => ' with block $b',
Storage(name: final name, key: final String key) =>
' with storage ${DataStorage(name).toString(context)} $key',
_ => ''
};

return Command('function $pack:$path$argString');
}

@override
Expand Down
47 changes: 24 additions & 23 deletions lib/src/basic/score.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class Score extends RestActionAble {
);
}

String _getESStr({Entity? entity, String? score}) {
@override
String toString({Entity? entity, String? score}) {
entity ??= this.entity;
score ??= this.score;
return '$entity $score';
Expand Down Expand Up @@ -245,7 +246,7 @@ class Score extends RestActionAble {
Score set(int val) {
return addCommandRet(
Command(
'scoreboard players set ${_getESStr()} $val',
'scoreboard players set ${toString()} $val',
),
);
}
Expand All @@ -254,7 +255,7 @@ class Score extends RestActionAble {
Score reset() {
return addCommandRet(
Command(
'scoreboard players reset ${_getESStr()}',
'scoreboard players reset ${toString()}',
),
);
}
Expand All @@ -263,7 +264,7 @@ class Score extends RestActionAble {
Score add([int val = 1]) {
return addCommandRet(
Command(
'scoreboard players add ${_getESStr()} $val',
'scoreboard players add ${toString()} $val',
),
);
}
Expand All @@ -272,7 +273,7 @@ class Score extends RestActionAble {
Score subtract([int val = 1]) {
return addCommandRet(
Command(
'scoreboard players remove ${_getESStr()} $val',
'scoreboard players remove ${toString()} $val',
),
);
}
Expand All @@ -281,7 +282,7 @@ class Score extends RestActionAble {
Score get() {
return addCommandRet(
Command(
'scoreboard players get ${_getESStr()}',
'scoreboard players get ${toString()}',
),
);
}
Expand All @@ -300,7 +301,7 @@ class Score extends RestActionAble {
Score swapWith(Score score) {
return addCommandRet(
Command(
'scoreboard players operation ${_getESStr()} >< ${_getESStr(entity: score.entity, score: score.score)}',
'scoreboard players operation ${toString()} >< ${toString(entity: score.entity, score: score.score)}',
),
);
}
Expand All @@ -327,7 +328,7 @@ class Score extends RestActionAble {
Score addScore(Score score) {
return addCommandRet(
Command(
'scoreboard players operation ${_getESStr()} += ${_getESStr(entity: score.entity, score: score.score)}',
'scoreboard players operation ${toString()} += ${toString(entity: score.entity, score: score.score)}',
),
);
}
Expand All @@ -336,7 +337,7 @@ class Score extends RestActionAble {
Score subtractScore(Score score) {
return addCommandRet(
Command(
'scoreboard players operation ${_getESStr()} -= ${_getESStr(entity: score.entity, score: score.score)}',
'scoreboard players operation ${toString()} -= ${toString(entity: score.entity, score: score.score)}',
),
);
}
Expand All @@ -345,7 +346,7 @@ class Score extends RestActionAble {
Score multiplyByScore(Score score) {
return addCommandRet(
Command(
'scoreboard players operation ${_getESStr()} *= ${_getESStr(entity: score.entity, score: score.score)}',
'scoreboard players operation ${toString()} *= ${toString(entity: score.entity, score: score.score)}',
),
);
}
Expand All @@ -354,7 +355,7 @@ class Score extends RestActionAble {
Score divideByScore(Score score) {
return addCommandRet(
Command(
'scoreboard players operation ${_getESStr()} /= ${_getESStr(entity: score.entity, score: score.score)}',
'scoreboard players operation ${toString()} /= ${toString(entity: score.entity, score: score.score)}',
),
);
}
Expand All @@ -363,7 +364,7 @@ class Score extends RestActionAble {
Score modulo(Score score) {
return addCommandRet(
Command(
'scoreboard players operation ${_getESStr()} %= ${_getESStr(entity: score.entity, score: score.score)}',
'scoreboard players operation ${toString()} %= ${toString(entity: score.entity, score: score.score)}',
),
);
}
Expand All @@ -376,7 +377,7 @@ class Score extends RestActionAble {
return addCommandRet(
Builder(
(c) => Command(
'execute store result score ${_getESStr()} run data get ${data.getTarget(c)} ${data.path} ${data.scale ?? 1}',
'execute store result score ${toString()} run data get ${data.getTarget(c)} ${data.path} ${data.scale ?? 1}',
),
),
);
Expand All @@ -389,7 +390,7 @@ class Score extends RestActionAble {
Score setToResult(Command commmand, {bool useSuccess = false}) {
return addCommandRet(
Command(
'execute store ${useSuccess ? 'success' : 'result'} score ${_getESStr()} run $commmand',
'execute store ${useSuccess ? 'success' : 'result'} score ${toString()} run $commmand',
),
);
}
Expand All @@ -399,7 +400,7 @@ class Score extends RestActionAble {
Group setToWidget(Widget widget, {bool useSuccess = false}) {
return Group(
prefix:
'execute store ${useSuccess ? 'success' : 'result'} score ${_getESStr()} run',
'execute store ${useSuccess ? 'success' : 'result'} score ${toString()} run',
children: [widget],
);
}
Expand All @@ -408,7 +409,7 @@ class Score extends RestActionAble {
Score setToCondition(Condition cond, {bool useSuccess = false}) {
return addCommandRet(
Command(
'execute store ${useSuccess ? 'success' : 'result'} score ${_getESStr()} ${Condition.getPrefixes(cond.getList())[0]}',
'execute store ${useSuccess ? 'success' : 'result'} score ${toString()} ${Condition.getPrefixes(cond.getList())[0]}',
),
);
}
Expand Down Expand Up @@ -453,45 +454,45 @@ class Score extends RestActionAble {

Score isEqual(Score score) {
return Score.str(
'${_getESStr()} = ${_getESStr(entity: score.entity, score: score.score)}',
'${toString()} = ${toString(entity: score.entity, score: score.score)}',
);
}

Score isSmaller(Score score) {
return Score.str(
'${_getESStr()} < ${_getESStr(entity: score.entity, score: score.score)}',
'${toString()} < ${toString(entity: score.entity, score: score.score)}',
);
}

Score isSmallerOrEqual(Score score) {
return Score.str(
'${_getESStr()} <= ${_getESStr(entity: score.entity, score: score.score)}',
'${toString()} <= ${toString(entity: score.entity, score: score.score)}',
);
}

Score isBiggerOrEqual(Score score) {
return Score.str(
'${_getESStr()} >= ${_getESStr(entity: score.entity, score: score.score)}',
'${toString()} >= ${toString(entity: score.entity, score: score.score)}',
);
}

Score isBigger(Score score) {
return Score.str(
'${_getESStr()} > ${_getESStr(entity: score.entity, score: score.score)}',
'${toString()} > ${toString(entity: score.entity, score: score.score)}',
);
}

String _match = '0';
String getMatch() => _match;
Score matches(int value) {
_match = value.toString();
return Score.str('${_getESStr()} matches $_match',
return Score.str('${toString()} matches $_match',
score: score, match: _match);
}

Score matchesRange(Range range) {
_match = range.toString();
return Score.str('${_getESStr()} matches $_match',
return Score.str('${toString()} matches $_match',
score: score, match: _match);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/basic/types/biomes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Biomes {
import cog
import requests

version = '1.20/releases-candidate/1.20.1-rc1'
version = '1.20/snapshots/23w51b'

res = requests.get(f'https://raw.githubusercontent.com/PixiGeko/Minecraft-generated-data/master/{version}/custom-generated/lists/worldgen/biome.txt')
blocks = []
Expand Down
Loading