Skip to content

Commit

Permalink
Added missing pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucraft committed Sep 25, 2024
1 parent 92101c1 commit cfa3611
Show file tree
Hide file tree
Showing 15 changed files with 926 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/compatibilities/_category_.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"label": "Mod Compatibilities",
"position": 5
"position": 6
}
3 changes: 3 additions & 0 deletions docs/compatibilities/kubejs/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"label": "KubeJS"
}
44 changes: 44 additions & 0 deletions docs/compatibilities/kubejs/basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Basics

Scripts are not a part of Palladium but rather a part of KubeJS. Palladium adds a lot of compatibility features. KubeJS scripts allow you to use the JavaScript programming language to execute code from events that happen in-game. For example, you can grant players a diamond every time they break a block. It's helpful to know a little Javascript but it is not a requirement. KubeJS has three types of scripts startup, server/world & client.

| Script Types | Reload Method | Content | Folder Structure |
|--------------|---------------------------------------|------------------------------------------------|-------------------------------------|
| Client | Pressing F3+T | Custom animations, custom HUDs | `assets/<namespace>/kubejs_scripts` |
| Server/World | Running `/reload` | e.g. manipulate entities, player/entity events | `data/<namespace>/kubejs_scripts` |
| Startup | None. Loads once when the game starts | Custom abilities, custom conditions | `addon/<namespace>/kubejs_scripts` |

## Example
Here's an example of what you can do with KubeJS scripts. If you would like to learn more, I recommend checking out their [wiki v1](https://mods.latvian.dev/books/kubejs) and [wiki v2](https://kubejs.com/wiki/).
```js
ItemEvents.rightClicked((event) => {

// Show player's SUPERPOWER [when rightclicking bread]
if (event.getItem().getId() === 'minecraft:bread') {
event.player.tell('Current Superpower: ' + event.player.data.powers.getSuperpower());
}

// Show all of player's powers (superpower, suit, etc.) [when rightclicking glow berries]
if (event.getItem().getId() === 'minecraft:glow_berries') {
event.player.tell('Current Powers:');
event.player.data.powers.getPowers().forEach(element => {
event.player.tell(' - ' + element);
});
}

// Show ALL AVAILABLE powers [when rightclicking rabbit stew]
else if (event.getItem().getId() === 'minecraft:rabbit_stew') {
event.player.tell('All Powers:');
event.level.data.powers.getPowers().forEach(element => {
event.player.tell(' - ' + element);
});
}

// Swing arm [when rightclicking bone]
else if (event.getItem().getId() === 'minecraft:bone') {
palladium.swingArm(event.player, event.getHand());
}
});
```
TIP: Comments in Javascript code have a `//` in front of them!
TIP: Since this is a server/world script, it's placed in `data/<namespace>/kubejs_scripts`.
70 changes: 70 additions & 0 deletions docs/compatibilities/kubejs/custom-abilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Custom Abilities

This page of the wiki will show you how to make a custom ability. Custom abilities are made using KubeJS scripts.

1. Make a file in the addon scripts directory.
2. Add the code to register the ability.
```js
StartupEvents.registry('palladium:abilities', (event) => {
// ID of the condition will be: 'kubejs:mycoolpack/mycoolability'
event.create('mycoolpack/mycoolability')
});
```
3. Add a preset icon.
```js
StartupEvents.registry('palladium:abilities', (event) => {
event.create('mycoolpack/mycoolability')
.icon(palladium.createItemIcon('palladium:vibranium_circuit'))
});
```
4. [OPTIONAL] Add the first tick handler. You can dfine the behaviour of what happens during the first tick of the ability being enabled.
```js
StartupEvents.registry('palladium:abilities', (event) => {
event.create('mycoolpack/mycoolability')
.icon(palladium.createItemIcon('palladium:vibranium_circuit'))

.firstTick((entity, entry, holder, enabled) => {
entity.tell('First Tick!');
});
});
```
5. [OPTIONAL] Add the tick handler. You can dfine the behaviour of what happens during every tick of the ability. You should use `enabled` to see if the ability is enabled.
```js
StartupEvents.registry('palladium:abilities', (event) => {
event.create('mycoolpack/mycoolability')
.icon(palladium.createItemIcon('palladium:vibranium_circuit'))

.firstTick((entity, entry, holder, enabled) => {
entity.tell('First Tick!');
})

.tick((entity, entry, holder, enabled) => {
if (enabled) {
entity.tell('Tick!');
}
});
});
```
6. [OPTIONAL] Add the last tick handler. You can dfine the behaviour of what happens during the last tick of the ability being enabled.
```js
StartupEvents.registry('palladium:abilities', (event) => {
event.create('mycoolpack/mycoolability')
.icon(palladium.createItemIcon('palladium:vibranium_circuit'))

.firstTick((entity, entry, holder, enabled) => {
entity.tell('First Tick!');
})

.tick((entity, entry, holder, enabled) => {
if (enabled) {
entity.tell('Tick!');
}
})

.lastTick((entity, entry, holder, enabled) => {
entity.tell('Last Tick!');
});
});
```

