Skip to content

Commit

Permalink
0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevertus committed Jul 19, 2019
1 parent 963ac71 commit 1f0e985
Show file tree
Hide file tree
Showing 84 changed files with 449 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .packages
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by pub on 2019-07-03 15:14:24.508408.
# Generated by pub on 2019-07-19 22:50:25.153527.
async:file:///C:/Users/Marten/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/async-2.0.8/lib/
collection:file:///C:/Users/Marten/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/collection-1.14.11/lib/
colorize:file:///C:/Users/Marten/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/colorize-2.0.0/lib/
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 0.2.4
* added ClickEvent Module
* added copyWith on Entities
* added setValues on Entity to change selections afterwards
* added Location.clone
* added desc to Log
* changed Color to const to allow defaults
* changed Particle to use a double type for speed and no requirement for a location
* fixed Particle.item to use ItemType instead of Item
* fixed CommandList Type Error
* fixed Raycast Error when not using stop in the ray property
* fixed missing Invisible Nbt on ArmorStand
## 0.2.3
* added new Module type to allow registering tick functions and files with a convenient api
* added modules property to Pack to inject new modules
Expand Down
64 changes: 62 additions & 2 deletions Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Open the pubspec.yaml file and add
```yaml
name: [unique_namespace]
dependencies:
objd: ^0.2.3
objd: ^0.2.4
```
Also remember to replace the `[unique_namespace]` with your own project name.
And run
Expand Down Expand Up @@ -533,6 +533,25 @@ Say(Entity().not(tags:["mytag"],nbt:{"istrue":1}))
⇒ say @e[tag=!mytag,nbt=!{"istrue":1}]
```

### Entity.copyWith
Creates a new Entity based on the existing one and applies new arguments. (same as constructors)

**Example:**
```dart
Entity ent1 = Entity(type:EntityType.sheep)
Entity ent2 = ent1.copyWith(distance:Range(to:1))
```

### Entity.setValues
Modifies the properties of the existing Entity and applies new arguments(same as constructors)

**Example:**
```dart
Entity ent1 = Entity(type:EntityType.sheep)
ent1.setValues(distance:Range(to:1))
⇒ @e[type=sheep,distance=..1]
```

[//]: # (basics/tag)
## Tag
A tag saves a boolean value with an entity inside the game.
Expand Down Expand Up @@ -813,6 +832,17 @@ Location.local(x: 0,y: 1,z: 2.5)
⇒ ^ ^1 ^2.5
```

To clone a Location use Location.clone:

|Location.clone| |
|--|--|
|Location|the source location|

```dart
Location.clone(Location.rel(y:2))
⇒ ~ ~2 ~
```

There is also a method for a location:

|methods| |
Expand Down Expand Up @@ -1762,6 +1792,8 @@ This works the same with ReplaceItem.block:
|slot|a Slot Object with the slot set(required)|

