Skip to content
Open
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
2 changes: 1 addition & 1 deletion Writerside/topics/How-to-migrate-to-VS-2.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ final class MyAttachment {

### Migrate from constraints to joints

> Try to avoid using `apigame` - we don't make any [backwards compatibility](Compatibility.md#backwards-compatibility)
> Try to avoid using `apigame` - we don't make any [backwards compatibility](todo/Compatibility.md#backwards-compatibility)
> guarantees for it.
>
{style="warning"}
Expand Down
4 changes: 2 additions & 2 deletions Writerside/topics/Section-Starting-Page.topic
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

<!-- Add up to 2 topics that you want to promote. Use the "type" attribute to select an icon. -->
<spotlight>
<a href="" type="academy" summary="This overrides the card summary of the topic">Custom card title</a>
<a href="" type="search" summary="This overrides the card summary of the topic">Another custom title</a>
<a href="" type="start" summary="How to get started on making your very own Valkyrien Skies addon!">Getting started</a>
<a href="How-to-migrate-to-VS-2.5.md" type="tools" summary="Information on how to migrate your addon to the VS2 2.5 API">Migrating to VS 2.5</a>
</spotlight>

<!-- Add several topics that are most important for this section. -->
Expand Down
51 changes: 0 additions & 51 deletions Writerside/topics/The-Attachment-System-Explained.md

This file was deleted.

File renamed without changes.
56 changes: 56 additions & 0 deletions Writerside/topics/concepts/Ship-Chunk-Claims.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Ship Chunk Claims
Every ship has a chunk claim.
This chunk claim specifies what section of the shipyard the ship "owns".
Currently, chunk claims are hardcoded to 256 by 256 chunks, so ships can't be bigger than that.

## `chunkClaim` field in `Ship`
The function
```kotlin
fun getTotalVoxelRegion(yRange: LevelYRange, destination: AABBi = AABBi()): AABBi
```
in `ChunkClaim` can be used to get the AABB of the chunk claim (= Shipyard area)
It takes an argument of the type `LevelYRange` which can be easily created from a level:

<tabs group="ktj">
<tab title="Java" group-key="java">

```java
new LevelYRange(level.getMinBuildHeight(), level.getMaxBuildHeight());
```

</tab>
<tab title="Kotlin" group-key="kotlin">

```kotlin
LevelYRange(level.minBuildHeight, level.maxBuildHeight)
```

</tab>
</tabs>

This creates a Y-Range using the build height of the level given.

## `chunkClaimDimension` field in `Ship`

<tabs group="ktj">
<tab title="Java" group-key="java">

```java
String dim = ship.getChunkClaimDimension();
```

</tab>
<tab title="Kotlin" group-key="kotlin">

```kotlin
var dim = ship.chunkClaimDimension
```

</tab>
</tabs>

The dimension ID of the chunk claim.

The ship always has to be in the same dimension as the chunk claim, so this is also the dimension ID of the ship.

You can find more information about dimension IDs [here](Dimension-Ids.md)
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,8 @@ from existing performance mods like Lithium and Sodium.

## Chunk claims

In the shipyard, each ship is assigned a **chunk claim** inside the shipyard. In VS2, each chunk claim is 256x256
chunks. The chunks in the chunk claim are then "projected" into the world using the corresponding ship's transform.
In the shipyard, each ship is assigned a **chunk claim**.
The chunks in the chunk claim are then "projected" into the world using the ship's transform.
> See [Ship Chunk Claims](Ship-Chunk-Claims.md) for more info on how chunk claims are used
>
{style="note"}
58 changes: 58 additions & 0 deletions Writerside/topics/docs/Dimension-Ids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Dimension IDs
Dimension IDs are slightly different in VS2, so you need to keep that in mind when using vanilla dimension ids

VS Dimension IDs are in the format `minecraft:dimension:[mod]:[dimension name]`.
To convert this to a `ResourceKey<Level>` (which is how Minecraft stores level IDs), you can do this:

<tabs group="ktj">
<tab title="Java" group-key="java">

```java
public static ResourceKey<Level> VSToDimensionKey(String vsDimId) {
// Split 'minecraft:dimension:namespace:dimension_name' into
// [minecraft, dimension, namespace, dimension_name]
String split = vsDimId.split(":");
ResourceLocation re = ResourceLocation(split[split.size - 2], split[split.size - 1]);
return ResourceKey.create(Registry.DIMENSION_REGISTRY, rl);
}
```

</tab>
<tab title="Kotlin" group-key="kotlin">

```kotlin
/* DimensionId in VS2 is a type alias for String */
fun DimensionId.toDimensionKey() {
// Split 'minecraft:dimension:namespace:dimension_name' into
// [minecraft, dimension, namespace, dimension_name]
val split = this.split(":")
val rl = ResourceLocation(split[split.size - 2], split[split.size - 1])
return ResourceKey.create(Registry.DIMENSION_REGISTRY, rl)
}
```

</tab>
</tabs>

This can now be used to, for example, get the `ServerLevel` of a ship when given a `MinecraftServer` object. Something like:

<tabs group="ktj">
<tab title="Java" group-key="java">

```java
public static ServerLevel fromLevelRL(ResourceKey<Level> rl) {
return server.getLevel(rl);
}
```

</tab>
<tab title="Kotlin" group-key="kotlin">

```kotlin
fun fromLevelRL(rl: ResourceKey<Level?>?): ServerLevel {
return server.getLevel(rl)
}
```

</tab>
</tabs>
77 changes: 77 additions & 0 deletions Writerside/topics/docs/Events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

# Events
VS2 provides some useful events in `VSEvents` and `VSGameEvents`

## All events

`org.valkyrienskies.core.impl.hooks.VSEvents`:

| Name | Description | Arguments |
|-----------------------|--------------------------------------------------------------|--------------------------------|
| `shipLoadEvent` | Will be called once a ship gets (chunk) loaded on the server | `ship: ShipObjectServer` |
| `shipLoadEventClient` | Will be called once a ship gets (chunk) loaded on the client | `ship: ShipObjectClient` |
| `tickEndEvent` | Will be called at the end of the server ticking a world | `world: ShipObjectServerWorld` |


`org.valkyrienskies.mod.common.hooks.VSGameEvents`:

| Name | Description | Arguments |
|-----------------------|------------------------------------------------------------------------|--------------------------------------------|
| `registriesCompleted` | Will be called once the mass & similar registries are filled with data | |
| `tagsAreLoaded` | Will be called after Minecraft tags are loaded | |
| `renderShip` | Will be called before a ship is rendered | `event: VSGameEvents.ShipRenderEvent` |
| `postRenderShip` | Will be called after a ship is rendered | `event: VSGameEvents.ShipRenderEvent` |
| `shipsStartRendering` | Will be called before all ships are rendered | `event: VSGameEvents.ShipStartRenderEvent` |

## How to listen to events
There is a `on` method in all of those events. Register event listeners to the event through this method.
Its recommended to do this in your mods on-load (init) method. Use it like so:

<tabs group="ktj">
<tab title="Java" group-key="java">

```java
[DesiredEvent].Companion.on((event) -> {
// ...
});
```

</tab>
<tab title="Kotlin" group-key="kotlin">

```kotlin
[DesiredEvent].on {(event) -> {
// ...
}}
```

</tab>
</tabs>

## Example
Print the slug (name) of every ship in a world every tick:

<tabs group="ktj">
<tab title="Java" group-key="java">

```java
VSEvents.TickEndEvent.Companion.on((e) -> {
e.getWorld().getAllShips().forEach((ship) -> {
System.out.println(ship.getSlug());
});
});
```

</tab>
<tab title="Kotlin" group-key="kotlin">

```kotlin
VSEvents.tickEndEvent.on { e ->
e.world.allShips.forEach { ship ->
println(ship.slug)
}
}
```

</tab>
</tabs>
Loading