Skip to content

Commit

Permalink
Merge pull request #32 from CCpcalvin/bugfix
Browse files Browse the repository at this point in the history
Use deepcopy instead of shallowcopy in `Entity.Clone`
  • Loading branch information
Stevertus authored Nov 27, 2023
2 parents 771067d + 43a5b85 commit 4cc0e5f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/src/basic/types/area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Area {
dz = (loc2.z - loc1.z).abs();
}

Map getRanges() {
Map<String, double> getRanges() {
var ret = <String, double>{};
ret['x'] = loc1.x;
ret['y'] = loc1.y;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/basic/types/entity.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: non_constant_identifier_names

import 'package:objd/core.dart';
import 'package:deep_collection/deep_collection.dart';
export 'entities.dart';

abstract class EntityClass {
Expand Down Expand Up @@ -287,7 +288,7 @@ class Entity extends GsonValue implements EntityClass {
Entity.clone(Entity ent)
: selector = ent.selector,
playerName = ent.playerName,
arguments = Map.from(ent.arguments);
arguments = ent.arguments.deepCopy();

/// Entity is an util class to convert an argument list into the Minecraft Entity format(@p...)
Entity({
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ environment:
dependencies:
ansicolor: ^2.0.1
archive: ^3.3.7
deep_collection: ^1.0.2
gson: ^0.1.6-dev
dev_dependencies:
lints: ^3.0.0
Expand Down
22 changes: 22 additions & 0 deletions test/entity_clone_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:objd/core.dart';
import 'package:test/test.dart';

import 'test_widget.dart';

void main() {
group('Entity Clone', () {
Entity newEntity = Entity(tags: ['test']);
Entity clonedEntity = newEntity.copyWith(tags: ['testCloned']);

command(
'Original Entity',
Execute.as(newEntity, children: [Say("hi")]),
'execute as @e[tag=test] run say hi',
);
command(
'Cloned Entity',
Execute.as(clonedEntity, children: [Say("hi")]),
'execute as @e[tag=test,tag=testCloned] run say hi',
);
});
}

0 comments on commit 4cc0e5f

Please sign in to comment.