[//]: # (wrappers/particle)
video
q8cI-Irpv9Q
## Particle
The particle command spawns particles in the world to enhance certain graphics.

Expand Down Expand Up @@ -1795,7 +1827,7 @@ For the Block and Item particle(shows item or block break) there is a named cons

|Particle.block or Particle.item| |
|--|--|
|Item or Block| the block or item you want to show |
|ItemType or Block| the block or item you want to show |
| ... | same as Particle

**Example:**
Expand Down Expand Up @@ -2185,6 +2217,7 @@ The log widgets displays a console logging in the players chat. That way you can
|--|--|
|String, Number, Boolean, Score or Entity| message to display |
|to|which player you want to send the log(default = `Entity.All()`) |
|desc| a message that is inserted before the value |
|color|the color of the console indicator(default = Color.DarkAqua)|

**Example:**
Expand Down Expand Up @@ -2481,6 +2514,31 @@ ScoreTimerModule(
)
```

[//]: # (modules/click_event)
## ClickEvent
The ClickEvent Module uses the trigger of a carrot on a stick to register right clicks with a scoreboard and execute a [onClick] Widget.

This module has to be executed every tick to work!

| constructor | |
|--|--|
|name|used to identify different click Events|
|onClick| Widget that is executed if the COAS is clicked |
|selectedItem| just triggers the click if this Item is selected(optional) |
|path| path to create the click handler function(default = `events/`) |

**Example:**

```dart
ClickEvent(
onClick: Log("Clicked"),
name: "firstClick",
selectedItem: Item(ItemType.carrot_on_a_stick),
path: "events/"
)
```


[//]: # (utils/main)
# Utils
Util Widgets provide a complete solution that Minecraft does not support that easily out of the box and make your workflow easier and faster.
Expand Down Expand Up @@ -2580,6 +2638,8 @@ execute if score repeat1 objd_repeat matches ..10 run schedule function mypack:t
This function is executed until the score becomes 11.

[//]: # (utils/armorstand)
video
dQvZRGUH4F8
## ArmorStand
An armorstand can be created with the Summon Widget, but there is also a specific Widget with special properties for an ArmorStand.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Open the pubspec.yaml file and add
```yaml
name: [unique_namespace]
dependencies:
objd: ^0.2.2
objd: ^0.2.4
```
Also remember to replace the `[unique_namespace]` with your own project name.
And run
Expand Down
1 change: 1 addition & 0 deletions example/files/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class MainFile extends Widget {
Widget generate(Context context) {
return For.of([
// put your tick widgets here
Raycast(Entity.Selected(),onhit: [Say("Hi")],step: 0.25,ray: (stop,hit){return For.of([Say("Hi")]);})
]);
}
}
1 change: 0 additions & 1 deletion example/packs/examplePack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ExamplePack extends Widget {
return Pack(
name: "mypack", // name of the subpack
modules: [

],
main: File( // definining a file that runs every tick
'main',
Expand Down
1 change: 1 addition & 0 deletions folder name/data/mypack/functions/main.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
execute anchored eyes positioned ^ ^ ^ anchored feet run function mypack:objd/ray1
6 changes: 6 additions & 0 deletions folder name/data/mypack/functions/objd/ray1.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated ray1 Group Widget from main
say Hi
execute unless block ~ ~ ~ minecraft:air run tag @s add objd_ray_hit
execute unless entity @s[tag=objd_ray_hit] positioned ^ ^ ^0.25 run function mypack:objd/ray1
execute if entity @s[tag=objd_ray_hit] run function mypack:objd/rayhit1
execute if entity @s[tag=objd_ray_hit] run tag @s remove objd_ray_hit
2 changes: 2 additions & 0 deletions folder name/data/mypack/functions/objd/rayhit1.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is the raycast result from your raycast widget in main
say Hi
2 changes: 1 addition & 1 deletion folder name/objd.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"folder name","path":"./","packs":[{"name":"mypack","files":{"main":[],"load":[]},"main":"main","load":"load"}],"description":"This is a datapack generated with objd by Stevertus"}
{"name":"folder name","path":"./","packs":[{"name":"mypack","files":{"main":["execute anchored eyes positioned ^ ^ ^ anchored feet run function mypack:objd/ray1"],"load":[],"objd/ray1":["# Generated ray1 Group Widget from main","say Hi","execute unless block ~ ~ ~ minecraft:air run tag @s add objd_ray_hit","execute unless entity @s[tag=objd_ray_hit] positioned ^ ^ ^0.25 run function mypack:objd/ray1","execute if entity @s[tag=objd_ray_hit] run function mypack:objd/rayhit1","execute if entity @s[tag=objd_ray_hit] run tag @s remove objd_ray_hit"],"objd/rayhit1":["# This is the raycast result from your raycast widget in main","say Hi"]},"main":"main","load":"load"}],"description":"This is a datapack generated with objd by Stevertus"}
12 changes: 6 additions & 6 deletions lib/basic/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:objd/build/build.dart';
import './text.dart';
import './for_list.dart';

class CommandList extends Widget {
class CommandList<T> extends Widget {
List _commands;
/// There is a more efficient way to list raw Minecraft commands.
///
Expand All @@ -17,11 +17,11 @@ class CommandList extends Widget {
/// Command('say 3')
/// ]),
/// ```
CommandList(List commands) {
if (commands[0] is String)
_commands = commands.map((x) => Command(x)).toList();
else if (commands[0] is Command)
_commands = commands;
CommandList(List<T> commands) {
if (T.toString() == "String")
_commands = commands.map((x) => Command(x.toString())).toList();
else if (T.toString() == "Command")
_commands = (commands as List<Command>);
else
throw ('Please insert a string or a list into CommandList');
}
Expand Down
1 change: 1 addition & 0 deletions lib/basic/condition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Condition {
}

_setCond(dynamic cond, {bool invert = false, Block block, Location target}) {
if(cond == null) return;
switch (_getType(cond)) {
case "Condition":
_children.add(cond);
Expand Down
44 changes: 44 additions & 0 deletions lib/basic/entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ class Entity implements EntityClass{

_setArguments(limit,tags,team,scores,nbt,strNbt,type,area,distance,level,gamemode,name,isRotated,horizontalRotation,verticalRotation,false);
}

/// Modifies the properties of the existing Entity and applies new arguments(same as constructors)
setValues({int limit,
List<dynamic> tags,
Team team,
List<Score> scores,
Map<String,dynamic> nbt,
String strNbt,
EntityType type,
Area area,
Range distance,
Range level,
Gamemode gamemode,
String name,
Rotation isRotated,
Range horizontalRotation,
Range verticalRotation,}){
_setArguments(limit,tags,team,scores,nbt,strNbt,type,area,distance,level,gamemode,name,isRotated,horizontalRotation,verticalRotation,false);
}
_setArguments(
int limit,
List<dynamic> tags,
Expand Down Expand Up @@ -170,6 +189,31 @@ class Entity implements EntityClass{
],
);
}
/// Creates a new Entity based on the existing one and applies new arguments. (same as constructors)
///
/// **Example:**
/// ```dart
/// Entity ent1 = Entity(type:EntityType.sheep)
/// Entity ent2 = ent1.copyWith(distance:Range(to:1))
/// ```
Entity copyWith({
int limit,
List<dynamic> tags,
Team team,
List<Score> scores,
Map<String,dynamic> nbt,
String strNbt,
EntityType type,
Area area,
Range distance,
Range level,
Gamemode gamemode,
String name,
Rotation isRotated,
Range horizontalRotation,
Range verticalRotation,}){
return Entity.clone(this)._setArguments(limit, tags, team, scores, nbt, strNbt, type, area, distance, level, gamemode, name, isRotated, horizontalRotation, verticalRotation, false);
}

Tag addTag(String tag){
return Tag(tag,entity: this,value: true);
Expand Down
9 changes: 8 additions & 1 deletion lib/basic/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class Location {
_location = "~ ~ ~";
x = y = z = 0;
}
/// Clones a Location:
Location.clone(Location loc){
x = loc.x;
y = loc.y;
z = loc.z;
_location = loc.toString();
}

/// This stores a result or success of a [command] in the nbt [path] of a location.
/// **Example:**
Expand All @@ -61,6 +68,6 @@ class Location {

@override
String toString() {
return _location.replaceAll('.0', '');
return _location.replaceAll('.0 ', ' ');
}
}
34 changes: 17 additions & 17 deletions lib/basic/text_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,24 +230,24 @@ class TextHoverEvent {
/// See all available colors: https://minecraft.gamepedia.com/Formatting_codes#Color_codes
class Color {
final String _color;
Color(this._color);
const Color(this._color);

static Color White = Color('white');
static Color Black = Color('black');
static Color DarkBlue = Color('dark_blue');
static Color DarkGreen = Color('dark_green');
static Color DarkAqua = Color('dark_aqua');
static Color DarkRed = Color('dark_red');
static Color DarkPurple = Color('dark_purple');
static Color Gold = Color('gold');
static Color Gray = Color('gray');
static Color DarkGray = Color('dark_gray');
static Color Blue = Color('blue');
static Color Green = Color('green');
static Color Aqua = Color('aqua');
static Color Red = Color('red');
static Color LightPurple = Color('light_purple');
static Color Yellow = Color('yellow');
static const Color White = Color('white');
static const Color Black = Color('black');
static const Color DarkBlue = Color('dark_blue');
static const Color DarkGreen = Color('dark_green');
static const Color DarkAqua = Color('dark_aqua');
static const Color DarkRed = Color('dark_red');
static const Color DarkPurple = Color('dark_purple');
static const Color Gold = Color('gold');
static const Color Gray = Color('gray');
static const Color DarkGray = Color('dark_gray');
static const Color Blue = Color('blue');
static const Color Green = Color('green');
static const Color Aqua = Color('aqua');
static const Color Red = Color('red');
static const Color LightPurple = Color('light_purple');
static const Color Yellow = Color('yellow');

@override
String toString() {
Expand Down
55 changes: 55 additions & 0 deletions lib/modules/click_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:objd/core.dart';

/// The ClickEvent Module uses the trigger of a carrot on a stick to register right clicks with a scoreboard and execute a [onClick] Widget.
class ClickEvent extends Module {
String path;
String name;
Widget onClick;
Item selectedItem;
Score _score = Score.fromSelected("objd_click");
/// The ClickEvent Module uses the trigger of a carrot on a stick to register right clicks with a scoreboard and execute a [onClick] Widget.
///
/// This module has to be executed every tick to work!
///
/// | constructor | |
/// |--|--|
/// |name|used to identify different click Events|
/// |onClick| Widget that is executed if the COAS is clicked |
/// |selectedItem| just triggers the click if this Item is selected(optional) |
/// |path| path to create the click handler function(default = `events/`) |
ClickEvent(
{this.name = "objd_click",
this.onClick,
this.selectedItem,
this.path = "events/"});

@override
generate(Context context) {
return For.of([
Scoreboard("objd_click",
type: "minecraft.used:minecraft.carrot_on_a_stick"),
Execute.asat(
Entity.All(
scores: [
_score.matchesRange(
Range(from: 1),
),
],
nbt: selectedItem != null
? {"SelectedItem": selectedItem.getMap()}
: null),
children: [File.execute(path + name, create: false)]),
]);
}

List<File> registerFiles() => <File>[
File(
path + name,
child: For.of([
onClick,
_score.reset(),
]),
),
];
}
Loading

0 comments on commit 1f0e985

Please sign in to comment.