That's it! Now you can use your ability in your power json file. You can find the ID in the abilities.html.
73 changes: 73 additions & 0 deletions docs/compatibilities/kubejs/custom-animations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Custom Animations

Using KubeJS you can also animate the player model itself.

To get started you create a client-side script (`assets/<namespace>/kubejs_scripts/<name>.js`) and subscribe to the event for registering animations:

```js
PalladiumEvents.registerAnimations((event) => {
event.register('test/ability_test', 10, (builder) => {
// animation part
});
});
```

In the `register` function you specificy the ID, the priority, and then a function for animating, which just needs a `builder` parameter.



Let's animate the right arm when the player is crouching. **You should wrap every animation in an `if` to make it dependent on something!**
In the animation part (look above) you can write this to get a player part:
```js
if (builder.getPlayer().isCrouching()) {
builder.get('right_arm');
}
```
With this function you get access to the player's arm and can modify it. To rotate it to a certain angle, we can do this:
```js
if (builder.getPlayer().isCrouching()) {
builder.get('right_arm').setXRotDegrees(90);
}
```
This will rotate the right arm by 90 degrees.

This will happen instantly though. If you want to progress this animation over time, we need an animation timer ability. Let's say you have named an animation timer ability 'animation' in a 'test:kubejs_animation' power, your script can now look like this:
```js
const progress = animationUtil.getAnimationTimerAbilityValue(builder.getPlayer(), 'test:kubejs_animation', 'animation', builder.getPartialTicks());
if (progress > 0.0) {
builder.get('right_arm').setXRotDegrees(90).multiplier(progress);
}
```
With this we are also now having the animation depend on that timer, and not on the crouching anymore. The `animationUtil.getAnimationTimerAbilityValue` function gives you a number from 0.0 to 1.0. This is then used in `multiplier` to make the animation happen.

