From 4a9aa26601c26f715ca101075b8a16b3f5790749 Mon Sep 17 00:00:00 2001 From: Matthias <56599453+12rcu@users.noreply.github.com> Date: Sat, 29 Jun 2024 19:23:49 +0200 Subject: [PATCH] Chore/update doc 0.4.3 (#99) * Update addon config doc Signed-off-by: Matthias <56599453+12rcu@users.noreply.github.com> * added projectile/item/attachable doc * spelling * added rideable doc --------- Signed-off-by: Matthias <56599453+12rcu@users.noreply.github.com> --- README.md | 2 +- docs/pages/Addon.md | 41 ++--- docs/pages/Entities.md | 164 +++++++++++++++++- .../entitiy/components/scraped/Rideable.kt | 7 + .../monstera/addon/entitiy/BasicEntityTest.kt | 10 ++ 5 files changed, 194 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 0afe451..cda8658 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ repositories { } dependencies { - implementation("com.lotsofpixelsstudios:monstera:0.3.2") + implementation("com.lotsofpixelsstudios:monstera:0.4.3") } ```` diff --git a/docs/pages/Addon.md b/docs/pages/Addon.md index e0380df..01ae0db 100644 --- a/docs/pages/Addon.md +++ b/docs/pages/Addon.md @@ -4,30 +4,22 @@ Within the `Main.kt` is already an addon structure given and hints on what is possible. +### Addon Config + +To create an addon, Monstera needs some basic information in the form of a config, if no config exists as in the +template, one will be created for you when you run the program once. In the console or std in/out Monstera will ask for +the project name and short, other information can be edited directly in the config. + ````kotlin -addon(config(projectName = "Template") { - //config - "npm.cmd run build".runCommand(File(System.getProperty("user.dir"), "scripting")) - projectShort = "te" - description = "sample description" - packIcon = getResource("general/pack.png") - world = getResource("world/template-world") - version = arrayListOf(0, 1, 0) - targetMcVersion = arrayListOf(1, 20, 0) - scriptEntryFile = File("scripting", "dist", "src", "index.js") - scriptingVersion = "1.6.0-beta" +val conf = addon(loadConfig().getOrElse { + it.printStackTrace() + return //something went wrong loading the config, for example an I/O error }) { //addon body } ```` -Within the header of the addon function we can define some basics of the addon we want to have. The projectShort is -thereby also used as the namespace of entities etc. - -Within the Body or the Addon Context we can define entities, items, etc. that will automatically be associated with the -addon. - -## :fa-solid fa-screwdriver-wrench: Modifications +### :fa-solid fa-screwdriver-wrench: Modifications of the Config This section may be interesting for publishing the addon, as for example overwriting the end users version may be a bit different as on the machine of the developer: @@ -46,14 +38,8 @@ Note: You may not use components of a newer Version then. ### My mc folder can't be found -This can happen if minecraft wasn't installed with the default parameters, change the direcotry like: - -```kotlin -addon(/*...*/) { - properties.comMojangPath = - System.getenv("LOCALAPPDATA") + "\\Packages\\Microsoft.MinecraftUWP_8wekyb3d8bbwe\\LocalState\\games\\com.mojang" -} -``` +If an error like this happens, have a look at the monstera-local.json, there is the minecraft path that Monstera +assumed, you can change this path so that it points to the correct directory. ## :fa-solid fa-hammer: Build the addon @@ -94,4 +80,5 @@ To correctly package the addon, see the Package page. ## :fa-solid fa-flask: Experimental Features -Currently, the JSON UI is experimental and may be discontinued as it will be deprecated in future mc versions. \ No newline at end of file +The JSON UI is not currently in the latest builds and is not currently being worked on, if you are interested open a +discussion. \ No newline at end of file diff --git a/docs/pages/Entities.md b/docs/pages/Entities.md index db89580..e4f8232 100644 --- a/docs/pages/Entities.md +++ b/docs/pages/Entities.md @@ -197,7 +197,9 @@ components { ## :fa-solid fa-horse: Resource -### Blockbench Files +### Blockbench Files (Experimental) + +Note: some complex stuff with UV scaling/mirroring is not supported! Monstera has also the option to load blockbench files, note: this is a std lib feature: @@ -430,4 +432,162 @@ craftingRecipe { context() } } -``` \ No newline at end of file +``` + +## Examples + +### Projectile Entity + +Projectiles require only a few basic components + +````kotlin +behaviour { + components { + projectile { + power = 4 + gravity = 0.1f + anchor = 1 + shouldBounce = true + offset(0f, -0.1f, 0f) + + onHit { + impactDamage { + damage(4, 6) + knockback = true + destroyOnHit = false + semiRandomDiffDamage = false + } + stickInGround { + shakeTime = 0 + } + } + } + collisionBox { + width = 0.25 + height = 0.35 + } + physics { } + pushable { + isPushable = false + } + balloonable { + mass = 0.1f + } + conditionalBandwidthOptimization { + defaultValues { + maxOptimizedDistance = 80 + maxDroppedTicks = 7 + useMotionPredictionHints = true + } + } + } +} +```` + +It may be beneficial to add a runtime identifier, otherwise the projectile may look strange. + +````kotlin +behaviour { + runtimeIdentifier = RuntimeIdentifier.SNOWBLL +} +```` + +### Throw the projectile with a custom item + +When you create an item, you have the option to add a component so that you can throw or shoot your custom projectile. + +````kotlin +val spear = entity("spear") { + behaviour { + components { + projectile { + //... + } + } + } +} + +item("fishing_spear", "Fishing Spear") { + texture(getResource("spear/spear_ico.png")) + components { + maxStackSize(1) + throwable { + scalePowerByDrawDuration = true + maxDrawDuration = 1 + minDrawDuration = 0.2 + launchPowerScale = 1.2 + maxLaunchPower = 2 + } + projectile { + projectileEntity = spear.getIdentifier() + } + } +} +```` + +Instead of the throwable component, consider using the shooter component + +````kotlin +components { + shooter { } +} +```` + +### Adding an attachable for your item + +To add an attachable you need a geo with texture and at least 2 animations, one for the first person and one for the +third person. For custom armor you can omit the first person or set the scale to 0. + +````kotlin +item("fishing_spear", "Fishing Spear") { + texture(getResource("spear/spear_ico.png")) + components { + //... + } + attachable { + material("parrot", "parrot") + geometry(getResource("spear/spear.geo.json")) + texture(getResource("spear/spear/spear.png")) + + //contains the "hold_first_person" and "hold_third_person" anim + animation(getResource("spear/spear.animation.json")) + renderController("controller.render.item_default") + scripts { + animate("hold_first_person", Query("context.is_first_person == 1.0")) + animate("hold_third_person", Query("context.is_first_person == 0.0")) + } + } +} +```` + + +### Rideable Entities + +You can add the Rideable component to an entity to allow players or mobs to ride on the entity. The player will need a +form of input if they want to be able to move with the entity. + +````kotlin +rideable { + pullInEntities = true //pulls in the parrots like the player does for parrots + familyTypes("parrot") + seat { + position(0.2, 1.8, 0) + } + seatCountFromSeats() +} +```` + +For the player you can use: + +````kotlin +rideable { + familyTypes("player") + seat { + position(0, 0, 2) + } + seatCountFromSeats() +} +inputGroundControlled { } +//or +itemControllable { } +```` \ No newline at end of file diff --git a/src/main/kotlin/com/lop/devtools/monstera/files/beh/entitiy/components/scraped/Rideable.kt b/src/main/kotlin/com/lop/devtools/monstera/files/beh/entitiy/components/scraped/Rideable.kt index f6a5f58..ccc74d9 100644 --- a/src/main/kotlin/com/lop/devtools/monstera/files/beh/entitiy/components/scraped/Rideable.kt +++ b/src/main/kotlin/com/lop/devtools/monstera/files/beh/entitiy/components/scraped/Rideable.kt @@ -13,6 +13,13 @@ class Rideable : MonsteraRawFile() { @SerializedName("seat_count") @Expose var seatCount: Number? = null + + /** + * needs to be called after the seats where created + */ + fun seatCountFromSeats() { + seatCount = seatsData?.size + } @SerializedName("passenger_max_width") @Expose diff --git a/src/test/kotlin/com/lop/devtools/monstera/addon/entitiy/BasicEntityTest.kt b/src/test/kotlin/com/lop/devtools/monstera/addon/entitiy/BasicEntityTest.kt index ffd844b..7b92ffb 100644 --- a/src/test/kotlin/com/lop/devtools/monstera/addon/entitiy/BasicEntityTest.kt +++ b/src/test/kotlin/com/lop/devtools/monstera/addon/entitiy/BasicEntityTest.kt @@ -52,6 +52,16 @@ class BasicEntityTest { avoidWater = true } additionalKeys = mapOf("my_component" to "my_value") + + rideable { + familyTypes("player") + seat { + position(0, 0, 2) + } + seatCountFromSeats() + } + inputGroundControlled { } + itemControllable { } } } }