This animation however is pretty linear and unnatural. There are various methods to "ease" this animation out. You can see them all [here](https://easings.net/). Let's say we want to use the "easeInOutCubic" from there in our animation, we remove the "ease" part of that name and use it like this:
```js
const progress = animationUtil.getAnimationTimerAbilityValue(builder.getPlayer(), 'test:kubejs_animation', 'animation', builder.getPartialTicks());
if (progress > 0.0) {
builder.get('right_arm').setXRotDegrees(90).animate('InOutCubic', progress);
}
```
This will make our animation nice and smooth!

That's basically it. This example only showed how to rotate the X axis, but here are all the functions you can use:
`setXRot` / `setYRot` / `setZRot` (use radians)
`setXRotDegrees` / `setYRotDegrees` / `setZRotDegrees` (use degrees)
`setX` / `setY` / `setZ`
`scale` / `scaleX` / `scaleY` / `scaleZ`

And here are all the body parts you can access:
`head`, `chest`, `right_arm`, `left_arm`, `right_leg`, `left_leg`, `body` (last one is able to rotate/scale/move the entire player model)

# First-Person-Specific Animations
If you want to have the animation in first-person be more specific, or even not appear at all, there are some functions you can use:
```js
PalladiumEvents.registerAnimations((event) => {
event.register('test/ability_test', 10, (builder) => {
if (builder.isFirstPerson()) {
// do first-person animations
} else {
// do third-person animations
}
});
});
```
24 changes: 24 additions & 0 deletions docs/compatibilities/kubejs/custom-conditions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Custom Conditions

This page of the wiki will show you how to make a custom condition. Custom conditions are made using KubeJS scripts.

1. Make a file in the addon scripts directory.
2. Add the code to register the condition.
```js
StartupEvents.registry('palladium:condition_serializer', (event) => {
// ID of the condition will be: 'kubejs:mycoolpack/mycoolcondition'
event.create('mycoolpack/mycoolcondition')
});
```
3. Add the condition handler.
```js
StartupEvents.registry('palladium:condition_serializer', (event) => {
event.create('mycoolpack/mycoolcondition')

// Handler for the condition, in this case, the condition will be fulfilled when the entity is crouching
.test((entity) => {
return entity.isCrouching();
});

});
```
24 changes: 24 additions & 0 deletions docs/compatibilities/kubejs/custom-huds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Custom HUDs

You can also use Palladium with KubeJS to make your own HUD. Simply register it in a client-side script like here:

```js
// Event for registering HUDs
PalladiumEvents.registerGuiOverlays((event) => {
event.register(
// ID for the overlay
'test/example_hud',

// Function for rendering
(minecraft, gui, poseStack, partialTick, screenWidth, screenHeight) => {
// Drawing text. Parameters: PoseStack, Text (as text component), X, Y, Color
guiUtil.drawString(poseStack, Component.string("I am a text"), 10, 10, 0xffffff);

// Drawing a piece of a texture
// Parameters: Texture, Gui, PoseStack, x, y, U on the texture, V on the texture, width, height
guiUtil.blit('test:textures/gui/my_cool_texture.png', gui, poseStack, 10, 20, 0, 10, 182, 5);
});
});
```

If you use the `blit` method, your texture file must be 256x256 pixels big. If you choose to have your own dimensions, simply add to more arguments add the end as the texture width & height.
78 changes: 78 additions & 0 deletions docs/compatibilities/kubejs/useful-functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Useful Functions

## Powers
`palladium.powers.getPowerIds(LivingEntity entity)`
Returns a list of the entity's current power IDs.

`palladium.powers.getPowerIdsForNamespace(LivingEntity entity, String namespace)`
Returns the IDs of the powers the entity currently has, filtered by the namespace

## Superpowers

`palladium.superpowers.setSuperpower(LivingEntity entity, ResourceLocation powerId)`
Sets the entity's superpowers to just the given one

`palladium.superpowers.setSuperpowerIds(LivingEntity entity, ResourceLocation... powerIds)`
Sets the entity's superpowers to the given ones

`palladium.superpowers.hasSuperpower(LivingEntity entity, ResourceLocation powerId)`
Tests if the entity has the given superpower

`palladium.superpowers.addSuperpower(LivingEntity entity, ResourceLocation powerId)`
Adds a superpower to the entity

`palladium.superpowers.removeSuperpower(LivingEntity entity, ResourceLocation powerId)`
Removes a superpower to the entity

`palladium.superpowers.removeAllSuperpowers(LivingEntity entity)`
Removes all superpowers from an entity

## Abilities

`palladium.abilities.getEntries(LivingEntity entity)`
Returns all ability entries from the given entity

`palladium.abilities.getEntries(LivingEntity entity, ResourceLocation abilityId)`
Returns all ability entries of the given ability type from the entity

`palladium.abilities.getEntry(LivingEntity entity, ResourceLocation powerId, String abilityKey)`
Returns a specific ability entry from a specific power

`palladium.abilities.isUnlocked(LivingEntity entity, ResourceLocation powerId, String abilityKey)`
Checks if a specific ability entry is unlocked

`palladium.abilities.isEnabled(LivingEntity entity, ResourceLocation powerId, String abilityKey)`
Checks if a specific ability entry is enabled

`palladium.abilities.hasPower(LivingEntity entity, ResourceLocation powerId)`
Checks if the entity has that power (can be superpower or power of any source)


## Scoreboard

`palladium.scoreboard.getScore(Entity entity, String objective, int fallback)`
Gets the entity's score for the given objective, or the fallback value if the entity has no score.
The `fallback` argument is optional and defaults to 0.

`palladium.scoreboard.setScore(Entity entity, String objective, int value)`
Sets the entity's score for the given objective to the given value.

`palladium.scoreboard.addScore(Entity entity, String objective, int value)`
Adds the given value to the entity's score for the given objective.

`palladium.scoreboard.subtractScore(Entity entity, String objective, int value)`
Removes the given value from the entity's score for the given objective.

## Animation

`palladium.animations.getAnimationTimerAbilityValue(LivingEntity entity, ResourceLocation powerId, String abilityKey, float partialTicks)`
Gives you the animation progress of the given ability, a float ranging from 0.0 to 1.0

`palladium.animations.getAnimationTimerAbilityValue(LivingEntity entity, ResourceLocation powerId, String abilityKey, float partialTicks, float start, float end)`
Gives you the animation progress of the given ability, a float ranging from 0.0 to 1.0. BUT you can determines which
part of the progress you want to look at. If the animation ability goes up to 30, and you only want to see the progress
of between 10 and 20 you can use this function.

`palladium.animations.getInbetweenProgress(float progress, float startingPoint, float endPoint)`
Calculcates the progress of a bigger number, given from two points. If `progress` is a float that goes up to 30, and you
want to see how far the number is from 10-20, you can use the other 2 parameters to determine that.
4 changes: 4 additions & 0 deletions docs/rendering/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Rendering",
"position": 4
}
Loading

0 comments on commit cfa3611

Please sign in to comment.