Compare commits
198
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1af1569f63 | ||
|
|
8a0c98c9ab | ||
|
|
36c5fe2419 | ||
|
|
0c79d102cf | ||
|
|
bd8f644b9a | ||
|
|
7c84cdb05d | ||
|
|
fd6fb5db47 | ||
|
|
a80ada8590 | ||
|
|
c4a4b9cb86 | ||
|
|
4912a89e6e | ||
|
|
f2e10d1b01 | ||
|
|
25eb197491 | ||
|
|
8de233b572 | ||
|
|
83972ca9e6 | ||
|
|
35e2190cae | ||
|
|
b966cd2db0 | ||
|
|
3e492541cc | ||
|
|
4e9541d7f5 | ||
|
|
2875e9efa9 | ||
|
|
2b42fff66b | ||
|
|
643a33a643 | ||
|
|
e348c48eff | ||
|
|
473f58cab9 | ||
|
|
987b8619a3 | ||
|
|
87632941e8 | ||
|
|
041acab7ca | ||
|
|
b3de7d1c1a | ||
|
|
afcb2dd77c | ||
|
|
a7bd6d2bf4 | ||
|
|
b096cb60a3 | ||
|
|
7f1c0c3d4c | ||
|
|
a4f0bf9d2f | ||
|
|
f46c748e9f | ||
|
|
065479c58c | ||
|
|
eee3d46a2d | ||
|
|
d7b43fcbfc | ||
|
|
c82e011f73 | ||
|
|
bf1b996962 | ||
|
|
fc46cdcda0 | ||
|
|
4e7b029afb | ||
|
|
5430f02770 | ||
|
|
6a51abe3ee | ||
|
|
008652b442 | ||
|
|
c1e088eb33 | ||
|
|
1669a2f428 | ||
|
|
2ba63f4641 | ||
|
|
41b9e9001d | ||
|
|
679920b786 | ||
|
|
f058d6e635 | ||
|
|
f9377b7489 | ||
|
|
e59b5094ad | ||
|
|
c8ec4e6f1f | ||
|
|
cbcc6abe40 | ||
|
|
64c9d47b0f | ||
|
|
c0d2803f61 | ||
|
|
e249d5238f | ||
|
|
e32e505e95 | ||
|
|
7642a84108 | ||
|
|
b6e20d69cc | ||
|
|
9d04e20a30 | ||
|
|
d2624813f7 | ||
|
|
a2789e70ed | ||
|
|
f6f607904e | ||
|
|
22ea0296c0 | ||
|
|
24ae2f5324 | ||
|
|
9284497cec | ||
|
|
36cb12952a | ||
|
|
2700dc7f39 | ||
|
|
c9d27d46b6 | ||
|
|
b68756378c | ||
|
|
1ff1880951 | ||
|
|
fea2d32de8 | ||
|
|
e3e6d4452c | ||
|
|
f687e8e658 | ||
|
|
2413981f6f | ||
|
|
4ac244003a | ||
|
|
9ac92a084f | ||
|
|
aacbcb1f28 | ||
|
|
39ff7e418c | ||
|
|
58498a091d | ||
|
|
a806f77aff | ||
|
|
60ae9e3a55 | ||
|
|
03ddc35d36 | ||
|
|
1b8e9b9b36 | ||
|
|
e52ac956f0 | ||
|
|
4bfe147730 | ||
|
|
493664bef2 | ||
|
|
981e3e5efc | ||
|
|
963614f5fa | ||
|
|
7fdb70e3c3 | ||
|
|
37e8f0eab6 | ||
|
|
a6d17659f8 | ||
|
|
05edafa5c4 | ||
|
|
997a6de23b | ||
|
|
c15350e647 | ||
|
|
f9e5784b10 | ||
|
|
cea600617e | ||
|
|
c948b6d885 | ||
|
|
5508980384 | ||
|
|
e39dee01e5 | ||
|
|
a81412e176 | ||
|
|
09f9dd91aa | ||
|
|
2efc3c72ac | ||
|
|
a92fb03093 | ||
|
|
ad5847983f | ||
|
|
bb25300513 | ||
|
|
de33804eb4 | ||
|
|
de042f71dd | ||
|
|
5a1e85bbf4 | ||
|
|
3489e0df74 | ||
|
|
afe8eec343 | ||
|
|
2f4b861f98 | ||
|
|
a7022268c1 | ||
|
|
3082600e11 | ||
|
|
a348cfd338 | ||
|
|
35bfc7bf6c | ||
|
|
ae87c3dd84 | ||
|
|
d944803571 | ||
|
|
2c3b474c01 | ||
|
|
c2538560e1 | ||
|
|
d10c058c74 | ||
|
|
d1b6d95d57 | ||
|
|
977387a184 | ||
|
|
69bbc09d6a | ||
|
|
46b04ad462 | ||
|
|
a1b6fd3d1a | ||
|
|
fb9ed28b74 | ||
|
|
4bfc2a97dd | ||
|
|
a2cf66fbc1 | ||
|
|
5bda81a5c4 | ||
|
|
32ccd15121 | ||
|
|
a51cda998b | ||
|
|
9dc14eff7c | ||
|
|
4b1690c62e | ||
|
|
d02251b67d | ||
|
|
54c8cbfbe8 | ||
|
|
2d8ce63dcd | ||
|
|
1a92af2cd6 | ||
|
|
7e088bdeec | ||
|
|
6142049d51 | ||
|
|
d031f339c6 | ||
|
|
3ddbc9b313 | ||
|
|
dd2c1ddbc6 | ||
|
|
badd7e8c2e | ||
|
|
d7c4380cc2 | ||
|
|
7fc26ab939 | ||
|
|
37f430ddf7 | ||
|
|
f0a2182149 | ||
|
|
9605775f1e | ||
|
|
f251bc20c1 | ||
|
|
a02b3d74b8 | ||
|
|
7f3a4c20b3 | ||
|
|
e76999c611 | ||
|
|
c2771bcb95 | ||
|
|
5b858b5982 | ||
|
|
7082220e29 | ||
|
|
1a87830a52 | ||
|
|
9eff6dcced | ||
|
|
52690c3aa6 | ||
|
|
8f0780c5f6 | ||
|
|
465a7fbe73 | ||
|
|
6b5abfa319 | ||
|
|
39197adebb | ||
|
|
4b1e192705 | ||
|
|
a3fa3d4b82 | ||
|
|
c5ad7a0fb7 | ||
|
|
d17f94c0d6 | ||
|
|
398bff4c15 | ||
|
|
e0655df5f0 | ||
|
|
9174aac64c | ||
|
|
3cdc4c7d97 | ||
|
|
9ce6acc44d | ||
|
|
f170ed726b | ||
|
|
979d6f02a6 | ||
|
|
3fbe80cb1a | ||
|
|
8fdb32273d | ||
|
|
d5c9d8d5b1 | ||
|
|
752c9c234e | ||
|
|
b7b6185ada | ||
|
|
211b886bf3 | ||
|
|
36d1008f29 | ||
|
|
1441625a6b | ||
|
|
3859eb574e | ||
|
|
b4a29214a7 | ||
|
|
6ca16a0161 | ||
|
|
2f31db2232 | ||
|
|
ed0e0fc65a | ||
|
|
c5dcfc57ea | ||
|
|
9997a5c4b4 | ||
|
|
2b70e5614c | ||
|
|
589c5381e2 | ||
|
|
4539703497 | ||
|
|
0152bc2e32 | ||
|
|
e175c44118 | ||
|
|
8913d3df11 | ||
|
|
3a55965704 | ||
|
|
7112c74bf2 | ||
|
|
faa1906290 |
No files matched your search
@@ -0,0 +1,12 @@
|
|||||||
|
### Additions
|
||||||
|
- Added functionality for marks.
|
||||||
|
- Added data for all marks and all title ribbons from Pokémon.
|
||||||
|
- Added marks screen within the summary UI.
|
||||||
|
- Added `/givemark <player> <partySlot> <mark>` command to give a mark to a Pokémon.
|
||||||
|
- Added `/takemark <player> <partySlot> <mark>` command to remove a mark from a Pokémon.
|
||||||
|
- Added `/giveallmarks <player> <partySlot>` command to give all available marks to a Pokémon.
|
||||||
|
|
||||||
|
### MoLang & Datapacks
|
||||||
|
- Added Flows for `bobber_spawn_pokemon_post`, `pokemon_entity_spawn`, and `fossil_revived`.
|
||||||
|
- Added `marks` datapack folder.
|
||||||
|
- Added MoLang functions `entity.is_in_rain`, `pokemon.add_marks(Mark...)`, `pokemon.add_potential_marks(Mark...)`, `pokemon.add_marks_with_chance(Mark...)`, `pokemon.apply_potential_marks`, and `world.is_snowing_at(x, y, z)`.
|
||||||
+17
-12
@@ -1,16 +1,21 @@
|
|||||||
### Additions
|
### Additions
|
||||||
|
- Added ability to rename PC Boxes by clicking on the name of a box.
|
||||||
- Added ability to rename PC Boxes by clicking on the name of a box
|
- Added box options buttons for boxes, toggleable by clicking the right icon button in the bottom bar.
|
||||||
- Added ability to set wallpapers per PC Box by clicking the button right to the box name
|
- The button on the right allows for changing the box wallpaper.
|
||||||
- Added sorting by Name, Level and type by clicking the button left of the box name (shift reverses order)
|
- The option buttons on the left side allow for sorting the box by name, level, Pokédex number, gender, and type. Shift clicking allows for sorting in reverse order.
|
||||||
- Added filtering/search functionality in PC UI, which also supports pokemon properties (e.g. shiny=yes shows all shinies)
|
- Added filter functionality in PC UI, which supports `PokemonProperties` (e.g. `shiny=yes` shows all shiny Pokémon).
|
||||||
- Added /changewallpaper <player> <boxNumber> <wallpaper> command to change a wallpaper through commands
|
- Added `/changewallpaper <player> <boxNumber> <wallpaper>` command to change a box wallpaper through commands.
|
||||||
- Added /renamebox <player> <boxNumber> <name> command to rename a PC box through commands
|
- Added `/renamebox <player> <boxNumber> <name>` command to rename a PC box through commands.
|
||||||
|
|
||||||
### Developer
|
### Developer
|
||||||
|
- Added `RenamePCBoxEvent.Pre` and `RenamePCBoxEvent.Post` events to prevent players from renaming a box or changing their input.
|
||||||
|
- Added `ChangePCBoxWallpaperEvent.Pre` and `ChangePCBoxWallpaperEvent.Post` to prevent players from changing wallpapers or changing their selection.
|
||||||
|
- Added `WallpaperCollectionEvent` which gets called when clients connect to a server, allowing the server to handle which of the client-found wallpapers it's allowed to move (collected wallpapers can be removed for example to make it "vanish" client-side).
|
||||||
|
- Added `WallpaperUnlockedEvent`.
|
||||||
|
- Renamed `SetPCBoxPokemonPacket` and the respective handler to `SetPCBoxPacket`.
|
||||||
|
|
||||||
- Added RenamePCBoxEvent.Pre/Post events to prevent players from renaming a box or change their input
|
### Addons
|
||||||
- Added ChangePCBoxWallpaperEvent.Pre/Post to prevent players from changing to a wallpaper or change their selection
|
- Added Flows for `player_tick_pre`, `player_tick_post`, `advancement_earned`, `right_clicked_entity`, `right_clicked_block`, `player_died`, `wallpaper_unlocked`.
|
||||||
- Added WallpaperCollectionEvent which gets called when clients connect to a server, allowing the server which of the clients found wallpapers it's allowed to move (collected wallpapers can be removed for example to make it "vanish" client-side)
|
- Flows now have `q.` for any context properties in addition to the `c.` properties, making it a bit more convenient when calling other scripts from Flows.
|
||||||
- Wallpapers are loaded from `assets/<namespace>/textures/gui/pc/wallpaper/` and all wallpapers in this folder are available to the client to choose by default
|
- Added `unlockable_pc_box_wallpapers` datapack folder for wallpapers that need to be unlocked before they're usable.
|
||||||
- Renamed `SetPCBoxPokemonPacket` and the respective handler to `SetPCBoxPacket`
|
- Wallpapers are loaded from `assets/<namespace>/textures/gui/pc/wallpaper/` and all wallpapers in this folder are available to the client to choose by default.
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
### Additions
|
### Additions
|
||||||
|
|
||||||
- Added the ability to ride Pokémon by shift-right clicking and selecting the ride option.
|
- Added the ability to ride Pokémon by shift-right clicking and selecting the ride option.
|
||||||
|
- Added /calculateseatpositions command for approximating hitbox locations for riding configurations.
|
||||||
+29
-3
@@ -2,6 +2,7 @@
|
|||||||
## [1.7.0 (Month xth, 2025)](#1-7-0)
|
## [1.7.0 (Month xth, 2025)](#1-7-0)
|
||||||
|
|
||||||
### Additions
|
### Additions
|
||||||
|
- Added `/spectateBattle <player>` command to spectate battles without having to manually walk up to the target.
|
||||||
- Added an in-game configuration screen, allowing all settings from `main.json` to be edited directly in-game.
|
- Added an in-game configuration screen, allowing all settings from `main.json` to be edited directly in-game.
|
||||||
- Added `/cobblemonconfig reload` command to reload `main.json` configuration. **Note:** Some settings require a server restart to take effect; use this command cautiously.
|
- Added `/cobblemonconfig reload` command to reload `main.json` configuration. **Note:** Some settings require a server restart to take effect; use this command cautiously.
|
||||||
- Added `blacklisted_items_to_hold` and `whitelisted_items_to_hold` tags to allow for controlling which items players can give to their Pokémon. If the whitelist is empty, it will consider all item as allowed (unless they are in the blacklist).
|
- Added `blacklisted_items_to_hold` and `whitelisted_items_to_hold` tags to allow for controlling which items players can give to their Pokémon. If the whitelist is empty, it will consider all item as allowed (unless they are in the blacklist).
|
||||||
@@ -10,9 +11,18 @@
|
|||||||
- Added cosmetic item functionality for Pokémon. Certain cosmetic items can be given to applicable Pokémon via the interact menu.
|
- Added cosmetic item functionality for Pokémon. Certain cosmetic items can be given to applicable Pokémon via the interact menu.
|
||||||
- Added the various log blocks as cosmetic items for Timburr and Komala.
|
- Added the various log blocks as cosmetic items for Timburr and Komala.
|
||||||
- Added `visibility/hidden`, `visibility/hat` and `visibility/face` tags to control where and how certain items are rendered.
|
- Added `visibility/hidden`, `visibility/hat` and `visibility/face` tags to control where and how certain items are rendered.
|
||||||
|
- Added Pokémon markings, toggleable within the summary.
|
||||||
|
- Added `/boxcount` command to change PC boxes amount
|
||||||
|
- Added `/transformmodelpart (position|rotation|scale) <modelPart> <transform: x y z>` command that can add transformations to a pokemon's model part.
|
||||||
|
- The player executing the command must be facing the target pokemon entity. Transformations are not persistent and will revert when resources are reloaded.
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- Renamed `chargeGainedPerTick` config to `secondsToChargeHealingMachine`.
|
- Renamed `chargeGainedPerTick` config to `secondsToChargeHealingMachine`.
|
||||||
|
- Made Blocks of Gold count as Big Nuggets when held by a Pokémon (for Fling functionality)
|
||||||
|
- Substantially optimised spawning checks mainly by front-loading biome filtering.
|
||||||
|
- When using the `cobblemon` or `generation_9` capture calculators a critical capture with a single shake will always play for successful captures when you've already registered the Pokémon as caught in your Pokédex.
|
||||||
|
- Improved the performance of saving Pokédex and player data.
|
||||||
|
- Pokémon hitbox now scales with entity attribute `generic.scale`.
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- Fixed Particles sometimes facing the wrong direction (looking at you, Swords Dance)
|
- Fixed Particles sometimes facing the wrong direction (looking at you, Swords Dance)
|
||||||
@@ -34,6 +44,12 @@
|
|||||||
- Fixed owned Pokémon sometimes being un-interactable after the player relogs fast
|
- Fixed owned Pokémon sometimes being un-interactable after the player relogs fast
|
||||||
- Fixed field name in evolution requirements for Spewpa Pokeball.
|
- Fixed field name in evolution requirements for Spewpa Pokeball.
|
||||||
- Fixed LevelUpCriterion logic to correctly check that the Pokémon is a preEvo.
|
- Fixed LevelUpCriterion logic to correctly check that the Pokémon is a preEvo.
|
||||||
|
- Fixed `hide_additional_tooltip` vanilla flag not properly hiding tooltips on pokerod and bait items
|
||||||
|
- Fixed NPCs using Pokémon outside of their pool when a Pokémon name had a typo.
|
||||||
|
- Fixed an issue with datapacked species features not being applied properly when relogging.
|
||||||
|
- Fixed Pokémon marked as silent still playing shiny sounds and effects.
|
||||||
|
- Fixed an issue with newer versions of Fabric API where underground Pokémon were spawning in The End.
|
||||||
|
- Fixed spawning not working well when you're at high points surrounded by lower altitude spawning areas, such as flying.
|
||||||
|
|
||||||
### Developer
|
### Developer
|
||||||
- A finished battle now has winners and losers set inside of `PokemonBattle` instead of them always being empty.
|
- A finished battle now has winners and losers set inside of `PokemonBattle` instead of them always being empty.
|
||||||
@@ -44,9 +60,13 @@
|
|||||||
- Removed the NbtItemPredicate class, all the mod usages now use the vanilla item predicate solution, this causes breaking changes on Fossil, HeldItemRequirement & ItemInteractionEvolution
|
- Removed the NbtItemPredicate class, all the mod usages now use the vanilla item predicate solution, this causes breaking changes on Fossil, HeldItemRequirement & ItemInteractionEvolution
|
||||||
- Renamed Cobblemon's creative tabs to start with "Cobblemon: " to distinguish Cobblemon's tabs from tabs for other mods.
|
- Renamed Cobblemon's creative tabs to start with "Cobblemon: " to distinguish Cobblemon's tabs from tabs for other mods.
|
||||||
- Various items now have a rarity value.
|
- Various items now have a rarity value.
|
||||||
|
- Reworked observable handling in `Pokemon.kt` to cut down on RAM usage and clarify the file.
|
||||||
### Changes
|
- Note: This will break mods that used our observable functionality there or in MoveSet, IVs, EVs, or BenchedMoves.
|
||||||
- When using the `cobblemon` or `generation_9` capture calculators a critical capture with a single shake will always play for successful captures when you've already registered the Pokémon as caught in your Pokédex.
|
- Using `Pokemon#onChange()` is now the way to mark a Pokémon as needing a save.
|
||||||
|
- Using `[Pokemon].changeObservable` is now the way to get an `Observable` for any save-worthy changes.
|
||||||
|
- Updated NPCEntity beam positioning to properly account for the baseScale property.
|
||||||
|
- Updated NPCEntity pokeball throw positioning to properly account for the baseScale property.
|
||||||
|
- Fixed `[Pokemon].copyFrom` error causing forms, IVs, and EVs to not be applied properly when using `[Pokemon].loadFromJSON` or `[Pokemon].loadFromNBT`
|
||||||
|
|
||||||
### MoLang & Datapacks
|
### MoLang & Datapacks
|
||||||
- The following usages for item predicates can now use item conditions like advancements do, you can learn about them in the [Minecraft wiki](https://minecraft.wiki/w/Advancement_definition#minecraft:filled_bucket)
|
- The following usages for item predicates can now use item conditions like advancements do, you can learn about them in the [Minecraft wiki](https://minecraft.wiki/w/Advancement_definition#minecraft:filled_bucket)
|
||||||
@@ -54,6 +74,12 @@
|
|||||||
- The `itemCondition` for a held item evolution requirement
|
- The `itemCondition` for a held item evolution requirement
|
||||||
- The `fossils` for a fossil entry
|
- The `fossils` for a fossil entry
|
||||||
- Added MoLang flows for `poke_ball_capture_calculated`, `evolution_tested`, `evolution_accepted`, `evolution_completed`
|
- Added MoLang flows for `poke_ball_capture_calculated`, `evolution_tested`, `evolution_accepted`, `evolution_completed`
|
||||||
|
- Added `interpolate` boolean property to animated textures to allow gradual colour changes between frames.
|
||||||
|
- Fixed species additions not being capable of changing implemented status.
|
||||||
|
- Added support for action effects that are triggered by `|-activate|` Showdown instructions. `activate_{effect_id}` is the syntax.
|
||||||
|
- Added Molang functions for rendering items `render_item(item_id, locator_name)` and `clear_items()`.
|
||||||
|
- Fixed location spawn filter components causing crashes
|
||||||
|
- Added `pokemon` as an available Molang function for the `battleActor` functions.
|
||||||
|
|
||||||
## [1.6.1 (January 26th, 2025)](#1-6-1)
|
## [1.6.1 (January 26th, 2025)](#1-6-1)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common;
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.api.orientation.OrientationController;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.util.SmoothDouble;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.joml.Matrix3f;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public interface OrientationControllable {
|
||||||
|
OrientationController getOrientationController();
|
||||||
|
}
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 Cobblemon Contributors
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.cobblemon.mod.common;
|
|
||||||
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.joml.Matrix3f;
|
|
||||||
import org.joml.Vector3f;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public interface Rollable {
|
|
||||||
|
|
||||||
// From Minecraft's Camera
|
|
||||||
Vector3f FORWARDS = new Vector3f(0.0F, 0.0F, -1.0F);
|
|
||||||
Vector3f UP = new Vector3f(0.0F, 1.0F, 0.0F);
|
|
||||||
Vector3f LEFT = new Vector3f(-1.0F, 0.0F, 0.0F);
|
|
||||||
|
|
||||||
@Nullable Matrix3f getOrientation();
|
|
||||||
|
|
||||||
Rollable updateOrientation(Function<Matrix3f, Matrix3f> update);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The forward vector (0, 0, -1) after the rotation matrix is applied.
|
|
||||||
*/
|
|
||||||
default Vector3f getForwardVector() {
|
|
||||||
if (getOrientation() == null) return new Vector3f(FORWARDS);
|
|
||||||
return getOrientation().transform(FORWARDS, new Vector3f());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The left vector (-1, 0, 0) after the rotation matrix is applied.
|
|
||||||
*/
|
|
||||||
default Vector3f getLeftVector() {
|
|
||||||
if (getOrientation() == null) return new Vector3f(LEFT);
|
|
||||||
return getOrientation().transform(LEFT, new Vector3f());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The up vector (0, 1, 0) after the rotation matrix is applied.
|
|
||||||
*/
|
|
||||||
default Vector3f getUpVector() {
|
|
||||||
if (getOrientation() == null) return new Vector3f(UP);
|
|
||||||
return getOrientation().transform(UP, new Vector3f());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param yaw change in degrees
|
|
||||||
* @return The Rollable object this method was called on
|
|
||||||
*/
|
|
||||||
|
|
||||||
default Rollable rotateYaw(float yaw) {
|
|
||||||
return updateOrientation(prev -> prev.rotateY((float) Math.toRadians(-yaw)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param pitch change in degrees
|
|
||||||
* @return The Rollable object this method was called on
|
|
||||||
*/
|
|
||||||
|
|
||||||
default Rollable rotatePitch(float pitch) {
|
|
||||||
return updateOrientation(prev -> prev.rotateX((float) Math.toRadians(-pitch)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param roll change in degrees
|
|
||||||
* @return The Rollable object this method was called on
|
|
||||||
*/
|
|
||||||
default Rollable rotateRoll(float roll) {
|
|
||||||
return updateOrientation(prev -> prev.rotateZ((float) Math.toRadians(-roll)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Order matters when rotating an object. If you need a different order, individually call rotateYaw, rotatePitch, and rotateRoll
|
|
||||||
*
|
|
||||||
* @param yaw change in degrees
|
|
||||||
* @param pitch change in degrees
|
|
||||||
* @param roll change in degrees
|
|
||||||
* @return The Rollable object this method was called on
|
|
||||||
*/
|
|
||||||
default Rollable rotate(float yaw, float pitch, float roll) {
|
|
||||||
return rotateYaw(yaw).rotatePitch(pitch).rotateRoll(roll);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The pitch angle in degrees as a float.
|
|
||||||
* Value is between [-180, 180] with 0 being South, 90 being West, 180/-180 being North, and -90 being East
|
|
||||||
*/
|
|
||||||
default float getYaw() {
|
|
||||||
return (float) Mth.wrapDegrees(-Math.toDegrees(FORWARDS.angleSigned(getForwardVector(), UP)) + 180);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The yaw angle in degrees as a float.
|
|
||||||
* Value is between [-90, 90] with 0 being straight forward, 90 being straight down, and -90 being straight up
|
|
||||||
*/
|
|
||||||
default float getPitch() {
|
|
||||||
return (float) Mth.wrapDegrees(-Math.toDegrees(Math.asin(getForwardVector().y)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The roll angle in degrees as a float.
|
|
||||||
* Value is between [-180, 180] with 0 being no roll (normal), 90 being 90 degrees CW, 180/-180 being 180 degrees CW/CCW, and -90 being 90 degrees CCW
|
|
||||||
*/
|
|
||||||
default float getRoll() {
|
|
||||||
//Cobblemon.LOGGER.info("{}", (float) Math.toDegrees(getUpVector().angleSigned(UP, getForwardVector())));
|
|
||||||
return (float) Mth.wrapDegrees(-Math.toDegrees(getUpVector().angleSigned(UP, getForwardVector())));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shouldRoll();
|
|
||||||
|
|
||||||
void clearRotation();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(LocalPlayer.class)
|
||||||
|
public abstract class LocalPlayerMixin {
|
||||||
|
@Shadow
|
||||||
|
private float jumpRidingScale;
|
||||||
|
|
||||||
|
@Inject(method = "getJumpRidingScale", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void modifyJumpRidingScale(CallbackInfoReturnable<Float> cir) {
|
||||||
|
LocalPlayer player = (LocalPlayer) (Object) this;
|
||||||
|
if (player.isPassenger() && player.getVehicle() instanceof PokemonEntity pokemonEntity) {
|
||||||
|
var rideValue = pokemonEntity.<Float>ifRidingAvailableSupply(null, (behaviour, settings, state) -> {
|
||||||
|
if (behaviour.canJump(settings, state, pokemonEntity, player)) return null;
|
||||||
|
return behaviour.setRideBar(settings, state, pokemonEntity, player);
|
||||||
|
});
|
||||||
|
if (rideValue != null) {
|
||||||
|
cir.setReturnValue(rideValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.mixin;
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.platform.events.PlatformEvents;
|
||||||
|
import com.cobblemon.mod.common.platform.events.ServerPlayerEvent;
|
||||||
|
import net.minecraft.advancements.AdvancementHolder;
|
||||||
|
import net.minecraft.server.PlayerAdvancements;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(PlayerAdvancements.class)
|
||||||
|
public class PlayerAdvancementsMixin {
|
||||||
|
@Shadow private ServerPlayer player;
|
||||||
|
|
||||||
|
@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V"))
|
||||||
|
private void cobblemon$award(AdvancementHolder advancement, String criterionKey, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
PlatformEvents.SERVER_PLAYER_ADVANCEMENT_EARNED.emit(new ServerPlayerEvent.AdvancementEarned(player, advancement));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,9 +10,10 @@ package com.cobblemon.mod.common.mixin;
|
|||||||
|
|
||||||
import com.cobblemon.mod.common.Cobblemon;
|
import com.cobblemon.mod.common.Cobblemon;
|
||||||
import com.cobblemon.mod.common.CobblemonItems;
|
import com.cobblemon.mod.common.CobblemonItems;
|
||||||
import com.cobblemon.mod.common.Rollable;
|
import com.cobblemon.mod.common.OrientationControllable;
|
||||||
import com.cobblemon.mod.common.api.events.CobblemonEvents;
|
import com.cobblemon.mod.common.api.events.CobblemonEvents;
|
||||||
import com.cobblemon.mod.common.api.events.item.LeftoversCreatedEvent;
|
import com.cobblemon.mod.common.api.events.item.LeftoversCreatedEvent;
|
||||||
|
import com.cobblemon.mod.common.api.orientation.OrientationController;
|
||||||
import com.cobblemon.mod.common.api.pokemon.PokemonSpecies;
|
import com.cobblemon.mod.common.api.pokemon.PokemonSpecies;
|
||||||
import com.cobblemon.mod.common.api.riding.Rideable;
|
import com.cobblemon.mod.common.api.riding.Rideable;
|
||||||
import com.cobblemon.mod.common.api.storage.party.PartyStore;
|
import com.cobblemon.mod.common.api.storage.party.PartyStore;
|
||||||
@@ -31,25 +32,24 @@ import com.cobblemon.mod.common.util.DataKeys;
|
|||||||
import com.cobblemon.mod.common.world.gamerules.CobblemonGameRules;
|
import com.cobblemon.mod.common.world.gamerules.CobblemonGameRules;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
|
import net.minecraft.world.entity.EntityDimensions;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.entity.Pose;
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.food.FoodProperties;
|
import net.minecraft.world.food.FoodProperties;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Matrix3f;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
@@ -58,15 +58,11 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Mixin(Player.class)
|
@Mixin(Player.class)
|
||||||
public abstract class PlayerMixin extends LivingEntity implements Rollable, ScannableEntity {
|
public abstract class PlayerMixin extends LivingEntity implements ScannableEntity, OrientationControllable {
|
||||||
|
|
||||||
@Shadow public abstract CompoundTag getShoulderEntityLeft();
|
@Shadow public abstract CompoundTag getShoulderEntityLeft();
|
||||||
|
|
||||||
@@ -84,7 +80,9 @@ public abstract class PlayerMixin extends LivingEntity implements Rollable, Scan
|
|||||||
|
|
||||||
@Shadow public abstract void displayClientMessage(Component message, boolean overlay);
|
@Shadow public abstract void displayClientMessage(Component message, boolean overlay);
|
||||||
|
|
||||||
@Unique private Matrix3f orientation = null;
|
@Shadow @Final private static Map<Pose, EntityDimensions> POSES;
|
||||||
|
@Shadow @Final public static EntityDimensions STANDING_DIMENSIONS;
|
||||||
|
@Unique private OrientationController cobblemon$orientationController = new OrientationController(this);
|
||||||
|
|
||||||
protected PlayerMixin(EntityType<? extends LivingEntity> p_20966_, Level p_20967_) {
|
protected PlayerMixin(EntityType<? extends LivingEntity> p_20966_, Level p_20967_) {
|
||||||
super(p_20966_, p_20967_);
|
super(p_20966_, p_20967_);
|
||||||
@@ -112,6 +110,19 @@ public abstract class PlayerMixin extends LivingEntity implements Rollable, Scan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "tick", at = @At("HEAD"))
|
||||||
|
private void cobblemon$updateRenderOrientation(CallbackInfo ci) {
|
||||||
|
this.cobblemon$orientationController.tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityDimensions getDefaultDimensions(Pose pose) {
|
||||||
|
if (this.getVehicle() instanceof PokemonEntity) {
|
||||||
|
return STANDING_DIMENSIONS;
|
||||||
|
}
|
||||||
|
return (EntityDimensions)POSES.getOrDefault(pose, STANDING_DIMENSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "removeEntitiesOnShoulder",
|
method = "removeEntitiesOnShoulder",
|
||||||
at = @At(
|
at = @At(
|
||||||
@@ -238,7 +249,7 @@ public abstract class PlayerMixin extends LivingEntity implements Rollable, Scan
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void absMoveTo(double x, double y, double z, float yaw, float pitch) {
|
public void absMoveTo(double x, double y, double z, float yaw, float pitch) {
|
||||||
if (shouldRoll()) {
|
if (cobblemon$orientationController.getActive()) {
|
||||||
this.absMoveTo(x, y, z);
|
this.absMoveTo(x, y, z);
|
||||||
this.setYRot(yaw % 360.0f);
|
this.setYRot(yaw % 360.0f);
|
||||||
this.setXRot(pitch % 360.0f);
|
this.setXRot(pitch % 360.0f);
|
||||||
@@ -251,65 +262,21 @@ public abstract class PlayerMixin extends LivingEntity implements Rollable, Scan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "tick", at = @At("HEAD"))
|
|
||||||
public void tick(CallbackInfo ci) {
|
|
||||||
if (this.shouldRoll()) {
|
|
||||||
// Proof of concept for yaw movement
|
|
||||||
if (this.getMainHandItem().is(Items.STICK)) {
|
|
||||||
this.rotateYaw(2);
|
|
||||||
}
|
|
||||||
else if (this.getMainHandItem().is(Items.BLAZE_ROD)) {
|
|
||||||
this.rotateYaw(-2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Matrix3f getOrientation() {
|
|
||||||
return orientation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Rollable updateOrientation(Function<Matrix3f, Matrix3f> update) {
|
|
||||||
if (!shouldRoll()) return this;
|
|
||||||
|
|
||||||
if (this.orientation == null) {
|
|
||||||
this.orientation = new Matrix3f();
|
|
||||||
this.rotate(getYRot() - 180, getXRot(), 0);
|
|
||||||
}
|
|
||||||
this.orientation = update.apply(this.orientation);
|
|
||||||
setYRot(this.getYaw());
|
|
||||||
setXRot(this.getPitch());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRoll() {
|
|
||||||
LocalPlayer player = Minecraft.getInstance().player;
|
|
||||||
if (!this.equals(player)) return false;
|
|
||||||
if (player.isHolding(Items.DIAMOND)) return true;
|
|
||||||
|
|
||||||
var playerVehicle = player.getVehicle();
|
|
||||||
if (playerVehicle == null) return false;
|
|
||||||
if (!(playerVehicle instanceof PokemonEntity pokemonEntity)) return false;
|
|
||||||
|
|
||||||
return pokemonEntity.getRiding().shouldRoll(pokemonEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearRotation() {
|
|
||||||
this.orientation = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@WrapOperation(
|
@WrapOperation(
|
||||||
method = "rideTick()V",
|
method = "rideTick()V",
|
||||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;wantsToStopRiding()Z")
|
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;wantsToStopRiding()Z")
|
||||||
)
|
)
|
||||||
public boolean delegateDismountToController(Player instance, Operation<Boolean> original) {
|
public boolean delegateDismountToController(Player instance, Operation<Boolean> original) {
|
||||||
if (this.getVehicle() instanceof Rideable vehicle) {
|
if (this.getVehicle() instanceof PokemonEntity pokemonEntity) {
|
||||||
return vehicle.getRiding().dismountOnShift() && original.call(instance);
|
return pokemonEntity.ifRidingAvailableSupply(false, (behaviour, settings, state) -> {
|
||||||
|
return behaviour.dismountOnShift(settings, state, pokemonEntity) && original.call(instance);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return original.call(instance);
|
return original.call(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrientationController getOrientationController() {
|
||||||
|
return cobblemon$orientationController;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.mixin;
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.CobblemonNetwork;
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable;
|
||||||
|
import com.cobblemon.mod.common.api.net.NetworkPacket;
|
||||||
|
import com.cobblemon.mod.common.api.orientation.OrientationController;
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
||||||
|
import com.cobblemon.mod.common.mixin.accessor.ChunkMapAccessor;
|
||||||
|
import com.cobblemon.mod.common.mixin.accessor.TrackedEntityAccessor;
|
||||||
|
import com.cobblemon.mod.common.net.messages.client.orientation.ClientboundUpdateOrientationPacket;
|
||||||
|
import com.cobblemon.mod.common.net.messages.client.pokemon.update.ClientboundUpdateRidingStatePacket;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.server.level.ChunkMap;
|
||||||
|
import net.minecraft.server.level.ServerEntity;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerConnection;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import org.joml.Matrix3f;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@Mixin(ServerEntity.class)
|
||||||
|
public abstract class ServerEntityMixin {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
private Consumer<Packet<?>> broadcast;
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
private Entity entity;
|
||||||
|
@Unique
|
||||||
|
private Matrix3f cobblemon$lastSentOrientation;
|
||||||
|
@Unique
|
||||||
|
private boolean cobblemon$lastSentActive;
|
||||||
|
|
||||||
|
@Inject(method = "sendChanges", at = @At("TAIL"))
|
||||||
|
private void cobblemon$sendChanges(CallbackInfo ci) {
|
||||||
|
cobblemon$sendOrientationChanges();
|
||||||
|
cobblemon$sendRidingStateChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cobblemon$sendRidingStateChanges() {
|
||||||
|
if (!(this.entity instanceof PokemonEntity pokemonEntity)) return;
|
||||||
|
if (pokemonEntity.getRidingState() == null) return;
|
||||||
|
if (pokemonEntity.getRiding() == null) return;
|
||||||
|
var ridingBehaviour = pokemonEntity.getRiding();
|
||||||
|
var ridingState = pokemonEntity.getRidingState();
|
||||||
|
var previousRidingState = pokemonEntity.getPreviousRidingState();
|
||||||
|
if (previousRidingState != null && !ridingState.shouldSync(previousRidingState)) return;
|
||||||
|
cobblemon$broadcast(new ClientboundUpdateRidingStatePacket(pokemonEntity.getId(), ridingBehaviour.getKey(), pokemonEntity.getRidingState(), null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cobblemon$sendOrientationChanges() {
|
||||||
|
if (!(this.entity instanceof OrientationControllable controllable)) return;
|
||||||
|
OrientationController controller = controllable.getOrientationController();
|
||||||
|
Matrix3f currOrientation = controller.getOrientation();
|
||||||
|
boolean currActive = controller.getActive();
|
||||||
|
|
||||||
|
if (currOrientation == null || currOrientation.equals(cobblemon$lastSentOrientation) && (currActive == cobblemon$lastSentActive))
|
||||||
|
return;
|
||||||
|
cobblemon$lastSentOrientation = new Matrix3f(currOrientation);
|
||||||
|
cobblemon$lastSentActive = currActive;
|
||||||
|
|
||||||
|
cobblemon$broadcast(new ClientboundUpdateOrientationPacket(currOrientation, currActive, entity.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cobblemon$broadcast(NetworkPacket<?> packet) {
|
||||||
|
if (!(entity.level() instanceof ServerLevel level)) return;
|
||||||
|
ChunkMap chunkMap = level.getChunkSource().chunkMap;
|
||||||
|
Int2ObjectMap<?> entityMap = ((ChunkMapAccessor) chunkMap).getEntityMap();
|
||||||
|
Object tracked = entityMap.get(entity.getId());
|
||||||
|
if (!(tracked instanceof TrackedEntityAccessor tracker)) return;
|
||||||
|
|
||||||
|
Set<ServerPlayerConnection> seenBy = tracker.getSeenBy();
|
||||||
|
for (ServerPlayerConnection conn : seenBy) {
|
||||||
|
ServerPlayer player = conn.getPlayer();
|
||||||
|
if (player == entity) continue;
|
||||||
|
CobblemonNetwork.INSTANCE.sendPacketToPlayer(player, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.mixin;
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable;
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(ServerPlayer.class)
|
||||||
|
public abstract class ServerPlayerMixin {
|
||||||
|
|
||||||
|
@Inject(method = "rideTick", at = @At("HEAD"))
|
||||||
|
private void cobblemon$updateOrientationControllerRideTick(CallbackInfo ci) {
|
||||||
|
if (!(this instanceof OrientationControllable controllable)) return;
|
||||||
|
var shouldUseCustomOrientation = cobblemon$shouldUseCustomOrientation((ServerPlayer)(Object)this);
|
||||||
|
controllable.getOrientationController().setActive(shouldUseCustomOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private boolean cobblemon$shouldUseCustomOrientation(ServerPlayer player) {
|
||||||
|
var playerVehicle = player.getVehicle();
|
||||||
|
if (playerVehicle == null) return false;
|
||||||
|
if (!(playerVehicle instanceof PokemonEntity pokemonEntity)) return false;
|
||||||
|
return pokemonEntity.ifRidingAvailableSupply(false, (behaviour, settings, state) -> {
|
||||||
|
return behaviour.shouldRoll(settings, state, pokemonEntity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "stopRiding", at = @At("HEAD"))
|
||||||
|
public void cobblemon$resetOrientationOnDismount(CallbackInfo ci) {
|
||||||
|
if (!(this instanceof OrientationControllable controllable)) return;
|
||||||
|
controllable.getOrientationController().setActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.mixin.accessor;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import net.minecraft.server.level.ChunkMap;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(ChunkMap.class)
|
||||||
|
public interface ChunkMapAccessor {
|
||||||
|
@Accessor("entityMap")
|
||||||
|
Int2ObjectMap<?> getEntityMap();
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.mixin.accessor;
|
||||||
|
|
||||||
|
import net.minecraft.server.network.ServerPlayerConnection;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Mixin(targets = "net.minecraft.server.level.ChunkMap$TrackedEntity")
|
||||||
|
public interface TrackedEntityAccessor {
|
||||||
|
@Accessor("seenBy")
|
||||||
|
Set<ServerPlayerConnection> getSeenBy();
|
||||||
|
}
|
||||||
+10
@@ -9,8 +9,10 @@
|
|||||||
package com.cobblemon.mod.common.mixin.client;
|
package com.cobblemon.mod.common.mixin.client;
|
||||||
|
|
||||||
import com.cobblemon.mod.common.client.CobblemonClient;
|
import com.cobblemon.mod.common.client.CobblemonClient;
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
||||||
import com.cobblemon.mod.common.pokedex.scanner.PokedexUsageContext;
|
import com.cobblemon.mod.common.pokedex.scanner.PokedexUsageContext;
|
||||||
import net.minecraft.client.player.AbstractClientPlayer;
|
import net.minecraft.client.player.AbstractClientPlayer;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
@@ -30,5 +32,13 @@ public class AbstractClientPlayerMixin {
|
|||||||
if (usageContext.getScanningGuiOpen()) {
|
if (usageContext.getScanningGuiOpen()) {
|
||||||
cir.setReturnValue(usageContext.getFovMultiplier());
|
cir.setReturnValue(usageContext.getFovMultiplier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalPlayer player = (LocalPlayer) (Object) this;
|
||||||
|
if (player != null && player.isPassenger() && player.getVehicle() instanceof PokemonEntity) {
|
||||||
|
PokemonEntity ride = (PokemonEntity) player.getVehicle();
|
||||||
|
|
||||||
|
//Return custom fov mult
|
||||||
|
cir.setReturnValue(ride.rideFovMult());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
package com.cobblemon.mod.common.mixin.client;
|
package com.cobblemon.mod.common.mixin.client;
|
||||||
|
|
||||||
import com.cobblemon.mod.common.Rollable;
|
import com.cobblemon.mod.common.OrientationControllable;
|
||||||
|
import com.cobblemon.mod.common.api.orientation.OrientationController;
|
||||||
import com.cobblemon.mod.common.api.riding.Rideable;
|
import com.cobblemon.mod.common.api.riding.Rideable;
|
||||||
import com.cobblemon.mod.common.api.riding.Seat;
|
import com.cobblemon.mod.common.api.riding.Seat;
|
||||||
import com.cobblemon.mod.common.client.entity.PokemonClientDelegate;
|
import com.cobblemon.mod.common.client.entity.PokemonClientDelegate;
|
||||||
@@ -31,6 +32,7 @@ import org.spongepowered.asm.mixin.Unique;
|
|||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(Camera.class)
|
@Mixin(Camera.class)
|
||||||
public abstract class CameraMixin {
|
public abstract class CameraMixin {
|
||||||
@@ -44,13 +46,12 @@ public abstract class CameraMixin {
|
|||||||
@Shadow private float xRot;
|
@Shadow private float xRot;
|
||||||
@Shadow private float yRot;
|
@Shadow private float yRot;
|
||||||
|
|
||||||
@Shadow public abstract float getXRot();
|
|
||||||
@Shadow public abstract float getYRot();
|
|
||||||
|
|
||||||
@Shadow private Vec3 position;
|
@Shadow private Vec3 position;
|
||||||
@Shadow private float eyeHeight;
|
@Shadow private float eyeHeight;
|
||||||
@Shadow private float eyeHeightOld;
|
@Shadow private float eyeHeightOld;
|
||||||
|
|
||||||
|
@Shadow protected abstract void setPosition(Vec3 pos);
|
||||||
|
|
||||||
@Unique private float returnTimer = 0;
|
@Unique private float returnTimer = 0;
|
||||||
@Unique private float rollAngleStart = 0;
|
@Unique private float rollAngleStart = 0;
|
||||||
@Unique Minecraft minecraft = Minecraft.getInstance();
|
@Unique Minecraft minecraft = Minecraft.getInstance();
|
||||||
@@ -59,36 +60,37 @@ public abstract class CameraMixin {
|
|||||||
|
|
||||||
@Inject(method = "setRotation", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "setRotation", at = @At("HEAD"), cancellable = true)
|
||||||
public void open_camera$setRotation(float f, float g, CallbackInfo ci) {
|
public void open_camera$setRotation(float f, float g, CallbackInfo ci) {
|
||||||
if (!(this.entity instanceof Rollable rollable) || disableRollableCameraDebug) return;
|
if (!(this.entity instanceof OrientationControllable controllable) || disableRollableCameraDebug) return;
|
||||||
if (!rollable.shouldRoll() && rollable.getOrientation() != null) {
|
var controller = controllable.getOrientationController();
|
||||||
|
if (!controller.isActive() && controller.getOrientation() != null) {
|
||||||
if(this.returnTimer < 1) {
|
if(this.returnTimer < 1) {
|
||||||
//Rotation is taken from entity since we no longer handle mouse ourselves
|
//Rotation is taken from entity since we no longer handle mouse ourselves
|
||||||
//Stops a period of time when you can't input anything.
|
//Stops a period of time when you can't input anything.
|
||||||
rollable.getOrientation().set(
|
controller.getOrientation().set(
|
||||||
new Matrix3f()
|
new Matrix3f()
|
||||||
.rotateY((float) Math.toRadians(180 - this.entity.getYRot()))
|
.rotateY((float) Math.toRadians(180 - this.entity.getYRot()))
|
||||||
.rotateX((float) Math.toRadians(-this.entity.getXRot()))
|
.rotateX((float) Math.toRadians(-this.entity.getXRot()))
|
||||||
);
|
);
|
||||||
if(rollAngleStart == 0){
|
if(rollAngleStart == 0){
|
||||||
this.returnTimer = 1;
|
this.returnTimer = 1;
|
||||||
rollable.clearRotation();
|
controller.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rollable.getOrientation().rotateZ((float) Math.toRadians(-rollAngleStart*(1-returnTimer)));
|
controller.getOrientation().rotateZ((float) Math.toRadians(-rollAngleStart*(1-returnTimer)));
|
||||||
applyRotation();
|
applyRotation();
|
||||||
this.returnTimer += .05F;
|
this.returnTimer += .05F;
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
} else {
|
} else {
|
||||||
this.returnTimer = 1;
|
this.returnTimer = 1;
|
||||||
rollable.clearRotation();
|
controller.reset();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (rollable.getOrientation() == null) return;
|
if (controller.getOrientation() == null) return;
|
||||||
applyRotation();
|
applyRotation();
|
||||||
|
|
||||||
this.returnTimer = 0;
|
this.returnTimer = 0;
|
||||||
this.rollAngleStart = rollable.getRoll();
|
this.rollAngleStart = controller.getRoll();
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,11 +102,10 @@ public abstract class CameraMixin {
|
|||||||
|
|
||||||
if(vehicle instanceof Rideable){
|
if(vehicle instanceof Rideable){
|
||||||
//RidingCameraDelagate.INSTANCE.positionCamera(instance, x, y, z, original);
|
//RidingCameraDelagate.INSTANCE.positionCamera(instance, x, y, z, original);
|
||||||
if(!(vehicle instanceof PokemonEntity)){
|
if (!(vehicle instanceof PokemonEntity pokemon)) {
|
||||||
original.call(instance, x, y, z);
|
original.call(instance, x, y, z);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PokemonEntity pokemon = (PokemonEntity) vehicle;
|
|
||||||
|
|
||||||
int seatIndex = pokemon.getPassengers().indexOf(entity);
|
int seatIndex = pokemon.getPassengers().indexOf(entity);
|
||||||
Seat seat = pokemon.getSeats().get(seatIndex);
|
Seat seat = pokemon.getSeats().get(seatIndex);
|
||||||
@@ -123,12 +124,14 @@ public abstract class CameraMixin {
|
|||||||
Mth.lerp(instance.getPartialTickTime(), pokemon.zOld, pokemon.getZ())
|
Mth.lerp(instance.getPartialTickTime(), pokemon.zOld, pokemon.getZ())
|
||||||
);
|
);
|
||||||
|
|
||||||
Rollable rollable = (Rollable) entity;
|
OrientationControllable rollable = (OrientationControllable) entity;
|
||||||
float currEyeHeight = Mth.lerp(instance.getPartialTickTime(), eyeHeightOld, eyeHeight);
|
float currEyeHeight = Mth.lerp(instance.getPartialTickTime(), eyeHeightOld, eyeHeight);
|
||||||
Matrix3f orientation = rollable.shouldRoll() && rollable.getOrientation() != null ? rollable.getOrientation() : new Matrix3f();
|
var controller = rollable.getOrientationController();
|
||||||
|
Matrix3f orientation = controller.isActive() && controller.getOrientation() != null ? controller.getOrientation() : new Matrix3f();
|
||||||
Vec3 rotatedEyeHeight = new Vec3(orientation.transform(new Vector3f(0f, currEyeHeight, 0f)));
|
Vec3 rotatedEyeHeight = new Vec3(orientation.transform(new Vector3f(0f, currEyeHeight, 0f)));
|
||||||
|
|
||||||
position = locatorOffset.add(entityPos).add(rotatedEyeHeight);
|
var position = locatorOffset.add(entityPos).add(rotatedEyeHeight);
|
||||||
|
setPosition(position);
|
||||||
} else {
|
} else {
|
||||||
original.call(instance, x, y, z);
|
original.call(instance, x, y, z);
|
||||||
}
|
}
|
||||||
@@ -136,16 +139,17 @@ public abstract class CameraMixin {
|
|||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private void applyRotation(){
|
private void applyRotation(){
|
||||||
if (!(this.entity instanceof Rollable rollable) || rollable.getOrientation() == null) return;
|
if (!(this.entity instanceof OrientationControllable controllable) || controllable.getOrientationController().getOrientation() == null) return;
|
||||||
var newRotation = rollable.getOrientation().normal(new Matrix3f()).getNormalizedRotation(new Quaternionf());
|
var controller = controllable.getOrientationController();
|
||||||
|
var newRotation = controller.getOrientation().normal(new Matrix3f()).getNormalizedRotation(new Quaternionf());
|
||||||
if (this.minecraft.options.getCameraType().isMirrored()) {
|
if (this.minecraft.options.getCameraType().isMirrored()) {
|
||||||
newRotation.rotateY((float)Math.toRadians(180));
|
newRotation.rotateY((float)Math.toRadians(180));
|
||||||
}
|
}
|
||||||
this.rotation.set(newRotation);
|
this.rotation.set(newRotation);
|
||||||
this.xRot = rollable.getPitch();
|
this.xRot = controller.getPitch();
|
||||||
this.yRot = rollable.getYaw();
|
this.yRot = controller.getYaw();
|
||||||
this.forwards.set(rollable.getForwardVector());
|
this.forwards.set(controller.getForwardVector());
|
||||||
this.up.set(rollable.getUpVector());
|
this.up.set(controller.getUpVector());
|
||||||
this.left.set(rollable.getLeftVector());
|
this.left.set(controller.getLeftVector());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
package com.cobblemon.mod.common.mixin.client;
|
package com.cobblemon.mod.common.mixin.client;
|
||||||
|
|
||||||
import com.cobblemon.mod.common.Rollable;
|
import com.cobblemon.mod.common.OrientationControllable;
|
||||||
import com.cobblemon.mod.common.item.PokedexItem;
|
import com.cobblemon.mod.common.item.PokedexItem;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -31,14 +31,14 @@ public class ItemInHandRendererMixin {
|
|||||||
if (abstractClientPlayer.isUsingItem() && abstractClientPlayer.getUseItem().getItem() instanceof PokedexItem) {
|
if (abstractClientPlayer.isUsingItem() && abstractClientPlayer.getUseItem().getItem() instanceof PokedexItem) {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
else if (abstractClientPlayer instanceof Rollable rollable && rollable.shouldRoll()) {
|
else if (abstractClientPlayer instanceof OrientationControllable controllable && controllable.getOrientationController().isActive()) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "renderHandsWithItems", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V", ordinal = 1))
|
@Redirect(method = "renderHandsWithItems", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V", ordinal = 1))
|
||||||
private void cobblemon$renderHandswithItems(PoseStack instance, Quaternionf quaternion) {
|
private void cobblemon$renderHandswithItems(PoseStack instance, Quaternionf quaternion) {
|
||||||
if (!(Minecraft.getInstance().player instanceof Rollable rollable && rollable.shouldRoll())) {
|
if (!(Minecraft.getInstance().player instanceof OrientationControllable controllable && controllable.getOrientationController().isActive())) {
|
||||||
instance.mulPose(quaternion);
|
instance.mulPose(quaternion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,14 @@
|
|||||||
package com.cobblemon.mod.common.mixin.client;
|
package com.cobblemon.mod.common.mixin.client;
|
||||||
|
|
||||||
import com.cobblemon.mod.common.CobblemonNetwork;
|
import com.cobblemon.mod.common.CobblemonNetwork;
|
||||||
import com.cobblemon.mod.common.Rollable;
|
import com.cobblemon.mod.common.OrientationControllable;
|
||||||
import com.cobblemon.mod.common.net.messages.server.orientation.C2SUpdateOrientationPacket;
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
||||||
|
import com.cobblemon.mod.common.net.messages.server.orientation.ServerboundUpdateOrientationPacket;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import net.minecraft.world.entity.EntityType;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
import org.joml.Matrix3f;
|
import org.joml.Matrix3f;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
@@ -20,24 +25,55 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(LocalPlayer.class)
|
@Mixin(LocalPlayer.class)
|
||||||
public class LocalPlayerMixin {
|
public abstract class LocalPlayerMixin extends LivingEntity {
|
||||||
|
|
||||||
@Unique Matrix3f cobblemon$lastOrientation;
|
@Unique Matrix3f cobblemon$lastOrientation;
|
||||||
|
|
||||||
@Inject(method = "sendPosition", at = @At("TAIL"))
|
protected LocalPlayerMixin(EntityType<? extends LivingEntity> entityType, Level level) {
|
||||||
private void cobblemon_updateRotationMatrix(CallbackInfo ci) {
|
super(entityType, level);
|
||||||
if (!(this instanceof Rollable rollable)) return;
|
|
||||||
if (rollable.getOrientation() == cobblemon$lastOrientation) return;
|
|
||||||
cobblemon$lastOrientation = rollable.getOrientation() != null ? new Matrix3f(rollable.getOrientation()) : null;
|
|
||||||
CobblemonNetwork.INSTANCE.sendToServer(new C2SUpdateOrientationPacket(rollable.getOrientation()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Inject(method = "sendPosition", at = @At("TAIL"))
|
||||||
|
// private void cobblemon$updateRotationMatrix(CallbackInfo ci) {
|
||||||
|
// if (!(this instanceof OrientationControllable controllable)) return;
|
||||||
|
// var controller = controllable.getOrientationController();
|
||||||
|
// if (!controller.isActive() || controller.getOrientation() == cobblemon$lastOrientation) return;
|
||||||
|
// cobblemon$lastOrientation = controller.getOrientation() != null ? new Matrix3f(controller.getOrientation()) : null;
|
||||||
|
// CobblemonNetwork.INSTANCE.sendToServer(new ServerboundUpdateOrientationPacket(controller.getOrientation()));
|
||||||
|
// }
|
||||||
|
|
||||||
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientPacketListener;send(Lnet/minecraft/network/protocol/Packet;)V"))
|
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientPacketListener;send(Lnet/minecraft/network/protocol/Packet;)V"))
|
||||||
private void cobblemon_updateRotationMatrixPassenger(CallbackInfo ci) {
|
private void cobblemon$updateRotationMatrixPassenger(CallbackInfo ci) {
|
||||||
if (!(this instanceof Rollable rollable)) return;
|
if (!(this instanceof OrientationControllable controllable)) return;
|
||||||
if (rollable.getOrientation() == cobblemon$lastOrientation) return;
|
var controller = controllable.getOrientationController();
|
||||||
cobblemon$lastOrientation = rollable.getOrientation() != null ? new Matrix3f(rollable.getOrientation()) : null;
|
if (!controller.isActive() || controller.getOrientation() == cobblemon$lastOrientation) return;
|
||||||
CobblemonNetwork.INSTANCE.sendToServer(new C2SUpdateOrientationPacket(rollable.getOrientation()));
|
cobblemon$lastOrientation = controller.getOrientation() != null ? new Matrix3f(controller.getOrientation()) : null;
|
||||||
|
CobblemonNetwork.INSTANCE.sendToServer(new ServerboundUpdateOrientationPacket(controller.getOrientation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "rideTick", at = @At("HEAD"))
|
||||||
|
private void cobblemon$updateOrientationControllerRideTick(CallbackInfo ci) {
|
||||||
|
if (Minecraft.getInstance().player != (Object)this) return;
|
||||||
|
if (!(this instanceof OrientationControllable controllable)) return;
|
||||||
|
var shouldUseCustomOrientation = cobblemon$shouldUseCustomOrientation((LocalPlayer)(Object)this);
|
||||||
|
controllable.getOrientationController().setActive(shouldUseCustomOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private boolean cobblemon$shouldUseCustomOrientation(LocalPlayer player) {
|
||||||
|
var playerVehicle = player.getVehicle();
|
||||||
|
if (playerVehicle == null) return false;
|
||||||
|
if (!(playerVehicle instanceof PokemonEntity pokemonEntity)) return false;
|
||||||
|
return pokemonEntity.ifRidingAvailableSupply(false, (behaviour, settings, state) -> {
|
||||||
|
return behaviour.shouldRoll(settings, state, pokemonEntity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopRiding() {
|
||||||
|
super.stopRiding();
|
||||||
|
if (Minecraft.getInstance().player != (Object)this) return;
|
||||||
|
if (!(this instanceof OrientationControllable controllable)) return;
|
||||||
|
controllable.getOrientationController().setActive(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+108
-10
@@ -8,9 +8,10 @@
|
|||||||
|
|
||||||
package com.cobblemon.mod.common.mixin.client;
|
package com.cobblemon.mod.common.mixin.client;
|
||||||
|
|
||||||
import com.cobblemon.mod.common.Rollable;
|
import com.cobblemon.mod.common.OrientationControllable;
|
||||||
import com.cobblemon.mod.common.client.CobblemonClient;
|
import com.cobblemon.mod.common.client.CobblemonClient;
|
||||||
import com.cobblemon.mod.common.client.keybind.keybinds.PartySendBinding;
|
import com.cobblemon.mod.common.client.keybind.keybinds.PartySendBinding;
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
||||||
import com.cobblemon.mod.common.pokedex.scanner.PokedexUsageContext;
|
import com.cobblemon.mod.common.pokedex.scanner.PokedexUsageContext;
|
||||||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
@@ -19,6 +20,7 @@ import net.minecraft.client.MouseHandler;
|
|||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.util.SmoothDouble;
|
import net.minecraft.util.SmoothDouble;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@@ -33,8 +35,11 @@ public class MouseHandlerMixin {
|
|||||||
@Shadow private double accumulatedScrollY;
|
@Shadow private double accumulatedScrollY;
|
||||||
@Shadow @Final private Minecraft minecraft;
|
@Shadow @Final private Minecraft minecraft;
|
||||||
|
|
||||||
|
@Unique SmoothDouble xMouseSmoother = new SmoothDouble();
|
||||||
|
@Unique SmoothDouble yMouseSmoother = new SmoothDouble();
|
||||||
@Unique SmoothDouble pitchSmoother = new SmoothDouble();
|
@Unique SmoothDouble pitchSmoother = new SmoothDouble();
|
||||||
@Unique SmoothDouble rollSmoother = new SmoothDouble();
|
@Unique SmoothDouble rollSmoother = new SmoothDouble();
|
||||||
|
@Unique SmoothDouble yawSmoother = new SmoothDouble();
|
||||||
|
|
||||||
@Shadow @Final private SmoothDouble smoothTurnY;
|
@Shadow @Final private SmoothDouble smoothTurnY;
|
||||||
|
|
||||||
@@ -95,7 +100,13 @@ public class MouseHandlerMixin {
|
|||||||
target = "Lnet/minecraft/client/player/LocalPlayer;turn(DD)V"
|
target = "Lnet/minecraft/client/player/LocalPlayer;turn(DD)V"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
public boolean cobblemon$modifyRotation(LocalPlayer player, double cursorDeltaX, double cursorDeltaY, @Local(argsOnly = true) double d) {
|
public boolean cobblemon$modifyRotation(
|
||||||
|
LocalPlayer player,
|
||||||
|
double cursorDeltaX,
|
||||||
|
double cursorDeltaY,
|
||||||
|
@Local(argsOnly = true) double d,
|
||||||
|
@Local(argsOnly = true) double movementTime
|
||||||
|
) {
|
||||||
PokedexUsageContext usageContext = CobblemonClient.INSTANCE.getPokedexUsageContext();
|
PokedexUsageContext usageContext = CobblemonClient.INSTANCE.getPokedexUsageContext();
|
||||||
if (usageContext.getScanningGuiOpen()) {
|
if (usageContext.getScanningGuiOpen()) {
|
||||||
this.smoothTurnY.reset();
|
this.smoothTurnY.reset();
|
||||||
@@ -108,29 +119,116 @@ public class MouseHandlerMixin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(player instanceof Rollable rollable)) return true;
|
if (!(player instanceof OrientationControllable controllable)) return true;
|
||||||
if (!rollable.shouldRoll()) {
|
|
||||||
|
if (!controllable.getOrientationController().isActive()) {
|
||||||
|
xMouseSmoother.reset();
|
||||||
|
yMouseSmoother.reset();
|
||||||
pitchSmoother.reset();
|
pitchSmoother.reset();
|
||||||
rollSmoother.reset();
|
rollSmoother.reset();
|
||||||
|
yawSmoother.reset();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pitch = pitchSmoother.getNewDeltaValue(cursorDeltaY * 0.15f, d);
|
//Send mouse input to be interpreted into rotation
|
||||||
var roll = rollSmoother.getNewDeltaValue(cursorDeltaX * 0.15f, d);
|
//deltas by the ride controller
|
||||||
rollable.rotate(0.0F, (float)pitch, (float)roll);
|
Vec3 angVecMouse = cobblemon$getRideMouseRotation(cursorDeltaX, cursorDeltaY, movementTime);
|
||||||
|
|
||||||
|
//Perform Rotation using mouse influenced rotation deltas.
|
||||||
|
controllable.getOrientationController().rotate(
|
||||||
|
(float) angVecMouse.x,
|
||||||
|
(float) angVecMouse.y,
|
||||||
|
(float) angVecMouse.z
|
||||||
|
);
|
||||||
|
|
||||||
|
//Gather and apply the current rotation deltas
|
||||||
|
var angRot = cobblemon$getAngularVelocity(movementTime);
|
||||||
|
|
||||||
|
//Apply smoothing if requested by the controller.
|
||||||
|
//This Might be best if done by the controller itself?
|
||||||
|
if(cobblemon$shouldUseAngVelSmoothing())
|
||||||
|
{
|
||||||
|
var yaw = yawSmoother.getNewDeltaValue(angRot.x * 0.5f, d);
|
||||||
|
var pitch = pitchSmoother.getNewDeltaValue(angRot.y * 0.5f, d);
|
||||||
|
var roll = rollSmoother.getNewDeltaValue(angRot.z * 0.5f, d);
|
||||||
|
controllable.getOrientationController().rotate((float) yaw, (float) pitch, (float) roll);
|
||||||
|
}
|
||||||
|
//Otherwise simply apply the smoothing
|
||||||
|
else
|
||||||
|
{
|
||||||
|
controllable.getOrientationController().rotate((float) (angRot.x * 10 * d), (float) (angRot.y * 10 * d), (float) (angRot.z * 10 * d));
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "handleAccumulatedMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MouseHandler;isMouseGrabbed()Z", ordinal = 0))
|
@Inject(method = "handleAccumulatedMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MouseHandler;isMouseGrabbed()Z", ordinal = 0))
|
||||||
private void cobblemon$maintainMovementWhenInScreens(CallbackInfo ci, @Local(ordinal = 1) double e) {
|
private void cobblemon$maintainMovementWhenInScreens(CallbackInfo ci, @Local(ordinal = 1) double e) {
|
||||||
if (minecraft.player == null) return;
|
if (minecraft.player == null) return;
|
||||||
if (!(minecraft.player instanceof Rollable rollable)) return;
|
if (!(minecraft.player instanceof OrientationControllable controllable)) return;
|
||||||
if (!rollable.shouldRoll()) return;
|
if (!controllable.getOrientationController().isActive()) return;
|
||||||
if (minecraft.isPaused()) return;
|
if (minecraft.isPaused()) return;
|
||||||
|
|
||||||
var pitch = pitchSmoother.getNewDeltaValue(0, e);
|
var pitch = pitchSmoother.getNewDeltaValue(0, e);
|
||||||
var roll = rollSmoother.getNewDeltaValue(0, e);
|
var roll = rollSmoother.getNewDeltaValue(0, e);
|
||||||
rollable.rotate(0.0F, (float)pitch, (float)roll);
|
controllable.getOrientationController().rotate(0.0F, (float)pitch, (float)roll);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private Vec3 cobblemon$getAngularVelocity(double deltaTime) {
|
||||||
|
var player = minecraft.player;
|
||||||
|
if (player == null) return Vec3.ZERO;
|
||||||
|
if (!(player instanceof OrientationControllable)) return Vec3.ZERO;
|
||||||
|
|
||||||
|
var playerVehicle = player.getVehicle();
|
||||||
|
if (playerVehicle == null) return Vec3.ZERO;
|
||||||
|
if (!(playerVehicle instanceof PokemonEntity pokemonEntity)) return Vec3.ZERO;
|
||||||
|
return pokemonEntity.ifRidingAvailableSupply(Vec3.ZERO, (behaviour, settings, state) -> {
|
||||||
|
return behaviour.angRollVel(settings, state, pokemonEntity, player, deltaTime);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private Vec3 cobblemon$getRideMouseRotation(double mouseX, double mouseY, double deltaTime) {
|
||||||
|
var player = minecraft.player;
|
||||||
|
if (player == null) return Vec3.ZERO;
|
||||||
|
var vehicle = player.getVehicle();
|
||||||
|
if (vehicle == null) return Vec3.ZERO;
|
||||||
|
if (!(vehicle instanceof PokemonEntity pokemonEntity)) return Vec3.ZERO;
|
||||||
|
|
||||||
|
var sensitivity = cobblemon$getRidingSensitivity();
|
||||||
|
return pokemonEntity.ifRidingAvailableSupply(Vec3.ZERO, (behaviour, settings, state) -> {
|
||||||
|
return behaviour.rotationOnMouseXY(
|
||||||
|
settings,
|
||||||
|
state,
|
||||||
|
pokemonEntity,
|
||||||
|
player,
|
||||||
|
mouseY,
|
||||||
|
mouseX,
|
||||||
|
yMouseSmoother,
|
||||||
|
xMouseSmoother,
|
||||||
|
sensitivity,
|
||||||
|
deltaTime
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private double cobblemon$getRidingSensitivity() {
|
||||||
|
var sensitivity = this.minecraft.options.sensitivity().get() * 0.6000000238418579 + 0.20000000298023224;
|
||||||
|
return Math.pow(sensitivity, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private boolean cobblemon$shouldUseAngVelSmoothing() {
|
||||||
|
var player = minecraft.player;
|
||||||
|
if (player == null) return true;
|
||||||
|
|
||||||
|
var playerVehicle = player.getVehicle();
|
||||||
|
if (playerVehicle == null) return true;
|
||||||
|
if (!(playerVehicle instanceof PokemonEntity pokemonEntity)) return true;
|
||||||
|
return pokemonEntity.ifRidingAvailableSupply(true, (behaviour, settings, state) -> {
|
||||||
|
return behaviour.useAngVelSmoothing(settings, state, pokemonEntity);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package com.cobblemon.mod.common.mixin.client;
|
package com.cobblemon.mod.common.mixin.client;
|
||||||
import com.cobblemon.mod.common.api.riding.Rideable;
|
|
||||||
import com.cobblemon.mod.common.api.riding.RidingManager;
|
|
||||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
||||||
import net.minecraft.client.model.PlayerModel;
|
import net.minecraft.client.model.PlayerModel;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
@@ -22,13 +21,16 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
@Mixin(PlayerModel.class)
|
@Mixin(PlayerModel.class)
|
||||||
public class PlayerModelMixin {
|
public class PlayerModelMixin {
|
||||||
@Inject(method = "setupAnim(Lnet/minecraft/world/entity/LivingEntity;FFFFF)V", at = @At(value = "HEAD"))
|
@Inject(method = "setupAnim(Lnet/minecraft/world/entity/LivingEntity;FFFFF)V", at = @At(value = "HEAD"))
|
||||||
private void cobblemon$setHeadRotation(LivingEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, CallbackInfo ci){
|
private void cobblemon$setHeadRotation(LivingEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, CallbackInfo ci) {
|
||||||
if (!(entity instanceof Player)) return;
|
if (!(entity instanceof Player)) return;
|
||||||
Entity vehicle = entity.getVehicle();
|
Entity vehicle = entity.getVehicle();
|
||||||
|
|
||||||
if (!(vehicle instanceof PokemonEntity)) return;
|
if (!(vehicle instanceof PokemonEntity pokemonEntity)) return;
|
||||||
RidingManager ridingManager = ((Rideable) vehicle).getRiding();
|
|
||||||
if (ridingManager.shouldRotatePlayerHead((PokemonEntity) vehicle)) return;
|
var shouldRotatePlayerHead = pokemonEntity.ifRidingAvailableSupply(false, (behaviour, settings, state) -> {
|
||||||
|
return behaviour.shouldRotatePlayerHead(settings, state, pokemonEntity);
|
||||||
|
});
|
||||||
|
if (shouldRotatePlayerHead) return;
|
||||||
|
|
||||||
netHeadYaw = 0f;
|
netHeadYaw = 0f;
|
||||||
headPitch = 0f;
|
headPitch = 0f;
|
||||||
|
|||||||
+28
-1
@@ -11,9 +11,15 @@ package com.cobblemon.mod.common.mixin.client;
|
|||||||
import com.cobblemon.mod.common.client.render.ClientPlayerIcon;
|
import com.cobblemon.mod.common.client.render.ClientPlayerIcon;
|
||||||
import com.cobblemon.mod.common.client.render.player.MountedPlayerRenderer;
|
import com.cobblemon.mod.common.client.render.player.MountedPlayerRenderer;
|
||||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import net.minecraft.client.model.EntityModel;
|
||||||
|
import net.minecraft.client.model.PlayerModel;
|
||||||
import net.minecraft.client.player.AbstractClientPlayer;
|
import net.minecraft.client.player.AbstractClientPlayer;
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
|
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
|
||||||
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
|
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -23,12 +29,33 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(PlayerRenderer.class)
|
@Mixin(PlayerRenderer.class)
|
||||||
public class PlayerRendererMixin {
|
public abstract class PlayerRendererMixin extends LivingEntityRenderer<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> {
|
||||||
|
|
||||||
|
public PlayerRendererMixin(EntityRendererProvider.Context context, PlayerModel<AbstractClientPlayer> model, float shadowRadius) {
|
||||||
|
super(context, model, shadowRadius);
|
||||||
|
}
|
||||||
|
|
||||||
@Inject(method = "render(Lnet/minecraft/world/entity/LivingEntity;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "TAIL"))
|
@Inject(method = "render(Lnet/minecraft/world/entity/LivingEntity;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "TAIL"))
|
||||||
public void cobblemon$clientPlayerIcon(LivingEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight, CallbackInfo ci) {
|
public void cobblemon$clientPlayerIcon(LivingEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight, CallbackInfo ci) {
|
||||||
ClientPlayerIcon.Companion.onRenderPlayer((Player) entity);
|
ClientPlayerIcon.Companion.onRenderPlayer((Player) entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WrapOperation(method = "getRenderOffset(Lnet/minecraft/client/player/AbstractClientPlayer;F)Lnet/minecraft/world/phys/Vec3;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/AbstractClientPlayer;isCrouching()Z"))
|
||||||
|
private boolean cobblemon$disableCrouchOffset(AbstractClientPlayer instance, Operation<Boolean> original) {
|
||||||
|
if (instance.isPassenger() && instance.getVehicle() instanceof PokemonEntity) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return original.call(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "setModelProperties", at = @At("TAIL"))
|
||||||
|
private void cobblemon$setModelProperties(AbstractClientPlayer player, CallbackInfo ci) {
|
||||||
|
if (player.isPassenger() && player.getVehicle() instanceof PokemonEntity) {
|
||||||
|
PlayerModel<AbstractClientPlayer> playerModel = this.getModel();
|
||||||
|
playerModel.crouching = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "setupRotations(Lnet/minecraft/client/player/AbstractClientPlayer;Lcom/mojang/blaze3d/vertex/PoseStack;FFFF)V",
|
method = "setupRotations(Lnet/minecraft/client/player/AbstractClientPlayer;Lcom/mojang/blaze3d/vertex/PoseStack;FFFF)V",
|
||||||
at = @At("HEAD")
|
at = @At("HEAD")
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.cobblemon.mod.common.api.drop.ItemDropEntry
|
|||||||
import com.cobblemon.mod.common.api.events.CobblemonEvents
|
import com.cobblemon.mod.common.api.events.CobblemonEvents
|
||||||
import com.cobblemon.mod.common.api.events.CobblemonEvents.DATA_SYNCHRONIZED
|
import com.cobblemon.mod.common.api.events.CobblemonEvents.DATA_SYNCHRONIZED
|
||||||
import com.cobblemon.mod.common.api.interaction.RequestManager
|
import com.cobblemon.mod.common.api.interaction.RequestManager
|
||||||
|
import com.cobblemon.mod.common.api.molang.ObjectValue
|
||||||
import com.cobblemon.mod.common.api.permission.PermissionValidator
|
import com.cobblemon.mod.common.api.permission.PermissionValidator
|
||||||
import com.cobblemon.mod.common.api.pokeball.catching.calculators.CaptureCalculator
|
import com.cobblemon.mod.common.api.pokeball.catching.calculators.CaptureCalculator
|
||||||
import com.cobblemon.mod.common.api.pokeball.catching.calculators.CaptureCalculators
|
import com.cobblemon.mod.common.api.pokeball.catching.calculators.CaptureCalculators
|
||||||
@@ -62,7 +63,11 @@ import com.cobblemon.mod.common.api.storage.player.adapter.PlayerDataMongoBacken
|
|||||||
import com.cobblemon.mod.common.api.storage.player.factory.CachedPlayerDataStoreFactory
|
import com.cobblemon.mod.common.api.storage.player.factory.CachedPlayerDataStoreFactory
|
||||||
import com.cobblemon.mod.common.api.tags.CobblemonEntityTypeTags
|
import com.cobblemon.mod.common.api.tags.CobblemonEntityTypeTags
|
||||||
import com.cobblemon.mod.common.api.tags.CobblemonItemTags
|
import com.cobblemon.mod.common.api.tags.CobblemonItemTags
|
||||||
import com.cobblemon.mod.common.battles.*
|
import com.cobblemon.mod.common.battles.BagItems
|
||||||
|
import com.cobblemon.mod.common.battles.BattleFormat
|
||||||
|
import com.cobblemon.mod.common.battles.BattleRegistry
|
||||||
|
import com.cobblemon.mod.common.battles.BattleSide
|
||||||
|
import com.cobblemon.mod.common.battles.ShowdownThread
|
||||||
import com.cobblemon.mod.common.battles.actor.PokemonBattleActor
|
import com.cobblemon.mod.common.battles.actor.PokemonBattleActor
|
||||||
import com.cobblemon.mod.common.battles.pokemon.BattlePokemon
|
import com.cobblemon.mod.common.battles.pokemon.BattlePokemon
|
||||||
import com.cobblemon.mod.common.client.CobblemonPack
|
import com.cobblemon.mod.common.client.CobblemonPack
|
||||||
@@ -86,11 +91,23 @@ import com.cobblemon.mod.common.pokemon.aspects.SHINY_ASPECT
|
|||||||
import com.cobblemon.mod.common.pokemon.evolution.variants.BlockClickEvolution
|
import com.cobblemon.mod.common.pokemon.evolution.variants.BlockClickEvolution
|
||||||
import com.cobblemon.mod.common.pokemon.feature.TagSeasonResolver
|
import com.cobblemon.mod.common.pokemon.feature.TagSeasonResolver
|
||||||
import com.cobblemon.mod.common.pokemon.helditem.CobblemonHeldItemManager
|
import com.cobblemon.mod.common.pokemon.helditem.CobblemonHeldItemManager
|
||||||
import com.cobblemon.mod.common.pokemon.properties.*
|
import com.cobblemon.mod.common.pokemon.properties.AspectPropertyType
|
||||||
|
import com.cobblemon.mod.common.pokemon.properties.BattleCloneProperty
|
||||||
|
import com.cobblemon.mod.common.pokemon.properties.FreezeFrameProperty
|
||||||
|
import com.cobblemon.mod.common.pokemon.properties.HiddenAbilityPropertyType
|
||||||
|
import com.cobblemon.mod.common.pokemon.properties.NoAIProperty
|
||||||
|
import com.cobblemon.mod.common.pokemon.properties.UnaspectPropertyType
|
||||||
|
import com.cobblemon.mod.common.pokemon.properties.UncatchableProperty
|
||||||
import com.cobblemon.mod.common.pokemon.properties.tags.PokemonFlagProperty
|
import com.cobblemon.mod.common.pokemon.properties.tags.PokemonFlagProperty
|
||||||
import com.cobblemon.mod.common.pokemon.stat.CobblemonStatProvider
|
import com.cobblemon.mod.common.pokemon.stat.CobblemonStatProvider
|
||||||
import com.cobblemon.mod.common.starter.CobblemonStarterHandler
|
import com.cobblemon.mod.common.starter.CobblemonStarterHandler
|
||||||
import com.cobblemon.mod.common.util.*
|
import com.cobblemon.mod.common.util.DataKeys
|
||||||
|
import com.cobblemon.mod.common.util.cobblemonResource
|
||||||
|
import com.cobblemon.mod.common.util.ifDedicatedServer
|
||||||
|
import com.cobblemon.mod.common.util.isLaterVersion
|
||||||
|
import com.cobblemon.mod.common.util.party
|
||||||
|
import com.cobblemon.mod.common.util.requestWallpapers
|
||||||
|
import com.cobblemon.mod.common.util.server
|
||||||
import com.cobblemon.mod.common.world.feature.CobblemonPlacedFeatures
|
import com.cobblemon.mod.common.world.feature.CobblemonPlacedFeatures
|
||||||
import com.cobblemon.mod.common.world.feature.ore.CobblemonOrePlacedFeatures
|
import com.cobblemon.mod.common.world.feature.ore.CobblemonOrePlacedFeatures
|
||||||
import com.cobblemon.mod.common.world.gamerules.CobblemonGameRules
|
import com.cobblemon.mod.common.world.gamerules.CobblemonGameRules
|
||||||
@@ -98,27 +115,29 @@ import com.mongodb.ConnectionString
|
|||||||
import com.mongodb.MongoClientSettings
|
import com.mongodb.MongoClientSettings
|
||||||
import com.mongodb.client.MongoClient
|
import com.mongodb.client.MongoClient
|
||||||
import com.mongodb.client.MongoClients
|
import com.mongodb.client.MongoClients
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileReader
|
||||||
|
import java.io.FileWriter
|
||||||
|
import java.io.PrintWriter
|
||||||
|
import java.util.UUID
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
import kotlin.properties.Delegates
|
||||||
|
import kotlin.reflect.full.memberProperties
|
||||||
|
import kotlin.reflect.jvm.isAccessible
|
||||||
|
import kotlin.reflect.jvm.javaField
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.commands.synchronization.SingletonArgumentInfo
|
import net.minecraft.commands.synchronization.SingletonArgumentInfo
|
||||||
import net.minecraft.resources.ResourceKey
|
import net.minecraft.resources.ResourceKey
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
import net.minecraft.server.level.ServerPlayer
|
import net.minecraft.server.level.ServerPlayer
|
||||||
import net.minecraft.server.packs.PackType
|
import net.minecraft.server.packs.PackType
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.item.NameTagItem
|
import net.minecraft.world.item.NameTagItem
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.storage.LevelResource
|
import net.minecraft.world.level.storage.LevelResource
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import org.apache.logging.log4j.Logger
|
import org.apache.logging.log4j.Logger
|
||||||
import java.io.File
|
|
||||||
import java.io.FileReader
|
|
||||||
import java.io.FileWriter
|
|
||||||
import java.io.PrintWriter
|
|
||||||
import java.util.*
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
import kotlin.properties.Delegates
|
|
||||||
import kotlin.reflect.full.memberProperties
|
|
||||||
import kotlin.reflect.jvm.isAccessible
|
|
||||||
import kotlin.reflect.jvm.javaField
|
|
||||||
|
|
||||||
object Cobblemon {
|
object Cobblemon {
|
||||||
const val MODID = CobblemonBuildDetails.MOD_ID
|
const val MODID = CobblemonBuildDetails.MOD_ID
|
||||||
@@ -152,7 +171,9 @@ object Cobblemon {
|
|||||||
var permissionValidator: PermissionValidator by Delegates.observable(LaxPermissionValidator().also { it.initialize() }) { _, _, newValue -> newValue.initialize() }
|
var permissionValidator: PermissionValidator by Delegates.observable(LaxPermissionValidator().also { it.initialize() }) { _, _, newValue -> newValue.initialize() }
|
||||||
var statProvider: StatProvider = CobblemonStatProvider
|
var statProvider: StatProvider = CobblemonStatProvider
|
||||||
var seasonResolver: SeasonResolver = TagSeasonResolver
|
var seasonResolver: SeasonResolver = TagSeasonResolver
|
||||||
var wallpapers = mapOf<UUID, List<ResourceLocation>>()
|
var wallpapers = mutableMapOf<UUID, Set<ResourceLocation>>()
|
||||||
|
|
||||||
|
val serverPlayerStructs = mutableMapOf<UUID, ObjectValue<Player>>()
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val builtinPacks = listOf<CobblemonPack>(
|
val builtinPacks = listOf<CobblemonPack>(
|
||||||
@@ -218,6 +239,7 @@ object Cobblemon {
|
|||||||
storage.onPlayerDisconnect(it.player)
|
storage.onPlayerDisconnect(it.player)
|
||||||
playerDataManager.onPlayerDisconnect(it.player)
|
playerDataManager.onPlayerDisconnect(it.player)
|
||||||
RequestManager.onLogoff(it.player)
|
RequestManager.onLogoff(it.player)
|
||||||
|
serverPlayerStructs.remove(it.player.uuid)
|
||||||
}
|
}
|
||||||
PlatformEvents.PLAYER_DEATH.subscribe {
|
PlatformEvents.PLAYER_DEATH.subscribe {
|
||||||
PCLinkManager.removeLink(it.player.uuid)
|
PCLinkManager.removeLink(it.player.uuid)
|
||||||
@@ -387,9 +409,11 @@ object Cobblemon {
|
|||||||
PlatformEvents.SERVER_STOPPED.subscribe {
|
PlatformEvents.SERVER_STOPPED.subscribe {
|
||||||
storage.unregisterAll(it.server.registryAccess())
|
storage.unregisterAll(it.server.registryAccess())
|
||||||
playerDataManager.saveAllStores()
|
playerDataManager.saveAllStores()
|
||||||
|
playerDataManager.saveExecutor.shutdown()
|
||||||
|
playerDataManager.saveExecutor.awaitTermination(30L, TimeUnit.SECONDS)
|
||||||
}
|
}
|
||||||
PlatformEvents.SERVER_STARTED.subscribe {
|
PlatformEvents.SERVER_STARTED.subscribe { event ->
|
||||||
bestSpawner.onServerStarted()
|
bestSpawner.onServerStarted(event.server)
|
||||||
battleRegistry.onServerStarted()
|
battleRegistry.onServerStarted()
|
||||||
}
|
}
|
||||||
PlatformEvents.SERVER_TICK_POST.subscribe { ServerTickHandler.onTick(it.server) }
|
PlatformEvents.SERVER_TICK_POST.subscribe { ServerTickHandler.onTick(it.server) }
|
||||||
@@ -537,6 +561,10 @@ object Cobblemon {
|
|||||||
this.implementation.registerCommandArgument(cobblemonResource("form"), FormArgumentType::class, SingletonArgumentInfo.contextFree(FormArgumentType::form))
|
this.implementation.registerCommandArgument(cobblemonResource("form"), FormArgumentType::class, SingletonArgumentInfo.contextFree(FormArgumentType::form))
|
||||||
this.implementation.registerCommandArgument(cobblemonResource("dex"), DexArgumentType::class, SingletonArgumentInfo.contextFree (DexArgumentType::dex))
|
this.implementation.registerCommandArgument(cobblemonResource("dex"), DexArgumentType::class, SingletonArgumentInfo.contextFree (DexArgumentType::dex))
|
||||||
this.implementation.registerCommandArgument(cobblemonResource("npc_class"), NPCClassArgumentType::class, SingletonArgumentInfo.contextFree(NPCClassArgumentType::npcClass))
|
this.implementation.registerCommandArgument(cobblemonResource("npc_class"), NPCClassArgumentType::class, SingletonArgumentInfo.contextFree(NPCClassArgumentType::npcClass))
|
||||||
|
this.implementation.registerCommandArgument(cobblemonResource("wallpaper"), UnlockablePCBoxWallpaperArgumentType::class, SingletonArgumentInfo.contextFree(UnlockablePCBoxWallpaperArgumentType::wallpaper))
|
||||||
|
this.implementation.registerCommandArgument(cobblemonResource("mark"), MarkArgumentType::class, SingletonArgumentInfo.contextFree(MarkArgumentType::mark))
|
||||||
|
this.implementation.registerCommandArgument(cobblemonResource("transform_type"), TransformTypeArgumentType::class, SingletonArgumentInfo.contextFree(TransformTypeArgumentType::transformType))
|
||||||
|
this.implementation.registerCommandArgument(cobblemonResource("model_part"), ModelPartArgumentType::class, SingletonArgumentInfo.contextFree(ModelPartArgumentType::modelPart))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ object CobblemonCommands {
|
|||||||
ChangeEyeHeight.register(dispatcher)
|
ChangeEyeHeight.register(dispatcher)
|
||||||
ChangeScaleAndSize.register(dispatcher)
|
ChangeScaleAndSize.register(dispatcher)
|
||||||
ChangeWalkSpeed.register(dispatcher)
|
ChangeWalkSpeed.register(dispatcher)
|
||||||
ChangeJointScaleCommand.register(dispatcher)
|
TransformModelPartCommand.register(dispatcher)
|
||||||
TestCommand.register(dispatcher)
|
TestCommand.register(dispatcher)
|
||||||
ReloadShowdownCommand.register(dispatcher)
|
ReloadShowdownCommand.register(dispatcher)
|
||||||
ClickTextCommand.register(dispatcher)
|
ClickTextCommand.register(dispatcher)
|
||||||
@@ -60,10 +60,17 @@ object CobblemonCommands {
|
|||||||
RenameBoxCommand.register(dispatcher)
|
RenameBoxCommand.register(dispatcher)
|
||||||
ChangeBoxWallpaperCommand.register(dispatcher)
|
ChangeBoxWallpaperCommand.register(dispatcher)
|
||||||
RunMolangScriptCommand.register(dispatcher)
|
RunMolangScriptCommand.register(dispatcher)
|
||||||
|
SpectateBattleCommand.register(dispatcher)
|
||||||
CobblemonConfigCommand.register(dispatcher)
|
CobblemonConfigCommand.register(dispatcher)
|
||||||
|
UnlockPCBoxWallpaperCommand.register(dispatcher)
|
||||||
|
ChangePCBoxesCommand.register(dispatcher)
|
||||||
|
MarkGiveCommand.register(dispatcher)
|
||||||
|
MarkTakeCommand.register(dispatcher)
|
||||||
|
MarkGiveAllCommand.register(dispatcher)
|
||||||
|
|
||||||
// Possibly lock down registration if and only if under dev environment or running in an environment
|
// Possibly lock down registration if and only if under dev environment or running in an environment
|
||||||
// with a certain system environment variable set
|
// with a certain system environment variable set
|
||||||
CobblemonInfoCommand.register(dispatcher)
|
CobblemonInfoCommand.register(dispatcher)
|
||||||
|
CalculateSeatPositionCommand.register(dispatcher)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,6 +99,9 @@ object CobblemonFlows : DataRegistry {
|
|||||||
runtime.environment.query.addFunction("cancel") { cancelable }
|
runtime.environment.query.addFunction("cancel") { cancelable }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Most places in the mod use query structs so it's probably nicer to present the things as query values.
|
||||||
|
context.forEach { (key, value) -> runtime.environment.query.addFunction(key) { return@addFunction value } }
|
||||||
|
|
||||||
functions.forEach { (name, function) -> runtime.environment.query.addFunction(name, function) }
|
functions.forEach { (name, function) -> runtime.environment.query.addFunction(name, function) }
|
||||||
|
|
||||||
flows[eventResourceLocation]?.forEach {
|
flows[eventResourceLocation]?.forEach {
|
||||||
|
|||||||
@@ -1278,6 +1278,7 @@ object CobblemonItems : PlatformRegistry<Registry<Item>, ResourceKey<Registry<It
|
|||||||
CobblemonHeldItemManager.registerRemap(it, remappedName)
|
CobblemonHeldItemManager.registerRemap(it, remappedName)
|
||||||
CobblemonHeldItemManager.registerRemap(Items.BONE, "thickclub")
|
CobblemonHeldItemManager.registerRemap(Items.BONE, "thickclub")
|
||||||
CobblemonHeldItemManager.registerRemap(Items.SNOWBALL, "snowball")
|
CobblemonHeldItemManager.registerRemap(Items.SNOWBALL, "snowball")
|
||||||
|
CobblemonHeldItemManager.registerRemap(Items.GOLD_BLOCK, "bignugget")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
package com.cobblemon.mod.common
|
package com.cobblemon.mod.common
|
||||||
|
|
||||||
import com.cobblemon.mod.common.api.net.NetworkPacket
|
import com.cobblemon.mod.common.api.net.NetworkPacket
|
||||||
|
import com.cobblemon.mod.common.client.net.CalculateSeatPositionsHandler
|
||||||
import com.cobblemon.mod.common.client.net.PlayerInteractOptionsHandler
|
import com.cobblemon.mod.common.client.net.PlayerInteractOptionsHandler
|
||||||
import com.cobblemon.mod.common.client.net.SetClientPlayerDataHandler
|
import com.cobblemon.mod.common.client.net.SetClientPlayerDataHandler
|
||||||
import com.cobblemon.mod.common.client.net.animation.PlayPosableAnimationHandler
|
import com.cobblemon.mod.common.client.net.animation.PlayPosableAnimationHandler
|
||||||
@@ -28,11 +29,13 @@ import com.cobblemon.mod.common.client.net.gui.PokedexUIPacketHandler
|
|||||||
import com.cobblemon.mod.common.client.net.gui.SummaryUIPacketHandler
|
import com.cobblemon.mod.common.client.net.gui.SummaryUIPacketHandler
|
||||||
import com.cobblemon.mod.common.client.net.npc.CloseNPCEditorHandler
|
import com.cobblemon.mod.common.client.net.npc.CloseNPCEditorHandler
|
||||||
import com.cobblemon.mod.common.client.net.npc.OpenNPCEditorHandler
|
import com.cobblemon.mod.common.client.net.npc.OpenNPCEditorHandler
|
||||||
|
import com.cobblemon.mod.common.client.net.orientation.S2CUpdateOrientationHandler
|
||||||
import com.cobblemon.mod.common.client.net.pasture.ClosePastureHandler
|
import com.cobblemon.mod.common.client.net.pasture.ClosePastureHandler
|
||||||
import com.cobblemon.mod.common.client.net.pasture.OpenPastureHandler
|
import com.cobblemon.mod.common.client.net.pasture.OpenPastureHandler
|
||||||
import com.cobblemon.mod.common.client.net.pasture.PokemonPasturedHandler
|
import com.cobblemon.mod.common.client.net.pasture.PokemonPasturedHandler
|
||||||
import com.cobblemon.mod.common.client.net.pasture.PokemonUnpasturedHandler
|
import com.cobblemon.mod.common.client.net.pasture.PokemonUnpasturedHandler
|
||||||
import com.cobblemon.mod.common.client.net.pokedex.ServerConfirmedRegisterHandler
|
import com.cobblemon.mod.common.client.net.pokedex.ServerConfirmedRegisterHandler
|
||||||
|
import com.cobblemon.mod.common.client.net.pokemon.update.ClientboundUpdateRidingStateHandler
|
||||||
import com.cobblemon.mod.common.client.net.pokemon.update.PokemonUpdatePacketHandler
|
import com.cobblemon.mod.common.client.net.pokemon.update.PokemonUpdatePacketHandler
|
||||||
import com.cobblemon.mod.common.client.net.settings.OpenCobblemonConfigEditorHandler
|
import com.cobblemon.mod.common.client.net.settings.OpenCobblemonConfigEditorHandler
|
||||||
import com.cobblemon.mod.common.client.net.settings.ServerSettingsPacketHandler
|
import com.cobblemon.mod.common.client.net.settings.ServerSettingsPacketHandler
|
||||||
@@ -56,6 +59,7 @@ import com.cobblemon.mod.common.client.net.trade.TradeProcessStartedHandler
|
|||||||
import com.cobblemon.mod.common.client.net.trade.TradeStartedHandler
|
import com.cobblemon.mod.common.client.net.trade.TradeStartedHandler
|
||||||
import com.cobblemon.mod.common.client.net.trade.TradeUpdatedHandler
|
import com.cobblemon.mod.common.client.net.trade.TradeUpdatedHandler
|
||||||
import com.cobblemon.mod.common.net.PacketRegisterInfo
|
import com.cobblemon.mod.common.net.PacketRegisterInfo
|
||||||
|
import com.cobblemon.mod.common.net.messages.client.CalculateSeatPositionsPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.PlayerInteractOptionsPacket
|
import com.cobblemon.mod.common.net.messages.client.PlayerInteractOptionsPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.SetClientPlayerDataPacket
|
import com.cobblemon.mod.common.net.messages.client.SetClientPlayerDataPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.animation.PlayPosableAnimationPacket
|
import com.cobblemon.mod.common.net.messages.client.animation.PlayPosableAnimationPacket
|
||||||
@@ -71,6 +75,7 @@ import com.cobblemon.mod.common.net.messages.client.effect.SpawnSnowstormEntityP
|
|||||||
import com.cobblemon.mod.common.net.messages.client.effect.SpawnSnowstormParticlePacket
|
import com.cobblemon.mod.common.net.messages.client.effect.SpawnSnowstormParticlePacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.npc.CloseNPCEditorPacket
|
import com.cobblemon.mod.common.net.messages.client.npc.CloseNPCEditorPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.npc.OpenNPCEditorPacket
|
import com.cobblemon.mod.common.net.messages.client.npc.OpenNPCEditorPacket
|
||||||
|
import com.cobblemon.mod.common.net.messages.client.orientation.ClientboundUpdateOrientationPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.pasture.ClosePasturePacket
|
import com.cobblemon.mod.common.net.messages.client.pasture.ClosePasturePacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.pasture.OpenPasturePacket
|
import com.cobblemon.mod.common.net.messages.client.pasture.OpenPasturePacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.pasture.PokemonPasturedPacket
|
import com.cobblemon.mod.common.net.messages.client.pasture.PokemonPasturedPacket
|
||||||
@@ -104,6 +109,7 @@ import com.cobblemon.mod.common.net.messages.client.storage.pc.SetPCPokemonPacke
|
|||||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.ChangePCBoxWallpaperPacket
|
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.ChangePCBoxWallpaperPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.RequestPCBoxWallpapersPacket
|
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.RequestPCBoxWallpapersPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.SetPCBoxWallpapersPacket
|
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.SetPCBoxWallpapersPacket
|
||||||
|
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.UnlockPCBoxWallpaperPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.toast.ToastPacket
|
import com.cobblemon.mod.common.net.messages.client.toast.ToastPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeAcceptanceChangedPacket
|
import com.cobblemon.mod.common.net.messages.client.trade.TradeAcceptanceChangedPacket
|
||||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeCancelledPacket
|
import com.cobblemon.mod.common.net.messages.client.trade.TradeCancelledPacket
|
||||||
@@ -139,7 +145,7 @@ import com.cobblemon.mod.common.net.messages.server.callback.partymove.PartyPoke
|
|||||||
import com.cobblemon.mod.common.net.messages.server.dialogue.EscapeDialoguePacket
|
import com.cobblemon.mod.common.net.messages.server.dialogue.EscapeDialoguePacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.dialogue.InputToDialoguePacket
|
import com.cobblemon.mod.common.net.messages.server.dialogue.InputToDialoguePacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.npc.SaveNPCPacket
|
import com.cobblemon.mod.common.net.messages.server.npc.SaveNPCPacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.orientation.C2SUpdateOrientationPacket
|
import com.cobblemon.mod.common.net.messages.server.orientation.ServerboundUpdateOrientationPacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.pasture.PasturePokemonPacket
|
import com.cobblemon.mod.common.net.messages.server.pasture.PasturePokemonPacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.pasture.UnpastureAllPokemonPacket
|
import com.cobblemon.mod.common.net.messages.server.pasture.UnpastureAllPokemonPacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.pasture.UnpasturePokemonPacket
|
import com.cobblemon.mod.common.net.messages.server.pasture.UnpasturePokemonPacket
|
||||||
@@ -148,6 +154,9 @@ import com.cobblemon.mod.common.net.messages.server.pokedex.scanner.StartScannin
|
|||||||
import com.cobblemon.mod.common.net.messages.server.pokemon.interact.InteractPokemonPacket
|
import com.cobblemon.mod.common.net.messages.server.pokemon.interact.InteractPokemonPacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetItemHiddenPacket
|
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetItemHiddenPacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetNicknamePacket
|
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetNicknamePacket
|
||||||
|
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetActiveMarkPacket
|
||||||
|
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetMarkingsPacket
|
||||||
|
import com.cobblemon.mod.common.net.messages.server.pokemon.update.ServerboundUpdateRidingStatePacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.evolution.AcceptEvolutionPacket
|
import com.cobblemon.mod.common.net.messages.server.pokemon.update.evolution.AcceptEvolutionPacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.starter.RequestStarterScreenPacket
|
import com.cobblemon.mod.common.net.messages.server.starter.RequestStarterScreenPacket
|
||||||
import com.cobblemon.mod.common.net.messages.server.storage.SwapPCPartyPokemonPacket
|
import com.cobblemon.mod.common.net.messages.server.storage.SwapPCPartyPokemonPacket
|
||||||
@@ -190,6 +199,9 @@ import com.cobblemon.mod.common.net.serverhandling.pokedex.scanner.StartScanning
|
|||||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.interact.InteractPokemonHandler
|
import com.cobblemon.mod.common.net.serverhandling.pokemon.interact.InteractPokemonHandler
|
||||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetItemHiddenHandler
|
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetItemHiddenHandler
|
||||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetNicknameHandler
|
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetNicknameHandler
|
||||||
|
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetActiveMarkHandler
|
||||||
|
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetMarkingsHandler
|
||||||
|
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.ServerboundUpdateRidingStateHandler
|
||||||
import com.cobblemon.mod.common.net.serverhandling.starter.RequestStarterScreenHandler
|
import com.cobblemon.mod.common.net.serverhandling.starter.RequestStarterScreenHandler
|
||||||
import com.cobblemon.mod.common.net.serverhandling.starter.SelectStarterPacketHandler
|
import com.cobblemon.mod.common.net.serverhandling.starter.SelectStarterPacketHandler
|
||||||
import com.cobblemon.mod.common.net.serverhandling.storage.BenchMoveHandler
|
import com.cobblemon.mod.common.net.serverhandling.storage.BenchMoveHandler
|
||||||
@@ -262,6 +274,13 @@ object CobblemonNetwork {
|
|||||||
list.add(PacketRegisterInfo(DmaxLevelUpdatePacket.ID, DmaxLevelUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
list.add(PacketRegisterInfo(DmaxLevelUpdatePacket.ID, DmaxLevelUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
list.add(PacketRegisterInfo(GmaxFactorUpdatePacket.ID, GmaxFactorUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
list.add(PacketRegisterInfo(GmaxFactorUpdatePacket.ID, GmaxFactorUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
list.add(PacketRegisterInfo(CosmeticItemUpdatePacket.ID, CosmeticItemUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
list.add(PacketRegisterInfo(CosmeticItemUpdatePacket.ID, CosmeticItemUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
|
list.add(PacketRegisterInfo(ActiveMarkUpdatePacket.ID, ActiveMarkUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
|
list.add(PacketRegisterInfo(MarkAddUpdatePacket.ID, MarkAddUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
|
list.add(PacketRegisterInfo(MarkRemoveUpdatePacket.ID, MarkRemoveUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
|
list.add(PacketRegisterInfo(MarkPotentialAddUpdatePacket.ID, MarkPotentialAddUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
|
list.add(PacketRegisterInfo(MarksUpdatePacket.ID, MarksUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
|
list.add(PacketRegisterInfo(MarksPotentialUpdatePacket.ID, MarksPotentialUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
|
list.add(PacketRegisterInfo(MarkingsUpdatePacket.ID, MarkingsUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||||
|
|
||||||
// Evolution start
|
// Evolution start
|
||||||
list.add(PacketRegisterInfo(AddEvolutionPacket.ID, AddEvolutionPacket::decode, PokemonUpdatePacketHandler()))
|
list.add(PacketRegisterInfo(AddEvolutionPacket.ID, AddEvolutionPacket::decode, PokemonUpdatePacketHandler()))
|
||||||
@@ -287,6 +306,7 @@ object CobblemonNetwork {
|
|||||||
list.add(PacketRegisterInfo(RequestPCBoxWallpapersPacket.ID, RequestPCBoxWallpapersPacket::decode, RequestPCBoxWallpapersHandler))
|
list.add(PacketRegisterInfo(RequestPCBoxWallpapersPacket.ID, RequestPCBoxWallpapersPacket::decode, RequestPCBoxWallpapersHandler))
|
||||||
list.add(PacketRegisterInfo(SetPCBoxWallpapersPacket.ID, SetPCBoxWallpapersPacket::decode, SetPCBoxWallpapersHandler))
|
list.add(PacketRegisterInfo(SetPCBoxWallpapersPacket.ID, SetPCBoxWallpapersPacket::decode, SetPCBoxWallpapersHandler))
|
||||||
list.add(PacketRegisterInfo(ChangePCBoxWallpaperPacket.ID, ChangePCBoxWallpaperPacket::decode, ChangePCBoxWallpaperHandler))
|
list.add(PacketRegisterInfo(ChangePCBoxWallpaperPacket.ID, ChangePCBoxWallpaperPacket::decode, ChangePCBoxWallpaperHandler))
|
||||||
|
list.add(PacketRegisterInfo(UnlockPCBoxWallpaperPacket.ID, UnlockPCBoxWallpaperPacket::decode, UnlockPCBoxWallpaperHandler))
|
||||||
|
|
||||||
// UI Packets
|
// UI Packets
|
||||||
list.add(PacketRegisterInfo(SummaryUIPacket.ID, SummaryUIPacket::decode, SummaryUIPacketHandler))
|
list.add(PacketRegisterInfo(SummaryUIPacket.ID, SummaryUIPacket::decode, SummaryUIPacketHandler))
|
||||||
@@ -353,6 +373,7 @@ object CobblemonNetwork {
|
|||||||
list.add(PacketRegisterInfo(FishingBaitRegistrySyncPacket.ID, FishingBaitRegistrySyncPacket::decode, DataRegistrySyncPacketHandler()))
|
list.add(PacketRegisterInfo(FishingBaitRegistrySyncPacket.ID, FishingBaitRegistrySyncPacket::decode, DataRegistrySyncPacketHandler()))
|
||||||
list.add(PacketRegisterInfo(FlowRegistrySyncPacket.ID, FlowRegistrySyncPacket::decode, DataRegistrySyncPacketHandler()))
|
list.add(PacketRegisterInfo(FlowRegistrySyncPacket.ID, FlowRegistrySyncPacket::decode, DataRegistrySyncPacketHandler()))
|
||||||
list.add(PacketRegisterInfo(CosmeticItemAssignmentSyncPacket.ID, CosmeticItemAssignmentSyncPacket::decode, DataRegistrySyncPacketHandler()))
|
list.add(PacketRegisterInfo(CosmeticItemAssignmentSyncPacket.ID, CosmeticItemAssignmentSyncPacket::decode, DataRegistrySyncPacketHandler()))
|
||||||
|
list.add(PacketRegisterInfo(MarkRegistrySyncPacket.ID, MarkRegistrySyncPacket::decode, DataRegistrySyncPacketHandler()))
|
||||||
|
|
||||||
// Effects
|
// Effects
|
||||||
list.add(PacketRegisterInfo(SpawnSnowstormParticlePacket.ID, SpawnSnowstormParticlePacket::decode, SpawnSnowstormParticleHandler))
|
list.add(PacketRegisterInfo(SpawnSnowstormParticlePacket.ID, SpawnSnowstormParticlePacket::decode, SpawnSnowstormParticleHandler))
|
||||||
@@ -383,6 +404,9 @@ object CobblemonNetwork {
|
|||||||
list.add(PacketRegisterInfo(PokemonPasturedPacket.ID, PokemonPasturedPacket::decode, PokemonPasturedHandler))
|
list.add(PacketRegisterInfo(PokemonPasturedPacket.ID, PokemonPasturedPacket::decode, PokemonPasturedHandler))
|
||||||
list.add(PacketRegisterInfo(PokemonUnpasturedPacket.ID, PokemonUnpasturedPacket::decode, PokemonUnpasturedHandler))
|
list.add(PacketRegisterInfo(PokemonUnpasturedPacket.ID, PokemonUnpasturedPacket::decode, PokemonUnpasturedHandler))
|
||||||
|
|
||||||
|
// Orientation
|
||||||
|
list.add(PacketRegisterInfo(ClientboundUpdateOrientationPacket.ID, ClientboundUpdateOrientationPacket::decode, S2CUpdateOrientationHandler))
|
||||||
|
|
||||||
// Behaviours
|
// Behaviours
|
||||||
list.add(PacketRegisterInfo(PlayPosableAnimationPacket.ID, PlayPosableAnimationPacket::decode, PlayPosableAnimationHandler))
|
list.add(PacketRegisterInfo(PlayPosableAnimationPacket.ID, PlayPosableAnimationPacket::decode, PlayPosableAnimationHandler))
|
||||||
|
|
||||||
@@ -405,6 +429,13 @@ object CobblemonNetwork {
|
|||||||
|
|
||||||
// Pokédex scanning
|
// Pokédex scanning
|
||||||
list.add(PacketRegisterInfo(ServerConfirmedRegisterPacket.ID, ServerConfirmedRegisterPacket::decode, ServerConfirmedRegisterHandler))
|
list.add(PacketRegisterInfo(ServerConfirmedRegisterPacket.ID, ServerConfirmedRegisterPacket::decode, ServerConfirmedRegisterHandler))
|
||||||
|
|
||||||
|
// Debug / cheats
|
||||||
|
list.add(PacketRegisterInfo(CalculateSeatPositionsPacket.ID, CalculateSeatPositionsPacket::decode, CalculateSeatPositionsHandler))
|
||||||
|
|
||||||
|
// Riding
|
||||||
|
list.add(PacketRegisterInfo(ClientboundUpdateRidingStatePacket.ID, ClientboundUpdateRidingStatePacket::decode, ClientboundUpdateRidingStateHandler))
|
||||||
|
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,6 +444,8 @@ object CobblemonNetwork {
|
|||||||
// Pokemon Update Packets
|
// Pokemon Update Packets
|
||||||
list.add(PacketRegisterInfo(SetNicknamePacket.ID, SetNicknamePacket::decode, SetNicknameHandler))
|
list.add(PacketRegisterInfo(SetNicknamePacket.ID, SetNicknamePacket::decode, SetNicknameHandler))
|
||||||
list.add(PacketRegisterInfo(SetItemHiddenPacket.ID, SetItemHiddenPacket::decode, SetItemHiddenHandler))
|
list.add(PacketRegisterInfo(SetItemHiddenPacket.ID, SetItemHiddenPacket::decode, SetItemHiddenHandler))
|
||||||
|
list.add(PacketRegisterInfo(SetActiveMarkPacket.ID, SetActiveMarkPacket::decode, SetActiveMarkHandler))
|
||||||
|
list.add(PacketRegisterInfo(SetMarkingsPacket.ID, SetMarkingsPacket::decode, SetMarkingsHandler))
|
||||||
|
|
||||||
// Evolution Packets
|
// Evolution Packets
|
||||||
list.add(PacketRegisterInfo(AcceptEvolutionPacket.ID, AcceptEvolutionPacket::decode, AcceptEvolutionHandler))
|
list.add(PacketRegisterInfo(AcceptEvolutionPacket.ID, AcceptEvolutionPacket::decode, AcceptEvolutionHandler))
|
||||||
@@ -440,6 +473,7 @@ object CobblemonNetwork {
|
|||||||
list.add(PacketRegisterInfo(RequestRenamePCBoxPacket.Companion.ID, RequestRenamePCBoxPacket.Companion::decode, RequestRenamePCBoxHandler))
|
list.add(PacketRegisterInfo(RequestRenamePCBoxPacket.Companion.ID, RequestRenamePCBoxPacket.Companion::decode, RequestRenamePCBoxHandler))
|
||||||
list.add(PacketRegisterInfo(PCBoxWallpapersPacket.ID, PCBoxWallpapersPacket::decode, PCBoxWallpapersHandler))
|
list.add(PacketRegisterInfo(PCBoxWallpapersPacket.ID, PCBoxWallpapersPacket::decode, PCBoxWallpapersHandler))
|
||||||
list.add(PacketRegisterInfo(RequestChangePCBoxWallpaperPacket.ID, RequestChangePCBoxWallpaperPacket::decode, RequestChangePCBoxWallpaperHandler))
|
list.add(PacketRegisterInfo(RequestChangePCBoxWallpaperPacket.ID, RequestChangePCBoxWallpaperPacket::decode, RequestChangePCBoxWallpaperHandler))
|
||||||
|
list.add(PacketRegisterInfo(MarkPCBoxWallpapersSeenPacket.ID, MarkPCBoxWallpapersSeenPacket::decode, MarkPCBoxWallpapersSeenHandler))
|
||||||
|
|
||||||
// Starter packets
|
// Starter packets
|
||||||
list.add(PacketRegisterInfo(SelectStarterPacket.ID, SelectStarterPacket::decode, SelectStarterPacketHandler))
|
list.add(PacketRegisterInfo(SelectStarterPacket.ID, SelectStarterPacket::decode, SelectStarterPacketHandler))
|
||||||
@@ -499,8 +533,9 @@ object CobblemonNetwork {
|
|||||||
// NPC packets
|
// NPC packets
|
||||||
list.add(PacketRegisterInfo(SaveNPCPacket.ID, SaveNPCPacket::decode, SaveNPCHandler))
|
list.add(PacketRegisterInfo(SaveNPCPacket.ID, SaveNPCPacket::decode, SaveNPCHandler))
|
||||||
|
|
||||||
// Orientation packet(s)
|
// Riding packet(s)
|
||||||
list.add(PacketRegisterInfo(C2SUpdateOrientationPacket.ID, C2SUpdateOrientationPacket::decode, OrientationPacketHandler))
|
list.add(PacketRegisterInfo(ServerboundUpdateOrientationPacket.ID, ServerboundUpdateOrientationPacket::decode, OrientationPacketHandler))
|
||||||
|
list.add(PacketRegisterInfo(ServerboundUpdateRidingStatePacket.ID, ServerboundUpdateRidingStatePacket::decode, ServerboundUpdateRidingStateHandler))
|
||||||
|
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ object CobblemonSounds : PlatformRegistry<Registry<SoundEvent>, ResourceKey<Regi
|
|||||||
val PC_RELEASE = this.create("pc.release")
|
val PC_RELEASE = this.create("pc.release")
|
||||||
@JvmField
|
@JvmField
|
||||||
val PC_CLICK = this.create("pc.click")
|
val PC_CLICK = this.create("pc.click")
|
||||||
|
@JvmField
|
||||||
|
val PC_WALLPAPER_UNLOCK = this.create("pc.wallpaper.unlock")
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val VILLAGER_WORK_NURSE = this.create("entity.villager.work_nurse")
|
val VILLAGER_WORK_NURSE = this.create("entity.villager.work_nurse")
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common
|
||||||
|
|
||||||
|
import com.bedrockk.molang.Expression
|
||||||
|
import com.cobblemon.mod.common.api.data.JsonDataRegistry
|
||||||
|
import com.cobblemon.mod.common.api.molang.ExpressionLike
|
||||||
|
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
||||||
|
import com.cobblemon.mod.common.api.storage.pc.UnlockablePCWallpaper
|
||||||
|
import com.cobblemon.mod.common.util.adapters.ExpressionAdapter
|
||||||
|
import com.cobblemon.mod.common.util.adapters.ExpressionLikeAdapter
|
||||||
|
import com.cobblemon.mod.common.util.adapters.IdentifierAdapter
|
||||||
|
import com.cobblemon.mod.common.util.adapters.TextAdapter
|
||||||
|
import com.cobblemon.mod.common.util.cobblemonResource
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.server.level.ServerPlayer
|
||||||
|
import net.minecraft.server.packs.PackType
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A data registry for unlockable wallpapers that can be applied to a PC box. This is different to a resource packed
|
||||||
|
* wallpaper, as those are purely client-side and don't require any unlocking.
|
||||||
|
*
|
||||||
|
* See docs/pc_wallpapers.md
|
||||||
|
*
|
||||||
|
* @author Hiroku
|
||||||
|
* @since February 9th, 2025
|
||||||
|
*/
|
||||||
|
object CobblemonUnlockableWallpapers : JsonDataRegistry<UnlockablePCWallpaper> {
|
||||||
|
override val gson: Gson = GsonBuilder()
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.registerTypeAdapter(Expression::class.java, ExpressionAdapter)
|
||||||
|
.registerTypeAdapter(ExpressionLike::class.java, ExpressionLikeAdapter)
|
||||||
|
.registerTypeAdapter(ResourceLocation::class.java, IdentifierAdapter)
|
||||||
|
.registerTypeAdapter(Component::class.java, TextAdapter)
|
||||||
|
.create()
|
||||||
|
|
||||||
|
override val typeToken = TypeToken.get(UnlockablePCWallpaper::class.java)
|
||||||
|
override val resourcePath = "unlockable_pc_box_wallpapers"
|
||||||
|
override val id: ResourceLocation = cobblemonResource("unlockable_pc_box_wallpapers")
|
||||||
|
override val type = PackType.SERVER_DATA
|
||||||
|
override val observable = SimpleObservable<CobblemonUnlockableWallpapers>()
|
||||||
|
|
||||||
|
val unlockableWallpapers = mutableMapOf<ResourceLocation, UnlockablePCWallpaper>()
|
||||||
|
|
||||||
|
override fun sync(player: ServerPlayer) { /* These don't sync, they're applied to a PC instance from which they're hooked into RequestChangePCBoxWallpaperHandler. */ }
|
||||||
|
|
||||||
|
override fun reload(data: Map<ResourceLocation, UnlockablePCWallpaper>) {
|
||||||
|
unlockableWallpapers.clear()
|
||||||
|
data.forEach { (id, value) -> value.id = id }
|
||||||
|
unlockableWallpapers.putAll(data)
|
||||||
|
observable.emit(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -28,7 +28,7 @@ class BattleCountableCriterion(
|
|||||||
val CODEC: Codec<BattleCountableCriterion> = RecordCodecBuilder.create { it.group(
|
val CODEC: Codec<BattleCountableCriterion> = RecordCodecBuilder.create { it.group(
|
||||||
ContextAwarePredicate.CODEC.optionalFieldOf("player").forGetter(BattleCountableCriterion::playerCtx),
|
ContextAwarePredicate.CODEC.optionalFieldOf("player").forGetter(BattleCountableCriterion::playerCtx),
|
||||||
Codec.STRING.listOf().optionalFieldOf("battle_types", listOf("any")).forGetter(BattleCountableCriterion::battleTypes),
|
Codec.STRING.listOf().optionalFieldOf("battle_types", listOf("any")).forGetter(BattleCountableCriterion::battleTypes),
|
||||||
Codec.INT.optionalFieldOf( "count", 0).forGetter(BattleCountableCriterion::count)
|
Codec.INT.optionalFieldOf("count", 0).forGetter(BattleCountableCriterion::count)
|
||||||
).apply(it, ::BattleCountableCriterion) }
|
).apply(it, ::BattleCountableCriterion) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
package com.cobblemon.mod.common.api.conditional
|
package com.cobblemon.mod.common.api.conditional
|
||||||
|
|
||||||
|
import net.minecraft.core.Holder
|
||||||
import net.minecraft.core.Registry
|
import net.minecraft.core.Registry
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,5 +18,10 @@ import net.minecraft.core.Registry
|
|||||||
* @since July 16th, 2022
|
* @since July 16th, 2022
|
||||||
*/
|
*/
|
||||||
interface RegistryLikeCondition<T> {
|
interface RegistryLikeCondition<T> {
|
||||||
fun fits(t: T, registry: Registry<T>): Boolean
|
fun fits(t: T, registry: Registry<T>): Boolean {
|
||||||
|
val holder = registry.wrapAsHolder(t)
|
||||||
|
return holder != null && fits(holder)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fits(holder: Holder<T>): Boolean
|
||||||
}
|
}
|
||||||
+3
-2
@@ -9,7 +9,7 @@
|
|||||||
package com.cobblemon.mod.common.api.conditional
|
package com.cobblemon.mod.common.api.conditional
|
||||||
|
|
||||||
import com.google.gson.JsonElement
|
import com.google.gson.JsonElement
|
||||||
import net.minecraft.core.Registry
|
import net.minecraft.core.Holder
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,5 +24,6 @@ open class RegistryLikeIdentifierCondition<T : Any>(val identifier: ResourceLoca
|
|||||||
constructor: (ResourceLocation) -> RegistryLikeIdentifierCondition<T>
|
constructor: (ResourceLocation) -> RegistryLikeIdentifierCondition<T>
|
||||||
): (JsonElement) -> RegistryLikeIdentifierCondition<T>? = { constructor(ResourceLocation.parse(it.asString)) }
|
): (JsonElement) -> RegistryLikeIdentifierCondition<T>? = { constructor(ResourceLocation.parse(it.asString)) }
|
||||||
}
|
}
|
||||||
override fun fits(t: T, registry: Registry<T>) = registry.getKey(t) == identifier
|
|
||||||
|
override fun fits(t: Holder<T>) = t.`is`(identifier)
|
||||||
}
|
}
|
||||||
+2
-12
@@ -9,6 +9,7 @@
|
|||||||
package com.cobblemon.mod.common.api.conditional
|
package com.cobblemon.mod.common.api.conditional
|
||||||
|
|
||||||
import com.google.gson.JsonElement
|
import com.google.gson.JsonElement
|
||||||
|
import net.minecraft.core.Holder
|
||||||
import net.minecraft.core.Registry
|
import net.minecraft.core.Registry
|
||||||
import net.minecraft.resources.ResourceKey
|
import net.minecraft.resources.ResourceKey
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
@@ -39,16 +40,5 @@ open class RegistryLikeTagCondition<T : Any>(val tag: TagKey<T>) : RegistryLikeC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fits(t: T, registry: Registry<T>): Boolean {
|
override fun fits(t: Holder<T>) = t.`is`(tag)
|
||||||
// val registryHasTag = registry.containsTag(tag)
|
|
||||||
// if (!registryHasTag) {
|
|
||||||
//// LOGGER.warn("No tag in registry: ${tag.id}")
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
|
|
||||||
return registry.getResourceKey(t)
|
|
||||||
.flatMap(registry::getHolder)
|
|
||||||
.map { entry -> entry.`is`(tag) }
|
|
||||||
.orElse(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -46,6 +46,7 @@ import com.cobblemon.mod.common.api.events.storage.ChangePCBoxWallpaperEvent
|
|||||||
import com.cobblemon.mod.common.api.events.storage.ReleasePokemonEvent
|
import com.cobblemon.mod.common.api.events.storage.ReleasePokemonEvent
|
||||||
import com.cobblemon.mod.common.api.events.storage.RenamePCBoxEvent
|
import com.cobblemon.mod.common.api.events.storage.RenamePCBoxEvent
|
||||||
import com.cobblemon.mod.common.api.events.storage.WallpaperCollectionEvent
|
import com.cobblemon.mod.common.api.events.storage.WallpaperCollectionEvent
|
||||||
|
import com.cobblemon.mod.common.api.events.storage.WallpaperUnlockedEvent
|
||||||
import com.cobblemon.mod.common.api.events.world.BigRootPropagatedEvent
|
import com.cobblemon.mod.common.api.events.world.BigRootPropagatedEvent
|
||||||
import com.cobblemon.mod.common.api.reactive.CancelableObservable
|
import com.cobblemon.mod.common.api.reactive.CancelableObservable
|
||||||
import com.cobblemon.mod.common.api.reactive.EventObservable
|
import com.cobblemon.mod.common.api.reactive.EventObservable
|
||||||
@@ -179,6 +180,8 @@ object CobblemonEvents {
|
|||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val WALLPAPER_COLLECTION_EVENT = EventObservable<WallpaperCollectionEvent>()
|
val WALLPAPER_COLLECTION_EVENT = EventObservable<WallpaperCollectionEvent>()
|
||||||
|
@JvmField
|
||||||
|
val WALLPAPER_UNLOCKED_EVENT = CancelableObservable<WallpaperUnlockedEvent>()
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val CHANGE_PC_BOX_WALLPAPER_EVENT_PRE = CancelableObservable<ChangePCBoxWallpaperEvent.Pre>()
|
val CHANGE_PC_BOX_WALLPAPER_EVENT_PRE = CancelableObservable<ChangePCBoxWallpaperEvent.Pre>()
|
||||||
|
|||||||
+13
-1
@@ -8,10 +8,16 @@
|
|||||||
|
|
||||||
package com.cobblemon.mod.common.api.events.fishing
|
package com.cobblemon.mod.common.api.events.fishing
|
||||||
|
|
||||||
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
|
import com.bedrockk.molang.runtime.value.MoValue
|
||||||
import com.cobblemon.mod.common.api.events.Cancelable
|
import com.cobblemon.mod.common.api.events.Cancelable
|
||||||
|
import com.cobblemon.mod.common.api.molang.MoLangFunctions.asMoLangValue
|
||||||
|
import com.cobblemon.mod.common.api.molang.ObjectValue
|
||||||
import com.cobblemon.mod.common.api.spawning.SpawnBucket
|
import com.cobblemon.mod.common.api.spawning.SpawnBucket
|
||||||
import com.cobblemon.mod.common.entity.fishing.PokeRodFishingBobberEntity
|
import com.cobblemon.mod.common.entity.fishing.PokeRodFishingBobberEntity
|
||||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.itemRegistry
|
||||||
|
import net.minecraft.core.registries.Registries
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,5 +61,11 @@ interface BobberSpawnPokemonEvent {
|
|||||||
val chosenBucket: SpawnBucket,
|
val chosenBucket: SpawnBucket,
|
||||||
val bait: ItemStack,
|
val bait: ItemStack,
|
||||||
val pokemon: PokemonEntity
|
val pokemon: PokemonEntity
|
||||||
) : BobberSpawnPokemonEvent
|
) : BobberSpawnPokemonEvent {
|
||||||
|
val context = mutableMapOf<String, MoValue>(
|
||||||
|
"chosen_bucket" to ObjectValue(chosenBucket, { it.name }),
|
||||||
|
"bait" to pokemon.level().itemRegistry.wrapAsHolder(bait.item).asMoLangValue(Registries.ITEM),
|
||||||
|
"pokemon_entity" to pokemon.asMoLangValue()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+9
-1
@@ -8,10 +8,18 @@
|
|||||||
|
|
||||||
package com.cobblemon.mod.common.api.events.pokemon
|
package com.cobblemon.mod.common.api.events.pokemon
|
||||||
|
|
||||||
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
|
import com.bedrockk.molang.runtime.value.MoValue
|
||||||
|
import com.cobblemon.mod.common.api.molang.MoLangFunctions.asMoLangValue
|
||||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||||
import net.minecraft.server.level.ServerPlayer
|
import net.minecraft.server.level.ServerPlayer
|
||||||
|
|
||||||
data class FossilRevivedEvent (
|
data class FossilRevivedEvent (
|
||||||
val pokemon: Pokemon,
|
val pokemon: Pokemon,
|
||||||
val player: ServerPlayer?
|
val player: ServerPlayer?
|
||||||
)
|
) {
|
||||||
|
val context = mutableMapOf<String, MoValue>(
|
||||||
|
"pokemon" to pokemon.struct,
|
||||||
|
"player" to (player?.asMoLangValue() ?: DoubleValue.ZERO)
|
||||||
|
)
|
||||||
|
}
|
||||||
+1
-1
@@ -31,7 +31,7 @@ data class PokemonInteractionGUICreationEvent(
|
|||||||
|
|
||||||
private fun getNextFreeOrientation(): Orientation {
|
private fun getNextFreeOrientation(): Orientation {
|
||||||
var largest = Orientation.TOP_LEFT
|
var largest = Orientation.TOP_LEFT
|
||||||
for(orientation in Orientation.values()) {
|
for (orientation in Orientation.entries) {
|
||||||
if(!options.containsKey(orientation)) {
|
if(!options.containsKey(orientation)) {
|
||||||
return orientation
|
return orientation
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -22,5 +22,5 @@ import net.minecraft.server.level.ServerPlayer
|
|||||||
*/
|
*/
|
||||||
data class WallpaperCollectionEvent(
|
data class WallpaperCollectionEvent(
|
||||||
val player: ServerPlayer,
|
val player: ServerPlayer,
|
||||||
val wallpapers: MutableList<ResourceLocation>
|
val wallpapers: MutableSet<ResourceLocation>
|
||||||
)
|
)
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.events.storage
|
||||||
|
|
||||||
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
|
import com.bedrockk.molang.runtime.value.MoValue
|
||||||
|
import com.cobblemon.mod.common.api.events.Cancelable
|
||||||
|
import com.cobblemon.mod.common.api.molang.MoLangFunctions.asMoLangValue
|
||||||
|
import com.cobblemon.mod.common.api.molang.MoLangFunctions.moLangFunctionMap
|
||||||
|
import com.cobblemon.mod.common.api.storage.pc.PCStore
|
||||||
|
import com.cobblemon.mod.common.api.storage.pc.UnlockablePCWallpaper
|
||||||
|
import com.cobblemon.mod.common.util.asArrayValue
|
||||||
|
import com.cobblemon.mod.common.util.getBoolean
|
||||||
|
import net.minecraft.server.level.ServerPlayer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event fired when a wallpaper is unlocked for a PC. Typically, this will have a single player, but it is not
|
||||||
|
* technically guaranteed to due to shared PCs and offline support.
|
||||||
|
*
|
||||||
|
* @author Hiroku
|
||||||
|
* @since February 10th, 2025
|
||||||
|
*/
|
||||||
|
data class WallpaperUnlockedEvent(
|
||||||
|
val pc: PCStore,
|
||||||
|
val wallpaper: UnlockablePCWallpaper,
|
||||||
|
var shouldNotify: Boolean
|
||||||
|
): Cancelable() {
|
||||||
|
/** For shared PCs with multiple players online, and for offline PC access, the player will be null. */
|
||||||
|
val player: ServerPlayer?
|
||||||
|
get() = pc.getObservingPlayers().takeIf { it.size == 1 }?.first()
|
||||||
|
|
||||||
|
/** All online, observing players for the PC. This would typically have a single player in it. */
|
||||||
|
val players = pc.getObservingPlayers()
|
||||||
|
|
||||||
|
val context: MutableMap<String, MoValue>
|
||||||
|
get() = mutableMapOf(
|
||||||
|
"pc" to pc.struct,
|
||||||
|
"wallpaper" to wallpaper.struct,
|
||||||
|
"player" to (player?.asMoLangValue() ?: DoubleValue.ZERO),
|
||||||
|
"players" to players.asArrayValue { it.asMoLangValue() },
|
||||||
|
"should_notify" to DoubleValue(shouldNotify)
|
||||||
|
)
|
||||||
|
|
||||||
|
val functions = moLangFunctionMap(
|
||||||
|
cancelFunc,
|
||||||
|
"set_should_notify" to { params ->
|
||||||
|
shouldNotify = params.getBoolean(0)
|
||||||
|
DoubleValue.ONE
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -37,6 +37,8 @@ import net.minecraft.resources.ResourceLocation
|
|||||||
import net.minecraft.util.FormattedCharSequence
|
import net.minecraft.util.FormattedCharSequence
|
||||||
import org.joml.Matrix4f
|
import org.joml.Matrix4f
|
||||||
import org.joml.Vector3f
|
import org.joml.Vector3f
|
||||||
|
import org.lwjgl.opengl.GL30
|
||||||
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun blitk(
|
fun blitk(
|
||||||
@@ -365,3 +367,25 @@ fun renderSprite(matrixStack: PoseStack, sprite: ResourceLocation) {
|
|||||||
|
|
||||||
BufferUploader.drawWithShader(buffer.buildOrThrow())
|
BufferUploader.drawWithShader(buffer.buildOrThrow())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getPixelRGB(x: Int, y: Int): Triple<Int, Int, Int> {
|
||||||
|
val window = Minecraft.getInstance().window
|
||||||
|
val scale = window.guiScale
|
||||||
|
val buffer = ByteBuffer.allocateDirect(4)
|
||||||
|
|
||||||
|
RenderSystem.readPixels(
|
||||||
|
(x * scale).toInt(),
|
||||||
|
(window.height - y * scale - scale).toInt(),
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
GL30.GL_RGBA,
|
||||||
|
GL30.GL_UNSIGNED_BYTE,
|
||||||
|
buffer
|
||||||
|
)
|
||||||
|
|
||||||
|
return Triple(
|
||||||
|
buffer[0].toInt() and 0xFF,
|
||||||
|
buffer[1].toInt() and 0xFF,
|
||||||
|
buffer[2].toInt() and 0xFF
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.mark
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.network.chat.MutableComponent
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.StringRepresentable
|
||||||
|
|
||||||
|
class Mark(
|
||||||
|
identifier: ResourceLocation,
|
||||||
|
val name: String,
|
||||||
|
val description: String,
|
||||||
|
val title: String?,
|
||||||
|
@SerializedName(value = "titleColor", alternate = ["titleColour"])
|
||||||
|
val titleColour: String?,
|
||||||
|
val texture: ResourceLocation,
|
||||||
|
val replace: List<ResourceLocation>?,
|
||||||
|
val group: String?,
|
||||||
|
val chance: Float = 0F,
|
||||||
|
val indexNumber: Int?
|
||||||
|
): StringRepresentable {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
internal fun decode(buffer: RegistryFriendlyByteBuf): Mark {
|
||||||
|
return Mark(
|
||||||
|
buffer.readIdentifier(),
|
||||||
|
buffer.readString(),
|
||||||
|
buffer.readString(),
|
||||||
|
buffer.readNullable { buffer.readString() },
|
||||||
|
buffer.readNullable { buffer.readString() },
|
||||||
|
buffer.readResourceLocation(),
|
||||||
|
buffer.readNullable { buffer.readList { buffer.readResourceLocation() } },
|
||||||
|
buffer.readNullable { buffer.readString() },
|
||||||
|
buffer.readFloat(),
|
||||||
|
buffer.readNullable { buffer.readInt() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
var identifier: ResourceLocation = identifier
|
||||||
|
internal set
|
||||||
|
|
||||||
|
override fun getSerializedName(): String = identifier.toString()
|
||||||
|
|
||||||
|
fun getName(): MutableComponent = name.asTranslated()
|
||||||
|
|
||||||
|
fun getDescription(): MutableComponent = description.asTranslated()
|
||||||
|
|
||||||
|
fun getTitle(name: MutableComponent): MutableComponent {
|
||||||
|
title?.let {
|
||||||
|
try {
|
||||||
|
return if (titleColour != null) it.asTranslated(name.withColor(-1)).withColor(titleColour.toInt(16))
|
||||||
|
else it.asTranslated(name)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Cobblemon.LOGGER.error("Error parsing titleColor hexadecimal color code for {}", identifier, e)
|
||||||
|
return it.asTranslated(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getChanceGroup(): Pair<String, Float> = Pair(group ?: chance.toString(), chance)
|
||||||
|
|
||||||
|
internal fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeIdentifier(identifier)
|
||||||
|
buffer.writeString(name)
|
||||||
|
buffer.writeString(description)
|
||||||
|
buffer.writeNullable(title) { _, v -> buffer.writeString(v) }
|
||||||
|
buffer.writeNullable(titleColour) { _, v -> buffer.writeString(v) }
|
||||||
|
buffer.writeResourceLocation(texture)
|
||||||
|
buffer.writeNullable(replace) { _, v -> buffer.writeCollection(v) { _, resource -> buffer.writeResourceLocation(resource) } }
|
||||||
|
buffer.writeNullable(group) { _, v -> buffer.writeString(v) }
|
||||||
|
buffer.writeFloat(chance)
|
||||||
|
buffer.writeNullable(indexNumber) { _, v -> buffer.writeInt(v) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.mark
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.api.data.JsonDataRegistry
|
||||||
|
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
||||||
|
import com.cobblemon.mod.common.net.messages.client.data.MarkRegistrySyncPacket
|
||||||
|
import com.cobblemon.mod.common.util.adapters.IdentifierAdapter
|
||||||
|
import com.cobblemon.mod.common.util.cobblemonResource
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.server.level.ServerPlayer
|
||||||
|
import net.minecraft.server.packs.PackType
|
||||||
|
|
||||||
|
object Marks: JsonDataRegistry<Mark> {
|
||||||
|
|
||||||
|
override val id: ResourceLocation = cobblemonResource("marks")
|
||||||
|
override val type: PackType = PackType.SERVER_DATA
|
||||||
|
override val observable = SimpleObservable<Marks>()
|
||||||
|
override val typeToken: TypeToken<Mark> = TypeToken.get(Mark::class.java)
|
||||||
|
override val resourcePath: String = "marks"
|
||||||
|
|
||||||
|
override val gson = GsonBuilder()
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.registerTypeAdapter(ResourceLocation::class.java, IdentifierAdapter)
|
||||||
|
.create()
|
||||||
|
|
||||||
|
private val marks = hashMapOf<ResourceLocation, Mark>()
|
||||||
|
|
||||||
|
override fun reload(data: Map<ResourceLocation, Mark>) {
|
||||||
|
this.marks.clear()
|
||||||
|
data.forEach { (identifier, mark) ->
|
||||||
|
try {
|
||||||
|
mark.identifier = identifier
|
||||||
|
this.marks[identifier] = mark
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Cobblemon.LOGGER.error("Skipped loading the {} mark", identifier, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Cobblemon.LOGGER.info("Loaded {} marks", this.marks.size)
|
||||||
|
this.observable.emit(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun sync(player: ServerPlayer) {
|
||||||
|
MarkRegistrySyncPacket(this.all()).sendToPlayer(player)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all loaded [Mark]s.
|
||||||
|
*/
|
||||||
|
fun all() = this.marks.values.toList()
|
||||||
|
fun identifiers(): Collection<String> = marks.keys.toSet().map { it.toString() }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a [Mark] by its [ResourceLocation].
|
||||||
|
* @param identifier The identifier of the mark.
|
||||||
|
* @return The [Mark] if loaded, otherwise null.
|
||||||
|
*/
|
||||||
|
fun getByIdentifier(identifier: ResourceLocation): Mark? = this.marks[identifier]
|
||||||
|
}
|
||||||
@@ -17,25 +17,17 @@ import com.bedrockk.molang.runtime.struct.VariableStruct
|
|||||||
import com.bedrockk.molang.runtime.value.DoubleValue
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
import com.bedrockk.molang.runtime.value.MoValue
|
import com.bedrockk.molang.runtime.value.MoValue
|
||||||
import com.bedrockk.molang.runtime.value.StringValue
|
import com.bedrockk.molang.runtime.value.StringValue
|
||||||
import com.cobblemon.mod.common.Cobblemon
|
import com.cobblemon.mod.common.*
|
||||||
import com.cobblemon.mod.common.CobblemonActivities
|
|
||||||
import com.cobblemon.mod.common.CobblemonBlockEntities
|
|
||||||
import com.cobblemon.mod.common.CobblemonMemories
|
|
||||||
import com.cobblemon.mod.common.api.battles.model.PokemonBattle
|
import com.cobblemon.mod.common.api.battles.model.PokemonBattle
|
||||||
import com.cobblemon.mod.common.api.battles.model.actor.ActorType
|
import com.cobblemon.mod.common.api.battles.model.actor.ActorType
|
||||||
import com.cobblemon.mod.common.api.battles.model.actor.BattleActor
|
import com.cobblemon.mod.common.api.battles.model.actor.BattleActor
|
||||||
import com.cobblemon.mod.common.api.dialogue.PlayerDialogueFaceProvider
|
import com.cobblemon.mod.common.api.dialogue.PlayerDialogueFaceProvider
|
||||||
import com.cobblemon.mod.common.api.dialogue.ReferenceDialogueFaceProvider
|
import com.cobblemon.mod.common.api.dialogue.ReferenceDialogueFaceProvider
|
||||||
|
import com.cobblemon.mod.common.api.mark.Marks
|
||||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffects
|
import com.cobblemon.mod.common.api.moves.animations.ActionEffects
|
||||||
import com.cobblemon.mod.common.api.moves.animations.NPCProvider
|
import com.cobblemon.mod.common.api.moves.animations.NPCProvider
|
||||||
import com.cobblemon.mod.common.api.pokedex.AbstractPokedexManager
|
import com.cobblemon.mod.common.api.pokedex.*
|
||||||
import com.cobblemon.mod.common.api.pokedex.CaughtCount
|
|
||||||
import com.cobblemon.mod.common.api.pokedex.CaughtPercent
|
|
||||||
import com.cobblemon.mod.common.api.pokedex.PokedexEntryProgress
|
|
||||||
import com.cobblemon.mod.common.api.pokedex.PokedexManager
|
|
||||||
import com.cobblemon.mod.common.api.pokedex.SeenCount
|
|
||||||
import com.cobblemon.mod.common.api.pokedex.SeenPercent
|
|
||||||
import com.cobblemon.mod.common.api.pokemon.PokemonProperties
|
import com.cobblemon.mod.common.api.pokemon.PokemonProperties
|
||||||
import com.cobblemon.mod.common.api.pokemon.evolution.Evolution
|
import com.cobblemon.mod.common.api.pokemon.evolution.Evolution
|
||||||
import com.cobblemon.mod.common.api.pokemon.stats.Stats
|
import com.cobblemon.mod.common.api.pokemon.stats.Stats
|
||||||
@@ -49,6 +41,7 @@ import com.cobblemon.mod.common.api.storage.pc.PCStore
|
|||||||
import com.cobblemon.mod.common.api.text.text
|
import com.cobblemon.mod.common.api.text.text
|
||||||
import com.cobblemon.mod.common.battles.BattleRegistry
|
import com.cobblemon.mod.common.battles.BattleRegistry
|
||||||
import com.cobblemon.mod.common.battles.actor.PlayerBattleActor
|
import com.cobblemon.mod.common.battles.actor.PlayerBattleActor
|
||||||
|
import com.cobblemon.mod.common.battles.actor.PokemonBattleActor
|
||||||
import com.cobblemon.mod.common.client.particle.BedrockParticleOptionsRepository
|
import com.cobblemon.mod.common.client.particle.BedrockParticleOptionsRepository
|
||||||
import com.cobblemon.mod.common.client.particle.ParticleStorm
|
import com.cobblemon.mod.common.client.particle.ParticleStorm
|
||||||
import com.cobblemon.mod.common.client.render.models.blockbench.wavefunction.WaveFunctions
|
import com.cobblemon.mod.common.client.render.models.blockbench.wavefunction.WaveFunctions
|
||||||
@@ -70,20 +63,15 @@ import com.cobblemon.mod.common.pokemon.evolution.variants.LevelUpEvolution
|
|||||||
import com.cobblemon.mod.common.pokemon.evolution.variants.TradeEvolution
|
import com.cobblemon.mod.common.pokemon.evolution.variants.TradeEvolution
|
||||||
import com.cobblemon.mod.common.util.*
|
import com.cobblemon.mod.common.util.*
|
||||||
import com.mojang.datafixers.util.Either
|
import com.mojang.datafixers.util.Either
|
||||||
import java.util.UUID
|
|
||||||
import kotlin.math.sqrt
|
|
||||||
import net.minecraft.client.multiplayer.ClientLevel
|
import net.minecraft.client.multiplayer.ClientLevel
|
||||||
import net.minecraft.commands.arguments.EntityAnchorArgument
|
import net.minecraft.commands.arguments.EntityAnchorArgument
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Holder
|
import net.minecraft.core.Holder
|
||||||
import net.minecraft.core.Registry
|
import net.minecraft.core.Registry
|
||||||
|
import net.minecraft.core.RegistryAccess
|
||||||
import net.minecraft.core.registries.BuiltInRegistries
|
import net.minecraft.core.registries.BuiltInRegistries
|
||||||
import net.minecraft.core.registries.Registries
|
import net.minecraft.core.registries.Registries
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.*
|
||||||
import net.minecraft.nbt.DoubleTag
|
|
||||||
import net.minecraft.nbt.ListTag
|
|
||||||
import net.minecraft.nbt.StringTag
|
|
||||||
import net.minecraft.nbt.Tag
|
|
||||||
import net.minecraft.resources.ResourceKey
|
import net.minecraft.resources.ResourceKey
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
import net.minecraft.server.MinecraftServer
|
import net.minecraft.server.MinecraftServer
|
||||||
@@ -92,22 +80,24 @@ import net.minecraft.server.level.ServerPlayer
|
|||||||
import net.minecraft.tags.TagKey
|
import net.minecraft.tags.TagKey
|
||||||
import net.minecraft.world.damagesource.DamageSource
|
import net.minecraft.world.damagesource.DamageSource
|
||||||
import net.minecraft.world.damagesource.DamageTypes
|
import net.minecraft.world.damagesource.DamageTypes
|
||||||
import net.minecraft.world.entity.EntityType
|
import net.minecraft.world.entity.*
|
||||||
import net.minecraft.world.entity.LightningBolt
|
|
||||||
import net.minecraft.world.entity.LivingEntity
|
|
||||||
import net.minecraft.world.entity.PathfinderMob
|
|
||||||
import net.minecraft.world.entity.ai.behavior.BlockPosTracker
|
import net.minecraft.world.entity.ai.behavior.BlockPosTracker
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType
|
import net.minecraft.world.entity.ai.memory.MemoryModuleType
|
||||||
import net.minecraft.world.entity.ai.memory.MemoryStatus
|
import net.minecraft.world.entity.ai.memory.MemoryStatus
|
||||||
import net.minecraft.world.entity.ai.memory.WalkTarget
|
import net.minecraft.world.entity.ai.memory.WalkTarget
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.Level.ExplosionInteraction
|
import net.minecraft.world.level.Level.ExplosionInteraction
|
||||||
import net.minecraft.world.level.biome.Biome
|
import net.minecraft.world.level.biome.Biome
|
||||||
import net.minecraft.world.level.block.Block
|
import net.minecraft.world.level.block.Block
|
||||||
import net.minecraft.world.level.dimension.DimensionType
|
import net.minecraft.world.level.dimension.DimensionType
|
||||||
|
import net.minecraft.world.level.levelgen.Heightmap
|
||||||
import net.minecraft.world.phys.AABB
|
import net.minecraft.world.phys.AABB
|
||||||
import net.minecraft.world.phys.Vec3
|
import net.minecraft.world.phys.Vec3
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds a bunch of useful MoLang trickery that can be used or extended in API
|
* Holds a bunch of useful MoLang trickery that can be used or extended in API
|
||||||
@@ -228,6 +218,22 @@ object MoLangFunctions {
|
|||||||
val z = params.getInt(2)
|
val z = params.getInt(2)
|
||||||
return@put DoubleValue(world.isRainingAt(BlockPos(x, y, z)))
|
return@put DoubleValue(world.isRainingAt(BlockPos(x, y, z)))
|
||||||
}
|
}
|
||||||
|
map.put("is_snowing_at") { params ->
|
||||||
|
val x = params.getInt(0)
|
||||||
|
val y = params.getInt(1)
|
||||||
|
val z = params.getInt(2)
|
||||||
|
val blockPos = BlockPos(x, y, z)
|
||||||
|
if (!world.isRaining()) {
|
||||||
|
return@put DoubleValue.ZERO
|
||||||
|
} else if (!world.canSeeSky(blockPos)) {
|
||||||
|
return@put DoubleValue.ZERO
|
||||||
|
} else if (world.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, blockPos).getY() > blockPos.getY()) {
|
||||||
|
return@put DoubleValue.ZERO
|
||||||
|
} else {
|
||||||
|
val biome = world.getBiome(blockPos).value() as Biome
|
||||||
|
return@put DoubleValue(biome.getPrecipitationAt(blockPos) == Biome.Precipitation.SNOW)
|
||||||
|
}
|
||||||
|
}
|
||||||
map.put("is_chunk_loaded_at") { params ->
|
map.put("is_chunk_loaded_at") { params ->
|
||||||
val x = params.getInt(0)
|
val x = params.getInt(0)
|
||||||
val y = params.getInt(1)
|
val y = params.getInt(1)
|
||||||
@@ -306,6 +312,11 @@ object MoLangFunctions {
|
|||||||
.map { it.asMostSpecificMoLangValue() }
|
.map { it.asMostSpecificMoLangValue() }
|
||||||
.asArrayValue()
|
.asArrayValue()
|
||||||
}
|
}
|
||||||
|
map.put("is_healer_in_use") { params ->
|
||||||
|
val pos = params.get<ArrayStruct>(0).asBlockPos()
|
||||||
|
val healer = world.getBlockEntity(pos, CobblemonBlockEntities.HEALING_MACHINE).orElse(null) ?: return@put DoubleValue.ONE
|
||||||
|
return@put DoubleValue(healer.isInUse)
|
||||||
|
}
|
||||||
|
|
||||||
return@mutableListOf map
|
return@mutableListOf map
|
||||||
}
|
}
|
||||||
@@ -317,8 +328,8 @@ object MoLangFunctions {
|
|||||||
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||||
map.put("username") { _ -> StringValue(player.gameProfile.name) }
|
map.put("username") { _ -> StringValue(player.gameProfile.name) }
|
||||||
map.put("uuid") { _ -> StringValue(player.gameProfile.id.toString()) }
|
map.put("uuid") { _ -> StringValue(player.gameProfile.id.toString()) }
|
||||||
map.put("main_held_item") { _ -> player.level().itemRegistry.wrapAsHolder(player.mainHandItem.item).asMoLangValue(Registries.ITEM) }
|
map.put("main_held_item") { _ -> player.mainHandItem.asMoLangValue(player.registryAccess()) }
|
||||||
map.put("off_held_item") { _ -> player.level().itemRegistry.wrapAsHolder(player.offhandItem.item).asMoLangValue(Registries.ITEM) }
|
map.put("off_held_item") { _ -> player.offhandItem.asMoLangValue(player.registryAccess()) }
|
||||||
map.put("face") { params -> ObjectValue(PlayerDialogueFaceProvider(player.uuid, params.getBooleanOrNull(0) != false)) }
|
map.put("face") { params -> ObjectValue(PlayerDialogueFaceProvider(player.uuid, params.getBooleanOrNull(0) != false)) }
|
||||||
map.put("swing_hand") { _ -> player.swing(player.usedItemHand) }
|
map.put("swing_hand") { _ -> player.swing(player.usedItemHand) }
|
||||||
map.put("food_level") { _ -> DoubleValue(player.foodData.foodLevel) }
|
map.put("food_level") { _ -> DoubleValue(player.foodData.foodLevel) }
|
||||||
@@ -412,11 +423,39 @@ object MoLangFunctions {
|
|||||||
return@put DoubleValue.ONE
|
return@put DoubleValue.ONE
|
||||||
}
|
}
|
||||||
map.put("pokedex") { player.pokedex().struct }
|
map.put("pokedex") { player.pokedex().struct }
|
||||||
|
map.put("has_advancement") { params ->
|
||||||
|
val requiredAdvancement = ResourceLocation.parse(params.getString(0))
|
||||||
|
for (entry in player.advancements.progress) {
|
||||||
|
if (entry.key.id == requiredAdvancement && entry.value.isDone) {
|
||||||
|
return@put DoubleValue.ONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@put DoubleValue.ZERO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
val entityFunctions: MutableList<(LivingEntity) -> HashMap<String, java.util.function.Function<MoParams, Any>>> = mutableListOf<(LivingEntity) -> HashMap<String, java.util.function.Function<MoParams, Any>>>(
|
val itemStackFunctions = mutableListOf<(ItemStack, RegistryAccess) -> HashMap<String, java.util.function.Function<MoParams, Any>>>(
|
||||||
|
{ stack, registryAccess ->
|
||||||
|
val itemRegistry = registryAccess.registryOrThrow(Registries.ITEM)
|
||||||
|
val holder = itemRegistry.wrapAsHolder(stack.item)
|
||||||
|
|
||||||
|
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||||
|
map.put("item") { _ -> holder.asMoLangValue(Registries.ITEM) }
|
||||||
|
map.put("count") { _ -> DoubleValue(stack.count.toDouble()) }
|
||||||
|
map.put("damage_value") { _ -> DoubleValue(stack.damageValue) }
|
||||||
|
map.put("max_damage") { _ -> DoubleValue(stack.maxDamage) }
|
||||||
|
map.put("is_empty") { _ -> DoubleValue(stack.isEmpty) }
|
||||||
|
map.put("shrink") { params -> stack.shrink(params.getInt(0)) }
|
||||||
|
map.put("grow") { params -> stack.grow(params.getInt(0)) }
|
||||||
|
map.put("is_of") { params -> DoubleValue(holder.`is`(params.getString(0).asIdentifierDefaultingNamespace())) }
|
||||||
|
map.put("is_in") { params -> DoubleValue(holder.`is`(TagKey.create(Registries.ITEM, params.getString(0).replace("#", "").asIdentifierDefaultingNamespace()))) }
|
||||||
|
return@mutableListOf map
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
val entityFunctions: MutableList<(Entity) -> HashMap<String, java.util.function.Function<MoParams, Any>>> = mutableListOf(
|
||||||
{ entity ->
|
{ entity ->
|
||||||
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||||
map.put("uuid") { _ -> StringValue(entity.uuid.toString()) }
|
map.put("uuid") { _ -> StringValue(entity.uuid.toString()) }
|
||||||
@@ -425,48 +464,23 @@ object MoLangFunctions {
|
|||||||
val source = DamageSource(entity.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolder(DamageTypes.GENERIC).get())
|
val source = DamageSource(entity.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolder(DamageTypes.GENERIC).get())
|
||||||
entity.hurt(source, amount.toFloat())
|
entity.hurt(source, amount.toFloat())
|
||||||
}
|
}
|
||||||
map.put("walk_to") { params ->
|
|
||||||
val x = params.getDouble(0)
|
|
||||||
val y = params.getDouble(1)
|
|
||||||
val z = params.getDouble(2)
|
|
||||||
val speedMultiplier = params.getDoubleOrNull(3) ?: 0.35
|
|
||||||
if (entity is PathfinderMob) {
|
|
||||||
if (entity.brain.checkMemory(MemoryModuleType.WALK_TARGET, MemoryStatus.REGISTERED)) {
|
|
||||||
entity.brain.setMemory(MemoryModuleType.WALK_TARGET, WalkTarget(Vec3(x, y, z), speedMultiplier.toFloat(), 1))
|
|
||||||
entity.brain.setMemory(MemoryModuleType.LOOK_TARGET, BlockPosTracker(Vec3(x, y + entity.eyeHeight, z)))
|
|
||||||
} else {
|
|
||||||
entity.navigation.moveTo(x, y, z, speedMultiplier)
|
|
||||||
entity.lookControl.setLookAt(Vec3(x, y + entity.eyeHeight, z))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
map.put("has_walk_target") { _ ->
|
|
||||||
if (entity is PathfinderMob) {
|
|
||||||
DoubleValue(entity.brain.getMemory(MemoryModuleType.WALK_TARGET).isPresent || entity.isPathFinding)
|
|
||||||
} else {
|
|
||||||
DoubleValue.ZERO
|
|
||||||
}
|
|
||||||
}
|
|
||||||
map.put("is_sneaking") { _ -> DoubleValue(entity.isShiftKeyDown) }
|
map.put("is_sneaking") { _ -> DoubleValue(entity.isShiftKeyDown) }
|
||||||
map.put("is_sprinting") { _ -> DoubleValue(entity.isSprinting) }
|
map.put("is_sprinting") { _ -> DoubleValue(entity.isSprinting) }
|
||||||
map.put("is_flying") { _ -> DoubleValue(entity.isFallFlying) }
|
|
||||||
map.put("is_in_water") { _ -> DoubleValue(entity.isUnderWater) }
|
map.put("is_in_water") { _ -> DoubleValue(entity.isUnderWater) }
|
||||||
|
map.put("is_in_rain") { _ -> DoubleValue(entity.isInWaterOrRain && !entity.isInWater) }
|
||||||
map.put("is_touching_water_or_rain") { _ -> DoubleValue(entity.isInWaterRainOrBubble) }
|
map.put("is_touching_water_or_rain") { _ -> DoubleValue(entity.isInWaterRainOrBubble) }
|
||||||
map.put("is_touching_water") { _ -> DoubleValue(entity.isInWater) }
|
map.put("is_touching_water") { _ -> DoubleValue(entity.isInWater) }
|
||||||
map.put("is_underwater") { DoubleValue(entity.getIsSubmerged()) }
|
map.put("is_underwater") { DoubleValue(entity.getIsSubmerged()) }
|
||||||
map.put("is_in_lava") { _ -> DoubleValue(entity.isInLava) }
|
map.put("is_in_lava") { _ -> DoubleValue(entity.isInLava) }
|
||||||
map.put("is_on_fire") { _ -> DoubleValue(entity.isOnFire) }
|
map.put("is_on_fire") { _ -> DoubleValue(entity.isOnFire) }
|
||||||
map.put("is_invisible") { _ -> DoubleValue(entity.isInvisible) }
|
map.put("is_invisible") { _ -> DoubleValue(entity.isInvisible) }
|
||||||
map.put("is_sleeping") { _ -> DoubleValue(entity.isSleeping) }
|
|
||||||
map.put("is_riding") { _ -> DoubleValue(entity.isPassenger) }
|
map.put("is_riding") { _ -> DoubleValue(entity.isPassenger) }
|
||||||
map.put("health") { _ -> DoubleValue(entity.health) }
|
|
||||||
map.put("distance_to_pos") { params ->
|
map.put("distance_to_pos") { params ->
|
||||||
val x = params.getDouble(0)
|
val x = params.getDouble(0)
|
||||||
val y = params.getDouble(1)
|
val y = params.getDouble(1)
|
||||||
val z = params.getDouble(2)
|
val z = params.getDouble(2)
|
||||||
return@put DoubleValue(sqrt(entity.distanceToSqr(Vec3(x, y, z))))
|
return@put DoubleValue(sqrt(entity.distanceToSqr(Vec3(x, y, z))))
|
||||||
}
|
}
|
||||||
map.put("max_health") { _ -> DoubleValue(entity.maxHealth) }
|
|
||||||
map.put("name") { _ -> StringValue(entity.effectiveName().string) }
|
map.put("name") { _ -> StringValue(entity.effectiveName().string) }
|
||||||
map.put("type") { _ ->
|
map.put("type") { _ ->
|
||||||
entity.registryAccess().registry(Registries.ENTITY_TYPE).get().getKey(entity.type)?.toString()?.let {
|
entity.registryAccess().registry(Registries.ENTITY_TYPE).get().getKey(entity.type)?.toString()?.let {
|
||||||
@@ -493,11 +507,6 @@ object MoLangFunctions {
|
|||||||
map.put("world") { _ -> entity.level().worldRegistry.wrapAsHolder(entity.level()).asWorldMoLangValue() }
|
map.put("world") { _ -> entity.level().worldRegistry.wrapAsHolder(entity.level()).asWorldMoLangValue() }
|
||||||
map.put("biome") { _ -> entity.level().getBiome(entity.blockPosition()).asBiomeMoLangValue() }
|
map.put("biome") { _ -> entity.level().getBiome(entity.blockPosition()).asBiomeMoLangValue() }
|
||||||
map.put("is_passenger") { DoubleValue(entity.isPassenger) }
|
map.put("is_passenger") { DoubleValue(entity.isPassenger) }
|
||||||
map.put("is_healer_in_use") { params ->
|
|
||||||
val pos = params.get<ArrayStruct>(0).asBlockPos()
|
|
||||||
val healer = entity.level().getBlockEntity(pos, CobblemonBlockEntities.HEALING_MACHINE).orElse(null) ?: return@put DoubleValue.ONE
|
|
||||||
return@put DoubleValue(healer.isInUse)
|
|
||||||
}
|
|
||||||
map.put("find_nearby_block") { params ->
|
map.put("find_nearby_block") { params ->
|
||||||
val type = params.getString(0).asIdentifierDefaultingNamespace(namespace = "minecraft")
|
val type = params.getString(0).asIdentifierDefaultingNamespace(namespace = "minecraft")
|
||||||
val isTag = type.path.startsWith("#")
|
val isTag = type.path.startsWith("#")
|
||||||
@@ -516,7 +525,7 @@ object MoLangFunctions {
|
|||||||
val distance = params.getDouble(0)
|
val distance = params.getDouble(0)
|
||||||
val entities = entity.level().getEntities(entity, AABB.ofSize(entity.position(), distance, distance, distance))
|
val entities = entity.level().getEntities(entity, AABB.ofSize(entity.position(), distance, distance, distance))
|
||||||
return@put entities
|
return@put entities
|
||||||
.filterIsInstance<LivingEntity>()
|
.filterIsInstance<Entity>()
|
||||||
.map { it.asMostSpecificMoLangValue() }
|
.map { it.asMostSpecificMoLangValue() }
|
||||||
.asArrayValue()
|
.asArrayValue()
|
||||||
}
|
}
|
||||||
@@ -573,6 +582,45 @@ object MoLangFunctions {
|
|||||||
packet.sendToPlayer(player)
|
packet.sendToPlayer(player)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return@mutableListOf map
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
val livingEntityFunctions: MutableList<(LivingEntity) -> HashMap<String, java.util.function.Function<MoParams, Any>>> = mutableListOf<(LivingEntity) -> HashMap<String, java.util.function.Function<MoParams, Any>>>(
|
||||||
|
{ entity ->
|
||||||
|
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||||
|
map.put("is_living_entity") { DoubleValue.ONE }
|
||||||
|
map.put("is_flying") { _ -> DoubleValue(entity.isFallFlying) }
|
||||||
|
map.put("is_sleeping") { _ -> DoubleValue(entity.isSleeping) }
|
||||||
|
map.put("health") { _ -> DoubleValue(entity.health) }
|
||||||
|
map.put("max_health") { _ -> DoubleValue(entity.maxHealth) }
|
||||||
|
|
||||||
|
if (entity is PathfinderMob) {
|
||||||
|
map.put("walk_to") { params ->
|
||||||
|
val x = params.getDouble(0)
|
||||||
|
val y = params.getDouble(1)
|
||||||
|
val z = params.getDouble(2)
|
||||||
|
val speedMultiplier = params.getDoubleOrNull(3) ?: 0.35
|
||||||
|
|
||||||
|
if (entity.brain.checkMemory(MemoryModuleType.WALK_TARGET, MemoryStatus.REGISTERED)) {
|
||||||
|
entity.brain.setMemory(
|
||||||
|
MemoryModuleType.WALK_TARGET,
|
||||||
|
WalkTarget(Vec3(x, y, z), speedMultiplier.toFloat(), 1)
|
||||||
|
)
|
||||||
|
entity.brain.setMemory(
|
||||||
|
MemoryModuleType.LOOK_TARGET,
|
||||||
|
BlockPosTracker(Vec3(x, y + entity.eyeHeight, z))
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
entity.navigation.moveTo(x, y, z, speedMultiplier)
|
||||||
|
entity.lookControl.setLookAt(Vec3(x, y + entity.eyeHeight, z))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map.put("has_walk_target") { _ ->
|
||||||
|
DoubleValue(entity.brain.getMemory(MemoryModuleType.WALK_TARGET).isPresent || entity.isPathFinding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -691,6 +739,8 @@ object MoLangFunctions {
|
|||||||
map.put("npc") { battleActor.entity.struct }
|
map.put("npc") { battleActor.entity.struct }
|
||||||
} else if (battleActor is PlayerBattleActor) {
|
} else if (battleActor is PlayerBattleActor) {
|
||||||
map.put("player") { battleActor.entity?.asMoLangValue() ?: DoubleValue.ZERO }
|
map.put("player") { battleActor.entity?.asMoLangValue() ?: DoubleValue.ZERO }
|
||||||
|
} else if (battleActor is PokemonBattleActor) {
|
||||||
|
map.put("pokemon") { battleActor.entity?.asMoLangValue() ?: DoubleValue.ZERO }
|
||||||
}
|
}
|
||||||
return@mutableListOf map
|
return@mutableListOf map
|
||||||
}
|
}
|
||||||
@@ -729,6 +779,34 @@ object MoLangFunctions {
|
|||||||
DoubleValue.ONE
|
DoubleValue.ONE
|
||||||
}
|
}
|
||||||
map.put("owner") { pokemon.getOwnerPlayer()?.asMoLangValue() ?: DoubleValue.ZERO }
|
map.put("owner") { pokemon.getOwnerPlayer()?.asMoLangValue() ?: DoubleValue.ZERO }
|
||||||
|
map.put("add_marks") { params ->
|
||||||
|
for (param in params.params) {
|
||||||
|
val identifier = param.asString().asIdentifierDefaultingNamespace()
|
||||||
|
val mark = Marks.getByIdentifier(identifier)
|
||||||
|
if (mark != null) pokemon.exchangeMark(mark, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map.put("add_marks_with_chance") { params ->
|
||||||
|
for (param in params.params) {
|
||||||
|
val identifier = param.asString().asIdentifierDefaultingNamespace()
|
||||||
|
val mark = Marks.getByIdentifier(identifier)
|
||||||
|
mark?.let {
|
||||||
|
val probability = it.chance.coerceIn(0F, 1F) * 100
|
||||||
|
val randomValue = Random.nextDouble(0.0, 100.0)
|
||||||
|
if (randomValue < probability) pokemon.exchangeMark(it, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map.put("add_potential_marks") { params ->
|
||||||
|
for (param in params.params) {
|
||||||
|
val identifier = param.asString().asIdentifierDefaultingNamespace()
|
||||||
|
val mark = Marks.getByIdentifier(identifier)
|
||||||
|
if (mark != null) pokemon.addPotentialMark(mark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map.put("apply_potential_marks") {
|
||||||
|
return@put DoubleValue(pokemon.applyPotentialMarks())
|
||||||
|
}
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -739,8 +817,10 @@ object MoLangFunctions {
|
|||||||
map.put("in_battle") { DoubleValue(pokemonEntity.isBattling) }
|
map.put("in_battle") { DoubleValue(pokemonEntity.isBattling) }
|
||||||
map.put("is_moving") { DoubleValue((pokemonEntity.moveControl as? PokemonMoveControl)?.hasWanted() == true) }
|
map.put("is_moving") { DoubleValue((pokemonEntity.moveControl as? PokemonMoveControl)?.hasWanted() == true) }
|
||||||
map.put("is_flying") { DoubleValue(pokemonEntity.getBehaviourFlag(PokemonBehaviourFlag.FLYING)) }
|
map.put("is_flying") { DoubleValue(pokemonEntity.getBehaviourFlag(PokemonBehaviourFlag.FLYING)) }
|
||||||
|
map.put("is_gliding") { DoubleValue(pokemonEntity.useRidingAltPose()) }
|
||||||
map.put("has_aspect") { DoubleValue(it.getString(0) in pokemonEntity.aspects) }
|
map.put("has_aspect") { DoubleValue(it.getString(0) in pokemonEntity.aspects) }
|
||||||
map.put("is_pokemon") { DoubleValue.ONE }
|
map.put("is_pokemon") { DoubleValue.ONE }
|
||||||
|
map.put("is_holding_item") { DoubleValue(!pokemonEntity.entityData.get(PokemonEntity.SHOWN_HELD_ITEM).isEmpty) }
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -748,6 +828,7 @@ object MoLangFunctions {
|
|||||||
val pokemonStoreFunctions = mutableListOf<(PokemonStore<*>) -> HashMap<String, java.util.function.Function<MoParams, Any>>>(
|
val pokemonStoreFunctions = mutableListOf<(PokemonStore<*>) -> HashMap<String, java.util.function.Function<MoParams, Any>>>(
|
||||||
{ store ->
|
{ store ->
|
||||||
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||||
|
map.put("uuid") { StringValue(store.uuid.toString()) }
|
||||||
map.put("add") { params ->
|
map.put("add") { params ->
|
||||||
val pokemon = params.get<ObjectValue<Pokemon>>(0)
|
val pokemon = params.get<ObjectValue<Pokemon>>(0)
|
||||||
return@put DoubleValue(store.add(pokemon.obj))
|
return@put DoubleValue(store.add(pokemon.obj))
|
||||||
@@ -848,6 +929,17 @@ object MoLangFunctions {
|
|||||||
return@put DoubleValue.ONE
|
return@put DoubleValue.ONE
|
||||||
}
|
}
|
||||||
map.put("get_box_count") { _ -> DoubleValue(pc.boxes.size.toDouble()) }
|
map.put("get_box_count") { _ -> DoubleValue(pc.boxes.size.toDouble()) }
|
||||||
|
map.put("has_unlocked_wallpaper") { params ->
|
||||||
|
val wallpaper = params.getString(0).asIdentifierDefaultingNamespace()
|
||||||
|
return@put DoubleValue(pc.unlockedWallpapers.contains(wallpaper))
|
||||||
|
}
|
||||||
|
map.put("get_unlocked_wallpapers") { pc.unlockedWallpapers.asArrayValue { StringValue(it.toString()) } }
|
||||||
|
map.put("unlock_wallpaper") {
|
||||||
|
val wallpaper = it.getString(0).asIdentifierDefaultingNamespace()
|
||||||
|
val playSound = it.getBooleanOrNull(1) != false
|
||||||
|
CobblemonUnlockableWallpapers.unlockableWallpapers[wallpaper] ?: return@put DoubleValue.ZERO
|
||||||
|
return@put DoubleValue(pc.unlockWallpaper(wallpaper, playSound))
|
||||||
|
}
|
||||||
return@mutableListOf map
|
return@mutableListOf map
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -856,7 +948,7 @@ object MoLangFunctions {
|
|||||||
{ spawningContext ->
|
{ spawningContext ->
|
||||||
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||||
val worldValue = spawningContext.world.registryAccess().registryOrThrow(Registries.DIMENSION).wrapAsHolder(spawningContext.world).asWorldMoLangValue()
|
val worldValue = spawningContext.world.registryAccess().registryOrThrow(Registries.DIMENSION).wrapAsHolder(spawningContext.world).asWorldMoLangValue()
|
||||||
val biomeValue = spawningContext.biomeRegistry.wrapAsHolder(spawningContext.biome).asBiomeMoLangValue()
|
val biomeValue = spawningContext.biomeHolder.asBiomeMoLangValue()
|
||||||
map.put("biome") { _ -> biomeValue }
|
map.put("biome") { _ -> biomeValue }
|
||||||
map.put("world") { _ -> worldValue }
|
map.put("world") { _ -> worldValue }
|
||||||
map.put("light") { _ -> DoubleValue(spawningContext.light.toDouble()) }
|
map.put("light") { _ -> DoubleValue(spawningContext.light.toDouble()) }
|
||||||
@@ -1084,18 +1176,35 @@ object MoLangFunctions {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun ItemStack.asMoLangValue(registryAccess: RegistryAccess) = ObjectValue(this).addStandardFunctions().addFunctions(itemStackFunctions.flatMap { it(this, registryAccess).entries.map { it.key to it.value } }.toMap())
|
||||||
fun Holder<Biome>.asBiomeMoLangValue() = asMoLangValue(Registries.BIOME).addFunctions(biomeFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
fun Holder<Biome>.asBiomeMoLangValue() = asMoLangValue(Registries.BIOME).addFunctions(biomeFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
fun Holder<Level>.asWorldMoLangValue() = asMoLangValue(Registries.DIMENSION).addFunctions(worldFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
fun Holder<Level>.asWorldMoLangValue() = asMoLangValue(Registries.DIMENSION).addFunctions(worldFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
fun Holder<Block>.asBlockMoLangValue() = asMoLangValue(Registries.BLOCK).addFunctions(blockFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
fun Holder<Block>.asBlockMoLangValue() = asMoLangValue(Registries.BLOCK).addFunctions(blockFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
fun MinecraftServer.asMoLangValue() = ObjectValue(this).addStandardFunctions().addFunctions(serverFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
fun MinecraftServer.asMoLangValue() = ObjectValue(this).addStandardFunctions().addFunctions(serverFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
fun Holder<DimensionType>.asDimensionTypeMoLangValue() = asMoLangValue(Registries.DIMENSION_TYPE).addFunctions(dimensionTypeFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
fun Holder<DimensionType>.asDimensionTypeMoLangValue() = asMoLangValue(Registries.DIMENSION_TYPE).addFunctions(dimensionTypeFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
fun Player.asMoLangValue(): ObjectValue<Player> {
|
fun Player.asMoLangValue(): ObjectValue<Player> {
|
||||||
|
if (this is ServerPlayer && uuid in Cobblemon.serverPlayerStructs) {
|
||||||
|
val existing = Cobblemon.serverPlayerStructs[uuid]!!
|
||||||
|
if (existing.obj == this) {
|
||||||
|
return existing
|
||||||
|
} else {
|
||||||
|
Cobblemon.serverPlayerStructs.remove(uuid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val value = ObjectValue(
|
val value = ObjectValue(
|
||||||
obj = this,
|
obj = this,
|
||||||
stringify = { it.effectiveName().string }
|
stringify = { it.effectiveName().string }
|
||||||
)
|
)
|
||||||
|
|
||||||
value.addFunctions(entityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
value.addFunctions(entityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
|
value.addFunctions(livingEntityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
value.addFunctions(playerFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
value.addFunctions(playerFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
|
|
||||||
|
if (this is ServerPlayer) {
|
||||||
|
Cobblemon.serverPlayerStructs[uuid] = value
|
||||||
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1150,6 +1259,7 @@ object MoLangFunctions {
|
|||||||
stringify = { it.name.string }
|
stringify = { it.name.string }
|
||||||
)
|
)
|
||||||
value.addFunctions(entityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
value.addFunctions(entityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
|
value.addFunctions(livingEntityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
value.addFunctions(npcFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
value.addFunctions(npcFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
@@ -1160,6 +1270,7 @@ object MoLangFunctions {
|
|||||||
stringify = { it.pokemon.uuid.toString() }
|
stringify = { it.pokemon.uuid.toString() }
|
||||||
)
|
)
|
||||||
value.addFunctions(entityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
value.addFunctions(entityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
|
value.addFunctions(livingEntityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
value.addFunctions(pokemonFunctions.flatMap { it(this.pokemon).entries.map { it.key to it.value } }.toMap()) // Convenience
|
value.addFunctions(pokemonFunctions.flatMap { it(this.pokemon).entries.map { it.key to it.value } }.toMap()) // Convenience
|
||||||
value.addFunctions(pokemonEntityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
value.addFunctions(pokemonEntityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
return value
|
return value
|
||||||
@@ -1195,12 +1306,18 @@ object MoLangFunctions {
|
|||||||
/**
|
/**
|
||||||
* Different functions exist depending on
|
* Different functions exist depending on
|
||||||
*/
|
*/
|
||||||
fun LivingEntity.asMostSpecificMoLangValue(): ObjectValue<out LivingEntity> {
|
fun Entity.asMostSpecificMoLangValue(): ObjectValue<out Entity> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Player -> asMoLangValue()
|
is Player -> asMoLangValue()
|
||||||
is PokemonEntity -> struct
|
is PokemonEntity -> struct
|
||||||
is NPCEntity -> struct
|
is NPCEntity -> struct
|
||||||
else -> ObjectValue(this).also { it.addStandardFunctions().addFunctions(entityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap()) }
|
else -> ObjectValue(this).also {
|
||||||
|
it.addStandardFunctions()
|
||||||
|
it.addFunctions(entityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
|
if (this is LivingEntity) {
|
||||||
|
it.addFunctions(livingEntityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1225,7 +1342,7 @@ object MoLangFunctions {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun QueryStruct.addEntityFunctions(entity: LivingEntity): QueryStruct {
|
fun QueryStruct.addEntityFunctions(entity: Entity): QueryStruct {
|
||||||
val addedFunctions = entityFunctions
|
val addedFunctions = entityFunctions
|
||||||
.flatMap { it.invoke(entity).entries }
|
.flatMap { it.invoke(entity).entries }
|
||||||
.associate { it.key to it.value }
|
.associate { it.key to it.value }
|
||||||
@@ -1233,6 +1350,14 @@ object MoLangFunctions {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun QueryStruct.addLivingEntityFunctions(entity: LivingEntity): QueryStruct {
|
||||||
|
val addedFunctions = livingEntityFunctions
|
||||||
|
.flatMap { it.invoke(entity).entries }
|
||||||
|
.associate { it.key to it.value }
|
||||||
|
functions.putAll(addedFunctions)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
fun QueryStruct.addPokedexFunctions(pokedexManager: AbstractPokedexManager): QueryStruct {
|
fun QueryStruct.addPokedexFunctions(pokedexManager: AbstractPokedexManager): QueryStruct {
|
||||||
val addedFunctions = pokedexFunctions
|
val addedFunctions = pokedexFunctions
|
||||||
.flatMap { it.invoke(pokedexManager).entries }
|
.flatMap { it.invoke(pokedexManager).entries }
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
package com.cobblemon.mod.common.api.moves
|
package com.cobblemon.mod.common.api.moves
|
||||||
|
|
||||||
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
|
||||||
import com.cobblemon.mod.common.net.IntSize
|
import com.cobblemon.mod.common.net.IntSize
|
||||||
import com.cobblemon.mod.common.util.DataKeys
|
import com.cobblemon.mod.common.util.DataKeys
|
||||||
import com.cobblemon.mod.common.util.readSizedInt
|
import com.cobblemon.mod.common.util.readSizedInt
|
||||||
@@ -24,7 +23,7 @@ import net.minecraft.nbt.ListTag
|
|||||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
|
||||||
class BenchedMoves : Iterable<BenchedMove> {
|
class BenchedMoves : Iterable<BenchedMove> {
|
||||||
val observable = SimpleObservable<BenchedMoves>()
|
var changeFunction: ((BenchedMoves) -> Unit) = {}
|
||||||
private var emit = true
|
private var emit = true
|
||||||
private val benchedMoves = mutableListOf<BenchedMove>()
|
private val benchedMoves = mutableListOf<BenchedMove>()
|
||||||
|
|
||||||
@@ -50,7 +49,7 @@ class BenchedMoves : Iterable<BenchedMove> {
|
|||||||
|
|
||||||
fun update() {
|
fun update() {
|
||||||
if (emit) {
|
if (emit) {
|
||||||
observable.emit(this)
|
changeFunction(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ package com.cobblemon.mod.common.api.moves
|
|||||||
|
|
||||||
import com.bedrockk.molang.runtime.struct.QueryStruct
|
import com.bedrockk.molang.runtime.struct.QueryStruct
|
||||||
import com.bedrockk.molang.runtime.value.DoubleValue
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
|
||||||
import com.cobblemon.mod.common.net.IntSize
|
import com.cobblemon.mod.common.net.IntSize
|
||||||
import com.cobblemon.mod.common.util.DataKeys
|
import com.cobblemon.mod.common.util.DataKeys
|
||||||
import com.cobblemon.mod.common.util.readSizedInt
|
import com.cobblemon.mod.common.util.readSizedInt
|
||||||
@@ -24,7 +23,7 @@ import com.mojang.serialization.Codec
|
|||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class MoveSet : Iterable<Move> {
|
class MoveSet : Iterable<Move> {
|
||||||
val observable = SimpleObservable<MoveSet>()
|
var changeFunction: (MoveSet) -> Unit = {}
|
||||||
private var emit = true
|
private var emit = true
|
||||||
|
|
||||||
private val moves = arrayOfNulls<Move>(MOVE_COUNT)
|
private val moves = arrayOfNulls<Move>(MOVE_COUNT)
|
||||||
@@ -153,7 +152,7 @@ class MoveSet : Iterable<Move> {
|
|||||||
|
|
||||||
fun update() {
|
fun update() {
|
||||||
if (emit) {
|
if (emit) {
|
||||||
observable.emit(this)
|
changeFunction(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ open class MoveTemplate(
|
|||||||
// TODO: Handle Liquid Voice: need to know what moves have the sound flag
|
// TODO: Handle Liquid Voice: need to know what moves have the sound flag
|
||||||
// TODO: Handle weatherball, naturalgift, judgement, technoblast, terrainpulse, and terrablast
|
// TODO: Handle weatherball, naturalgift, judgement, technoblast, terrainpulse, and terrablast
|
||||||
if (this.elementalType == ElementalTypes.NORMAL) {
|
if (this.elementalType == ElementalTypes.NORMAL) {
|
||||||
if( this.damageCategory != DamageCategories.STATUS) {
|
if (this.damageCategory != DamageCategories.STATUS) {
|
||||||
return when (pokemon.ability.name) {
|
return when (pokemon.ability.name) {
|
||||||
"pixilate" -> ElementalTypes.FAIRY
|
"pixilate" -> ElementalTypes.FAIRY
|
||||||
"aerilate" -> ElementalTypes.FLYING
|
"aerilate" -> ElementalTypes.FLYING
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.net.serializers
|
||||||
|
|
||||||
|
object RidingStateSerializer {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+35
-18
@@ -7,27 +7,31 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package com.cobblemon.mod.common.api.npc.partyproviders
|
package com.cobblemon.mod.common.api.npc.partyproviders
|
||||||
|
|
||||||
import com.bedrockk.molang.Expression
|
import com.bedrockk.molang.Expression
|
||||||
import com.bedrockk.molang.runtime.MoLangRuntime
|
import com.bedrockk.molang.runtime.MoLangRuntime
|
||||||
import com.bedrockk.molang.runtime.value.DoubleValue
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
|
import com.cobblemon.mod.common.Cobblemon.LOGGER
|
||||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.asMoLangValue
|
import com.cobblemon.mod.common.api.molang.MoLangFunctions.asMoLangValue
|
||||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.setup
|
import com.cobblemon.mod.common.api.molang.MoLangFunctions.setup
|
||||||
import com.cobblemon.mod.common.api.npc.NPCPartyProvider
|
import com.cobblemon.mod.common.api.npc.NPCPartyProvider
|
||||||
import com.cobblemon.mod.common.api.pokemon.PokemonProperties
|
import com.cobblemon.mod.common.api.pokemon.PokemonProperties
|
||||||
import com.cobblemon.mod.common.api.storage.party.NPCPartyStore
|
import com.cobblemon.mod.common.api.storage.party.NPCPartyStore
|
||||||
import com.cobblemon.mod.common.entity.npc.NPCEntity
|
import com.cobblemon.mod.common.entity.npc.NPCEntity
|
||||||
import com.cobblemon.mod.common.util.asArrayValue
|
import com.cobblemon.mod.common.util.*
|
||||||
import com.cobblemon.mod.common.util.asExpression
|
|
||||||
import com.cobblemon.mod.common.util.resolveFloat
|
|
||||||
import com.cobblemon.mod.common.util.resolveInt
|
|
||||||
import com.cobblemon.mod.common.util.weightedSelection
|
|
||||||
import com.cobblemon.mod.common.util.withQueryValue
|
|
||||||
import com.google.gson.JsonElement
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonPrimitive
|
import com.google.gson.JsonPrimitive
|
||||||
import kotlin.random.Random
|
|
||||||
import net.minecraft.server.level.ServerPlayer
|
import net.minecraft.server.level.ServerPlayer
|
||||||
|
import kotlin.collections.List
|
||||||
|
import kotlin.collections.any
|
||||||
|
import kotlin.collections.filter
|
||||||
|
import kotlin.collections.first
|
||||||
|
import kotlin.collections.mutableListOf
|
||||||
|
import kotlin.collections.mutableMapOf
|
||||||
|
import kotlin.collections.randomOrNull
|
||||||
|
import kotlin.collections.set
|
||||||
|
import kotlin.collections.toMutableList
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A provider of a party for battling the NPC. It generates a party using a more complex process
|
* A provider of a party for battling the NPC. It generates a party using a more complex process
|
||||||
@@ -60,9 +64,9 @@ class PoolPartyProvider : NPCPartyProvider {
|
|||||||
json as JsonObject
|
json as JsonObject
|
||||||
this.minPokemon = json.getAsJsonPrimitive("minPokemon").asString?.asExpression() ?: "1".asExpression()
|
this.minPokemon = json.getAsJsonPrimitive("minPokemon").asString?.asExpression() ?: "1".asExpression()
|
||||||
this.maxPokemon = json.getAsJsonPrimitive("maxPokemon").asString?.asExpression() ?: "6".asExpression()
|
this.maxPokemon = json.getAsJsonPrimitive("maxPokemon").asString?.asExpression() ?: "6".asExpression()
|
||||||
this.pool = json.getAsJsonArray("pool").map {
|
this.pool = json.getAsJsonArray("pool").mapNotNull {
|
||||||
if (it is JsonPrimitive) {
|
if (it is JsonPrimitive) {
|
||||||
return@map DynamicPokemon(
|
return@mapNotNull DynamicPokemon(
|
||||||
PokemonProperties.parse(it.asString),
|
PokemonProperties.parse(it.asString),
|
||||||
"0".asExpression(),
|
"0".asExpression(),
|
||||||
null,
|
null,
|
||||||
@@ -73,17 +77,26 @@ class PoolPartyProvider : NPCPartyProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it as JsonObject
|
it as JsonObject
|
||||||
DynamicPokemon(
|
val properties = PokemonProperties.parse(it.get("pokemon").asString)
|
||||||
PokemonProperties.parse(it.get("pokemon").asString),
|
// Checks for errors on Pokémon name, if not a valid species ignores it to avoid random Pokémon in the Pool.
|
||||||
it.get("levelVariation")?.asString?.asExpression() ?: "0".asExpression(),
|
if (properties.species == null) {
|
||||||
it.get("level")?.asString?.asExpression(),
|
LOGGER.warn("Error making NPC pokemon pool. ${it.get("pokemon").asString.substringBefore(" ")} is not a valid species, ignoring")
|
||||||
it.get("npcLevels")?.asString?.split("-")?.let { it[0].toInt()..it[1].toInt() } ?: 1..100,
|
null
|
||||||
it.get("selectableTimes")?.asString?.asExpression() ?: "1".asExpression(),
|
}
|
||||||
it.get("weight")?.asString?.asExpression() ?: "1".asExpression()
|
else {
|
||||||
)
|
DynamicPokemon(
|
||||||
|
properties,
|
||||||
|
it.get("levelVariation")?.asString?.asExpression() ?: "0".asExpression(),
|
||||||
|
it.get("level")?.asString?.asExpression(),
|
||||||
|
it.get("npcLevels")?.asString?.split("-")?.let { it[0].toInt()..it[1].toInt() } ?: 1..100,
|
||||||
|
it.get("selectableTimes")?.asString?.asExpression() ?: "1".asExpression(),
|
||||||
|
it.get("weight")?.asString?.asExpression() ?: "1".asExpression()
|
||||||
|
)
|
||||||
|
}
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
isStatic = json.get("isStatic").asBoolean
|
isStatic = json.get("isStatic").asBoolean
|
||||||
json.get("useFixedRandom")?.asBoolean?.let { useFixedRandom = it }
|
json.get("useFixedRandom")?.asBoolean?.let { useFixedRandom = it }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynamicPokemon(
|
class DynamicPokemon(
|
||||||
@@ -137,6 +150,10 @@ class PoolPartyProvider : NPCPartyProvider {
|
|||||||
val instance = selected.pokemon.copy().also { it.level = it.level ?: dictatedLevel ?: randomLevel }.create()
|
val instance = selected.pokemon.copy().also { it.level = it.level ?: dictatedLevel ?: randomLevel }.create()
|
||||||
party.add(instance)
|
party.add(instance)
|
||||||
}
|
}
|
||||||
|
if (party.none()) {
|
||||||
|
LOGGER.error("${npc} has no Pokemon on Party")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun provide(npc: NPCEntity, level: Int, players: List<ServerPlayer>): NPCPartyStore {
|
override fun provide(npc: NPCEntity, level: Int, players: List<ServerPlayer>): NPCPartyStore {
|
||||||
|
|||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.orientation
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.util.math.geometry.toDegrees
|
||||||
|
import com.cobblemon.mod.common.util.math.geometry.toRadians
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.Mth
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import org.joml.Matrix3f
|
||||||
|
import org.joml.Quaternionf
|
||||||
|
import org.joml.Vector3f
|
||||||
|
import kotlin.math.asin
|
||||||
|
|
||||||
|
open class OrientationController(val entity: LivingEntity) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val FORWARDS: Vector3f = Vector3f(0.0f, 0.0f, -1.0f)
|
||||||
|
val UP: Vector3f = Vector3f(0.0f, 1.0f, 0.0f)
|
||||||
|
val LEFT: Vector3f = Vector3f(-1.0f, 0.0f, 0.0f)
|
||||||
|
}
|
||||||
|
|
||||||
|
open var active: Boolean = false
|
||||||
|
|
||||||
|
var orientation: Matrix3f? = null
|
||||||
|
private set
|
||||||
|
|
||||||
|
private var renderOrientationO: Matrix3f? = null
|
||||||
|
private var renderOrientation: Matrix3f? = null
|
||||||
|
|
||||||
|
/** Adding this simply because it irritates me seeing `getActive` when most of this is Java. */
|
||||||
|
fun isActive() = active
|
||||||
|
|
||||||
|
fun updateOrientation(fn: (Matrix3f) -> Matrix3f?) {
|
||||||
|
if (!active) return
|
||||||
|
if (orientation == null) {
|
||||||
|
orientation = Matrix3f()
|
||||||
|
rotate(entity.yRot - 180, entity.xRot, 0f)
|
||||||
|
}
|
||||||
|
orientation = fn(orientation!!)
|
||||||
|
entity.yRot = yaw
|
||||||
|
entity.xRot = pitch
|
||||||
|
}
|
||||||
|
|
||||||
|
fun reset() {
|
||||||
|
orientation = null
|
||||||
|
renderOrientationO = null
|
||||||
|
renderOrientation = null
|
||||||
|
active = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rotate(yaw: Float, pitch: Float, roll: Float) {
|
||||||
|
rotateYaw(yaw)
|
||||||
|
rotatePitch(pitch)
|
||||||
|
rotateRoll(roll)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getRenderOrientation(delta: Float): Quaternionf {
|
||||||
|
val old = renderOrientationO ?: renderOrientation ?: orientation
|
||||||
|
val new = renderOrientation ?: old
|
||||||
|
val oldQuat = Quaternionf().setFromUnnormalized(old)
|
||||||
|
val newQuat = Quaternionf().setFromUnnormalized(new)
|
||||||
|
oldQuat.slerp(newQuat, delta)
|
||||||
|
return oldQuat
|
||||||
|
}
|
||||||
|
|
||||||
|
fun tick() {
|
||||||
|
if (!active || orientation == null) return
|
||||||
|
renderOrientationO = renderOrientation
|
||||||
|
val current = orientation
|
||||||
|
val renderMatrix = this.renderOrientation ?: current
|
||||||
|
val renderQuat = Quaternionf().setFromUnnormalized(renderMatrix)
|
||||||
|
val targetQuat = Quaternionf().setFromUnnormalized(current)
|
||||||
|
val dampingFactor = 0.66f // We can change this factor for faster transitions
|
||||||
|
renderQuat.slerp(targetQuat, dampingFactor)
|
||||||
|
|
||||||
|
val newRenderOrientation = Matrix3f()
|
||||||
|
renderQuat.get(newRenderOrientation)
|
||||||
|
renderOrientation = newRenderOrientation
|
||||||
|
}
|
||||||
|
|
||||||
|
val forwardVector: Vector3f
|
||||||
|
get() = orientation?.transform(FORWARDS, Vector3f()) ?: Vector3f(FORWARDS)
|
||||||
|
|
||||||
|
val leftVector: Vector3f
|
||||||
|
get() = orientation?.transform(LEFT, Vector3f()) ?: Vector3f(LEFT)
|
||||||
|
|
||||||
|
val upVector : Vector3f
|
||||||
|
get() = orientation?.transform(UP, Vector3f()) ?: Vector3f(UP)
|
||||||
|
|
||||||
|
fun rotateYaw(yaw: Float) = updateOrientation { it.rotateY(-yaw.toRadians()) }
|
||||||
|
fun rotatePitch(pitch: Float) = updateOrientation { it.rotateX(-pitch.toRadians()) }
|
||||||
|
fun rotateRoll(roll: Float) = updateOrientation { it.rotateZ(-roll.toRadians()) }
|
||||||
|
|
||||||
|
val yaw: Float
|
||||||
|
get() = Mth.wrapDegrees(-FORWARDS.angleSigned(forwardVector, UP).toDegrees() + 180)
|
||||||
|
|
||||||
|
val pitch: Float
|
||||||
|
get() = Mth.wrapDegrees(-asin(forwardVector.y).toDegrees())
|
||||||
|
|
||||||
|
val roll: Float
|
||||||
|
get() = Mth.wrapDegrees(-upVector.angleSigned(UP, forwardVector).toDegrees())
|
||||||
|
|
||||||
|
}
|
||||||
+62
-12
@@ -13,80 +13,130 @@ object CobblemonPermissions {
|
|||||||
private const val COMMAND_PREFIX = "command."
|
private const val COMMAND_PREFIX = "command."
|
||||||
private val permissions = arrayListOf<Permission>()
|
private val permissions = arrayListOf<Permission>()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val CHANGE_EYE_HEIGHT = this.create("${COMMAND_PREFIX}changeeyeheight", PermissionLevel.ALL_COMMANDS)
|
val CHANGE_EYE_HEIGHT = this.create("${COMMAND_PREFIX}changeeyeheight", PermissionLevel.ALL_COMMANDS)
|
||||||
|
@JvmStatic
|
||||||
val CHANGE_SCALE_AND_SIZE = this.create("${COMMAND_PREFIX}changescaleandsize", PermissionLevel.ALL_COMMANDS)
|
val CHANGE_SCALE_AND_SIZE = this.create("${COMMAND_PREFIX}changescaleandsize", PermissionLevel.ALL_COMMANDS)
|
||||||
|
@JvmStatic
|
||||||
val CHANGE_WALK_SPEED = this.create("${COMMAND_PREFIX}changewalkspeed", PermissionLevel.ALL_COMMANDS)
|
val CHANGE_WALK_SPEED = this.create("${COMMAND_PREFIX}changewalkspeed", PermissionLevel.ALL_COMMANDS)
|
||||||
val CHANGE_JOINT_SCALE = this.create("${COMMAND_PREFIX}changejointscale", PermissionLevel.ALL_COMMANDS)
|
@JvmStatic
|
||||||
|
val TRANSFORM_MODEL_PART = this.create("${COMMAND_PREFIX}transformmodelpart", PermissionLevel.ALL_COMMANDS)
|
||||||
|
@JvmStatic
|
||||||
val CHECKSPAWNS = this.create("${COMMAND_PREFIX}checkspawns", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val CHECKSPAWNS = this.create("${COMMAND_PREFIX}checkspawns", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val GET_NBT = this.create("${COMMAND_PREFIX}getnbt", PermissionLevel.ALL_COMMANDS)
|
val GET_NBT = this.create("${COMMAND_PREFIX}getnbt", PermissionLevel.ALL_COMMANDS)
|
||||||
|
|
||||||
private const val GIVE_POKEMON_BASE = "${COMMAND_PREFIX}givepokemon"
|
private const val GIVE_POKEMON_BASE = "${COMMAND_PREFIX}givepokemon"
|
||||||
|
@JvmStatic
|
||||||
val GIVE_POKEMON_SELF = this.create("${GIVE_POKEMON_BASE}.self", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val GIVE_POKEMON_SELF = this.create("${GIVE_POKEMON_BASE}.self", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val GIVE_POKEMON_OTHER = this.create("${GIVE_POKEMON_BASE}.other", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val GIVE_POKEMON_OTHER = this.create("${GIVE_POKEMON_BASE}.other", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
private const val HEAL_POKEMON_BASE = "${COMMAND_PREFIX}healpokemon"
|
private const val HEAL_POKEMON_BASE = "${COMMAND_PREFIX}healpokemon"
|
||||||
|
@JvmStatic
|
||||||
val HEAL_POKEMON_SELF = this.create("$HEAL_POKEMON_BASE.self", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val HEAL_POKEMON_SELF = this.create("$HEAL_POKEMON_BASE.self", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val HEAL_POKEMON_OTHER = this.create("$HEAL_POKEMON_BASE.other", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val HEAL_POKEMON_OTHER = this.create("$HEAL_POKEMON_BASE.other", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
|
||||||
private const val LEVEL_UP_BASE = "${COMMAND_PREFIX}levelup"
|
private const val LEVEL_UP_BASE = "${COMMAND_PREFIX}levelup"
|
||||||
|
@JvmStatic
|
||||||
val LEVEL_UP_SELF = this.create("$LEVEL_UP_BASE.self", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val LEVEL_UP_SELF = this.create("$LEVEL_UP_BASE.self", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val LEVEL_UP_OTHER = this.create("$LEVEL_UP_BASE.other", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val LEVEL_UP_OTHER = this.create("$LEVEL_UP_BASE.other", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val OPEN_STARTER_SCREEN = this.create("${COMMAND_PREFIX}openstarterscreen", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val OPEN_STARTER_SCREEN = this.create("${COMMAND_PREFIX}openstarterscreen", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val BEDROCK_PARTICLE = this.create("${COMMAND_PREFIX}bedrockparticle", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val BEDROCK_PARTICLE = this.create("${COMMAND_PREFIX}bedrockparticle", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val OPEN_DIALOGUE = this.create("${COMMAND_PREFIX}opendialogue", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val OPEN_DIALOGUE = this.create("${COMMAND_PREFIX}opendialogue", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
|
val UNLOCK_PC_BOX_WALLPAPER = this.create("${COMMAND_PREFIX}unlockpcboxwallpaper", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
private const val POKEMON_EDIT_BASE = "${COMMAND_PREFIX}pokemonedit"
|
private const val POKEMON_EDIT_BASE = "${COMMAND_PREFIX}pokemonedit"
|
||||||
|
@JvmStatic
|
||||||
val POKEMON_EDIT_SELF = this.create("$POKEMON_EDIT_BASE.self", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val POKEMON_EDIT_SELF = this.create("$POKEMON_EDIT_BASE.self", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val POKEMON_EDIT_OTHER = this.create("$POKEMON_EDIT_BASE.other", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val POKEMON_EDIT_OTHER = this.create("$POKEMON_EDIT_BASE.other", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val SPAWN_ALL_POKEMON = this.create("${COMMAND_PREFIX}spawnallpokemon", PermissionLevel.ALL_COMMANDS)
|
val SPAWN_ALL_POKEMON = this.create("${COMMAND_PREFIX}spawnallpokemon", PermissionLevel.ALL_COMMANDS)
|
||||||
|
@JvmStatic
|
||||||
val GIVE_ALL_POKEMON = this.create("${COMMAND_PREFIX}giveallpokemon", PermissionLevel.ALL_COMMANDS)
|
val GIVE_ALL_POKEMON = this.create("${COMMAND_PREFIX}giveallpokemon", PermissionLevel.ALL_COMMANDS)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val SPAWN_POKEMON = this.create("${COMMAND_PREFIX}spawnpokemon", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val SPAWN_POKEMON = this.create("${COMMAND_PREFIX}spawnpokemon", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val SPAWN_NPC = this.create("${COMMAND_PREFIX}spawnnpc", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val SPAWN_NPC = this.create("${COMMAND_PREFIX}spawnnpc", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val STOP_BATTLE = this.create("${COMMAND_PREFIX}stopbattle", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val STOP_BATTLE = this.create("${COMMAND_PREFIX}stopbattle", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val TAKE_POKEMON = this.create("${COMMAND_PREFIX}takepokemon", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val TAKE_POKEMON = this.create("${COMMAND_PREFIX}takepokemon", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val TEACH = this.create("${COMMAND_PREFIX}teach.base", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val TEACH = this.create("${COMMAND_PREFIX}teach.base", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val TEACH_BYPASS_LEARNSET = this.create("${COMMAND_PREFIX}teach.bypass", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val TEACH_BYPASS_LEARNSET = this.create("${COMMAND_PREFIX}teach.bypass", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val FRIENDSHIP = this.create("${COMMAND_PREFIX}friendship", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val FRIENDSHIP = this.create("${COMMAND_PREFIX}friendship", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val HELD_ITEM = this.create("${COMMAND_PREFIX}helditem", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val HELD_ITEM = this.create("${COMMAND_PREFIX}helditem", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
val PC = this.create("${COMMAND_PREFIX}pc", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
@JvmStatic
|
||||||
|
val CHANGE_MARK = this.create("${COMMAND_PREFIX}changemark", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
val PC = this.create("${COMMAND_PREFIX}pc", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val POKEBOX = this.create("${COMMAND_PREFIX}pokebox", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val POKEBOX = this.create("${COMMAND_PREFIX}pokebox", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val RENAMEBOX = this.create("${COMMAND_PREFIX}renamebox", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val RENAMEBOX = this.create("${COMMAND_PREFIX}renamebox", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val CHANGE_WALLPAPER = this.create("${COMMAND_PREFIX}changewallpaper", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val CHANGE_WALLPAPER = this.create("${COMMAND_PREFIX}changewallpaper", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val TEST_STORE = this.create("${COMMAND_PREFIX}teststore", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val TEST_STORE = this.create("${COMMAND_PREFIX}teststore", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val QUERY_LEARNSET = this.create("${COMMAND_PREFIX}querylearnset", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val QUERY_LEARNSET = this.create("${COMMAND_PREFIX}querylearnset", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val TEST_PC_SLOT = this.create("${COMMAND_PREFIX}testpcslot", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val TEST_PC_SLOT = this.create("${COMMAND_PREFIX}testpcslot", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val TEST_PARTY_SLOT = this.create("${COMMAND_PREFIX}testpartyslot", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val TEST_PARTY_SLOT = this.create("${COMMAND_PREFIX}testpartyslot", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val CLEAR_PARTY = this.create("${COMMAND_PREFIX}clearparty", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val CLEAR_PARTY = this.create("${COMMAND_PREFIX}clearparty", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val CLEAR_PC = this.create("${COMMAND_PREFIX}clearpc", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val CLEAR_PC = this.create("${COMMAND_PREFIX}clearpc", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val POKEDEX = this.create("${COMMAND_PREFIX}pokedex", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val POKEDEX = this.create("${COMMAND_PREFIX}pokedex", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
val NPC_EDIT = this.create("${COMMAND_PREFIX}npcedit", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val NPC_EDIT = this.create("${COMMAND_PREFIX}npcedit", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val NPC_DELETE = this.create("${COMMAND_PREFIX}npcdelete", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val NPC_DELETE = this.create("${COMMAND_PREFIX}npcdelete", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val FREEZE_POKEMON = this.create("${COMMAND_PREFIX}freezepokemon", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val FREEZE_POKEMON = this.create("${COMMAND_PREFIX}freezepokemon", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val APPLY_PLAYER_TEXTURE = this.create("${COMMAND_PREFIX}applyplayertexture", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val APPLY_PLAYER_TEXTURE = this.create("${COMMAND_PREFIX}applyplayertexture", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val ABANDON_MULTITEAM = this.create("${COMMAND_PREFIX}abandonmultiteam", PermissionLevel.NONE)
|
val ABANDON_MULTITEAM = this.create("${COMMAND_PREFIX}abandonmultiteam", PermissionLevel.NONE)
|
||||||
|
@JvmStatic
|
||||||
val RUN_MOLANG_SCRIPT = this.create("${COMMAND_PREFIX}runmolangscript", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val RUN_MOLANG_SCRIPT = this.create("${COMMAND_PREFIX}runmolangscript", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
val COBBLEMON_CONFIG_RELOAD = this.create("${COMMAND_PREFIX}cobblemonconfig.reload", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
val COBBLEMON_CONFIG_RELOAD = this.create("${COMMAND_PREFIX}cobblemonconfig.reload", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
|
val CALCULATE_SEAT_POSITIONS = this.create("${COMMAND_PREFIX}calculateseatpositions", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
|
val CHANGE_BOX_COUNT = this.create("${COMMAND_PREFIX}boxcount", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||||
|
@JvmStatic
|
||||||
|
val SPECTATE_BATTLE = this.create("${COMMAND_PREFIX}spectatebattle", PermissionLevel.ALL_COMMANDS)
|
||||||
|
|
||||||
fun all(): Iterable<Permission> = this.permissions
|
fun all(): Iterable<Permission> = this.permissions
|
||||||
|
|
||||||
|
|||||||
@@ -722,8 +722,8 @@ open class PokemonProperties {
|
|||||||
nature = json.get(DataKeys.POKEMON_NATURE)?.asString
|
nature = json.get(DataKeys.POKEMON_NATURE)?.asString
|
||||||
ability = json.get(DataKeys.POKEMON_ABILITY)?.asString
|
ability = json.get(DataKeys.POKEMON_ABILITY)?.asString
|
||||||
status = json.get(DataKeys.POKEMON_STATUS_NAME)?.asString
|
status = json.get(DataKeys.POKEMON_STATUS_NAME)?.asString
|
||||||
ivs = json.getAsJsonObject(DataKeys.POKEMON_IVS)?.let { IVs().loadFromJSON(it) } as IVs
|
ivs = json.getAsJsonObject(DataKeys.POKEMON_IVS)?.let { IVs().loadFromJSON(it) } as? IVs
|
||||||
evs = json.getAsJsonObject(DataKeys.POKEMON_EVS)?.let { EVs().loadFromJSON(it) } as EVs
|
evs = json.getAsJsonObject(DataKeys.POKEMON_EVS)?.let { EVs().loadFromJSON(it) } as? EVs
|
||||||
type = json.get(DataKeys.ELEMENTAL_TYPE)?.asString
|
type = json.get(DataKeys.ELEMENTAL_TYPE)?.asString
|
||||||
teraType = json.get(DataKeys.POKEMON_TERA_TYPE)?.asString
|
teraType = json.get(DataKeys.POKEMON_TERA_TYPE)?.asString
|
||||||
dmaxLevel = json.get(DataKeys.POKEMON_DMAX_LEVEL)?.asInt
|
dmaxLevel = json.get(DataKeys.POKEMON_DMAX_LEVEL)?.asInt
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ package com.cobblemon.mod.common.api.pokemon
|
|||||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||||
|
|
||||||
enum class PokemonSortMode(val comparator: Comparator<Pokemon?>, val reverseComparator: Comparator<Pokemon?>) {
|
enum class PokemonSortMode(val comparator: Comparator<Pokemon?>, val reverseComparator: Comparator<Pokemon?>) {
|
||||||
NAME( { it?.getDisplayName()?.string } ),
|
NAME({ it?.getDisplayName()?.string }),
|
||||||
LEVEL( { it?.level } ),
|
LEVEL({ it?.level }),
|
||||||
TYPE( { it?.primaryType?.name } );
|
TYPE({ it?.primaryType?.name }),
|
||||||
|
POKEDEX_NUMBER({ it?.species?.nationalPokedexNumber }),
|
||||||
|
GENDER({ it?.gender });
|
||||||
|
|
||||||
constructor(mapper: (Pokemon?) -> Comparable<*>?) : this(compareBy({ it == null }, mapper),
|
constructor(mapper: (Pokemon?) -> Comparable<*>?) : this(compareBy({ it == null }, mapper),
|
||||||
compareBy<Pokemon?> { it == null }.thenComparing(compareBy(mapper).reversed()))
|
compareBy<Pokemon?> { it == null }.thenComparing(compareBy(mapper).reversed()))
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import com.cobblemon.mod.common.api.pokemon.moves.Learnset
|
|||||||
import com.cobblemon.mod.common.api.pokemon.stats.Stat
|
import com.cobblemon.mod.common.api.pokemon.stats.Stat
|
||||||
import com.cobblemon.mod.common.api.pokemon.stats.Stats
|
import com.cobblemon.mod.common.api.pokemon.stats.Stats
|
||||||
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
||||||
import com.cobblemon.mod.common.api.riding.controller.RideController
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourSettings
|
||||||
import com.cobblemon.mod.common.api.riding.stats.RidingStatDefinition
|
import com.cobblemon.mod.common.api.riding.stats.RidingStatDefinition
|
||||||
import com.cobblemon.mod.common.api.spawning.TimeRange
|
import com.cobblemon.mod.common.api.spawning.TimeRange
|
||||||
import com.cobblemon.mod.common.api.types.ElementalType
|
import com.cobblemon.mod.common.api.types.ElementalType
|
||||||
@@ -48,8 +48,9 @@ import com.cobblemon.mod.common.pokemon.evolution.adapters.CobblemonRequirementA
|
|||||||
import com.cobblemon.mod.common.pokemon.evolution.adapters.LegacyItemConditionWrapperAdapter
|
import com.cobblemon.mod.common.pokemon.evolution.adapters.LegacyItemConditionWrapperAdapter
|
||||||
import com.cobblemon.mod.common.pokemon.helditem.CobblemonHeldItemManager
|
import com.cobblemon.mod.common.pokemon.helditem.CobblemonHeldItemManager
|
||||||
import com.cobblemon.mod.common.util.adapters.*
|
import com.cobblemon.mod.common.util.adapters.*
|
||||||
import com.cobblemon.mod.common.util.adapters.RideControllerAdapter
|
import com.cobblemon.mod.common.util.adapters.RidingBehaviourSettingsAdapter
|
||||||
import com.cobblemon.mod.common.util.cobblemonResource
|
import com.cobblemon.mod.common.util.cobblemonResource
|
||||||
|
import com.cobblemon.mod.common.util.ifClient
|
||||||
import com.google.common.collect.HashBasedTable
|
import com.google.common.collect.HashBasedTable
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
@@ -106,7 +107,7 @@ object PokemonSpecies : JsonDataRegistry<Species> {
|
|||||||
.registerTypeAdapter(EggGroup::class.java, EggGroupAdapter)
|
.registerTypeAdapter(EggGroup::class.java, EggGroupAdapter)
|
||||||
.registerTypeAdapter(MobEffect::class.java, RegistryElementAdapter<MobEffect>(BuiltInRegistries::MOB_EFFECT))
|
.registerTypeAdapter(MobEffect::class.java, RegistryElementAdapter<MobEffect>(BuiltInRegistries::MOB_EFFECT))
|
||||||
.registerTypeAdapter(ItemPredicate::class.java, LegacyItemConditionWrapperAdapter)
|
.registerTypeAdapter(ItemPredicate::class.java, LegacyItemConditionWrapperAdapter)
|
||||||
.registerTypeAdapter(RideController::class.java, RideControllerAdapter)
|
.registerTypeAdapter(RidingBehaviourSettings::class.java, RidingBehaviourSettingsAdapter)
|
||||||
.registerTypeAdapter(RidingStatDefinition::class.java, RidingStatDefinitionAdapter)
|
.registerTypeAdapter(RidingStatDefinition::class.java, RidingStatDefinitionAdapter)
|
||||||
.registerTypeAdapter(Expression::class.java, ExpressionAdapter)
|
.registerTypeAdapter(Expression::class.java, ExpressionAdapter)
|
||||||
.disableHtmlEscaping()
|
.disableHtmlEscaping()
|
||||||
@@ -128,6 +129,11 @@ object PokemonSpecies : JsonDataRegistry<Species> {
|
|||||||
init {
|
init {
|
||||||
SpeciesAdditions.observable.subscribe {
|
SpeciesAdditions.observable.subscribe {
|
||||||
this.species.forEach(Species::initialize)
|
this.species.forEach(Species::initialize)
|
||||||
|
this.species.forEach {
|
||||||
|
if (it.implemented) {
|
||||||
|
this.implemented.add(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
this.species.forEach(Species::resolveEvolutionMoves)
|
this.species.forEach(Species::resolveEvolutionMoves)
|
||||||
Cobblemon.showdownThread.queue {
|
Cobblemon.showdownThread.queue {
|
||||||
it.registerSpecies()
|
it.registerSpecies()
|
||||||
@@ -206,8 +212,10 @@ object PokemonSpecies : JsonDataRegistry<Species> {
|
|||||||
this.speciesByDex.remove(old.resourceIdentifier.namespace, old.nationalPokedexNumber)
|
this.speciesByDex.remove(old.resourceIdentifier.namespace, old.nationalPokedexNumber)
|
||||||
}
|
}
|
||||||
this.speciesByDex.put(species.resourceIdentifier.namespace, species.nationalPokedexNumber, species)
|
this.speciesByDex.put(species.resourceIdentifier.namespace, species.nationalPokedexNumber, species)
|
||||||
if (species.implemented) {
|
ifClient {
|
||||||
this.implemented.add(species)
|
if (species.implemented) {
|
||||||
|
this.implemented.add(species)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ interface Evolution : EvolutionLike {
|
|||||||
pokemonEntity.after(11.2F) {
|
pokemonEntity.after(11.2F) {
|
||||||
evolutionMethod(pokemon)
|
evolutionMethod(pokemon)
|
||||||
}
|
}
|
||||||
pokemonEntity.after( seconds = 12F ) {
|
pokemonEntity.after(seconds = 12F) {
|
||||||
cryAnimation(pokemonEntity)
|
cryAnimation(pokemonEntity)
|
||||||
pokemonEntity.entityData.set(PokemonEntity.EVOLUTION_STARTED, false)
|
pokemonEntity.entityData.set(PokemonEntity.EVOLUTION_STARTED, false)
|
||||||
pokemon.getOwnerPlayer()?.sendSystemMessage(lang("ui.evolve.into", preEvoName, pokemon.species.translatedName))
|
pokemon.getOwnerPlayer()?.sendSystemMessage(lang("ui.evolve.into", preEvoName, pokemon.species.translatedName))
|
||||||
|
|||||||
+2
-2
@@ -68,8 +68,8 @@ object SpeciesFeatures : JsonDataRegistry<SpeciesFeatureProvider<*>> {
|
|||||||
data.forEach(this::registerFromAssets)
|
data.forEach(this::registerFromAssets)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCodeFeature(name: String) = resourceFeatures[name]
|
fun getCodeFeature(name: String) = codeFeatures[name]
|
||||||
fun getResourceFeature(name: String) = codeFeatures[name]
|
fun getResourceFeature(name: String) = resourceFeatures[name]
|
||||||
fun getFeature(name: String) = getCodeFeature(name) ?: getResourceFeature(name)
|
fun getFeature(name: String) = getCodeFeature(name) ?: getResourceFeature(name)
|
||||||
fun loadOnClient(entries: Collection<Map.Entry<String, SpeciesFeatureProvider<*>>>) {
|
fun loadOnClient(entries: Collection<Map.Entry<String, SpeciesFeatureProvider<*>>>) {
|
||||||
codeFeatures.putAll(entries.map { it.toPair() })
|
codeFeatures.putAll(entries.map { it.toPair() })
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
package com.cobblemon.mod.common.api.riding
|
package com.cobblemon.mod.common.api.riding
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviour
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourSettings
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourState
|
||||||
import net.minecraft.world.entity.PlayerRideableJumping
|
import net.minecraft.world.entity.PlayerRideableJumping
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,6 +23,6 @@ interface Rideable : PlayerRideableJumping {
|
|||||||
/**
|
/**
|
||||||
* Denotes the manager responsible for handling any instance of riding taking place on an entity
|
* Denotes the manager responsible for handling any instance of riding taking place on an entity
|
||||||
*/
|
*/
|
||||||
val riding: RidingManager
|
val riding: RidingBehaviour<RidingBehaviourSettings, RidingBehaviourState>?
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.cobblemon.mod.common.api.riding.controller
|
package com.cobblemon.mod.common.api.riding
|
||||||
|
|
||||||
import com.cobblemon.mod.common.util.readString
|
import com.cobblemon.mod.common.util.readString
|
||||||
import com.cobblemon.mod.common.util.writeString
|
import com.cobblemon.mod.common.util.writeString
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 Cobblemon Contributors
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.cobblemon.mod.common.api.riding
|
|
||||||
|
|
||||||
import com.bedrockk.molang.runtime.MoLangRuntime
|
|
||||||
import com.bedrockk.molang.runtime.value.DoubleValue
|
|
||||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.setup
|
|
||||||
import com.cobblemon.mod.common.api.riding.controller.RideController
|
|
||||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
|
||||||
import com.cobblemon.mod.common.util.withQueryValue
|
|
||||||
import net.minecraft.resources.ResourceLocation
|
|
||||||
import net.minecraft.world.entity.LivingEntity
|
|
||||||
import net.minecraft.world.entity.player.Player
|
|
||||||
import net.minecraft.world.phys.Vec2
|
|
||||||
import net.minecraft.world.phys.Vec3
|
|
||||||
|
|
||||||
data class RidingManager(val entity: PokemonEntity) {
|
|
||||||
var lastSpeed = 0F
|
|
||||||
var states: MutableMap<ResourceLocation, RidingState> = mutableMapOf()
|
|
||||||
var deltaRotation = Vec2.ZERO
|
|
||||||
|
|
||||||
val runtime: MoLangRuntime by lazy {
|
|
||||||
MoLangRuntime()
|
|
||||||
.setup()
|
|
||||||
.withQueryValue("entity", entity.struct)
|
|
||||||
.also {
|
|
||||||
it.environment.query.addFunction("passenger_count") { DoubleValue(entity.passengers.size.toDouble()) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T : RidingState> getState(id: ResourceLocation, constructor: (PokemonEntity) -> T): T {
|
|
||||||
val storedState = states[id]
|
|
||||||
if (storedState == null) {
|
|
||||||
val newState = constructor(entity)
|
|
||||||
states[id] = newState
|
|
||||||
return newState
|
|
||||||
}
|
|
||||||
|
|
||||||
return storedState as T
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getController(entity: PokemonEntity): RideController? {
|
|
||||||
return entity.pokemon.riding.controller?.takeIf { it.condition.invoke(entity) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Responsible for handling riding conditions and transitions amongst controllers. This will tick
|
|
||||||
* whenever the entity receives a tickControlled interaction.
|
|
||||||
*/
|
|
||||||
fun tick(entity: PokemonEntity, driver: Player, input: Vec3) {
|
|
||||||
val controller = getController(entity) ?: return
|
|
||||||
|
|
||||||
val pose = controller.pose(entity)
|
|
||||||
entity.entityData.set(PokemonEntity.POSE_TYPE, pose)
|
|
||||||
|
|
||||||
// driver.displayClientMessage(Component.literal("Speed: ").withStyle { it.withColor(ChatFormatting.GREEN) }.append(Component.literal("$lastSpeed b/t")), true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun speed(entity: PokemonEntity, driver: Player): Float {
|
|
||||||
val controller = getController(entity) ?: return 0.05F
|
|
||||||
this.lastSpeed = controller.speed(entity, driver)
|
|
||||||
return this.lastSpeed
|
|
||||||
}
|
|
||||||
|
|
||||||
fun controlledRotation(entity: PokemonEntity, driver: Player): Vec2 {
|
|
||||||
val controller = getController(entity) ?: return entity.rotationVector
|
|
||||||
val previousRotation = entity.rotationVector
|
|
||||||
val rotation = controller.rotation(entity, driver)
|
|
||||||
this.deltaRotation = Vec2(rotation.x - previousRotation.x, rotation.y - previousRotation.y)
|
|
||||||
return rotation
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clampPassengerRotation(entity: PokemonEntity, driver: LivingEntity) {
|
|
||||||
val controller = getController(entity) ?: return
|
|
||||||
return controller.clampPassengerRotation(entity, driver)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updatePassengerRotation(entity: PokemonEntity, driver: LivingEntity) {
|
|
||||||
val controller = getController(entity) ?: return
|
|
||||||
return controller.updatePassengerRotation(entity, driver)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun velocity(entity: PokemonEntity, driver: Player, input: Vec3): Vec3 {
|
|
||||||
val controller = getController(entity) ?: return Vec3.ZERO
|
|
||||||
return controller.velocity(entity, driver, input)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun canJump(entity: PokemonEntity, driver: Player): Boolean {
|
|
||||||
val controller = getController(entity) ?: return false
|
|
||||||
return controller.canJump(entity, driver)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun jumpVelocity(entity: PokemonEntity, driver: Player, jumpStrength: Int): Vec3 {
|
|
||||||
val controller = getController(entity) ?: return Vec3.ZERO
|
|
||||||
return controller.jumpForce(entity, driver, jumpStrength)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun gravity(entity: PokemonEntity, regularGravity: Double): Double? {
|
|
||||||
val controller = getController(entity) ?: return null
|
|
||||||
return controller.gravity(entity, regularGravity)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun shouldRoll(entity: PokemonEntity): Boolean {
|
|
||||||
val controller = getController(entity) ?: return false
|
|
||||||
return controller.shouldRoll(entity)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun shouldRotatePlayerHead(entity: PokemonEntity): Boolean {
|
|
||||||
val controller = getController(entity) ?: return false
|
|
||||||
return controller.shouldRotatePlayerHead()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun shouldRotatePokemonHead(entity: PokemonEntity): Boolean {
|
|
||||||
val controller = getController(entity) ?: return false
|
|
||||||
return controller.shouldRotatePokemonHead()
|
|
||||||
}
|
|
||||||
|
|
||||||
//FIXME: Make this not just be false for all controllers lol
|
|
||||||
fun dismountOnShift(): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,44 +9,40 @@
|
|||||||
package com.cobblemon.mod.common.api.riding
|
package com.cobblemon.mod.common.api.riding
|
||||||
|
|
||||||
import com.bedrockk.molang.Expression
|
import com.bedrockk.molang.Expression
|
||||||
import com.cobblemon.mod.common.api.riding.controller.RideController
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourSettings
|
||||||
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||||
import com.cobblemon.mod.common.api.riding.stats.RidingStatDefinition
|
import com.cobblemon.mod.common.api.riding.stats.RidingStatDefinition
|
||||||
import com.cobblemon.mod.common.util.adapters.RideControllerAdapter
|
import com.cobblemon.mod.common.util.*
|
||||||
import com.cobblemon.mod.common.util.asExpression
|
import com.cobblemon.mod.common.util.adapters.RidingBehaviourSettingsAdapter
|
||||||
import com.cobblemon.mod.common.util.getString
|
|
||||||
import com.cobblemon.mod.common.util.readIdentifier
|
|
||||||
import com.cobblemon.mod.common.util.readString
|
|
||||||
import com.cobblemon.mod.common.util.writeString
|
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
|
||||||
class RidingProperties(
|
class RidingProperties(
|
||||||
val stats: Map<RidingStat, RidingStatDefinition> = mapOf(),
|
val stats: Map<RidingStat, RidingStatDefinition> = mapOf(),
|
||||||
val seats: List<Seat> = listOf(),
|
val seats: List<Seat> = listOf(),
|
||||||
val conditions: List<Expression> = listOf(),
|
val conditions: List<Expression> = listOf(),
|
||||||
val controller: RideController? = null
|
val behaviour: RidingBehaviourSettings? = null
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun decode(buffer: RegistryFriendlyByteBuf): RidingProperties {
|
fun decode(buffer: RegistryFriendlyByteBuf): RidingProperties {
|
||||||
val stats: Map<RidingStat, RidingStatDefinition> = buffer.readMap(
|
val stats: Map<RidingStat, RidingStatDefinition> = buffer.readMap(
|
||||||
{ buffer.readEnum<RidingStat>(RidingStat::class.java) },
|
{ buffer.readEnum(RidingStat::class.java) },
|
||||||
{ RidingStatDefinition.decode(buffer) }
|
{ RidingStatDefinition.decode(buffer) }
|
||||||
)
|
)
|
||||||
val seats: List<Seat> = buffer.readList { _ -> Seat.decode(buffer) }
|
val seats: List<Seat> = buffer.readList { _ -> Seat.decode(buffer) }
|
||||||
val conditions = buffer.readList { buffer.readString().asExpression() }
|
val conditions = buffer.readList { buffer.readString().asExpression() }
|
||||||
val controller = buffer.readNullable { _ ->
|
val behaviour = buffer.readNullable { _ ->
|
||||||
val key = buffer.readIdentifier()
|
val key = buffer.readResourceLocation()
|
||||||
val controller = RideControllerAdapter.types[key]?.getConstructor()?.newInstance() ?: error("Unknown controller key: $key")
|
val settings = RidingBehaviourSettingsAdapter.types[key]?.getConstructor()?.newInstance() ?: error("Unknown controller key: $key")
|
||||||
controller.decode(buffer)
|
settings.decode(buffer)
|
||||||
return@readNullable controller
|
return@readNullable settings
|
||||||
}
|
}
|
||||||
|
|
||||||
return RidingProperties(stats = stats, seats = seats, conditions = conditions, controller = controller)
|
return RidingProperties(stats = stats, seats = seats, conditions = conditions, behaviour = behaviour)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val canRide: Boolean
|
val canRide: Boolean
|
||||||
get() = seats.isNotEmpty() && controller != null
|
get() = seats.isNotEmpty() && behaviour != null
|
||||||
|
|
||||||
fun encode(buffer: RegistryFriendlyByteBuf) {
|
fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
buffer.writeMap(
|
buffer.writeMap(
|
||||||
@@ -56,7 +52,10 @@ class RidingProperties(
|
|||||||
)
|
)
|
||||||
buffer.writeCollection(seats) { _, seat -> seat.encode(buffer) }
|
buffer.writeCollection(seats) { _, seat -> seat.encode(buffer) }
|
||||||
buffer.writeCollection(conditions) { _, condition -> buffer.writeString(condition.getString()) }
|
buffer.writeCollection(conditions) { _, condition -> buffer.writeString(condition.getString()) }
|
||||||
buffer.writeNullable(controller) { _, controller -> controller.encode(buffer) }
|
buffer.writeNullable(behaviour) { _, behaviour ->
|
||||||
|
buffer.writeResourceLocation(behaviour.key)
|
||||||
|
behaviour.encode(buffer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun calculate(stat: RidingStat, style: RidingStyle, boosts: Int): Float {
|
fun calculate(stat: RidingStat, style: RidingStyle, boosts: Int): Float {
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 Cobblemon Contributors
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.cobblemon.mod.common.api.riding
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Honestly having a base interface is probably unnecessary I'm just considering whether there's going to be some
|
|
||||||
* kind of shared state later.
|
|
||||||
*
|
|
||||||
* @author Hiroku
|
|
||||||
* @since October 6th, 2024
|
|
||||||
*/
|
|
||||||
interface RidingState
|
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
package com.cobblemon.mod.common.api.riding
|
package com.cobblemon.mod.common.api.riding
|
||||||
|
|
||||||
import com.cobblemon.mod.common.api.net.Encodable
|
import com.cobblemon.mod.common.api.net.Encodable
|
||||||
import com.cobblemon.mod.common.api.riding.controller.RidingAnimation
|
|
||||||
import com.cobblemon.mod.common.entity.PoseType
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
import com.cobblemon.mod.common.util.readString
|
import com.cobblemon.mod.common.util.readString
|
||||||
import com.cobblemon.mod.common.util.writeString
|
import com.cobblemon.mod.common.util.writeString
|
||||||
|
|||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the behaviour of a Pokemon when being ridden.
|
||||||
|
* This is intended to contain the logic for how a Pokemon should behave when being ridden.
|
||||||
|
*
|
||||||
|
* This class should remain stateless as it is intended to be shared between multiple instances of Pokemon.
|
||||||
|
*
|
||||||
|
* @author landonjw
|
||||||
|
*/
|
||||||
|
interface RidingBehaviour<Settings : RidingBehaviourSettings, State : RidingBehaviourState> {
|
||||||
|
val key: ResourceLocation
|
||||||
|
|
||||||
|
fun isActive(settings: Settings, state: State, vehicle: PokemonEntity): Boolean
|
||||||
|
|
||||||
|
fun tick(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player, input: Vec3) {}
|
||||||
|
|
||||||
|
fun pose(settings: Settings, state: State, vehicle: PokemonEntity): PoseType
|
||||||
|
|
||||||
|
fun speed(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Float
|
||||||
|
|
||||||
|
fun clampPassengerRotation(settings: Settings, state: State, entity: PokemonEntity, driver: LivingEntity) {}
|
||||||
|
|
||||||
|
fun updatePassengerRotation(settings: Settings, state: State, entity: PokemonEntity, driver: LivingEntity) {}
|
||||||
|
|
||||||
|
fun rotation(settings: Settings, state: State, vehicle: PokemonEntity, driver: LivingEntity): Vec2
|
||||||
|
|
||||||
|
fun velocity(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player, input: Vec3): Vec3
|
||||||
|
|
||||||
|
fun angRollVel(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player, deltaTime: Double): Vec3
|
||||||
|
|
||||||
|
fun rotationOnMouseXY(
|
||||||
|
settings: Settings,
|
||||||
|
state: State,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3
|
||||||
|
|
||||||
|
fun canJump(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Boolean
|
||||||
|
|
||||||
|
fun setRideBar(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Float
|
||||||
|
|
||||||
|
fun jumpForce(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player, jumpStrength: Int): Vec3
|
||||||
|
|
||||||
|
fun gravity(settings: Settings, state: State, vehicle: PokemonEntity, regularGravity: Double): Double
|
||||||
|
|
||||||
|
fun rideFovMultiplier(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Float
|
||||||
|
|
||||||
|
fun useAngVelSmoothing(settings: Settings, state: State, vehicle: PokemonEntity): Boolean
|
||||||
|
|
||||||
|
fun useRidingAltPose(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Boolean
|
||||||
|
|
||||||
|
fun inertia(settings: Settings, state: State, vehicle: PokemonEntity): Double
|
||||||
|
|
||||||
|
fun shouldRoll(settings: Settings, state: State, vehicle: PokemonEntity): Boolean
|
||||||
|
|
||||||
|
fun turnOffOnGround(settings: Settings, state: State, vehicle: PokemonEntity): Boolean
|
||||||
|
|
||||||
|
fun dismountOnShift(settings: Settings, state: State, vehicle: PokemonEntity): Boolean
|
||||||
|
|
||||||
|
fun shouldRotatePokemonHead(settings: Settings, state: State, vehicle: PokemonEntity): Boolean
|
||||||
|
|
||||||
|
fun shouldRotatePlayerHead(settings: Settings, state: State, vehicle: PokemonEntity): Boolean
|
||||||
|
|
||||||
|
fun createDefaultState(): State
|
||||||
|
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.api.net.Decodable
|
||||||
|
import com.cobblemon.mod.common.api.net.Encodable
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents static settings of a riding behaviour.
|
||||||
|
* Values in this class are intended to be constant and not change during the riding process.
|
||||||
|
* Typically this will be initialized for each pokemon form during deserialization
|
||||||
|
* to determine how they should ride.
|
||||||
|
*
|
||||||
|
* @author landonjw
|
||||||
|
*/
|
||||||
|
interface RidingBehaviourSettings: Encodable, Decodable {
|
||||||
|
val key: ResourceLocation
|
||||||
|
}
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.api.net.Decodable
|
||||||
|
import com.cobblemon.mod.common.api.net.Encodable
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.ifClient
|
||||||
|
import com.cobblemon.mod.common.util.ifServer
|
||||||
|
import net.minecraft.client.player.RemotePlayer
|
||||||
|
import net.minecraft.network.FriendlyByteBuf
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the state of a Pokemon when being ridden.
|
||||||
|
* This is intended to contain mutable state that is passed between the client and server
|
||||||
|
* or temporary state that is used during the riding process.
|
||||||
|
*
|
||||||
|
* This will be destroyed when the a user dismounts the Pokemon.
|
||||||
|
*
|
||||||
|
* @author landonjw
|
||||||
|
*/
|
||||||
|
interface RidingBehaviourState : Encodable, Decodable {
|
||||||
|
fun reset()
|
||||||
|
fun copy(): RidingBehaviourState
|
||||||
|
fun shouldSync(previous: RidingBehaviourState): Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
object NoState : RidingBehaviourState {
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) = Unit
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) = Unit
|
||||||
|
override fun copy() = NoState
|
||||||
|
override fun reset() = Unit
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState) = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> ridingState(value: T, side: Side) = SidedRidingState(value, side)
|
||||||
|
|
||||||
|
class SidedRidingState<T>(private var value: T, val side: Side) {
|
||||||
|
fun get() = value
|
||||||
|
|
||||||
|
fun set(value: T, forced: Boolean = false) {
|
||||||
|
if (forced) {
|
||||||
|
this.value = value
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
when (side) {
|
||||||
|
Side.BOTH -> { this.value = value }
|
||||||
|
Side.CLIENT -> { ifClient { this.value = value } }
|
||||||
|
Side.SERVER -> { ifServer { this.value = value } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (other is SidedRidingState<*>) {
|
||||||
|
return value == other.value
|
||||||
|
}
|
||||||
|
return super.equals(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return value.hashCode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Side {
|
||||||
|
SERVER, CLIENT, BOTH
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class DriverSide {
|
||||||
|
LOCAL, REMOTE, BOTH
|
||||||
|
}
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.types.*
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
|
||||||
|
object RidingBehaviours {
|
||||||
|
val behaviours = mutableMapOf<ResourceLocation, RidingBehaviour<*, *>>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
register(BirdAirBehaviour.KEY, BirdAirBehaviour())
|
||||||
|
register(DolphinBehaviour.KEY, DolphinBehaviour())
|
||||||
|
register(FallToGlideCompositeBehaviour.KEY, FallToGlideCompositeBehaviour())
|
||||||
|
register(GenericLandBehaviour.KEY, GenericLandBehaviour())
|
||||||
|
register(GenericSwimBehaviour.KEY, GenericSwimBehaviour())
|
||||||
|
register(GliderAirBehaviour.KEY, GliderAirBehaviour())
|
||||||
|
register(HelicopterBehaviour.KEY, HelicopterBehaviour())
|
||||||
|
register(JetAirBehaviour.KEY, JetAirBehaviour())
|
||||||
|
register(JumpToFlightCompositeBehaviour.KEY, JumpToFlightCompositeBehaviour())
|
||||||
|
register(RunToJetCompositeBehaviour.KEY, RunToJetCompositeBehaviour())
|
||||||
|
register(SwimDashBehaviour.KEY, SwimDashBehaviour())
|
||||||
|
register(VehicleLandBehaviour.KEY, VehicleLandBehaviour())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun register(key: ResourceLocation, behaviour: RidingBehaviour<*, *>) {
|
||||||
|
if (behaviours.contains(key)) error("Behaviour already registered to key $key")
|
||||||
|
behaviours[key] = RidingController(behaviour)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun get(key: ResourceLocation): RidingBehaviour<*, *> {
|
||||||
|
if (!behaviours.contains(key)) error("Behaviour not registered to key $key")
|
||||||
|
return behaviours[key]!!
|
||||||
|
}
|
||||||
|
}
|
||||||
+171
@@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Small wrapper around a RidingBehaviour to provide sane defaults in the event that the behaviour is not active.
|
||||||
|
*
|
||||||
|
* @author landonjw
|
||||||
|
*/
|
||||||
|
class RidingController<Settings : RidingBehaviourSettings, State : RidingBehaviourState>(val behaviour: RidingBehaviour<Settings, State>) : RidingBehaviour<Settings, State> {
|
||||||
|
|
||||||
|
override val key = behaviour.key
|
||||||
|
|
||||||
|
override fun isActive(settings: Settings, state: State, vehicle: PokemonEntity) =
|
||||||
|
behaviour.isActive(settings, state, vehicle)
|
||||||
|
|
||||||
|
override fun tick(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player, input: Vec3) =
|
||||||
|
behaviour.tick(settings, state, vehicle, driver, input)
|
||||||
|
|
||||||
|
override fun pose(settings: Settings, state: State, vehicle: PokemonEntity) =
|
||||||
|
behaviour.pose(settings, state, vehicle)
|
||||||
|
|
||||||
|
override fun speed(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Float {
|
||||||
|
if (!isActive(settings, state, vehicle)) return 0.0F
|
||||||
|
return behaviour.speed(settings, state, vehicle, driver)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(settings: Settings, state: State, vehicle: PokemonEntity, driver: LivingEntity): Vec2 {
|
||||||
|
if (!isActive(settings, state, vehicle)) return vehicle.rotationVector
|
||||||
|
return behaviour.rotation(settings, state, vehicle, driver)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: Settings,
|
||||||
|
state: State,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
if (!isActive(settings, state, vehicle)) return Vec3.ZERO
|
||||||
|
return behaviour.velocity(settings, state, vehicle, driver, input)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: Settings,
|
||||||
|
state: State,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (!isActive(settings, state, vehicle)) return Vec3.ZERO
|
||||||
|
return behaviour.angRollVel(settings, state, vehicle, driver, deltaTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: Settings,
|
||||||
|
state: State,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (!isActive(settings, state, vehicle)) return Vec3.ZERO
|
||||||
|
return behaviour.rotationOnMouseXY(
|
||||||
|
settings,
|
||||||
|
state,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
mouseY,
|
||||||
|
mouseX,
|
||||||
|
mouseYSmoother,
|
||||||
|
mouseXSmoother,
|
||||||
|
sensitivity,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Boolean {
|
||||||
|
if (!isActive(settings, state, vehicle)) return false
|
||||||
|
return behaviour.canJump(settings, state, vehicle, driver)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(settings: Settings, state: State, vehicle: PokemonEntity): Boolean {
|
||||||
|
if (!isActive(settings, state, vehicle)) return false
|
||||||
|
return behaviour.shouldRotatePlayerHead(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(settings: Settings, state: State, vehicle: PokemonEntity): Boolean {
|
||||||
|
if (!isActive(settings, state, vehicle)) return false
|
||||||
|
return behaviour.shouldRotatePokemonHead(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(settings: Settings, state: State, vehicle: PokemonEntity): Boolean {
|
||||||
|
if (!isActive(settings, state, vehicle)) return false
|
||||||
|
return behaviour.dismountOnShift(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(settings: Settings, state: State, vehicle: PokemonEntity): Boolean {
|
||||||
|
if (!isActive(settings, state, vehicle)) return false
|
||||||
|
return behaviour.turnOffOnGround(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(settings: Settings, state: State, vehicle: PokemonEntity): Boolean {
|
||||||
|
if (!isActive(settings, state, vehicle)) return false
|
||||||
|
return behaviour.shouldRoll(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(settings: Settings, state: State, vehicle: PokemonEntity): Double {
|
||||||
|
if (!isActive(settings, state, vehicle)) return 0.5
|
||||||
|
return behaviour.inertia(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Boolean {
|
||||||
|
if (!isActive(settings, state, vehicle)) return false
|
||||||
|
return behaviour.useRidingAltPose(settings, state, vehicle, driver)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(settings: Settings, state: State, vehicle: PokemonEntity): Boolean {
|
||||||
|
if (!isActive(settings, state, vehicle)) return true
|
||||||
|
return behaviour.useAngVelSmoothing(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Float {
|
||||||
|
if (!isActive(settings, state, vehicle)) return 1.0F
|
||||||
|
return behaviour.rideFovMultiplier(settings, state, vehicle, driver)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(settings: Settings, state: State, vehicle: PokemonEntity, regularGravity: Double): Double {
|
||||||
|
if (!isActive(settings, state, vehicle)) return regularGravity
|
||||||
|
return behaviour.gravity(settings, state, vehicle, regularGravity)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: Settings,
|
||||||
|
state: State,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
if (!isActive(settings, state, vehicle)) return Vec3.ZERO
|
||||||
|
return behaviour.jumpForce(settings, state, vehicle, driver, jumpStrength)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(settings: Settings, state: State, vehicle: PokemonEntity, driver: Player): Float {
|
||||||
|
if (!isActive(settings, state, vehicle)) return 0.0F
|
||||||
|
return behaviour.setRideBar(settings, state, vehicle, driver)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState(): State {
|
||||||
|
return behaviour.createDefaultState()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+525
@@ -0,0 +1,525 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.Expression
|
||||||
|
import com.bedrockk.molang.runtime.MoLangMath.lerp
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.*
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
import kotlin.math.*
|
||||||
|
|
||||||
|
class BirdAirBehaviour : RidingBehaviour<BirdAirSettings, BirdAirState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("air/bird")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key: ResourceLocation = KEY
|
||||||
|
|
||||||
|
val poseProvider = PoseProvider<BirdAirSettings, BirdAirState>(PoseType.HOVER)
|
||||||
|
.with(PoseOption(PoseType.FLY) { _, state, _ -> state.rideVel.get().z > 0.2 })
|
||||||
|
|
||||||
|
override fun isActive(settings: BirdAirSettings, state: BirdAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(settings: BirdAirSettings, state: BirdAirState, vehicle: PokemonEntity): PoseType {
|
||||||
|
return poseProvider.select(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return state.rideVel.get().length().toFloat()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return Vec2(driver.xRot * 0.5f, driver.yRot)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
var yVel = 0.0
|
||||||
|
var leftForce = 0.0
|
||||||
|
var upForce = 0.0
|
||||||
|
var forwardForce = 0.0
|
||||||
|
|
||||||
|
//Perform ride velocity update
|
||||||
|
calculateRideSpaceVel(settings, state, vehicle, driver)
|
||||||
|
|
||||||
|
//Translate ride space velocity to world space velocity.
|
||||||
|
val controller = (driver as? OrientationControllable)?.orientationController
|
||||||
|
if (controller != null) {
|
||||||
|
//Need to deadzone this when straight up or down
|
||||||
|
|
||||||
|
upForce += -1.0 * sin(Math.toRadians(controller.pitch.toDouble())) * state.rideVel.get().z
|
||||||
|
forwardForce += cos(Math.toRadians(controller.pitch.toDouble())) * state.rideVel.get().z
|
||||||
|
|
||||||
|
upForce += cos(Math.toRadians(controller.pitch.toDouble())) * state.rideVel.get().y
|
||||||
|
forwardForce += sin(Math.toRadians(controller.pitch.toDouble())) * state.rideVel.get().y
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Bring the ride out of the sky when stamina is depleted.
|
||||||
|
if (state.stamina.get() <= 0.0) {
|
||||||
|
upForce -= 0.3
|
||||||
|
}
|
||||||
|
|
||||||
|
val altitudeLimit = vehicle.runtime.resolveDouble(settings.jumpExpr)
|
||||||
|
|
||||||
|
//Only limit altitude if altitude is not infinite
|
||||||
|
if (!vehicle.runtime.resolveBoolean(settings.infiniteAltitude)) {
|
||||||
|
//Provide a hard limit on altitude
|
||||||
|
upForce = if (vehicle.y >= altitudeLimit && upForce > 0) 0.0 else upForce
|
||||||
|
}
|
||||||
|
|
||||||
|
val velocity = Vec3(state.rideVel.get().x , upForce, forwardForce)
|
||||||
|
return velocity
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculates the change in the ride space vector due to player input and ride state
|
||||||
|
*/
|
||||||
|
fun calculateRideSpaceVel(settings: BirdAirSettings, state: BirdAirState, vehicle: PokemonEntity, driver: Player) {
|
||||||
|
//retrieve stats
|
||||||
|
val topSpeed = vehicle.runtime.resolveDouble(settings.speedExpr)
|
||||||
|
val glideTopSpeed = vehicle.runtime.resolveDouble(settings.glidespeedExpr)
|
||||||
|
val accel = vehicle.runtime.resolveDouble(settings.accelerationExpr)
|
||||||
|
val staminaStat = vehicle.runtime.resolveDouble(settings.staminaExpr)
|
||||||
|
|
||||||
|
var glideSpeedChange = 0.0
|
||||||
|
|
||||||
|
val currSpeed = state.rideVel.get().length()
|
||||||
|
|
||||||
|
//Flag for determining if player is actively inputting
|
||||||
|
var activeInput = false
|
||||||
|
|
||||||
|
var newVelocity = Vec3(state.rideVel.get().x, state.rideVel.get().y, state.rideVel.get().z)
|
||||||
|
|
||||||
|
//speed up and slow down based on input
|
||||||
|
if (driver.zza != 0.0f && state.stamina.get() > 0.0) {
|
||||||
|
//make sure it can't exceed top speed
|
||||||
|
val forwardInput = when {
|
||||||
|
driver.zza > 0 && newVelocity.z > topSpeed -> 0.0
|
||||||
|
driver.zza < 0 && newVelocity.z < (-topSpeed / 3.0) -> 0.0
|
||||||
|
else -> driver.zza.sign
|
||||||
|
}
|
||||||
|
|
||||||
|
newVelocity = Vec3(
|
||||||
|
newVelocity.x,
|
||||||
|
newVelocity.y,
|
||||||
|
(newVelocity.z + (accel * forwardInput.toDouble())))
|
||||||
|
|
||||||
|
activeInput = true
|
||||||
|
}
|
||||||
|
|
||||||
|
val controller = (driver as? OrientationControllable)?.orientationController
|
||||||
|
if (controller != null) {
|
||||||
|
//Base glide speed change on current pitch of the ride.
|
||||||
|
glideSpeedChange = sin(Math.toRadians(controller.pitch.toDouble()))
|
||||||
|
glideSpeedChange = glideSpeedChange.pow(3) * 0.5
|
||||||
|
|
||||||
|
//TODO: Possibly create a deadzone around parallel where glide doesn't affect speed?
|
||||||
|
if (glideSpeedChange <= 0.0) {
|
||||||
|
//Ensures that a propelling force is still able to be applied when
|
||||||
|
//climbing in height
|
||||||
|
if (driver.zza <= 0) {
|
||||||
|
//speed decrease should be 2x speed increase?
|
||||||
|
//state.currSpeed = max(state.currSpeed + (0.0166) * glideSpeedChange, 0.0 )
|
||||||
|
newVelocity = Vec3(
|
||||||
|
newVelocity.x,
|
||||||
|
newVelocity.y,
|
||||||
|
lerp( newVelocity.z, 0.0,glideSpeedChange * -0.0166 * 2 )
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// only add to the speed if it hasn't exceeded the current
|
||||||
|
//glide angles maximum amount of speed that it can give.
|
||||||
|
//state.currSpeed = min(state.currSpeed + ((0.0166 * 2) * glideSpeedChange), maxGlideSpeed)
|
||||||
|
newVelocity = Vec3(
|
||||||
|
newVelocity.x,
|
||||||
|
newVelocity.y,
|
||||||
|
min(newVelocity.z + ((0.0166 * 2) * glideSpeedChange), glideTopSpeed)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Lateral movement based on driver input.
|
||||||
|
val latTopSpeed = topSpeed / 2.0
|
||||||
|
if (driver.xxa != 0.0f && state.stamina.get() > 0.0) {
|
||||||
|
newVelocity = Vec3(
|
||||||
|
(newVelocity.x + (accel * driver.xxa)).coerceIn(-latTopSpeed, latTopSpeed),
|
||||||
|
newVelocity.y,
|
||||||
|
newVelocity.z)
|
||||||
|
activeInput = true
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newVelocity = Vec3(
|
||||||
|
lerp(newVelocity.x, 0.0, latTopSpeed / 20.0),
|
||||||
|
newVelocity.y,
|
||||||
|
newVelocity.z)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Vertical movement based on driver input.
|
||||||
|
val vertTopSpeed = topSpeed / 2.0
|
||||||
|
val vertInput = when {
|
||||||
|
driver.jumping -> 1.0
|
||||||
|
driver.isShiftKeyDown -> -1.0
|
||||||
|
else -> 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vertInput != 0.0 && state.stamina.get() > 0.0) {
|
||||||
|
newVelocity = Vec3(
|
||||||
|
newVelocity.x,
|
||||||
|
(newVelocity.y + (accel * vertInput)).coerceIn(-vertTopSpeed, vertTopSpeed),
|
||||||
|
newVelocity.z)
|
||||||
|
activeInput = true
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newVelocity = Vec3(
|
||||||
|
newVelocity.x,
|
||||||
|
lerp(newVelocity.y, 0.0, vertTopSpeed / 20.0),
|
||||||
|
newVelocity.z)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if the ride should be gliding
|
||||||
|
if (driver.isLocalPlayer) {
|
||||||
|
if (activeInput && state.stamina.get() > 0.0) {
|
||||||
|
state.gliding.set(false)
|
||||||
|
} else {
|
||||||
|
state.gliding.set(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Only perform stamina logic if the ride does not have infinite stamina
|
||||||
|
if (!vehicle.runtime.resolveBoolean(settings.infiniteStamina)) {
|
||||||
|
if (activeInput) {
|
||||||
|
state.stamina.set(state.stamina.get() - (0.05 / staminaStat).toFloat())
|
||||||
|
}
|
||||||
|
|
||||||
|
//Lose a base amount of stamina just for being airborne
|
||||||
|
state.stamina.set(state.stamina.get() - (0.01 / staminaStat).toFloat())
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state.stamina.set(1.0f)
|
||||||
|
}
|
||||||
|
|
||||||
|
//air resistance
|
||||||
|
if( abs(newVelocity.z) > 0) {
|
||||||
|
newVelocity = newVelocity.subtract(0.0, 0.0, min(0.003 * newVelocity.z.sign, newVelocity.z))
|
||||||
|
}
|
||||||
|
state.rideVel.set(newVelocity)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (driver !is OrientationControllable) return Vec3.ZERO
|
||||||
|
val controller = (driver as OrientationControllable).orientationController
|
||||||
|
|
||||||
|
//TODO: Tie into handling
|
||||||
|
val handling = vehicle.runtime.resolveDouble(settings.handlingExpr)
|
||||||
|
val topSpeed = vehicle.runtime.resolveDouble(settings.speedExpr)
|
||||||
|
val rotationChangeRate = 10.0
|
||||||
|
|
||||||
|
var yawForce = rotationChangeRate * sin(Math.toRadians(controller.roll.toDouble()))
|
||||||
|
//for a bit of correction on the rolls limit it to a quarter the amount
|
||||||
|
var pitchForce = -0.35 * rotationChangeRate * abs(sin(Math.toRadians(controller.roll.toDouble())))
|
||||||
|
|
||||||
|
//limit rotation modulation when pitched up heavily or pitched down heavily
|
||||||
|
yawForce *= abs(cos(Math.toRadians(controller.pitch.toDouble())))
|
||||||
|
pitchForce *= abs(cos(Math.toRadians(controller.pitch.toDouble()))) * 1.5
|
||||||
|
|
||||||
|
return Vec3(yawForce, pitchForce, 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (driver !is OrientationControllable) return Vec3.ZERO
|
||||||
|
val controller = (driver as OrientationControllable).orientationController
|
||||||
|
|
||||||
|
val handling = vehicle.runtime.resolveDouble(settings.handlingExpr)
|
||||||
|
val topSpeed = vehicle.runtime.resolveDouble(settings.speedExpr)
|
||||||
|
|
||||||
|
//Smooth out mouse input.
|
||||||
|
val smoothingSpeed = 4.0
|
||||||
|
val invertRoll = if (Cobblemon.config.invertRoll) -1 else 1
|
||||||
|
val invertPitch = if (Cobblemon.config.invertPitch) -1 else 1
|
||||||
|
val mouseXc = (mouseX).coerceIn(-60.0, 60.0)
|
||||||
|
val mouseYc = (mouseY).coerceIn(-60.0, 60.0)
|
||||||
|
val xInput = mouseXSmoother.getNewDeltaValue(mouseXc * 0.1 * invertRoll, deltaTime * smoothingSpeed);
|
||||||
|
val yInput = mouseYSmoother.getNewDeltaValue(mouseYc * 0.1 * invertPitch, deltaTime * smoothingSpeed);
|
||||||
|
|
||||||
|
//limit rolling based on handling and current speed.
|
||||||
|
//modulated by speed so that when flapping idle in air you are ont wobbling around to look around
|
||||||
|
val rotMin = 15.0
|
||||||
|
var rollForce = xInput
|
||||||
|
val rotLimit = max(handling * normalizeVal(state.rideVel.get().length(), 0.0, topSpeed).pow(3), rotMin)
|
||||||
|
|
||||||
|
//Limit roll by non linearly decreasing inputs towards
|
||||||
|
// a rotation limit based on the current distance from
|
||||||
|
// that rotation limit
|
||||||
|
if (abs(controller.roll + rollForce) < rotLimit) {
|
||||||
|
if (sign(rollForce) == sign(controller.roll).toDouble()) {
|
||||||
|
val d = abs(abs(controller.roll) - rotLimit)
|
||||||
|
rollForce *= (d.pow(2)) / (rotLimit.pow(2))
|
||||||
|
}
|
||||||
|
} else if (sign(rollForce) == sign(controller.roll).toDouble()) {
|
||||||
|
rollForce = 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
//Give the ability to yaw with x mouse input when at low speeds.
|
||||||
|
val yawForce = xInput * ( 1.0 - normalizeVal(state.rideVel.get().length(), 0.0, topSpeed).pow(3))
|
||||||
|
|
||||||
|
//yaw, pitch, roll
|
||||||
|
return Vec3(yawForce, yInput, rollForce)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Normalizes the given value between a min and a max.
|
||||||
|
* The result is clamped between 0.0 and 1.0, where 0.0 represents x is at or below min
|
||||||
|
* and 1.0 represents x is at or above it.
|
||||||
|
*/
|
||||||
|
private fun normalizeVal(x: Double, min: Double, max: Double): Double {
|
||||||
|
require(max > min) { "max must be greater than min" }
|
||||||
|
return ((x - min) / (max - min)).coerceIn(0.0, 1.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return (state.stamina.get() / 1.0f)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
return Vec3.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
val topSpeed = vehicle.runtime.resolveDouble(settings.speedExpr)
|
||||||
|
val glideTopSpeed = vehicle.runtime.resolveDouble(settings.glidespeedExpr)
|
||||||
|
|
||||||
|
//Must I ensure that topspeed is greater than minimum?
|
||||||
|
val normalizedGlideSpeed = normalizeVal(state.rideVel.get().length(), topSpeed, glideTopSpeed)
|
||||||
|
|
||||||
|
//Only ever want the fov change to be a max of 0.2 and for it to have non linear scaling.
|
||||||
|
return 1.0f + normalizedGlideSpeed.pow(2).toFloat() * 0.2f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return state.gliding.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(settings: BirdAirSettings, state: BirdAirState, vehicle: PokemonEntity): Double {
|
||||||
|
return 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(settings: BirdAirSettings, state: BirdAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(settings: BirdAirSettings, state: BirdAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(settings: BirdAirSettings, state: BirdAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(
|
||||||
|
settings: BirdAirSettings,
|
||||||
|
state: BirdAirState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = BirdAirState()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class BirdAirSettings : RidingBehaviourSettings {
|
||||||
|
override val key = BirdAirBehaviour.KEY
|
||||||
|
|
||||||
|
var infiniteAltitude: Expression = "false".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var infiniteStamina: Expression = "false".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
//max y level for the ride
|
||||||
|
var jumpExpr: Expression = "q.get_ride_stats('JUMP', 'AIR', 200.0, 128.0)".asExpression()
|
||||||
|
var handlingExpr: Expression = "q.get_ride_stats('SKILL', 'AIR', 135.0, 45.0)".asExpression()
|
||||||
|
var speedExpr: Expression = "q.get_ride_stats('SPEED', 'AIR', 1.0, 0.35)".asExpression()
|
||||||
|
var accelerationExpr: Expression = "q.get_ride_stats('ACCELERATION', 'AIR', (1.0 / (20.0 * 3.0)), (1.0 / (20.0 * 8.0)))".asExpression()
|
||||||
|
var staminaExpr: Expression = "q.get_ride_stats('STAMINA', 'AIR', 120.0, 20.0)".asExpression()
|
||||||
|
|
||||||
|
var glidespeedExpr: Expression = "q.get_ride_stats('SPEED', 'AIR', 2.0, 1.0)".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeExpression(infiniteAltitude)
|
||||||
|
buffer.writeExpression(infiniteStamina)
|
||||||
|
buffer.writeExpression(glidespeedExpr)
|
||||||
|
buffer.writeExpression(jumpExpr)
|
||||||
|
buffer.writeExpression(handlingExpr)
|
||||||
|
buffer.writeExpression(speedExpr)
|
||||||
|
buffer.writeExpression(accelerationExpr)
|
||||||
|
buffer.writeExpression(staminaExpr)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
infiniteAltitude = buffer.readExpression()
|
||||||
|
infiniteStamina = buffer.readExpression()
|
||||||
|
glidespeedExpr = buffer.readExpression()
|
||||||
|
jumpExpr = buffer.readExpression()
|
||||||
|
handlingExpr = buffer.readExpression()
|
||||||
|
speedExpr = buffer.readExpression()
|
||||||
|
accelerationExpr = buffer.readExpression()
|
||||||
|
staminaExpr = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BirdAirState : RidingBehaviourState {
|
||||||
|
var rideVel = ridingState(Vec3.ZERO, Side.CLIENT)
|
||||||
|
var stamina = ridingState(1.0f, Side.CLIENT)
|
||||||
|
var gliding = ridingState(false, Side.CLIENT)
|
||||||
|
var lastGlide = ridingState(-100L, Side.CLIENT)
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeVec3(rideVel.get())
|
||||||
|
buffer.writeFloat(stamina.get())
|
||||||
|
buffer.writeBoolean(gliding.get())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
rideVel.set(buffer.readVec3(), forced = true)
|
||||||
|
stamina.set(buffer.readFloat(), forced = true)
|
||||||
|
gliding.set(buffer.readBoolean(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
rideVel.set(Vec3.ZERO, forced = true)
|
||||||
|
stamina.set(1.0f, forced = true)
|
||||||
|
gliding.set(false, forced = true)
|
||||||
|
lastGlide.set(-100L, forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "BirdAirState(rideVel=${rideVel.get()}, stamina=${stamina.get()}, gliding=${gliding.get()})"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy() = BirdAirState().also {
|
||||||
|
it.rideVel.set(this.rideVel.get(), forced = true)
|
||||||
|
it.stamina.set(this.stamina.get(), forced = true)
|
||||||
|
it.gliding.set(this.gliding.get(), forced = true)
|
||||||
|
it.lastGlide.set(this.lastGlide.get(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState): Boolean {
|
||||||
|
if (previous !is BirdAirState) return false
|
||||||
|
if (previous.rideVel != rideVel) return true
|
||||||
|
if (previous.stamina != stamina) return true
|
||||||
|
if (previous.gliding != gliding) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
+328
@@ -0,0 +1,328 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.*
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
import net.minecraft.world.phys.shapes.Shapes
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.sin
|
||||||
|
|
||||||
|
class DolphinBehaviour : RidingBehaviour<DolphinSettings, DolphinState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("swim/dolphin")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val poseProvider = PoseProvider<DolphinSettings, DolphinState>(PoseType.FLOAT)
|
||||||
|
.with(PoseOption(PoseType.SWIM) { _, _, entity -> entity.entityData.get(PokemonEntity.MOVING) })
|
||||||
|
|
||||||
|
override fun isActive(settings: DolphinSettings, state: DolphinState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return Shapes.create(vehicle.boundingBox).blockPositionsAsListRounded().any {
|
||||||
|
if (it.y.toDouble() == (vehicle.position().y)) {
|
||||||
|
val blockState = vehicle.level().getBlockState(it.below())
|
||||||
|
return@any (blockState.isAir || !blockState.fluidState.isEmpty ) ||
|
||||||
|
(vehicle.isInWater || vehicle.isUnderWater)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(settings: DolphinSettings, state: DolphinState, vehicle: PokemonEntity): PoseType {
|
||||||
|
return poseProvider.select(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(settings: DolphinSettings, state: DolphinState, vehicle: PokemonEntity, driver: Player): Float {
|
||||||
|
return vehicle.runtime.resolveFloat(settings.speed)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return Vec2(driver.xRot * 0.5f, driver.yRot)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
|
||||||
|
if (!vehicle.isInWater && !vehicle.isUnderWater)
|
||||||
|
{
|
||||||
|
state.lastVelocity.set(Vec3(state.lastVelocity.get().x, state.lastVelocity.get().y - 0.035, state.lastVelocity.get().z))
|
||||||
|
return state.lastVelocity.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
val driveFactor = runtime.resolveFloat(settings.driveFactor)
|
||||||
|
val strafeFactor = runtime.resolveFloat(settings.strafeFactor)
|
||||||
|
val f = driver.xxa * strafeFactor
|
||||||
|
var g = driver.zza * driveFactor
|
||||||
|
if (g <= 0.0f) {
|
||||||
|
g *= runtime.resolveFloat(settings.reverseDriveFactor)
|
||||||
|
}
|
||||||
|
|
||||||
|
var yComp = 0.0
|
||||||
|
|
||||||
|
//Get roll to add a left and right strafe during roll
|
||||||
|
//Not sure if this is desired? Will need to mess around with this
|
||||||
|
//a bit more
|
||||||
|
var zComp = 0.0
|
||||||
|
val controller = (driver as? OrientationControllable)?.orientationController
|
||||||
|
if (controller != null)
|
||||||
|
{
|
||||||
|
//Can be used again if I better figure out how to deadzone it near the tops?
|
||||||
|
zComp = -1.0 * g.toDouble() * sin(Math.toRadians(controller.roll.toDouble()))
|
||||||
|
yComp = -1.0 * g.toDouble() * sin(Math.toRadians(controller.pitch.toDouble()))
|
||||||
|
}
|
||||||
|
|
||||||
|
val currVelocity = Vec3(0.0, yComp , g.toDouble())
|
||||||
|
state.lastVelocity.set(currVelocity)
|
||||||
|
return currVelocity
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (!vehicle.isInWater && !vehicle.isUnderWater)
|
||||||
|
{
|
||||||
|
return Vec3(0.0, 0.0, 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
val controller = (driver as? OrientationControllable)?.orientationController
|
||||||
|
|
||||||
|
//this should be changed to be speed maybe?
|
||||||
|
val movingForce = driver.zza
|
||||||
|
if (controller != null) {
|
||||||
|
var yawAngVel = 3 * sin(Math.toRadians(controller.roll.toDouble())).toFloat()
|
||||||
|
var pitchAngVel = -1 * Math.abs(sin(Math.toRadians(controller.roll.toDouble())).toFloat())
|
||||||
|
|
||||||
|
//limit rotation modulation when pitched up heavily or pitched down heavily
|
||||||
|
yawAngVel *= (abs(cos(Math.toRadians(controller.pitch.toDouble())))).toFloat()
|
||||||
|
pitchAngVel *= (abs(cos(Math.toRadians(controller.pitch.toDouble())))).toFloat()
|
||||||
|
//if you are not pressing forward then don't turn
|
||||||
|
//yawAngVel *= movingForce
|
||||||
|
//Ignore x,y,z its angular velocity:
|
||||||
|
//yaw, pitch, roll
|
||||||
|
return Vec3(yawAngVel.toDouble(), pitchAngVel.toDouble(), 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Vec3(0.0, 0.0, 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (driver !is OrientationControllable) return Vec3.ZERO
|
||||||
|
|
||||||
|
//Might need to add the smoothing here for default.
|
||||||
|
val invertRoll = if (Cobblemon.config.invertRoll) -1 else 1
|
||||||
|
val invertPitch = if (Cobblemon.config.invertPitch) -1 else 1
|
||||||
|
return Vec3(0.0, mouseY * invertPitch, mouseX * invertRoll)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return vehicle.runtime.resolveBoolean(settings.canJump)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 0.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
runtime.environment.query.addFunction("jump_strength") { DoubleValue(jumpStrength.toDouble()) }
|
||||||
|
val jumpVector = settings.jumpVector.map { runtime.resolveFloat(it) }
|
||||||
|
return Vec3(jumpVector[0].toDouble(), jumpVector[1].toDouble(), jumpVector[2].toDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 1.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(settings: DolphinSettings, state: DolphinState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(settings: DolphinSettings, state: DolphinState, vehicle: PokemonEntity): Double {
|
||||||
|
return 0.05
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(settings: DolphinSettings, state: DolphinState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(settings: DolphinSettings, state: DolphinState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(settings: DolphinSettings, state: DolphinState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(
|
||||||
|
settings: DolphinSettings,
|
||||||
|
state: DolphinState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = DolphinState()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DolphinSettings : RidingBehaviourSettings {
|
||||||
|
override val key = DolphinBehaviour.KEY
|
||||||
|
|
||||||
|
var canJump = "true".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var jumpVector = listOf("0".asExpression(), "0.3".asExpression(), "0".asExpression())
|
||||||
|
private set
|
||||||
|
|
||||||
|
var speed = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var driveFactor = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var reverseDriveFactor = "0.25".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var strafeFactor = "0.2".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeExpression(canJump)
|
||||||
|
buffer.writeExpression(jumpVector[0])
|
||||||
|
buffer.writeExpression(jumpVector[1])
|
||||||
|
buffer.writeExpression(jumpVector[2])
|
||||||
|
buffer.writeExpression(speed)
|
||||||
|
buffer.writeExpression(driveFactor)
|
||||||
|
buffer.writeExpression(reverseDriveFactor)
|
||||||
|
buffer.writeExpression(strafeFactor)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
canJump = buffer.readExpression()
|
||||||
|
jumpVector = listOf(
|
||||||
|
buffer.readExpression(),
|
||||||
|
buffer.readExpression(),
|
||||||
|
buffer.readExpression()
|
||||||
|
)
|
||||||
|
speed = buffer.readExpression()
|
||||||
|
driveFactor = buffer.readExpression()
|
||||||
|
reverseDriveFactor = buffer.readExpression()
|
||||||
|
strafeFactor = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DolphinState : RidingBehaviourState {
|
||||||
|
var lastVelocity = ridingState(Vec3.ZERO, Side.BOTH)
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) = Unit
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) = Unit
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
lastVelocity.set(Vec3.ZERO, forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "DolphinState(lastVelocity=${lastVelocity.get()})"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy() = DolphinState().also {
|
||||||
|
it.lastVelocity.set(lastVelocity.get(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState) = false
|
||||||
|
}
|
||||||
+434
@@ -0,0 +1,434 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.Expression
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.*
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonBehaviourFlag
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
|
||||||
|
class FallToGlideCompositeBehaviour : RidingBehaviour<FallToGlideCompositeSettings, FallToGlideCompositeState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("composite/fall_to_glide")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val landBehaviour: GenericLandBehaviour = GenericLandBehaviour()
|
||||||
|
val glideBehaviour: GliderAirBehaviour = GliderAirBehaviour()
|
||||||
|
|
||||||
|
override fun tick(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
) {
|
||||||
|
val shouldBeFlying = checkShouldBeFlying(settings, vehicle, state.activeController.get() == GliderAirBehaviour.KEY)
|
||||||
|
if (state.activeController.get() == GliderAirBehaviour.KEY && !shouldBeFlying) { // && entity.onGround() && state.timeTransitioned + 20 < entity.level().gameTime) {
|
||||||
|
state.activeController.set(GenericLandBehaviour.KEY)
|
||||||
|
vehicle.setBehaviourFlag(PokemonBehaviourFlag.FLYING, false)
|
||||||
|
} else if (state.activeController.get() == GenericLandBehaviour.KEY && shouldBeFlying) {
|
||||||
|
state.activeController.set(GliderAirBehaviour.KEY)
|
||||||
|
vehicle.setBehaviourFlag(PokemonBehaviourFlag.FLYING, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkShouldBeFlying(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
isFlyingAlready: Boolean
|
||||||
|
): Boolean {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
val minFallingSpeed = runtime.resolveFloat(settings.minimumFallSpeed)
|
||||||
|
val minForwardSpeed = runtime.resolveFloat(settings.minimumForwardSpeed)
|
||||||
|
val grounded = vehicle.onGround()
|
||||||
|
return if (isFlyingAlready) {
|
||||||
|
!grounded
|
||||||
|
} else {
|
||||||
|
vehicle.deltaMovement.y <= -minFallingSpeed && vehicle.deltaMovement.horizontalDistance() >= minForwardSpeed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isActive(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): PoseType {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.pose(settings.land, state.landState, vehicle)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.pose(settings.glide, NoState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.speed(settings.land, state.landState, vehicle, driver)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.speed(settings.glide, NoState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.rotation(settings.land, state.landState, vehicle, driver)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.rotation(settings.glide, NoState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.velocity(settings.land, state.landState, vehicle, driver, input)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.velocity(settings.glide, NoState, vehicle, driver, input)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.angRollVel(
|
||||||
|
settings.land,
|
||||||
|
state.landState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.angRollVel(settings.glide, NoState, vehicle, driver, deltaTime)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.rotationOnMouseXY(
|
||||||
|
settings.land,
|
||||||
|
state.landState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
mouseY,
|
||||||
|
mouseX,
|
||||||
|
mouseYSmoother,
|
||||||
|
mouseXSmoother,
|
||||||
|
sensitivity,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.rotationOnMouseXY(
|
||||||
|
settings.glide,
|
||||||
|
NoState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
mouseY,
|
||||||
|
mouseX,
|
||||||
|
mouseYSmoother,
|
||||||
|
mouseXSmoother,
|
||||||
|
sensitivity,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.canJump(settings.land, state.landState, vehicle, driver)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.canJump(settings.glide, NoState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.setRideBar(settings.land, state.landState, vehicle, driver)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.setRideBar(settings.glide, NoState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.jumpForce(
|
||||||
|
settings.land,
|
||||||
|
state.landState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
jumpStrength
|
||||||
|
)
|
||||||
|
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.jumpForce(settings.glide, NoState, vehicle, driver, jumpStrength)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.gravity(settings.land, state.landState, vehicle, regularGravity)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.gravity(settings.glide, NoState, vehicle, regularGravity)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.rideFovMultiplier(settings.land, state.landState, vehicle, driver)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.rideFovMultiplier(settings.glide, NoState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.useAngVelSmoothing(settings.land, state.landState, vehicle)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.useAngVelSmoothing(settings.glide, NoState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.useRidingAltPose(settings.land, state.landState, vehicle, driver)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.useRidingAltPose(settings.glide, NoState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Double {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.inertia(settings.land, state.landState, vehicle)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.inertia(settings.glide, NoState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.shouldRoll(settings.land, state.landState, vehicle)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.shouldRoll(settings.glide, NoState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.turnOffOnGround(settings.land, state.landState, vehicle)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.turnOffOnGround(settings.glide, NoState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.dismountOnShift(settings.land, state.landState, vehicle)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.dismountOnShift(settings.glide, NoState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.shouldRotatePokemonHead(settings.land, state.landState, vehicle)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.shouldRotatePokemonHead(settings.glide, NoState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(
|
||||||
|
settings: FallToGlideCompositeSettings,
|
||||||
|
state: FallToGlideCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.shouldRotatePlayerHead(settings.land, state.landState, vehicle)
|
||||||
|
GliderAirBehaviour.KEY -> glideBehaviour.shouldRotatePlayerHead(settings.glide, NoState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = FallToGlideCompositeState()
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class FallToGlideCompositeSettings : RidingBehaviourSettings {
|
||||||
|
override val key = FallToGlideCompositeBehaviour.KEY
|
||||||
|
|
||||||
|
var glide: GliderAirSettings = GliderAirSettings()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var land: GenericLandSettings = GenericLandSettings()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var minimumForwardSpeed: Expression = "0.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var minimumFallSpeed: Expression = "0.5".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
glide.encode(buffer)
|
||||||
|
land.encode(buffer)
|
||||||
|
buffer.writeExpression(minimumForwardSpeed)
|
||||||
|
buffer.writeExpression(minimumFallSpeed)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
glide.decode(buffer)
|
||||||
|
land.decode(buffer)
|
||||||
|
minimumForwardSpeed = buffer.readExpression()
|
||||||
|
minimumFallSpeed = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FallToGlideCompositeState : RidingBehaviourState {
|
||||||
|
var activeController = ridingState(GenericLandBehaviour.KEY, Side.CLIENT)
|
||||||
|
var landState: GenericLandState = GenericLandState()
|
||||||
|
var timeTransitioned = ridingState(-100L, Side.BOTH)
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeResourceLocation(activeController.get())
|
||||||
|
landState.encode(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
activeController.set(buffer.readResourceLocation(), forced = true)
|
||||||
|
landState.decode(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
activeController.set(GenericLandBehaviour.KEY, forced = true)
|
||||||
|
landState.reset()
|
||||||
|
timeTransitioned.set(-100L, forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "FallToGlideCompositeState(activeController=$activeController, landState=$landState, timeTransitioned=$timeTransitioned)"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy() = FallToGlideCompositeState().also {
|
||||||
|
it.activeController.set(activeController.get(), forced = true)
|
||||||
|
it.landState = landState.copy()
|
||||||
|
it.timeTransitioned.set(timeTransitioned.get(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState): Boolean {
|
||||||
|
if (previous !is FallToGlideCompositeState) return false
|
||||||
|
if (activeController != previous.activeController) return true
|
||||||
|
if (landState.shouldSync(previous.landState)) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
+425
@@ -0,0 +1,425 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.Expression
|
||||||
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.*
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
import net.minecraft.world.phys.shapes.Shapes
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
|
class GenericLandBehaviour : RidingBehaviour<GenericLandSettings, GenericLandState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("land/generic")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val poseProvider = PoseProvider<GenericLandSettings, GenericLandState>(PoseType.STAND)
|
||||||
|
.with(PoseOption(PoseType.WALK) { _, state, _ ->
|
||||||
|
return@PoseOption state.rideVel.get().z > 0.1
|
||||||
|
})
|
||||||
|
|
||||||
|
override fun isActive(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return Shapes.create(vehicle.boundingBox).blockPositionsAsListRounded().any {
|
||||||
|
//Need to check other fluids
|
||||||
|
if (vehicle.isInWater || vehicle.isUnderWater) {
|
||||||
|
return@any false
|
||||||
|
}
|
||||||
|
//This might not actually work, depending on what the yPos actually is. yPos of the middle of the entity? the feet?
|
||||||
|
if (it.y.toDouble() == (vehicle.position().y)) {
|
||||||
|
val blockState = vehicle.level().getBlockState(it.below())
|
||||||
|
return@any !blockState.isAir && blockState.fluidState.isEmpty
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): PoseType {
|
||||||
|
return this.poseProvider.select(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return state.rideVel.get().length().toFloat()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return Vec2(driver.xRot * 0.5f, driver.yRot)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
val driveFactor = runtime.resolveFloat(settings.driveFactor)
|
||||||
|
val strafeFactor = runtime.resolveFloat(settings.strafeFactor)
|
||||||
|
val f = driver.xxa * strafeFactor
|
||||||
|
var g = driver.zza * driveFactor
|
||||||
|
if (g <= 0.0f) {
|
||||||
|
g *= runtime.resolveFloat(settings.reverseDriveFactor)
|
||||||
|
}
|
||||||
|
val gravity = -1.0
|
||||||
|
|
||||||
|
val newVelocity = calculateRideSpaceVel(settings, state, vehicle, driver)
|
||||||
|
|
||||||
|
//Jump the thang!
|
||||||
|
if (driver.jumping && vehicle.onGround()) {
|
||||||
|
state.rideVel.set(Vec3(newVelocity.x, 2.0, newVelocity.z))
|
||||||
|
} else {
|
||||||
|
state.rideVel.set(newVelocity)
|
||||||
|
}
|
||||||
|
|
||||||
|
//This is cheap.
|
||||||
|
//Also make it stop quicker the slower it is.
|
||||||
|
val maxSpeed = 1.0
|
||||||
|
//state.currVel = state.currVel.lerp( Vec3(0.0, state.currVel.y, 0.0), 1.0/20.0 )
|
||||||
|
|
||||||
|
|
||||||
|
//entity.deltaMovement = entity.deltaMovement.lerp(velocity, 1.0)
|
||||||
|
//state.currVel = state.currVel.add( f.toDouble() / 20.0, gravity / 20.0 , g.toDouble() / 20.0)
|
||||||
|
return state.rideVel.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun calculateRideSpaceVel(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Vec3 {
|
||||||
|
val topSpeed = vehicle.runtime.resolveDouble(settings.topSpeedExpr)
|
||||||
|
val accel = vehicle.runtime.resolveDouble(settings.accelExpr)
|
||||||
|
val speed = state.rideVel.get().length()
|
||||||
|
|
||||||
|
val minSpeed = 0.0
|
||||||
|
|
||||||
|
var newVelocity = Vec3(state.rideVel.get().x, state.rideVel.get().y, state.rideVel.get().z)
|
||||||
|
|
||||||
|
//speed up and slow down based on input
|
||||||
|
if (driver.zza > 0.0 && speed <= topSpeed && state.stamina.get() > 0.0f) {
|
||||||
|
//modify acceleration to be slower when at closer speeds to top speed
|
||||||
|
val accelMod = max((normalizeSpeed(speed, minSpeed, topSpeed) - 1).pow(2), 0.1)
|
||||||
|
newVelocity = Vec3(newVelocity.x, newVelocity.y, min(newVelocity.z + (accel * accelMod), topSpeed))
|
||||||
|
} else if (driver.zza >= 0.0 && state.stamina.get() == 0.0f || speed > topSpeed) {
|
||||||
|
newVelocity = Vec3(newVelocity.x, newVelocity.y, max(newVelocity.z - ((accel) / 4), minSpeed))
|
||||||
|
} else if (driver.zza < 0.0 && speed > minSpeed) {
|
||||||
|
//modify deccel to be slower when at closer speeds to minimum speed
|
||||||
|
val deccelMod = max(-(normalizeSpeed(speed, minSpeed, topSpeed)) + 1, 0.0)
|
||||||
|
|
||||||
|
//Decelerate currently always a constant half of max acceleration.
|
||||||
|
newVelocity =
|
||||||
|
Vec3(newVelocity.x, newVelocity.y, max(newVelocity.z - ((accel * deccelMod) / 2), minSpeed))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vehicle.onGround()) {
|
||||||
|
newVelocity = Vec3(newVelocity.x, 0.0, newVelocity.z)
|
||||||
|
} else {
|
||||||
|
newVelocity = Vec3(newVelocity.x, max(newVelocity.y - 0.2, -1.0), newVelocity.z)
|
||||||
|
}
|
||||||
|
return newVelocity
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Normalizes the current speed between minSpeed and maxSpeed.
|
||||||
|
* The result is clamped between 0.0 and 1.0, where 0.0 represents minSpeed and 1.0 represents maxSpeed.
|
||||||
|
*/
|
||||||
|
private fun normalizeSpeed(currSpeed: Double, minSpeed: Double, maxSpeed: Double): Double {
|
||||||
|
require(maxSpeed > minSpeed) { "maxSpeed must be greater than minSpeed" }
|
||||||
|
return ((currSpeed - minSpeed) / (maxSpeed - minSpeed)).coerceIn(0.0, 1.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return Vec3.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
//Smooth out mouse input.
|
||||||
|
val smoothingSpeed = 4
|
||||||
|
val xInput = mouseXSmoother.getNewDeltaValue(mouseX * 0.1, deltaTime * smoothingSpeed);
|
||||||
|
val yInput = mouseYSmoother.getNewDeltaValue(mouseY * 0.1, deltaTime * smoothingSpeed);
|
||||||
|
|
||||||
|
//yaw, pitch, roll
|
||||||
|
return Vec3(0.0, yInput, xInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
//Retrieve stamina from state and tick up at a rate of 0.1 a second
|
||||||
|
val staminaGain = (1.0 / 20.0) * 0.1
|
||||||
|
state.stamina.set(min(state.stamina.get() + staminaGain, 1.0).toFloat())
|
||||||
|
return (state.stamina.get() / 1.0f)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
runtime.environment.query.addFunction("jump_strength") { DoubleValue(jumpStrength.toDouble()) }
|
||||||
|
val jumpVector = settings.jumpVector.map { runtime.resolveFloat(it) }
|
||||||
|
return Vec3(jumpVector[0].toDouble(), jumpVector[1].toDouble(), jumpVector[2].toDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 1.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Double {
|
||||||
|
return 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(
|
||||||
|
settings: GenericLandSettings,
|
||||||
|
state: GenericLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = GenericLandState()
|
||||||
|
}
|
||||||
|
|
||||||
|
class GenericLandSettings : RidingBehaviourSettings {
|
||||||
|
override val key = GenericLandBehaviour.KEY
|
||||||
|
|
||||||
|
var driveFactor = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var strafeFactor = "0.2".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var reverseDriveFactor = "0.25".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var topSpeedExpr: Expression = "q.get_ride_stats('SPEED', 'LAND', 1.0, 0.3)".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
// Max accel is a whole 1.0 in 1 second. The conversion in the function below is to convert seconds to ticks
|
||||||
|
var accelExpr: Expression =
|
||||||
|
"q.get_ride_stats('ACCELERATION', 'LAND', (1.0 / (20.0 * 0.5)), (1.0 / (20.0 * 5.0)))".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var jumpVector = listOf("0".asExpression(), "0.3".asExpression(), "0".asExpression())
|
||||||
|
private set
|
||||||
|
|
||||||
|
// Between 30 seconds and 10 seconds at the lowest when at full speed.
|
||||||
|
var staminaExpr: Expression = "q.get_ride_stats('STAMINA', 'LAND', 30.0, 10.0)".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
//Between a one block jump and a ten block jump
|
||||||
|
var jumpExpr: Expression = "q.get_ride_stats('JUMP', 'LAND', 10.0, 1.0)".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var handlingExpr: Expression = "q.get_ride_stats('SKILL', 'LAND', 140.0, 20.0)".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeExpression(driveFactor)
|
||||||
|
buffer.writeExpression(strafeFactor)
|
||||||
|
buffer.writeExpression(reverseDriveFactor)
|
||||||
|
buffer.writeExpression(topSpeedExpr)
|
||||||
|
buffer.writeExpression(accelExpr)
|
||||||
|
buffer.writeExpression(jumpVector[0])
|
||||||
|
buffer.writeExpression(jumpVector[1])
|
||||||
|
buffer.writeExpression(jumpVector[2])
|
||||||
|
buffer.writeExpression(staminaExpr)
|
||||||
|
buffer.writeExpression(jumpExpr)
|
||||||
|
buffer.writeExpression(handlingExpr)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
driveFactor = buffer.readExpression()
|
||||||
|
strafeFactor = buffer.readExpression()
|
||||||
|
reverseDriveFactor = buffer.readExpression()
|
||||||
|
topSpeedExpr = buffer.readExpression()
|
||||||
|
accelExpr = buffer.readExpression()
|
||||||
|
jumpVector = listOf(
|
||||||
|
buffer.readExpression(),
|
||||||
|
buffer.readExpression(),
|
||||||
|
buffer.readExpression()
|
||||||
|
)
|
||||||
|
staminaExpr = buffer.readExpression()
|
||||||
|
jumpExpr = buffer.readExpression()
|
||||||
|
handlingExpr = buffer.readExpression()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class GenericLandState : RidingBehaviourState {
|
||||||
|
var rideVel = ridingState(Vec3.ZERO, Side.CLIENT)
|
||||||
|
var stamina = ridingState(1.0f, Side.CLIENT)
|
||||||
|
var currSpeed = ridingState(0.0, Side.BOTH)
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeVec3(rideVel.get())
|
||||||
|
buffer.writeFloat(stamina.get())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
rideVel.set(buffer.readVec3(), forced = true)
|
||||||
|
stamina.set(buffer.readFloat(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
rideVel.set(Vec3.ZERO, forced = true)
|
||||||
|
stamina.set(1.0f, forced = true)
|
||||||
|
currSpeed.set(0.0, forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "GenericLandState(rideVel=${rideVel.get()}, stamina=${stamina.get()}, currSpeed=${currSpeed.get()})"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy() = GenericLandState().also {
|
||||||
|
it.rideVel.set(this.rideVel.get(), forced = true)
|
||||||
|
it.stamina.set(this.stamina.get(), forced = true)
|
||||||
|
it.currSpeed.set(this.currSpeed.get(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState): Boolean {
|
||||||
|
if (previous !is GenericLandState) return false
|
||||||
|
if (rideVel != previous.rideVel) return true
|
||||||
|
if (stamina != previous.stamina) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
+261
@@ -0,0 +1,261 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.NoState
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviour
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourSettings
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
import net.minecraft.world.phys.shapes.Shapes
|
||||||
|
|
||||||
|
class GenericSwimBehaviour : RidingBehaviour<GenericSwimSettings, NoState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("swim/generic")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val poseProvider = PoseProvider<GenericSwimSettings, NoState>(PoseType.FLOAT)
|
||||||
|
.with(PoseOption(PoseType.SWIM) { _, _, entity -> entity.isSwimming && entity.entityData.get(PokemonEntity.MOVING) })
|
||||||
|
|
||||||
|
override fun isActive(settings: GenericSwimSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return Shapes.create(vehicle.boundingBox).blockPositionsAsListRounded().any {
|
||||||
|
if (vehicle.isInWater || vehicle.isUnderWater) {
|
||||||
|
return@any true
|
||||||
|
}
|
||||||
|
val blockState = vehicle.level().getBlockState(it)
|
||||||
|
return@any !blockState.fluidState.isEmpty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(settings: GenericSwimSettings, state: NoState, vehicle: PokemonEntity): PoseType {
|
||||||
|
return poseProvider.select(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(settings: GenericSwimSettings, state: NoState, vehicle: PokemonEntity, driver: Player): Float {
|
||||||
|
return vehicle.runtime.resolveFloat(settings.speed)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return Vec2(driver.xRot * 0.5f, driver.yRot)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
val driveFactor = runtime.resolveFloat(settings.driveFactor)
|
||||||
|
val strafeFactor = runtime.resolveFloat(settings.strafeFactor)
|
||||||
|
val f = driver.xxa * strafeFactor
|
||||||
|
var g = driver.zza * driveFactor
|
||||||
|
if (g <= 0.0f) {
|
||||||
|
g *= runtime.resolveFloat(settings.reverseDriveFactor)
|
||||||
|
}
|
||||||
|
|
||||||
|
val velocity = Vec3(f.toDouble(), 0.0, g.toDouble())
|
||||||
|
|
||||||
|
return velocity
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return Vec3.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (driver !is OrientationControllable) return Vec3.ZERO
|
||||||
|
|
||||||
|
//Might need to add the smoothing here for default.
|
||||||
|
val invertRoll = if (Cobblemon.config.invertRoll) -1 else 1
|
||||||
|
val invertPitch = if (Cobblemon.config.invertPitch) -1 else 1
|
||||||
|
return Vec3(0.0, mouseY * invertPitch, mouseX * invertRoll)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return vehicle.runtime.resolveBoolean(settings.canJump)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 0.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
runtime.environment.query.addFunction("jump_strength") { DoubleValue(jumpStrength.toDouble()) }
|
||||||
|
val jumpVector = settings.jumpVector.map { runtime.resolveFloat(it) }
|
||||||
|
return Vec3(jumpVector[0].toDouble(), jumpVector[1].toDouble(), jumpVector[2].toDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return regularGravity
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 1.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(settings: GenericSwimSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(settings: GenericSwimSettings, state: NoState, vehicle: PokemonEntity): Double {
|
||||||
|
return 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(settings: GenericSwimSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(settings: GenericSwimSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(settings: GenericSwimSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(
|
||||||
|
settings: GenericSwimSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = NoState
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class GenericSwimSettings : RidingBehaviourSettings {
|
||||||
|
override val key = GenericSwimBehaviour.KEY
|
||||||
|
|
||||||
|
var canJump = "true".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var jumpVector = listOf("0".asExpression(), "0.3".asExpression(), "0".asExpression())
|
||||||
|
private set
|
||||||
|
|
||||||
|
var speed = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var driveFactor = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var reverseDriveFactor = "0.25".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var strafeFactor = "0.2".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeExpression(canJump)
|
||||||
|
buffer.writeExpression(jumpVector[0])
|
||||||
|
buffer.writeExpression(jumpVector[1])
|
||||||
|
buffer.writeExpression(jumpVector[2])
|
||||||
|
buffer.writeExpression(speed)
|
||||||
|
buffer.writeExpression(driveFactor)
|
||||||
|
buffer.writeExpression(reverseDriveFactor)
|
||||||
|
buffer.writeExpression(strafeFactor)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
canJump = buffer.readExpression()
|
||||||
|
jumpVector = listOf(
|
||||||
|
buffer.readExpression(),
|
||||||
|
buffer.readExpression(),
|
||||||
|
buffer.readExpression()
|
||||||
|
)
|
||||||
|
speed = buffer.readExpression()
|
||||||
|
driveFactor = buffer.readExpression()
|
||||||
|
reverseDriveFactor = buffer.readExpression()
|
||||||
|
strafeFactor = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
+212
@@ -0,0 +1,212 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.Expression
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable
|
||||||
|
import com.cobblemon.mod.common.api.riding.RidingStyle
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.NoState
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviour
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourSettings
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||||
|
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
|
||||||
|
class GliderAirBehaviour : RidingBehaviour<GliderAirSettings, NoState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("air/glider")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val poseProvider = PoseProvider<GliderAirSettings, NoState>(PoseType.HOVER)
|
||||||
|
.with(PoseOption(PoseType.FLY) { _, _, entity -> entity.entityData.get(PokemonEntity.MOVING) })
|
||||||
|
|
||||||
|
override fun isActive(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity): PoseType {
|
||||||
|
return poseProvider.select(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity, driver: Player): Float {
|
||||||
|
return vehicle.runtime.resolveFloat(settings.speed)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: GliderAirSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return Vec2(driver.xRot, driver.yRot)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: GliderAirSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
val xVector = if (vehicle.runtime.resolveBoolean(settings.canStrafe)) driver.xxa.toDouble() else 0.0
|
||||||
|
val yVector = -vehicle.runtime.resolveDouble(settings.glideSpeed)
|
||||||
|
val zVector = driver.zza.toDouble()
|
||||||
|
val statSpeed = vehicle.rideProp.calculate(RidingStat.SPEED, RidingStyle.AIR, 0 )
|
||||||
|
|
||||||
|
return Vec3(xVector, yVector, zVector)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: GliderAirSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return Vec3.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: GliderAirSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (driver !is OrientationControllable) return Vec3.ZERO
|
||||||
|
|
||||||
|
//Might need to add the smoothing here for default.
|
||||||
|
val invertRoll = if (Cobblemon.config.invertRoll) -1 else 1
|
||||||
|
val invertPitch = if (Cobblemon.config.invertPitch) -1 else 1
|
||||||
|
return Vec3(0.0, mouseY * invertPitch, mouseX * invertRoll)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity, driver: Player): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: GliderAirSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 0.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: GliderAirSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
return Vec3.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: GliderAirSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: GliderAirSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 1.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: GliderAirSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity): Double {
|
||||||
|
return 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(settings: GliderAirSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = NoState
|
||||||
|
}
|
||||||
|
|
||||||
|
class GliderAirSettings : RidingBehaviourSettings {
|
||||||
|
override val key = GliderAirBehaviour.KEY
|
||||||
|
|
||||||
|
var glideSpeed: Expression = "0.1".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var speed: Expression = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var canStrafe: Expression = "false".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeExpression(glideSpeed)
|
||||||
|
buffer.writeExpression(speed)
|
||||||
|
buffer.writeExpression(canStrafe)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
glideSpeed = buffer.readExpression()
|
||||||
|
speed = buffer.readExpression()
|
||||||
|
canStrafe = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
+302
@@ -0,0 +1,302 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.Expression
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.NoState
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviour
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourSettings
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
import net.minecraft.world.phys.shapes.Shapes
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.sin
|
||||||
|
|
||||||
|
class HelicopterBehaviour : RidingBehaviour<HelicopterSettings, NoState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("air/helicopter")
|
||||||
|
val ROTATION_LIMIT = 30.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val poseProvider = PoseProvider<HelicopterSettings, NoState>(PoseType.HOVER)
|
||||||
|
.with(PoseOption(PoseType.FLY) { _, _, entity -> entity.entityData.get(PokemonEntity.MOVING) })
|
||||||
|
|
||||||
|
override fun isActive(settings: HelicopterSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
//If there are only fluid blocks or air block below the ride
|
||||||
|
//then activate the controller. If it is in water the ride will
|
||||||
|
//dismount accordingly
|
||||||
|
return Shapes.create(vehicle.boundingBox).blockPositionsAsListRounded().any {
|
||||||
|
if (it.y.toDouble() == (vehicle.position().y)) {
|
||||||
|
val blockState = vehicle.level().getBlockState(it.below())
|
||||||
|
return@any (blockState.isAir || !blockState.fluidState.isEmpty)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(settings: HelicopterSettings, state: NoState, vehicle: PokemonEntity): PoseType {
|
||||||
|
return poseProvider.select(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(settings: HelicopterSettings, state: NoState, vehicle: PokemonEntity, driver: Player): Float {
|
||||||
|
//Increased max speed to exaggerate movement.
|
||||||
|
//This likely just needs to be a static number if it really is just
|
||||||
|
//the scalar for the velocity vector
|
||||||
|
return 2.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return Vec2(driver.xRot * 0.5f, driver.yRot)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
|
||||||
|
//If the player is not modulating height then hover
|
||||||
|
var yVel = if (driver.jumping) runtime.resolveDouble(settings.verticalVelocity)
|
||||||
|
else if (driver.isShiftKeyDown) -runtime.resolveDouble(settings.verticalVelocity)
|
||||||
|
else (0.0)
|
||||||
|
|
||||||
|
yVel *= 0.25
|
||||||
|
var xVel = 0.0
|
||||||
|
var zVel = 0.0
|
||||||
|
|
||||||
|
val controller = (driver as? OrientationControllable)?.orientationController
|
||||||
|
|
||||||
|
//Horizontal velocity is based on pitch and roll
|
||||||
|
if (controller != null) {
|
||||||
|
xVel = -1.0 * sin(Math.toRadians(controller.roll.toDouble()))
|
||||||
|
zVel = sin(Math.toRadians(controller.pitch.toDouble()))
|
||||||
|
}
|
||||||
|
|
||||||
|
return Vec3(xVel, yVel, zVel)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
val controller = (driver as? OrientationControllable)?.orientationController
|
||||||
|
|
||||||
|
//In degrees per second? It was supposed to be I think but
|
||||||
|
//I have messed something up
|
||||||
|
val rotationChangeRate = 2.0
|
||||||
|
val rotLimit = 30.0
|
||||||
|
|
||||||
|
var pitchForce = driver.zza * rotationChangeRate
|
||||||
|
var rollForce = -1.0 * driver.xxa * rotationChangeRate
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Fix accumulated movement causing pitch and roll out of set bounds
|
||||||
|
if (controller != null) {
|
||||||
|
//If the roll or pitch have exceeded the limit then do not modulate that
|
||||||
|
//rotation in that direction further
|
||||||
|
|
||||||
|
//modulate the forces so that they trend towards 0 as they approach rotation limit.
|
||||||
|
//The current function has it drop off very quickly which may not be ideal.
|
||||||
|
//Prev function:
|
||||||
|
// pitchForce = pitchForce * max(rotLim - abs(rollable.pitch.toDouble()), 0.0)
|
||||||
|
|
||||||
|
//The three denotes that the force will be 1/3 what it would have been at
|
||||||
|
//the rotation limit
|
||||||
|
rollForce *= 2.0.pow(-1.0 * (abs(controller.roll.toDouble()) / ROTATION_LIMIT))
|
||||||
|
|
||||||
|
pitchForce *= 2.0.pow(-1.0 * (abs(controller.pitch.toDouble()) / ROTATION_LIMIT))
|
||||||
|
|
||||||
|
if (controller.roll >= ROTATION_LIMIT && rollForce > 0.0) {
|
||||||
|
rollForce = 0.0;
|
||||||
|
}
|
||||||
|
if (controller.roll <= -ROTATION_LIMIT && rollForce < 0.0) {
|
||||||
|
rollForce = 0.0;
|
||||||
|
}
|
||||||
|
if (controller.pitch >= ROTATION_LIMIT && pitchForce > 0.0) {
|
||||||
|
pitchForce = 0.0;
|
||||||
|
}
|
||||||
|
if (controller.pitch <= -ROTATION_LIMIT && pitchForce < 0.0) {
|
||||||
|
pitchForce = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Ignore x,y,z its angular velocity:
|
||||||
|
//yaw, pitch, roll
|
||||||
|
return Vec3(0.0, pitchForce.toDouble(), rollForce)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Vec3(0.0, 0.0, 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (driver !is OrientationControllable) return Vec3.ZERO
|
||||||
|
|
||||||
|
val controller = (driver as OrientationControllable).orientationController
|
||||||
|
val invertYaw = if (Cobblemon.config.invertYaw) -1 else 1
|
||||||
|
//yaw, pitch, roll
|
||||||
|
return Vec3(mouseX * invertYaw, 0.0, 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 0.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
return Vec3.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 1.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(settings: HelicopterSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(settings: HelicopterSettings, state: NoState, vehicle: PokemonEntity): Double {
|
||||||
|
return 0.1
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(settings: HelicopterSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(settings: HelicopterSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(settings: HelicopterSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: HelicopterSettings,
|
||||||
|
state: NoState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(settings: HelicopterSettings, state: NoState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = NoState
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class HelicopterSettings : RidingBehaviourSettings {
|
||||||
|
override val key = HelicopterBehaviour.KEY
|
||||||
|
|
||||||
|
var gravity: Expression = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var horizontalAcceleration: Expression = "0.1".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var verticalVelocity: Expression = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var speed: Expression = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeExpression(gravity)
|
||||||
|
buffer.writeExpression(horizontalAcceleration)
|
||||||
|
buffer.writeExpression(verticalVelocity)
|
||||||
|
buffer.writeExpression(speed)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
gravity = buffer.readExpression()
|
||||||
|
horizontalAcceleration = buffer.readExpression()
|
||||||
|
verticalVelocity = buffer.readExpression()
|
||||||
|
speed = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
+442
@@ -0,0 +1,442 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.Expression
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.*
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
import kotlin.math.*
|
||||||
|
|
||||||
|
class JetAirBehaviour : RidingBehaviour<JetAirSettings, JetAirState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("air/jet")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val poseProvider = PoseProvider<JetAirSettings, JetAirState>(PoseType.HOVER)
|
||||||
|
.with(PoseOption(PoseType.FLY) { _, state, _ -> state.rideVel.get().z > 0.1 })
|
||||||
|
|
||||||
|
override fun isActive(settings: JetAirSettings, state: JetAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(settings: JetAirSettings, state: JetAirState, vehicle: PokemonEntity): PoseType {
|
||||||
|
return poseProvider.select(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(settings: JetAirSettings, state: JetAirState, vehicle: PokemonEntity, driver: Player): Float {
|
||||||
|
//retrieve stats
|
||||||
|
val topSpeed = vehicle.runtime.resolveDouble(settings.speedExpr)
|
||||||
|
val staminaStat = vehicle.runtime.resolveDouble(settings.staminaExpr)
|
||||||
|
|
||||||
|
//retrieve minSpeed
|
||||||
|
val minSpeed = vehicle.runtime.resolveDouble(settings.minSpeed)
|
||||||
|
|
||||||
|
//Reduce stamina unless stamina is infinite
|
||||||
|
if (!vehicle.runtime.resolveBoolean(settings.infiniteStamina)) {
|
||||||
|
//Calculate stamina loss due to speed
|
||||||
|
//At max speed it will tick down 0.1 a second so the stamina will last ten seconds
|
||||||
|
//There has got to be a better way to express this equation. It interpolates between 0.5 and 1.0
|
||||||
|
var staminaRate = (normalizeSpeed(state.rideVel.get().length(), minSpeed, topSpeed))
|
||||||
|
|
||||||
|
//interpolate between 0.25 and 1.0 so that you always have at least a min of 0.25 stam loss
|
||||||
|
staminaRate = 0.25 + (0.75 * staminaRate.pow(3))
|
||||||
|
|
||||||
|
//Calculate stamina loss in seconds achievable at top speed
|
||||||
|
val staminaLoss = staminaRate * (1.0 / (20.0 * staminaStat))
|
||||||
|
state.stamina.set(max(state.stamina.get() - staminaLoss, 0.0).toFloat())
|
||||||
|
} else {
|
||||||
|
state.stamina.set(1.0f)
|
||||||
|
}
|
||||||
|
|
||||||
|
return state.rideVel.get().length().toFloat()
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Move these functions to a riding util class.
|
||||||
|
/*
|
||||||
|
* Normalizes the current speed between minSpeed and maxSpeed.
|
||||||
|
* The result is clamped between 0.0 and 1.0, where 0.0 represents minSpeed and 1.0 represents maxSpeed.
|
||||||
|
*/
|
||||||
|
private fun normalizeSpeed(currSpeed: Double, minSpeed: Double, maxSpeed: Double): Double {
|
||||||
|
require(maxSpeed > minSpeed) { "maxSpeed must be greater than minSpeed" }
|
||||||
|
return ((currSpeed - minSpeed) / (maxSpeed - minSpeed)).coerceIn(0.0, 1.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return Vec2(driver.xRot * 0.5f, driver.yRot)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
var upForce = 0.0
|
||||||
|
var forwardForce = 0.0
|
||||||
|
|
||||||
|
val controller = (driver as? OrientationControllable)?.orientationController
|
||||||
|
|
||||||
|
//Calculate ride space velocity
|
||||||
|
calculateRideSpaceVel(settings, state, vehicle, driver)
|
||||||
|
|
||||||
|
//Translate ride space velocity to world space velocity.
|
||||||
|
if (controller != null) {
|
||||||
|
upForce = -1.0 * sin(Math.toRadians(controller.pitch.toDouble())) * state.rideVel.get().z
|
||||||
|
forwardForce = cos(Math.toRadians(controller.pitch.toDouble())) * state.rideVel.get().z
|
||||||
|
}
|
||||||
|
|
||||||
|
//If stamina has run out then initiate forced glide down.
|
||||||
|
upForce = if (state.stamina.get() > 0.0) upForce else -0.7
|
||||||
|
|
||||||
|
val altitudeLimit = vehicle.runtime.resolveDouble(settings.jumpExpr)
|
||||||
|
|
||||||
|
//Only limit altitude if altitude is not infinite
|
||||||
|
if (!vehicle.runtime.resolveBoolean(settings.infiniteAltitude)) {
|
||||||
|
//Provide a hard limit on altitude
|
||||||
|
upForce = if (vehicle.y >= altitudeLimit && upForce > 0) 0.0 else upForce
|
||||||
|
}
|
||||||
|
|
||||||
|
val velocity = Vec3(0.0, upForce, forwardForce)
|
||||||
|
|
||||||
|
return velocity
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculates the change in the ride space vector due to player input and ride state
|
||||||
|
*/
|
||||||
|
private fun calculateRideSpaceVel(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
) {
|
||||||
|
val topSpeed = vehicle.runtime.resolveDouble(settings.speedExpr)
|
||||||
|
val accel = vehicle.runtime.resolveDouble(settings.accelerationExpr)
|
||||||
|
val altitudeLimit = vehicle.runtime.resolveDouble(settings.jumpExpr)
|
||||||
|
val minSpeed = vehicle.runtime.resolveDouble(settings.minSpeed)
|
||||||
|
val speed = state.rideVel.get().length()
|
||||||
|
|
||||||
|
//Give no altitude limit if at max jump stat.
|
||||||
|
val pushingHeightLimit = if (vehicle.runtime.resolveBoolean(settings.infiniteStamina)) false
|
||||||
|
else (vehicle.y >= altitudeLimit && vehicle.xRot <= 0)
|
||||||
|
|
||||||
|
|
||||||
|
//speed up and slow down based on input
|
||||||
|
if (driver.zza > 0.0 && speed < topSpeed && state.stamina.get() > 0.0f && !pushingHeightLimit) {
|
||||||
|
//modify acceleration to be slower when at closer speeds to top speed
|
||||||
|
val accelMod = max(-(normalizeSpeed(speed, minSpeed, topSpeed)) + 1, 0.0)
|
||||||
|
state.rideVel.set(Vec3(state.rideVel.get().x, state.rideVel.get().y, min(state.rideVel.get().z + (accel * accelMod), topSpeed)))
|
||||||
|
} else if (driver.zza >= 0.0 && (state.stamina.get() == 0.0f || pushingHeightLimit)) {
|
||||||
|
state.rideVel.set(Vec3(state.rideVel.get().x, state.rideVel.get().y, max(state.rideVel.get().z - ((accel) / 4), minSpeed)))
|
||||||
|
} else if (driver.zza < 0.0 && speed > minSpeed) {
|
||||||
|
//modify deccel to be slower when at closer speeds to minimum speed
|
||||||
|
val deccelMod = max((normalizeSpeed(speed, minSpeed, topSpeed) - 1).pow(2), 0.1)
|
||||||
|
|
||||||
|
//Decelerate currently always a constant half of max acceleration.
|
||||||
|
state.rideVel.set(Vec3(state.rideVel.get().x, state.rideVel.get().y, max(state.rideVel.get().z - ((accel * deccelMod) / 2), minSpeed)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
//Cap at a rate of 5fps so frame skips dont lead to huge jumps
|
||||||
|
val cappedDeltaTime = min(deltaTime, 0.2)
|
||||||
|
|
||||||
|
//Get handling in degrees per second
|
||||||
|
val yawRotRate = vehicle.runtime.resolveDouble(settings.handlingYawExpr)
|
||||||
|
|
||||||
|
//Base the change off of deltatime.
|
||||||
|
var handlingYaw = yawRotRate * (cappedDeltaTime)
|
||||||
|
|
||||||
|
//apply stamina debuff if applicable
|
||||||
|
handlingYaw *= if (state.stamina.get() > 0.0) 1.0 else 0.5
|
||||||
|
|
||||||
|
//A+D to yaw
|
||||||
|
val yawForce = driver.xxa * handlingYaw * -1
|
||||||
|
|
||||||
|
return Vec3(yawForce, 0.0, 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (driver !is OrientationControllable) return Vec3.ZERO
|
||||||
|
//TODO: figure out a cleaner solution to this issue of large jumps when skipping frames or lagging
|
||||||
|
//Cap at a rate of 5fps so frame skips dont lead to huge jumps
|
||||||
|
val cappedDeltaTime = min(deltaTime, 0.2)
|
||||||
|
|
||||||
|
val invertRoll = if (Cobblemon.config.invertRoll) -1 else 1
|
||||||
|
val invertPitch = if (Cobblemon.config.invertPitch) -1 else 1
|
||||||
|
|
||||||
|
// Accumulate the mouse input
|
||||||
|
state.currMouseXForce.set((state.currMouseXForce.get() + (0.0015 * mouseX * invertRoll)).coerceIn(-1.0, 1.0))
|
||||||
|
state.currMouseYForce.set((state.currMouseYForce.get() + (0.0015 * mouseY * invertPitch)).coerceIn(-1.0, 1.0))
|
||||||
|
|
||||||
|
//Get handling in degrees per second
|
||||||
|
var handling = vehicle.runtime.resolveDouble(settings.handlingExpr)
|
||||||
|
|
||||||
|
//convert it to delta time
|
||||||
|
handling *= (cappedDeltaTime)
|
||||||
|
|
||||||
|
//apply stamina debuff if applicable
|
||||||
|
handling *= if (state.stamina.get() > 0.0) 1.0 else 0.5
|
||||||
|
|
||||||
|
val poke = driver.vehicle as? PokemonEntity
|
||||||
|
|
||||||
|
//TODO: reevaluate if deadzones are needed and if they are still causing issues.
|
||||||
|
//create deadzones for the constant input values.
|
||||||
|
//val xInput = remapWithDeadzone(state.currMouseXForce, 0.025, 1.0)
|
||||||
|
//val yInput = remapWithDeadzone(state.currMouseYForce, 0.025, 1.0)
|
||||||
|
|
||||||
|
val pitchRot = handling * state.currMouseYForce.get()
|
||||||
|
|
||||||
|
//Roll is 1.5 times as fast as pitch
|
||||||
|
val rollRot = handling * 1.5 * state.currMouseXForce.get()
|
||||||
|
|
||||||
|
//yaw, pitch, roll
|
||||||
|
return Vec3(0.0, pitchRot, rollRot)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return (state.stamina.get() / 1.0f)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
return Vec3.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
val topSpeed = vehicle.runtime.resolveDouble(settings.speedExpr)
|
||||||
|
val minSpeed = vehicle.runtime.resolveDouble(settings.minSpeed)
|
||||||
|
|
||||||
|
//Must I ensure that topspeed is greater than minimum?
|
||||||
|
val normalizedSpeed = normalizeSpeed(state.rideVel.get().length(), minSpeed, topSpeed)
|
||||||
|
|
||||||
|
//TODO: Determine if this should be based on max possible speed instead of top speed.
|
||||||
|
//Only ever want the fov change to be a max of 0.2 and for it to have non linear scaling.
|
||||||
|
return 1.0f + normalizedSpeed.pow(2).toFloat() * 0.2f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(settings: JetAirSettings, state: JetAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(settings: JetAirSettings, state: JetAirState, vehicle: PokemonEntity): Double {
|
||||||
|
return 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(settings: JetAirSettings, state: JetAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(settings: JetAirSettings, state: JetAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(settings: JetAirSettings, state: JetAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: JetAirSettings,
|
||||||
|
state: JetAirState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(settings: JetAirSettings, state: JetAirState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = JetAirState()
|
||||||
|
}
|
||||||
|
|
||||||
|
class JetAirSettings : RidingBehaviourSettings {
|
||||||
|
override val key = JetAirBehaviour.KEY
|
||||||
|
|
||||||
|
var gravity: Expression = "0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var minSpeed: Expression = "1.2".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var handlingYawExpr: Expression = "q.get_ride_stats('SKILL', 'AIR', 25.0, 8.0)".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
// Make configurable by json
|
||||||
|
var infiniteStamina: Expression = "false".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var infiniteAltitude: Expression = "false".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var jumpExpr: Expression = "q.get_ride_stats('JUMP', 'AIR', 300.0, 128.0)".asExpression()
|
||||||
|
private set
|
||||||
|
var handlingExpr: Expression = "q.get_ride_stats('SKILL', 'AIR', 140.0, 20.0)".asExpression()
|
||||||
|
private set
|
||||||
|
var speedExpr: Expression = "q.get_ride_stats('SPEED', 'AIR', 2.5, 1.0)".asExpression()
|
||||||
|
private set
|
||||||
|
var accelerationExpr: Expression = "q.get_ride_stats('ACCELERATION', 'AIR', (1.0 / (20.0 * 1.0)), (1.0 / (20.0 * 5.0)))".asExpression()
|
||||||
|
private set
|
||||||
|
var staminaExpr: Expression = "q.get_ride_stats('STAMINA', 'AIR', 60.0, 10.0)".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeExpression(gravity)
|
||||||
|
buffer.writeExpression(minSpeed)
|
||||||
|
buffer.writeExpression(handlingYawExpr)
|
||||||
|
buffer.writeExpression(infiniteStamina)
|
||||||
|
buffer.writeExpression(infiniteAltitude)
|
||||||
|
buffer.writeExpression(jumpExpr)
|
||||||
|
buffer.writeExpression(handlingExpr)
|
||||||
|
buffer.writeExpression(speedExpr)
|
||||||
|
buffer.writeExpression(accelerationExpr)
|
||||||
|
buffer.writeExpression(staminaExpr)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
gravity = buffer.readExpression()
|
||||||
|
minSpeed = buffer.readExpression()
|
||||||
|
handlingYawExpr = buffer.readExpression()
|
||||||
|
infiniteStamina = buffer.readExpression()
|
||||||
|
infiniteAltitude = buffer.readExpression()
|
||||||
|
jumpExpr = buffer.readExpression()
|
||||||
|
handlingExpr = buffer.readExpression()
|
||||||
|
speedExpr = buffer.readExpression()
|
||||||
|
accelerationExpr = buffer.readExpression()
|
||||||
|
staminaExpr = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JetAirState : RidingBehaviourState {
|
||||||
|
var currSpeed = ridingState(0.0, Side.CLIENT)
|
||||||
|
var stamina = ridingState(1.0f, Side.CLIENT)
|
||||||
|
var rideVel = ridingState(Vec3.ZERO, Side.CLIENT)
|
||||||
|
var currMouseXForce = ridingState(0.0, Side.BOTH)
|
||||||
|
var currMouseYForce = ridingState(0.0, Side.BOTH)
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeDouble(currSpeed.get())
|
||||||
|
buffer.writeFloat(stamina.get())
|
||||||
|
buffer.writeVec3(rideVel.get())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
currSpeed.set(buffer.readDouble(), forced = true)
|
||||||
|
stamina.set(buffer.readFloat(), forced = true)
|
||||||
|
rideVel.set(buffer.readVec3(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
currSpeed.set(0.0, forced = true)
|
||||||
|
stamina.set(1.0f, forced = true)
|
||||||
|
rideVel.set(Vec3.ZERO, forced = true)
|
||||||
|
currMouseXForce.set(0.0, forced = true)
|
||||||
|
currMouseYForce.set(0.0, forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "JetAirState(currSpeed=${currSpeed.get()}, stamina=${stamina.get()}, rideVel=${rideVel.get()}, currMouseXForce=${currMouseXForce.get()}, currMouseYForce=${currMouseYForce.get()})"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy() = JetAirState().also {
|
||||||
|
it.currSpeed.set(currSpeed.get(), forced = true)
|
||||||
|
it.stamina.set(stamina.get(), forced = true)
|
||||||
|
it.rideVel.set(rideVel.get(), forced = true)
|
||||||
|
it.currMouseXForce.set(currMouseXForce.get(), forced = true)
|
||||||
|
it.currMouseYForce.set(currMouseYForce.get(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState): Boolean {
|
||||||
|
if (previous !is JetAirState) return false
|
||||||
|
if (previous.currSpeed != currSpeed) return true
|
||||||
|
if (previous.stamina != stamina) return true
|
||||||
|
if (previous.rideVel != rideVel) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
+469
@@ -0,0 +1,469 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.Expression
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.*
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonBehaviourFlag
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.asExpression
|
||||||
|
import com.cobblemon.mod.common.util.cobblemonResource
|
||||||
|
import com.cobblemon.mod.common.util.readExpression
|
||||||
|
import com.cobblemon.mod.common.util.writeExpression
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
|
||||||
|
class JumpToFlightCompositeBehaviour : RidingBehaviour<JumpToFlightCompositeSettings, JumpToFlightCompositeState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("composite/jump_to_flight")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val landBehaviour: GenericLandBehaviour = GenericLandBehaviour()
|
||||||
|
val birdBehaviour: BirdAirBehaviour = BirdAirBehaviour()
|
||||||
|
|
||||||
|
override fun tick(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
) {
|
||||||
|
val flightState = state.flightState
|
||||||
|
val groundState = state.landState
|
||||||
|
if (shouldTransitionToGround(state, vehicle)) {
|
||||||
|
//Pass the speed to the next state
|
||||||
|
// groundState.currSpeed = flightState.currSpeed
|
||||||
|
groundState.rideVel.set(flightState.rideVel.get())
|
||||||
|
groundState.stamina.set(flightState.stamina.get())
|
||||||
|
|
||||||
|
state.activeController.set(GenericLandBehaviour.KEY)
|
||||||
|
vehicle.setBehaviourFlag(PokemonBehaviourFlag.FLYING, false)
|
||||||
|
state.timeTransitioned.set(vehicle.level().gameTime)
|
||||||
|
} else if (shouldTransitionToAir(state, vehicle, driver)) {
|
||||||
|
//Pass the speed to the next state
|
||||||
|
// flightState.currSpeed = groundState.currSpeed
|
||||||
|
flightState.rideVel.set(groundState.rideVel.get())
|
||||||
|
flightState.stamina.set(groundState.stamina.get())
|
||||||
|
|
||||||
|
state.activeController.set(BirdAirBehaviour.KEY)
|
||||||
|
vehicle.setBehaviourFlag(PokemonBehaviourFlag.FLYING, true)
|
||||||
|
state.timeTransitioned.set(vehicle.level().gameTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isActive(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun shouldTransitionToGround(state: JumpToFlightCompositeState, entity: PokemonEntity): Boolean {
|
||||||
|
return state.activeController.get() == BirdAirBehaviour.KEY
|
||||||
|
&& entity.onGround()
|
||||||
|
&& state.timeTransitioned.get() + 20 < entity.level().gameTime
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun shouldTransitionToAir(
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
entity: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return state.activeController.get() == GenericLandBehaviour.KEY
|
||||||
|
&& driver.jumping
|
||||||
|
&& state.timeTransitioned.get() + 20 < entity.level().gameTime
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): PoseType {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.pose(settings.land, state.landState, vehicle)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.pose(settings.bird, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.speed(settings.land, state.landState, vehicle, driver)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.speed(settings.bird, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.rotation(settings.land, state.landState, vehicle, driver)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.rotation(settings.bird, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.velocity(settings.land, state.landState, vehicle, driver, input)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.velocity(settings.bird, state.flightState, vehicle, driver, input)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.angRollVel(
|
||||||
|
settings.land,
|
||||||
|
state.landState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.angRollVel(
|
||||||
|
settings.bird,
|
||||||
|
state.flightState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.rotationOnMouseXY(
|
||||||
|
settings.land,
|
||||||
|
state.landState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
mouseY,
|
||||||
|
mouseX,
|
||||||
|
mouseYSmoother,
|
||||||
|
mouseXSmoother,
|
||||||
|
sensitivity,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.rotationOnMouseXY(
|
||||||
|
settings.bird,
|
||||||
|
state.flightState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
mouseY,
|
||||||
|
mouseX,
|
||||||
|
mouseYSmoother,
|
||||||
|
mouseXSmoother,
|
||||||
|
sensitivity,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.canJump(settings.land, state.landState, vehicle, driver)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.canJump(settings.bird, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.setRideBar(settings.land, state.landState, vehicle, driver)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.setRideBar(settings.bird, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.jumpForce(
|
||||||
|
settings.land,
|
||||||
|
state.landState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
jumpStrength
|
||||||
|
)
|
||||||
|
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.jumpForce(
|
||||||
|
settings.bird,
|
||||||
|
state.flightState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
jumpStrength
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.gravity(settings.land, state.landState, vehicle, regularGravity)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.gravity(settings.bird, state.flightState, vehicle, regularGravity)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.rideFovMultiplier(settings.land, state.landState, vehicle, driver)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.rideFovMultiplier(settings.bird, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.useAngVelSmoothing(settings.land, state.landState, vehicle)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.useAngVelSmoothing(settings.bird, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.useRidingAltPose(settings.land, state.landState, vehicle, driver)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.useRidingAltPose(settings.bird, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Double {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.inertia(settings.land, state.landState, vehicle)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.inertia(settings.bird, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.shouldRoll(settings.land, state.landState, vehicle)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.shouldRoll(settings.bird, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.turnOffOnGround(settings.land, state.landState, vehicle)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.turnOffOnGround(settings.bird, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.dismountOnShift(settings.land, state.landState, vehicle)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.dismountOnShift(settings.bird, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.shouldRotatePokemonHead(settings.land, state.landState, vehicle)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.shouldRotatePokemonHead(settings.bird, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(
|
||||||
|
settings: JumpToFlightCompositeSettings,
|
||||||
|
state: JumpToFlightCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.shouldRotatePlayerHead(settings.land, state.landState, vehicle)
|
||||||
|
BirdAirBehaviour.KEY -> birdBehaviour.shouldRotatePlayerHead(settings.bird, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = JumpToFlightCompositeState()
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpToFlightCompositeSettings : RidingBehaviourSettings {
|
||||||
|
override val key = JumpToFlightCompositeBehaviour.KEY
|
||||||
|
|
||||||
|
var bird: BirdAirSettings = BirdAirSettings()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var land: GenericLandSettings = GenericLandSettings()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var minimumSpeed: Expression = "0.5".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var minimumJump: Expression = "0.5".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
bird.encode(buffer)
|
||||||
|
land.encode(buffer)
|
||||||
|
buffer.writeExpression(minimumSpeed)
|
||||||
|
buffer.writeExpression(minimumJump)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
bird.decode(buffer)
|
||||||
|
land.decode(buffer)
|
||||||
|
minimumSpeed = buffer.readExpression()
|
||||||
|
minimumJump = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpToFlightCompositeState : RidingBehaviourState {
|
||||||
|
var activeController = ridingState(GenericLandBehaviour.KEY, Side.CLIENT)
|
||||||
|
var currSpeed = ridingState(0.0, Side.BOTH)
|
||||||
|
var timeTransitioned = ridingState(-100L, Side.BOTH)
|
||||||
|
var landState = GenericLandState()
|
||||||
|
var flightState = BirdAirState()
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeResourceLocation(activeController.get())
|
||||||
|
landState.encode(buffer)
|
||||||
|
flightState.encode(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
activeController.set(buffer.readResourceLocation(), forced = true)
|
||||||
|
landState.decode(buffer)
|
||||||
|
flightState.decode(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
activeController.set(GenericLandBehaviour.KEY, forced = true)
|
||||||
|
timeTransitioned.set(-100L, forced = true)
|
||||||
|
currSpeed.set(0.0, forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "JumpToFlightCompositeState(activeController=${activeController.get()}, landState=$landState, flightState=$flightState, currSpeed=${currSpeed.get()}, timeTransitioned=${timeTransitioned.get()})"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy() = JumpToFlightCompositeState().also {
|
||||||
|
it.activeController.set(activeController.get(), forced = true)
|
||||||
|
it.landState = landState.copy()
|
||||||
|
it.flightState = flightState.copy()
|
||||||
|
it.currSpeed.set(currSpeed.get(), forced = true)
|
||||||
|
it.timeTransitioned.set(timeTransitioned.get(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState): Boolean {
|
||||||
|
if (previous !is JumpToFlightCompositeState) return false
|
||||||
|
if (activeController != previous.activeController) return true
|
||||||
|
if (landState.shouldSync(previous.landState)) return true
|
||||||
|
if (flightState.shouldSync(previous.flightState)) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
+450
@@ -0,0 +1,450 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.Expression
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.*
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonBehaviourFlag
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.asExpression
|
||||||
|
import com.cobblemon.mod.common.util.cobblemonResource
|
||||||
|
import com.cobblemon.mod.common.util.readExpression
|
||||||
|
import com.cobblemon.mod.common.util.writeExpression
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
|
||||||
|
class RunToJetCompositeBehaviour : RidingBehaviour<RunToJetCompositeSettings, RunToJetCompositeState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("composite/run_to_jet")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val landBehaviour: GenericLandBehaviour = GenericLandBehaviour()
|
||||||
|
val jetBehaviour: JetAirBehaviour = JetAirBehaviour()
|
||||||
|
|
||||||
|
override fun tick(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
) {
|
||||||
|
val flightState = state.flightState
|
||||||
|
val groundState = state.landState
|
||||||
|
if (shouldTransitionToGround(state, vehicle, driver)) {
|
||||||
|
groundState.currSpeed = flightState.currSpeed
|
||||||
|
groundState.stamina = flightState.stamina
|
||||||
|
groundState.rideVel = flightState.rideVel
|
||||||
|
|
||||||
|
state.activeController.set(GenericLandBehaviour.KEY)
|
||||||
|
vehicle.setBehaviourFlag(PokemonBehaviourFlag.FLYING, false)
|
||||||
|
state.timeTransitioned.set(vehicle.level().gameTime)
|
||||||
|
} else if (shouldTransitionToAir(state, vehicle, driver, input)) {
|
||||||
|
flightState.currSpeed = groundState.currSpeed
|
||||||
|
flightState.stamina = groundState.stamina
|
||||||
|
flightState.rideVel = groundState.rideVel
|
||||||
|
|
||||||
|
state.activeController.set(JetAirBehaviour.KEY)
|
||||||
|
vehicle.setBehaviourFlag(PokemonBehaviourFlag.FLYING, true)
|
||||||
|
state.timeTransitioned.set(vehicle.level().gameTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun shouldTransitionToGround(
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
entity: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
if (state.activeController.get() != JetAirBehaviour.KEY) return false
|
||||||
|
if (state.timeTransitioned.get() + 20 >= entity.level().gameTime) return false
|
||||||
|
return driver.isSprinting || entity.onGround()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun shouldTransitionToAir(
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
entity: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Boolean {
|
||||||
|
if (state.activeController.get() != GenericLandBehaviour.KEY) return false
|
||||||
|
if (state.timeTransitioned.get() + 20 >= entity.level().gameTime) return false
|
||||||
|
return driver.isSprinting && input.z > 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isActive(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): PoseType {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.pose(settings.land, state.landState, vehicle)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.pose(settings.jet, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.speed(settings.land, state.landState, vehicle, driver)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.speed(settings.jet, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.rotation(settings.land, state.landState, vehicle, driver)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.rotation(settings.jet, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.velocity(settings.land, state.landState, vehicle, driver, input)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.velocity(settings.jet, state.flightState, vehicle, driver, input)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.angRollVel(
|
||||||
|
settings.land,
|
||||||
|
state.landState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.angRollVel(settings.jet, state.flightState, vehicle, driver, deltaTime)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.rotationOnMouseXY(
|
||||||
|
settings.land,
|
||||||
|
state.landState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
mouseY,
|
||||||
|
mouseX,
|
||||||
|
mouseYSmoother,
|
||||||
|
mouseXSmoother,
|
||||||
|
sensitivity,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.rotationOnMouseXY(
|
||||||
|
settings.jet,
|
||||||
|
state.flightState,
|
||||||
|
vehicle,
|
||||||
|
driver,
|
||||||
|
mouseY,
|
||||||
|
mouseX,
|
||||||
|
mouseYSmoother,
|
||||||
|
mouseXSmoother,
|
||||||
|
sensitivity,
|
||||||
|
deltaTime
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.canJump(settings.land, state.landState, vehicle, driver)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.canJump(settings.jet, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.setRideBar(settings.land, state.landState, vehicle, driver)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.setRideBar(settings.jet, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.jumpForce(settings.land, state.landState, vehicle, driver, jumpStrength)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.jumpForce(settings.jet, state.flightState, vehicle, driver, jumpStrength)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.gravity(settings.land, state.landState, vehicle, regularGravity)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.gravity(settings.jet, state.flightState, vehicle, regularGravity)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.rideFovMultiplier(settings.land, state.landState, vehicle, driver)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.rideFovMultiplier(settings.jet, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.useAngVelSmoothing(settings.land, state.landState, vehicle)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.useAngVelSmoothing(settings.jet, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.useRidingAltPose(settings.land, state.landState, vehicle, driver)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.useRidingAltPose(settings.jet, state.flightState, vehicle, driver)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Double {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.inertia(settings.land, state.landState, vehicle)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.inertia(settings.jet, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.shouldRoll(settings.land, state.landState, vehicle)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.shouldRoll(settings.jet, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.turnOffOnGround(settings.land, state.landState, vehicle)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.turnOffOnGround(settings.jet, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.dismountOnShift(settings.land, state.landState, vehicle)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.dismountOnShift(settings.jet, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.shouldRotatePokemonHead(settings.land, state.landState, vehicle)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.shouldRotatePokemonHead(settings.jet, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(
|
||||||
|
settings: RunToJetCompositeSettings,
|
||||||
|
state: RunToJetCompositeState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return when (state.activeController.get()) {
|
||||||
|
GenericLandBehaviour.KEY -> landBehaviour.shouldRotatePlayerHead(settings.land, state.landState, vehicle)
|
||||||
|
JetAirBehaviour.KEY -> jetBehaviour.shouldRotatePlayerHead(settings.jet, state.flightState, vehicle)
|
||||||
|
else -> error("Invalid controller: ${state.activeController.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = RunToJetCompositeState()
|
||||||
|
}
|
||||||
|
|
||||||
|
class RunToJetCompositeSettings : RidingBehaviourSettings {
|
||||||
|
override val key = RunToJetCompositeBehaviour.KEY
|
||||||
|
|
||||||
|
var jet: JetAirSettings = JetAirSettings()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var land: GenericLandSettings = GenericLandSettings()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var minimumSpeed: Expression = "0.5".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var minimumJump: Expression = "0.5".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
jet.encode(buffer)
|
||||||
|
land.encode(buffer)
|
||||||
|
buffer.writeExpression(minimumSpeed)
|
||||||
|
buffer.writeExpression(minimumJump)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
jet.decode(buffer)
|
||||||
|
land.decode(buffer)
|
||||||
|
minimumSpeed = buffer.readExpression()
|
||||||
|
minimumJump = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RunToJetCompositeState : RidingBehaviourState {
|
||||||
|
var activeController = ridingState(GenericLandBehaviour.KEY, Side.CLIENT)
|
||||||
|
var landState: GenericLandState = GenericLandState()
|
||||||
|
var flightState: JetAirState = JetAirState()
|
||||||
|
var currSpeed = ridingState(0.0, Side.BOTH)
|
||||||
|
var timeTransitioned = ridingState(-100L, Side.BOTH)
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeResourceLocation(activeController.get())
|
||||||
|
landState.encode(buffer)
|
||||||
|
flightState.encode(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
activeController.set(buffer.readResourceLocation(), forced = true)
|
||||||
|
landState.decode(buffer)
|
||||||
|
flightState.decode(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
activeController.set(GenericLandBehaviour.KEY, forced = true)
|
||||||
|
timeTransitioned.set(-100L, forced = true)
|
||||||
|
currSpeed.set(0.0, forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "RunToJetCompositeState(activeController=${activeController.get()}, landState=$landState, flightState=$flightState, currSpeed=${currSpeed.get()}, timeTransitioned=${timeTransitioned.get()})"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy() = RunToJetCompositeState().also {
|
||||||
|
it.activeController.set(activeController.get(), forced = true)
|
||||||
|
it.landState = landState.copy()
|
||||||
|
it.flightState = flightState.copy()
|
||||||
|
it.currSpeed.set(currSpeed.get(), forced = true)
|
||||||
|
it.timeTransitioned.set(timeTransitioned.get(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState): Boolean {
|
||||||
|
if (previous !is RunToJetCompositeState) return false
|
||||||
|
if (activeController != previous.activeController) return true
|
||||||
|
if (landState.shouldSync(previous.landState)) return true
|
||||||
|
if (flightState.shouldSync(previous.flightState)) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
+260
@@ -0,0 +1,260 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.*
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.blockPositionsAsListRounded
|
||||||
|
import com.cobblemon.mod.common.util.cobblemonResource
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
import net.minecraft.world.phys.shapes.Shapes
|
||||||
|
|
||||||
|
class SwimDashBehaviour : RidingBehaviour<SwimDashSettings, SwimDashState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("swim/dash")
|
||||||
|
const val DASH_TICKS: Int = 60
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val poseProvider = PoseProvider<SwimDashSettings, SwimDashState>(PoseType.FLOAT)
|
||||||
|
.with(PoseOption(PoseType.SWIM) { _, _, entity -> entity.isSwimming && entity.entityData.get(PokemonEntity.MOVING) })
|
||||||
|
|
||||||
|
override fun isActive(settings: SwimDashSettings, state: SwimDashState, vehicle: PokemonEntity): Boolean {
|
||||||
|
//This could be kinda weird... what if the top of the mon is in a fluid but the bottom isnt?
|
||||||
|
return Shapes.create(vehicle.boundingBox).blockPositionsAsListRounded().any {
|
||||||
|
if (vehicle.isInWater || vehicle.isUnderWater) {
|
||||||
|
return@any true
|
||||||
|
}
|
||||||
|
val blockState = vehicle.level().getBlockState(it)
|
||||||
|
return@any !blockState.fluidState.isEmpty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(settings: SwimDashSettings, state: SwimDashState, vehicle: PokemonEntity): PoseType {
|
||||||
|
return poseProvider.select(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
if(state.dashing.get()) {
|
||||||
|
state.ticks.set(state.ticks.get() + 1)
|
||||||
|
if(state.ticks.get() >= DASH_TICKS) {
|
||||||
|
state.dashing.set(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0.0F
|
||||||
|
}
|
||||||
|
|
||||||
|
state.dashing.set(true)
|
||||||
|
return settings.dashSpeed
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
return Vec2(driver.xRot * 0.5f, driver.yRot)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
val f = driver.xxa * 0.05f
|
||||||
|
var g = driver.zza * 0.6f
|
||||||
|
if (g <= 0.0f) {
|
||||||
|
g *= 0.25f
|
||||||
|
}
|
||||||
|
|
||||||
|
return Vec3(f.toDouble(), 0.0, g.toDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return Vec3.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (driver !is OrientationControllable) return Vec3.ZERO
|
||||||
|
|
||||||
|
//Might need to add the smoothing here for default.
|
||||||
|
val invertRoll = if (Cobblemon.config.invertRoll) -1 else 1
|
||||||
|
val invertPitch = if (Cobblemon.config.invertPitch) -1 else 1
|
||||||
|
return Vec3(0.0, mouseX * invertPitch, mouseY * invertRoll)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 0.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return regularGravity
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 1.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(settings: SwimDashSettings, state: SwimDashState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(settings: SwimDashSettings, state: SwimDashState, vehicle: PokemonEntity): Double {
|
||||||
|
return 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(settings: SwimDashSettings, state: SwimDashState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(settings: SwimDashSettings, state: SwimDashState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(settings: SwimDashSettings, state: SwimDashState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(
|
||||||
|
settings: SwimDashSettings,
|
||||||
|
state: SwimDashState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = SwimDashState()
|
||||||
|
}
|
||||||
|
|
||||||
|
class SwimDashSettings : RidingBehaviourSettings {
|
||||||
|
override val key = SwimDashBehaviour.KEY
|
||||||
|
|
||||||
|
var dashSpeed = 1F
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeFloat(dashSpeed)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
dashSpeed = buffer.readFloat()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SwimDashState : RidingBehaviourState {
|
||||||
|
var dashing = ridingState(false, Side.BOTH)
|
||||||
|
var ticks = ridingState(0, Side.BOTH)
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) = Unit
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) = Unit
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
dashing.set(false, forced = true)
|
||||||
|
ticks.set(0, forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "SwimDashState(dashing=${dashing.get()}, ticks=${ticks.get()})"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy() = SwimDashState().also {
|
||||||
|
it.dashing.set(dashing.get(), forced = true)
|
||||||
|
it.ticks.set(ticks. get(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState) = false
|
||||||
|
}
|
||||||
+349
@@ -0,0 +1,349 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.behaviour.types
|
||||||
|
|
||||||
|
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.OrientationControllable
|
||||||
|
import com.cobblemon.mod.common.api.riding.RidingStyle
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.*
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||||
|
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||||
|
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import com.cobblemon.mod.common.util.*
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.util.SmoothDouble
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.phys.Vec2
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
import net.minecraft.world.phys.shapes.Shapes
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
|
class VehicleLandBehaviour : RidingBehaviour<VehicleLandSettings, VehicleLandState> {
|
||||||
|
companion object {
|
||||||
|
val KEY = cobblemonResource("land/vehicle")
|
||||||
|
|
||||||
|
val MAX_TOP_SPEED = 1.0 // 20 bl/s
|
||||||
|
val MIN_TOP_SPEED = 0.35 // 7 bl/s
|
||||||
|
//val MIN_SPEED = 0.25 // 5 bl/s
|
||||||
|
|
||||||
|
//Accel will lie between 1.0 second and 5.0 seconds
|
||||||
|
val MAX_ACCEL = (MAX_TOP_SPEED) / (20*3) //3.0 second to max speed
|
||||||
|
val MIN_ACCEL = (MAX_TOP_SPEED) / (20*8) // 8 seconds to max speed
|
||||||
|
|
||||||
|
//Can rotate 90 degrees
|
||||||
|
val MAX_HANDLING = 90.0
|
||||||
|
val MIN_HANDLING = 30.0
|
||||||
|
|
||||||
|
|
||||||
|
val MAX_YAW_HANDLING = 16.0
|
||||||
|
val MIN_YAW_HANDLING = 8.0
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key = KEY
|
||||||
|
|
||||||
|
val poseProvider = PoseProvider<VehicleLandSettings, VehicleLandState>(PoseType.STAND)
|
||||||
|
.with(PoseOption(PoseType.WALK) { _, _, entity -> entity.entityData.get(PokemonEntity.MOVING) })
|
||||||
|
|
||||||
|
override fun isActive(settings: VehicleLandSettings, state: VehicleLandState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return Shapes.create(vehicle.boundingBox).blockPositionsAsListRounded().any {
|
||||||
|
//Need to check other fluids
|
||||||
|
if (vehicle.isInWater || vehicle.isUnderWater) {
|
||||||
|
return@any false
|
||||||
|
}
|
||||||
|
//This might not actually work, depending on what the yPos actually is. yPos of the middle of the entity? the feet?
|
||||||
|
if (it.y.toDouble() == (vehicle.position().y)) {
|
||||||
|
val blockState = vehicle.level().getBlockState(it.below())
|
||||||
|
return@any !(!blockState.isAir && blockState.fluidState.isEmpty)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pose(settings: VehicleLandSettings, state: VehicleLandState, vehicle: PokemonEntity): PoseType {
|
||||||
|
return poseProvider.select(settings, state, vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun speed(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
val topSpeed = vehicle.getRideStat(RidingStat.SPEED, RidingStyle.AIR, MIN_TOP_SPEED, MAX_TOP_SPEED)
|
||||||
|
val accel = vehicle.getRideStat(RidingStat.ACCELERATION, RidingStyle.AIR, MIN_ACCEL, MAX_ACCEL)
|
||||||
|
|
||||||
|
//speed up and slow down based on input
|
||||||
|
if (driver.zza > 0.0 && state.currSpeed.get() < topSpeed) {
|
||||||
|
state.currSpeed.set(min(state.currSpeed.get() + accel , topSpeed))
|
||||||
|
} else if (driver.zza < 0.0 && state.currSpeed.get() > 0.0) {
|
||||||
|
//Decelerate is now always a constant half of max acceleration.
|
||||||
|
state.currSpeed.set(max(state.currSpeed.get() - (MAX_ACCEL / 2), 0.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
return state.currSpeed.get().toFloat()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotation(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: LivingEntity
|
||||||
|
): Vec2 {
|
||||||
|
val rotationDegrees = driver.xxa * vehicle.runtime.resolveFloat(settings.rotationSpeed)
|
||||||
|
val rotation = Vec2(driver.xRot, vehicle.yRot - rotationDegrees)
|
||||||
|
state.deltaRotation.set(Vec2(rotation.x - driver.rotationVector.x, rotation.y - vehicle.rotationVector.y))
|
||||||
|
return rotation
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun velocity(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
input: Vec3
|
||||||
|
): Vec3 {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
val driveFactor = runtime.resolveFloat(settings.driveFactor)
|
||||||
|
var g = driver.zza * driveFactor
|
||||||
|
if (g <= 0.0f) {
|
||||||
|
g *= runtime.resolveFloat(settings.reverseDriveFactor)
|
||||||
|
}
|
||||||
|
if (driver.xxa != 0F && g.absoluteValue < runtime.resolveFloat(settings.minimumSpeedToTurn)) {
|
||||||
|
driver.xxa = 0F
|
||||||
|
}
|
||||||
|
val velocity = Vec3(0.0 /* Maybe do drifting here later */, 0.0, g.toDouble() * state.currSpeed.get())
|
||||||
|
|
||||||
|
return velocity
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun angRollVel(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
return Vec3.ZERO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rotationOnMouseXY(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
mouseY: Double,
|
||||||
|
mouseX: Double,
|
||||||
|
mouseYSmoother: SmoothDouble,
|
||||||
|
mouseXSmoother: SmoothDouble,
|
||||||
|
sensitivity: Double,
|
||||||
|
deltaTime: Double
|
||||||
|
): Vec3 {
|
||||||
|
if (driver !is OrientationControllable) return Vec3.ZERO
|
||||||
|
|
||||||
|
//Might need to add the smoothing here for default.
|
||||||
|
val invertRoll = if (Cobblemon.config.invertRoll) -1 else 1
|
||||||
|
val invertPitch = if (Cobblemon.config.invertPitch) -1 else 1
|
||||||
|
return Vec3(0.0, mouseY * invertPitch, mouseX * invertRoll)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canJump(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return vehicle.runtime.resolveBoolean(settings.canJump)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRideBar(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 0.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpForce(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player,
|
||||||
|
jumpStrength: Int
|
||||||
|
): Vec3 {
|
||||||
|
val runtime = vehicle.runtime
|
||||||
|
runtime.environment.query.addFunction("jump_strength") { DoubleValue(jumpStrength.toDouble()) }
|
||||||
|
val jumpVector = settings.jumpVector.map { runtime.resolveFloat(it) }
|
||||||
|
return Vec3(jumpVector[0].toDouble(), jumpVector[1].toDouble(), jumpVector[2].toDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun gravity(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
regularGravity: Double
|
||||||
|
): Double {
|
||||||
|
return regularGravity
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun rideFovMultiplier(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Float {
|
||||||
|
return 1.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useAngVelSmoothing(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useRidingAltPose(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity,
|
||||||
|
driver: Player
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun inertia(settings: VehicleLandSettings, state: VehicleLandState, vehicle: PokemonEntity): Double {
|
||||||
|
return 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRoll(settings: VehicleLandSettings, state: VehicleLandState, vehicle: PokemonEntity): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun turnOffOnGround(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismountOnShift(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePokemonHead(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRotatePlayerHead(
|
||||||
|
settings: VehicleLandSettings,
|
||||||
|
state: VehicleLandState,
|
||||||
|
vehicle: PokemonEntity
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createDefaultState() = VehicleLandState()
|
||||||
|
}
|
||||||
|
|
||||||
|
class VehicleLandSettings : RidingBehaviourSettings {
|
||||||
|
override val key = VehicleLandBehaviour.KEY
|
||||||
|
|
||||||
|
var canJump = "true".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var jumpVector = listOf("0".asExpression(), "0.3".asExpression(), "0".asExpression())
|
||||||
|
private set
|
||||||
|
|
||||||
|
var speed = "0.3".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var driveFactor = "1.0".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var reverseDriveFactor = "0.25".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var minimumSpeedToTurn = "0.1".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var rotationSpeed = "45/20".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
var lookYawLimit = "101".asExpression()
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
buffer.writeExpression(canJump)
|
||||||
|
buffer.writeExpression(jumpVector[0])
|
||||||
|
buffer.writeExpression(jumpVector[1])
|
||||||
|
buffer.writeExpression(jumpVector[2])
|
||||||
|
buffer.writeExpression(speed)
|
||||||
|
buffer.writeExpression(driveFactor)
|
||||||
|
buffer.writeExpression(reverseDriveFactor)
|
||||||
|
buffer.writeExpression(minimumSpeedToTurn)
|
||||||
|
buffer.writeExpression(rotationSpeed)
|
||||||
|
buffer.writeExpression(lookYawLimit)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) {
|
||||||
|
canJump = buffer.readExpression()
|
||||||
|
jumpVector = listOf(
|
||||||
|
buffer.readExpression(),
|
||||||
|
buffer.readExpression(),
|
||||||
|
buffer.readExpression()
|
||||||
|
)
|
||||||
|
speed = buffer.readExpression()
|
||||||
|
driveFactor = buffer.readExpression()
|
||||||
|
reverseDriveFactor = buffer.readExpression()
|
||||||
|
minimumSpeedToTurn = buffer.readExpression()
|
||||||
|
rotationSpeed = buffer.readExpression()
|
||||||
|
lookYawLimit = buffer.readExpression()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class VehicleLandState : RidingBehaviourState {
|
||||||
|
var currSpeed = ridingState(0.0, Side.BOTH)
|
||||||
|
var deltaRotation = ridingState(Vec2.ZERO, Side.BOTH)
|
||||||
|
|
||||||
|
override fun encode(buffer: RegistryFriendlyByteBuf) = Unit
|
||||||
|
override fun decode(buffer: RegistryFriendlyByteBuf) = Unit
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
currSpeed.set(0.0, forced = true)
|
||||||
|
deltaRotation.set(Vec2.ZERO, forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "VehicleLandState(currSpeed=${currSpeed.get()}, deltaRotation=${deltaRotation.get()})"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy() = VehicleLandState().also {
|
||||||
|
it.currSpeed.set(currSpeed.get(), forced = true)
|
||||||
|
it.deltaRotation.set(deltaRotation.get(), forced = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldSync(previous: RidingBehaviourState) = false
|
||||||
|
}
|
||||||
-106
@@ -1,106 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 Cobblemon Contributors
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.cobblemon.mod.common.api.riding.controller
|
|
||||||
|
|
||||||
import com.cobblemon.mod.common.api.net.Decodable
|
|
||||||
import com.cobblemon.mod.common.api.net.Encodable
|
|
||||||
import com.cobblemon.mod.common.api.riding.RidingState
|
|
||||||
import com.cobblemon.mod.common.api.riding.controller.posing.PoseProvider
|
|
||||||
import com.cobblemon.mod.common.entity.PoseType
|
|
||||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
|
||||||
import com.cobblemon.mod.common.util.writeIdentifier
|
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
|
||||||
import net.minecraft.resources.ResourceLocation
|
|
||||||
import net.minecraft.world.entity.LivingEntity
|
|
||||||
import net.minecraft.world.entity.player.Player
|
|
||||||
import net.minecraft.world.phys.Vec2
|
|
||||||
import net.minecraft.world.phys.Vec3
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A riding controller is the internal control mechanism for determining how a pokemon
|
|
||||||
* handles during riding. Controllers come into play once the pokemon being ridden has
|
|
||||||
* established the path it's capable of. For instance, a land based controller could have
|
|
||||||
* the pokemon experience drifting after movement, or generic movement. It's up to the
|
|
||||||
* controller to decide how the pokemon behaves.
|
|
||||||
*
|
|
||||||
* @since 1.7.0
|
|
||||||
*/
|
|
||||||
interface RideController : Encodable, Decodable {
|
|
||||||
|
|
||||||
/** A reference key used to denote the individual controller */
|
|
||||||
val key: ResourceLocation
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies the provider of poses which helps control updating the current pose on the pokemon
|
|
||||||
* being ridden. Controllers are expected to define the pose types responsible for posing the entity
|
|
||||||
* through all expected conditions. It should define a default pose, that will be used in all cases
|
|
||||||
* where a pose does not meet the current conditions for the current mount. Typically, this will be
|
|
||||||
* an idle pose.
|
|
||||||
*/
|
|
||||||
val poseProvider: PoseProvider
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a condition that must be met for this controller to be active. For instance, this can be used
|
|
||||||
* to evaluate things such as current velocity or block state of the entity.
|
|
||||||
*/
|
|
||||||
val condition: (PokemonEntity) -> Boolean
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies the pose the ridden mount should be positioned in. This queries the pose provider using
|
|
||||||
* the entity as a means of determining the conditions the entity is currently under. This allows for
|
|
||||||
* dynamic pose updates.
|
|
||||||
*/
|
|
||||||
fun pose(entity: PokemonEntity) : PoseType {
|
|
||||||
return this.poseProvider.select(entity)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the current speed of the mount.
|
|
||||||
*/
|
|
||||||
fun speed(entity: PokemonEntity, driver: Player) : Float
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the rotation of the mount. This is typically based on the controlling driver and is manipulated as
|
|
||||||
* necessary.
|
|
||||||
*/
|
|
||||||
fun rotation(entity: PokemonEntity, driver: LivingEntity) : Vec2
|
|
||||||
|
|
||||||
fun clampPassengerRotation(entity: PokemonEntity, driver: LivingEntity) {}
|
|
||||||
|
|
||||||
fun updatePassengerRotation(entity: PokemonEntity, driver: LivingEntity) {
|
|
||||||
driver.yRot = entity.yRot
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manipulates the movement input as necessary by the controller. This is primarily used to apply limits
|
|
||||||
* to the types of movements. For instance, we can apply limits to any sort of sideways movement input, so that
|
|
||||||
* it would otherwise be slower than normal forward movement.
|
|
||||||
*/
|
|
||||||
fun velocity(entity: PokemonEntity, driver: Player, input: Vec3) : Vec3
|
|
||||||
|
|
||||||
fun canJump(entity: PokemonEntity, driver: Player) : Boolean
|
|
||||||
fun jumpForce(entity: PokemonEntity, driver: Player, jumpStrength: Int) : Vec3
|
|
||||||
|
|
||||||
fun gravity(entity: PokemonEntity, regularGravity: Double) : Double? = null
|
|
||||||
|
|
||||||
fun shouldRoll(entity: PokemonEntity): Boolean = false
|
|
||||||
|
|
||||||
fun getRuntime(entity: PokemonEntity) = entity.riding.runtime
|
|
||||||
|
|
||||||
fun shouldRotatePokemonHead(): Boolean = false
|
|
||||||
fun shouldRotatePlayerHead(): Boolean = false
|
|
||||||
|
|
||||||
fun <T : RidingState> getState(entity: PokemonEntity, constructor: (PokemonEntity) -> T): T {
|
|
||||||
return entity.riding.getState(key, constructor)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
|
||||||
buffer.writeIdentifier(this.key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 Cobblemon Contributors
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.cobblemon.mod.common.api.riding.controller.posing
|
|
||||||
|
|
||||||
import com.cobblemon.mod.common.entity.PoseType
|
|
||||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
|
||||||
import java.util.function.Predicate
|
|
||||||
|
|
||||||
data class PoseOption(val pose: PoseType, val condition: Predicate<PokemonEntity>)
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 Cobblemon Contributors
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.cobblemon.mod.common.api.riding.controller.posing
|
|
||||||
|
|
||||||
import com.cobblemon.mod.common.entity.PoseType
|
|
||||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
|
||||||
|
|
||||||
class PoseProvider(private val fallback: PoseType) {
|
|
||||||
|
|
||||||
private val options = mutableListOf<PoseOption>()
|
|
||||||
|
|
||||||
fun select(entity: PokemonEntity) : PoseType {
|
|
||||||
return this.options.stream()
|
|
||||||
.filter { it.condition.test(entity) }
|
|
||||||
.map { it.pose }
|
|
||||||
.findFirst()
|
|
||||||
.orElse(this.fallback)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun with(option: PoseOption) : PoseProvider {
|
|
||||||
this.options.add(option)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.posing
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourSettings
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourState
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
|
||||||
|
data class PoseOption<Settings : RidingBehaviourSettings, State : RidingBehaviourState>(
|
||||||
|
val pose: PoseType,
|
||||||
|
val condition: (Settings, State, PokemonEntity) -> Boolean
|
||||||
|
)
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Cobblemon Contributors
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cobblemon.mod.common.api.riding.posing
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourSettings
|
||||||
|
import com.cobblemon.mod.common.api.riding.behaviour.RidingBehaviourState
|
||||||
|
import com.cobblemon.mod.common.entity.PoseType
|
||||||
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
|
||||||
|
class PoseProvider<Settings : RidingBehaviourSettings, State : RidingBehaviourState>(private val fallback: PoseType) {
|
||||||
|
|
||||||
|
private val options = mutableListOf<PoseOption<Settings, State>>()
|
||||||
|
|
||||||
|
fun select(settings: Settings, state: State, entity: PokemonEntity) : PoseType {
|
||||||
|
return this.options.stream()
|
||||||
|
.filter { it.condition(settings, state, entity) }
|
||||||
|
.map { it.pose }
|
||||||
|
.findFirst()
|
||||||
|
.orElse(this.fallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun with(option: PoseOption<Settings, State>) : PoseProvider<Settings, State> {
|
||||||
|
this.options.add(option)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,7 +10,14 @@ package com.cobblemon.mod.common.api.spawning
|
|||||||
|
|
||||||
import com.cobblemon.mod.common.Cobblemon.LOGGER
|
import com.cobblemon.mod.common.Cobblemon.LOGGER
|
||||||
import com.cobblemon.mod.common.api.entity.Despawner
|
import com.cobblemon.mod.common.api.entity.Despawner
|
||||||
import com.cobblemon.mod.common.api.spawning.condition.*
|
import com.cobblemon.mod.common.api.spawning.condition.AreaSpawningCondition
|
||||||
|
import com.cobblemon.mod.common.api.spawning.condition.BasicSpawningCondition
|
||||||
|
import com.cobblemon.mod.common.api.spawning.condition.FishingSpawningCondition
|
||||||
|
import com.cobblemon.mod.common.api.spawning.condition.GroundedSpawningCondition
|
||||||
|
import com.cobblemon.mod.common.api.spawning.condition.SeafloorSpawningCondition
|
||||||
|
import com.cobblemon.mod.common.api.spawning.condition.SpawningCondition
|
||||||
|
import com.cobblemon.mod.common.api.spawning.condition.SubmergedSpawningCondition
|
||||||
|
import com.cobblemon.mod.common.api.spawning.condition.SurfaceSpawningCondition
|
||||||
import com.cobblemon.mod.common.api.spawning.context.AreaContextResolver
|
import com.cobblemon.mod.common.api.spawning.context.AreaContextResolver
|
||||||
import com.cobblemon.mod.common.api.spawning.context.FishingSpawningContext
|
import com.cobblemon.mod.common.api.spawning.context.FishingSpawningContext
|
||||||
import com.cobblemon.mod.common.api.spawning.context.GroundedSpawningContext
|
import com.cobblemon.mod.common.api.spawning.context.GroundedSpawningContext
|
||||||
@@ -44,6 +51,7 @@ import com.cobblemon.mod.common.api.spawning.spawner.Spawner
|
|||||||
import com.cobblemon.mod.common.api.spawning.spawner.TickingSpawner
|
import com.cobblemon.mod.common.api.spawning.spawner.TickingSpawner
|
||||||
import com.cobblemon.mod.common.entity.pokemon.CobblemonAgingDespawner
|
import com.cobblemon.mod.common.entity.pokemon.CobblemonAgingDespawner
|
||||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A grouping of all the overarching behaviours of the Best Spawner system. This is a convenient accessor to
|
* A grouping of all the overarching behaviours of the Best Spawner system. This is a convenient accessor to
|
||||||
@@ -130,7 +138,8 @@ object BestSpawner {
|
|||||||
spawnerManagers.forEach(SpawnerManager::onConfigReload)
|
spawnerManagers.forEach(SpawnerManager::onConfigReload)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onServerStarted() {
|
fun onServerStarted(server: MinecraftServer) {
|
||||||
|
CobblemonSpawnPools.onServerLoad(server)
|
||||||
spawnerManagers.forEach(SpawnerManager::onServerStarted)
|
spawnerManagers.forEach(SpawnerManager::onServerStarted)
|
||||||
fishingSpawner = FishingSpawner()
|
fishingSpawner = FishingSpawner()
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-1
@@ -8,10 +8,13 @@
|
|||||||
|
|
||||||
package com.cobblemon.mod.common.api.spawning
|
package com.cobblemon.mod.common.api.spawning
|
||||||
|
|
||||||
|
import com.cobblemon.mod.common.Cobblemon
|
||||||
|
import com.cobblemon.mod.common.api.spawning.condition.BiomePrecalculation
|
||||||
import com.cobblemon.mod.common.api.spawning.condition.BucketPrecalculation
|
import com.cobblemon.mod.common.api.spawning.condition.BucketPrecalculation
|
||||||
import com.cobblemon.mod.common.api.spawning.condition.ContextPrecalculation
|
import com.cobblemon.mod.common.api.spawning.condition.ContextPrecalculation
|
||||||
import com.cobblemon.mod.common.api.spawning.detail.SpawnPool
|
import com.cobblemon.mod.common.api.spawning.detail.SpawnPool
|
||||||
import com.cobblemon.mod.common.data.CobblemonDataProvider
|
import com.cobblemon.mod.common.data.CobblemonDataProvider
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of all of Cobblemon's general-purpose [SpawnPool]s. These
|
* A collection of all of Cobblemon's general-purpose [SpawnPool]s. These
|
||||||
@@ -26,6 +29,18 @@ object CobblemonSpawnPools {
|
|||||||
lateinit var WORLD_SPAWN_POOL: SpawnPool
|
lateinit var WORLD_SPAWN_POOL: SpawnPool
|
||||||
|
|
||||||
fun load() {
|
fun load() {
|
||||||
WORLD_SPAWN_POOL = CobblemonDataProvider.register(SpawnPool("world").addPrecalculators(ContextPrecalculation, BucketPrecalculation))
|
WORLD_SPAWN_POOL = CobblemonDataProvider.register(SpawnPool("world")
|
||||||
|
.addPrecalculators(
|
||||||
|
ContextPrecalculation,
|
||||||
|
BucketPrecalculation,
|
||||||
|
BiomePrecalculation
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onServerLoad(server: MinecraftServer) {
|
||||||
|
Cobblemon.LOGGER.info("Optimizing spawn pools...")
|
||||||
|
WORLD_SPAWN_POOL.forEach { it.onServerLoad(server) }
|
||||||
|
WORLD_SPAWN_POOL.precalculate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -32,7 +32,7 @@ abstract class AreaTypeSpawningCondition<T : AreaSpawningContext> : SpawningCond
|
|||||||
return false
|
return false
|
||||||
} else if (maxHeight != null && ctx.height > maxHeight!!) {
|
} else if (maxHeight != null && ctx.height > maxHeight!!) {
|
||||||
return false
|
return false
|
||||||
} else if (neededNearbyBlocks != null && neededNearbyBlocks!!.none { cond -> ctx.nearbyBlockTypes.any { cond.fits(it, ctx.blockRegistry) } }) {
|
} else if (neededNearbyBlocks != null && neededNearbyBlocks!!.none { cond -> ctx.nearbyBlockHolders.any { cond.fits(it) } }) {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
return true
|
return true
|
||||||
|
|||||||
+11
@@ -10,6 +10,8 @@ package com.cobblemon.mod.common.api.spawning.condition
|
|||||||
|
|
||||||
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
||||||
import com.cobblemon.mod.common.api.spawning.detail.SpawnDetail
|
import com.cobblemon.mod.common.api.spawning.detail.SpawnDetail
|
||||||
|
import net.minecraft.core.Holder
|
||||||
|
import net.minecraft.world.level.biome.Biome
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A spawning condition that is composed of a list of conditions and anticonditions.
|
* A spawning condition that is composed of a list of conditions and anticonditions.
|
||||||
@@ -30,6 +32,15 @@ class CompositeSpawningCondition {
|
|||||||
var conditions = mutableListOf<SpawningCondition<*>>()
|
var conditions = mutableListOf<SpawningCondition<*>>()
|
||||||
var anticonditions = mutableListOf<SpawningCondition<*>>()
|
var anticonditions = mutableListOf<SpawningCondition<*>>()
|
||||||
|
|
||||||
|
fun isBiomeValid(holder: Holder<Biome>): Boolean {
|
||||||
|
if (conditions.isEmpty() || conditions.any { it.biomes == null || it.biomes!!.isEmpty() || it.biomes!!.any { it.fits(holder) } }) {
|
||||||
|
if (anticonditions.isEmpty() || anticonditions.none { it.biomes != null && it.biomes!!.any { it.fits(holder) } }) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun satisfiedBy(ctx: SpawningContext): Boolean {
|
fun satisfiedBy(ctx: SpawningContext): Boolean {
|
||||||
return if (conditions.isNotEmpty() && conditions.none { it.isSatisfiedBy(ctx) }) {
|
return if (conditions.isNotEmpty() && conditions.none { it.isSatisfiedBy(ctx) }) {
|
||||||
false
|
false
|
||||||
|
|||||||
+5
-1
@@ -30,7 +30,11 @@ abstract class GroundedTypeSpawningCondition<T : GroundedSpawningContext> : Area
|
|||||||
return false
|
return false
|
||||||
} else if (maxHeight != null && ctx.height > maxHeight!!) {
|
} else if (maxHeight != null && ctx.height > maxHeight!!) {
|
||||||
return false
|
return false
|
||||||
} else !(neededBaseBlocks != null && neededBaseBlocks!!.none { it.fits(ctx.baseBlock.block, ctx.blockRegistry) })
|
} else if (neededBaseBlocks != null && neededBaseBlocks!!.none { it.fits(ctx.baseBlockHolder) }) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun copyFrom(other: SpawningCondition<*>, merger: Merger) {
|
override fun copyFrom(other: SpawningCondition<*>, merger: Merger) {
|
||||||
|
|||||||
+8
-4
@@ -30,10 +30,14 @@ abstract class SeafloorTypeSpawningCondition<T : SeafloorSpawningContext> : Area
|
|||||||
return if (!super.fits(ctx)) {
|
return if (!super.fits(ctx)) {
|
||||||
false
|
false
|
||||||
} else if (minHeight != null && ctx.height < minHeight!!) {
|
} else if (minHeight != null && ctx.height < minHeight!!) {
|
||||||
return false
|
false
|
||||||
} else if (maxHeight != null && ctx.height > maxHeight!!) {
|
} else if (maxHeight != null && ctx.height > maxHeight!!) {
|
||||||
return false
|
false
|
||||||
} else !(neededBaseBlocks != null && neededBaseBlocks!!.none { it.fits(ctx.baseBlock.block, ctx.blockRegistry) })
|
} else if (neededBaseBlocks != null && neededBaseBlocks!!.none { it.fits(ctx.baseBlockHolder) }) {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun copyFrom(other: SpawningCondition<*>, merger: Merger) {
|
override fun copyFrom(other: SpawningCondition<*>, merger: Merger) {
|
||||||
@@ -44,7 +48,7 @@ abstract class SeafloorTypeSpawningCondition<T : SeafloorSpawningContext> : Area
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isValid(): Boolean {
|
override fun isValid(): Boolean {
|
||||||
val containsNullValues = neededBaseBlocks != null && neededBaseBlocks!!.any {it == null}
|
val containsNullValues = neededBaseBlocks != null && neededBaseBlocks!!.any { it == null }
|
||||||
return super.isValid() && !containsNullValues
|
return super.isValid() && !containsNullValues
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -42,6 +42,7 @@ abstract class SpawningCondition<T : SpawningContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dimensions: MutableList<ResourceLocation>? = null
|
var dimensions: MutableList<ResourceLocation>? = null
|
||||||
|
/** This gets checked in a precalculation but still needs to be checked for things like rarity multipliers. */
|
||||||
var biomes: MutableSet<RegistryLikeCondition<Biome>>? = null
|
var biomes: MutableSet<RegistryLikeCondition<Biome>>? = null
|
||||||
var moonPhase: MoonPhaseRange? = null
|
var moonPhase: MoonPhaseRange? = null
|
||||||
var canSeeSky: Boolean? = null
|
var canSeeSky: Boolean? = null
|
||||||
@@ -98,7 +99,7 @@ abstract class SpawningCondition<T : SpawningContext> {
|
|||||||
return false
|
return false
|
||||||
} else if (dimensions != null && dimensions!!.isNotEmpty() && ctx.world.dimensionType().effectsLocation !in dimensions!!) {
|
} else if (dimensions != null && dimensions!!.isNotEmpty() && ctx.world.dimensionType().effectsLocation !in dimensions!!) {
|
||||||
return false
|
return false
|
||||||
} else if (biomes != null && biomes!!.isNotEmpty() && biomes!!.none { condition -> condition.fits(ctx.biome, ctx.biomeRegistry) }) {
|
} else if (biomes != null && biomes!!.isNotEmpty() && biomes!!.none { condition -> condition.fits(ctx.biomeHolder) }) {
|
||||||
return false
|
return false
|
||||||
} else if (appendages.any { !it.fits(ctx) }) {
|
} else if (appendages.any { !it.fits(ctx) }) {
|
||||||
return false
|
return false
|
||||||
@@ -153,11 +154,11 @@ abstract class SpawningCondition<T : SpawningContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open fun isValid(): Boolean {
|
open fun isValid(): Boolean {
|
||||||
if(biomes != null && biomes!!.any {it == null})
|
if (biomes != null && biomes!!.any { it == null })
|
||||||
return false
|
return false
|
||||||
if(dimensions != null && dimensions!!.any {it == null})
|
if (dimensions != null && dimensions!!.any { it == null })
|
||||||
return false
|
return false
|
||||||
if(structures != null && structures!!.any {it == null})
|
if (structures != null && structures!!.any { it == null })
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-2
@@ -12,6 +12,7 @@ import com.cobblemon.mod.common.api.spawning.SpawnBucket
|
|||||||
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
||||||
import com.cobblemon.mod.common.api.spawning.detail.SpawnDetail
|
import com.cobblemon.mod.common.api.spawning.detail.SpawnDetail
|
||||||
import com.cobblemon.mod.common.api.spawning.spawner.Spawner
|
import com.cobblemon.mod.common.api.spawning.spawner.Spawner
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A type of precalculation that can occur on a list of [SpawnDetail] to accelerate
|
* A type of precalculation that can occur on a list of [SpawnDetail] to accelerate
|
||||||
@@ -31,7 +32,7 @@ import com.cobblemon.mod.common.api.spawning.spawner.Spawner
|
|||||||
*/
|
*/
|
||||||
interface SpawningPrecalculation<T : Any> {
|
interface SpawningPrecalculation<T : Any> {
|
||||||
/** Retrieves the precalculation keys for the given spawn detail. */
|
/** Retrieves the precalculation keys for the given spawn detail. */
|
||||||
fun select(detail: SpawnDetail): List<T>
|
fun select(detail: SpawnDetail): Collection<T>
|
||||||
/** Retrieves the precalculation key for the given context, if that key exists for this context. */
|
/** Retrieves the precalculation key for the given context, if that key exists for this context. */
|
||||||
fun select(ctx: SpawningContext): T?
|
fun select(ctx: SpawningContext): T?
|
||||||
|
|
||||||
@@ -71,7 +72,8 @@ interface SpawningPrecalculation<T : Any> {
|
|||||||
* @since January 31st, 2022
|
* @since January 31st, 2022
|
||||||
*/
|
*/
|
||||||
object RootPrecalculation : SpawningPrecalculation<Any> {
|
object RootPrecalculation : SpawningPrecalculation<Any> {
|
||||||
override fun select(detail: SpawnDetail): List<Any> = listOf(Unit)
|
val list = listOf(Unit)
|
||||||
|
override fun select(detail: SpawnDetail): List<Any> = list
|
||||||
override fun select(ctx: SpawningContext): Any = Unit
|
override fun select(ctx: SpawningContext): Any = Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +91,15 @@ object ContextPrecalculation : SpawningPrecalculation<Class<out SpawningContext>
|
|||||||
object BucketPrecalculation : SpawningPrecalculation<SpawnBucket> {
|
object BucketPrecalculation : SpawningPrecalculation<SpawnBucket> {
|
||||||
override fun select(detail: SpawnDetail) = listOf(detail.bucket)
|
override fun select(detail: SpawnDetail) = listOf(detail.bucket)
|
||||||
override fun select(ctx: SpawningContext) = ctx.cause.bucket
|
override fun select(ctx: SpawningContext) = ctx.cause.bucket
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This isn't so much of a precalculation as it is a yoinking of another precalculation.
|
||||||
|
* Uses pre-established [SpawnDetail.validBiomes] to shortcut knowing which spawns are valid for a biome.
|
||||||
|
*/
|
||||||
|
object BiomePrecalculation : SpawningPrecalculation<ResourceLocation> {
|
||||||
|
override fun select(detail: SpawnDetail) = detail.validBiomes
|
||||||
|
override fun select(ctx: SpawningContext) = ctx.biomeHolder.unwrapKey().map { it.location() }.orElse(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
@@ -18,6 +18,7 @@ import net.minecraft.world.level.block.Block
|
|||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
|
import net.minecraft.core.Holder
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A [SpawningContext] that is for a particular area, and therefore has spatial properties.
|
* A [SpawningContext] that is for a particular area, and therefore has spatial properties.
|
||||||
@@ -39,6 +40,7 @@ open class AreaSpawningContext(
|
|||||||
val slice: WorldSlice
|
val slice: WorldSlice
|
||||||
) : SpawningContext() {
|
) : SpawningContext() {
|
||||||
val nearbyBlockTypes: List<Block> by lazy { nearbyBlocks.mapNotNull { it.block }.distinct() }
|
val nearbyBlockTypes: List<Block> by lazy { nearbyBlocks.mapNotNull { it.block }.distinct() }
|
||||||
|
val nearbyBlockHolders: List<Holder<Block>> by lazy { nearbyBlockTypes.mapNotNull(blockRegistry::wrapAsHolder) }
|
||||||
|
|
||||||
override fun getStructureCache(pos: BlockPos): StructureChunkCache {
|
override fun getStructureCache(pos: BlockPos): StructureChunkCache {
|
||||||
return slice.getStructureCache(pos)
|
return slice.getStructureCache(pos)
|
||||||
|
|||||||
+4
@@ -11,9 +11,12 @@ package com.cobblemon.mod.common.api.spawning.context
|
|||||||
import com.cobblemon.mod.common.api.spawning.SpawnCause
|
import com.cobblemon.mod.common.api.spawning.SpawnCause
|
||||||
import com.cobblemon.mod.common.api.spawning.WorldSlice
|
import com.cobblemon.mod.common.api.spawning.WorldSlice
|
||||||
import com.cobblemon.mod.common.api.spawning.influence.SpawningInfluence
|
import com.cobblemon.mod.common.api.spawning.influence.SpawningInfluence
|
||||||
|
import com.cobblemon.mod.common.util.blockRegistry
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
|
import net.minecraft.core.Holder
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.tags.FluidTags
|
import net.minecraft.tags.FluidTags
|
||||||
|
import net.minecraft.world.level.block.Block
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,6 +39,7 @@ abstract class FlooredSpawningContext(
|
|||||||
) : AreaSpawningContext(cause, world, position, light, skyLight, canSeeSky, influences, height, nearbyBlocks, slice) {
|
) : AreaSpawningContext(cause, world, position, light, skyLight, canSeeSky, influences, height, nearbyBlocks, slice) {
|
||||||
/** The block that the spawning is occurring on. */
|
/** The block that the spawning is occurring on. */
|
||||||
val baseBlock = slice.getBlockState(position.x, position.y, position.z)
|
val baseBlock = slice.getBlockState(position.x, position.y, position.z)
|
||||||
|
val baseBlockHolder: Holder<Block> by lazy { world.blockRegistry.wrapAsHolder(baseBlock.block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-1
@@ -82,7 +82,9 @@ abstract class SpawningContext {
|
|||||||
/** The current phase of the moon at this location. */
|
/** The current phase of the moon at this location. */
|
||||||
val moonPhase: Int by lazy { world.moonPhase }
|
val moonPhase: Int by lazy { world.moonPhase }
|
||||||
/** The biome of this location. */
|
/** The biome of this location. */
|
||||||
val biome: Biome by lazy { world.getBiome(position).value() }
|
val biome: Biome by lazy { biomeHolder.value() }
|
||||||
|
/** The registry holder for the biome this context is in. */
|
||||||
|
val biomeHolder: Holder<Biome> by lazy { world.getBiome(position) }
|
||||||
|
|
||||||
val biomeRegistry: Registry<Biome> by lazy { world.registryAccess().registryOrThrow(Registries.BIOME) }
|
val biomeRegistry: Registry<Biome> by lazy { world.registryAccess().registryOrThrow(Registries.BIOME) }
|
||||||
val blockRegistry: Registry<Block> by lazy { world.registryAccess().registryOrThrow(Registries.BLOCK) }
|
val blockRegistry: Registry<Block> by lazy { world.registryAccess().registryOrThrow(Registries.BLOCK) }
|
||||||
|
|||||||
+2
-1
@@ -13,6 +13,7 @@ import com.cobblemon.mod.common.api.Priority
|
|||||||
import com.cobblemon.mod.common.api.spawning.SpawnCause
|
import com.cobblemon.mod.common.api.spawning.SpawnCause
|
||||||
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
|
import net.minecraft.tags.BlockTags
|
||||||
import net.minecraft.tags.FluidTags
|
import net.minecraft.tags.FluidTags
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ import net.minecraft.world.level.block.state.BlockState
|
|||||||
*/
|
*/
|
||||||
interface SpawningContextCalculator<I : SpawningContextInput, O : SpawningContext> {
|
interface SpawningContextCalculator<I : SpawningContextInput, O : SpawningContext> {
|
||||||
companion object {
|
companion object {
|
||||||
val isAirCondition: (BlockState) -> Boolean = { it.isAir || (!it.isSolid && !it.fluidState.`is`(FluidTags.WATER)) }
|
val isAirCondition: (BlockState) -> Boolean = { it.isAir || (!it.isSolid && !it.fluidState.`is`(FluidTags.WATER) && !it.`is`(BlockTags.RAILS)) }
|
||||||
val isSolidCondition: (BlockState) -> Boolean = { it.isSolid }
|
val isSolidCondition: (BlockState) -> Boolean = { it.isSolid }
|
||||||
val isWaterCondition: (BlockState) -> Boolean = { it.fluidState.`is`(FluidTags.WATER) && it.fluidState.isSource }
|
val isWaterCondition: (BlockState) -> Boolean = { it.fluidState.`is`(FluidTags.WATER) && it.fluidState.isSource }
|
||||||
val isLavaCondition: (BlockState) -> Boolean = { it.fluidState.`is`(FluidTags.LAVA) && it.fluidState.isSource }
|
val isLavaCondition: (BlockState) -> Boolean = { it.fluidState.`is`(FluidTags.LAVA) && it.fluidState.isSource }
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ import com.cobblemon.mod.common.api.spawning.multiplier.WeightMultiplier
|
|||||||
import com.cobblemon.mod.common.api.text.text
|
import com.cobblemon.mod.common.api.text.text
|
||||||
import com.cobblemon.mod.common.util.asArrayValue
|
import com.cobblemon.mod.common.util.asArrayValue
|
||||||
import com.cobblemon.mod.common.util.asTranslated
|
import com.cobblemon.mod.common.util.asTranslated
|
||||||
|
import net.minecraft.core.registries.Registries
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A spawnable unit in the Best Spawner API. This is extended for any kind of entity
|
* A spawnable unit in the Best Spawner API. This is extended for any kind of entity
|
||||||
@@ -56,6 +59,14 @@ abstract class SpawnDetail : ModDependant {
|
|||||||
|
|
||||||
var labels = mutableListOf<String>()
|
var labels = mutableListOf<String>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is calculated when the server starts. It is a set of all biome identifiers in which this spawn
|
||||||
|
* is possible. It is used as part of the [com.cobblemon.mod.common.api.spawning.condition.BiomePrecalculation].
|
||||||
|
*/
|
||||||
|
@Transient
|
||||||
|
val validBiomes = mutableSetOf<ResourceLocation>()
|
||||||
|
|
||||||
|
@Transient
|
||||||
val struct: QueryStruct = queryStructOf(
|
val struct: QueryStruct = queryStructOf(
|
||||||
"weight" to { DoubleValue(weight) },
|
"weight" to { DoubleValue(weight) },
|
||||||
"percentage" to { DoubleValue(percentage) },
|
"percentage" to { DoubleValue(percentage) },
|
||||||
@@ -74,6 +85,23 @@ abstract class SpawnDetail : ModDependant {
|
|||||||
|
|
||||||
open fun getName() = displayName?.asTranslated() ?: id.text()
|
open fun getName() = displayName?.asTranslated() ?: id.text()
|
||||||
|
|
||||||
|
open fun onServerLoad(server: MinecraftServer) {
|
||||||
|
val biomeRegistry = server.registryAccess().registryOrThrow(Registries.BIOME)
|
||||||
|
validBiomes.clear()
|
||||||
|
|
||||||
|
// Calculate in advance what biomes of this world the spawn detail is valid for.
|
||||||
|
biomeRegistry.holders().forEach { holder ->
|
||||||
|
val key = holder.unwrapKey().orElse(null) ?: return@forEach
|
||||||
|
if (conditions.isEmpty() || conditions.any { it.biomes == null || it.biomes!!.isEmpty() || it.biomes!!.any { it.fits(holder) } }) {
|
||||||
|
if (anticonditions.isEmpty() || anticonditions.none { it.biomes != null && it.biomes!!.any { it.fits(holder) } }) {
|
||||||
|
if (compositeCondition?.isBiomeValid(holder) != false) {
|
||||||
|
validBiomes.add(key.location())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open fun isSatisfiedBy(ctx: SpawningContext): Boolean {
|
open fun isSatisfiedBy(ctx: SpawningContext): Boolean {
|
||||||
if (!ctx.preFilter(this)) {
|
if (!ctx.preFilter(this)) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ package com.cobblemon.mod.common.api.spawning.detail
|
|||||||
|
|
||||||
import com.cobblemon.mod.common.api.data.JsonDataRegistry
|
import com.cobblemon.mod.common.api.data.JsonDataRegistry
|
||||||
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
||||||
|
import com.cobblemon.mod.common.api.spawning.CobblemonSpawnPools
|
||||||
import com.cobblemon.mod.common.api.spawning.SpawnLoader
|
import com.cobblemon.mod.common.api.spawning.SpawnLoader
|
||||||
import com.cobblemon.mod.common.api.spawning.SpawnSet
|
import com.cobblemon.mod.common.api.spawning.SpawnSet
|
||||||
import com.cobblemon.mod.common.api.spawning.condition.PrecalculationResult
|
import com.cobblemon.mod.common.api.spawning.condition.PrecalculationResult
|
||||||
@@ -18,6 +19,7 @@ import com.cobblemon.mod.common.api.spawning.condition.SpawningPrecalculation
|
|||||||
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
||||||
import com.cobblemon.mod.common.api.spawning.spawner.Spawner
|
import com.cobblemon.mod.common.api.spawning.spawner.Spawner
|
||||||
import com.cobblemon.mod.common.util.cobblemonResource
|
import com.cobblemon.mod.common.util.cobblemonResource
|
||||||
|
import com.cobblemon.mod.common.util.server
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
@@ -48,6 +50,10 @@ class SpawnPool(val name: String) : JsonDataRegistry<SpawnSet>, Iterable<SpawnDe
|
|||||||
for (set in data.values) {
|
for (set in data.values) {
|
||||||
details.addAll(set.filter { it.isValid() })
|
details.addAll(set.filter { it.isValid() })
|
||||||
}
|
}
|
||||||
|
val server = server()
|
||||||
|
if (server != null && server.isRunning) {
|
||||||
|
CobblemonSpawnPools.onServerLoad(server)
|
||||||
|
}
|
||||||
precalculate()
|
precalculate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 Cobblemon Contributors
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.cobblemon.mod.common.api.spawning.influence
|
|
||||||
|
|
||||||
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
|
||||||
import com.cobblemon.mod.common.api.spawning.detail.SpawnDetail
|
|
||||||
import net.minecraft.tags.BlockTags
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements a [SpawningInfluence] that prevents Pokémon spawning on certain blocks.
|
|
||||||
* This ensures that Pokémon don't spawn in areas that could disrupt player-built structures or mechanisms.
|
|
||||||
* The influence checks the block directly above the potential spawn location; if the block is in the restricted list,
|
|
||||||
* the spawn is disallowed.
|
|
||||||
*
|
|
||||||
* @author Aethen
|
|
||||||
* @since February 20th, 2024
|
|
||||||
*/
|
|
||||||
open class RestrictedSpawnBlocksInfluence
|
|
||||||
: SpawningInfluence {
|
|
||||||
|
|
||||||
// The list of blocks that Pokémon are not allowed to spawn on.
|
|
||||||
private val restrictedBlocks = BlockTags.RAILS
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Affects the spawnable status of a Pokémon spawn detail.
|
|
||||||
* If the block directly above the spawn location is in the restricted list, the spawn is disallowed.
|
|
||||||
*
|
|
||||||
* @param detail The Pokémon spawn detail to be affected.
|
|
||||||
* @param ctx The context of the spawning event.
|
|
||||||
* @return `true` if the spawn is allowed, `false` if it is disallowed.
|
|
||||||
*/
|
|
||||||
override fun affectSpawnable(detail: SpawnDetail, ctx: SpawningContext): Boolean {
|
|
||||||
// If the spawn detail is not a Pokémon, it is not affected by this influence.
|
|
||||||
if (detail.type != "pokemon") return true
|
|
||||||
|
|
||||||
// Get the position of the potential spawn location.
|
|
||||||
val pokemonSpawnPos = ctx.position
|
|
||||||
|
|
||||||
// Examine the block immediately above the spawn block to check for a rail
|
|
||||||
// Potentially need a refactor if we ever want to check the spawn block itself.
|
|
||||||
return ctx.world.getBlockState(pokemonSpawnPos.atY(pokemonSpawnPos.y + 1)).`is`(restrictedBlocks).not()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-2
@@ -61,9 +61,9 @@ class LocationRuleCalculator : SpawnRuleComponent {
|
|||||||
reusableContext.value = contextCalculator.name
|
reusableContext.value = contextCalculator.name
|
||||||
|
|
||||||
if (!this::reusableWorldValue.isInitialized) {
|
if (!this::reusableWorldValue.isInitialized) {
|
||||||
reusableWorldValue = world.registryAccess().registryOrThrow(Registries.DIMENSION).getHolder(world.dimension()).get().asWorldMoLangValue()
|
reusableWorldValue = world.registryAccess().registryOrThrow(Registries.DIMENSION).wrapAsHolder(world).asWorldMoLangValue()
|
||||||
} else {
|
} else {
|
||||||
reusableWorldValue.obj = world.registryAccess().registryOrThrow(Registries.DIMENSION).getHolder(world.dimension()).get()
|
reusableWorldValue.obj = world.registryAccess().registryOrThrow(Registries.DIMENSION).wrapAsHolder(world)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this::reusableDimensionTypeValue.isInitialized) {
|
if (!this::reusableDimensionTypeValue.isInitialized) {
|
||||||
|
|||||||
@@ -66,9 +66,12 @@ abstract class AreaSpawner(
|
|||||||
if (constrainedArea != null) {
|
if (constrainedArea != null) {
|
||||||
|
|
||||||
val areaBox = AABB.ofSize(
|
val areaBox = AABB.ofSize(
|
||||||
Vec3(
|
Vec3(constrainedArea.getCenter().toVec3f()),
|
||||||
constrainedArea.getCenter().toVec3f()
|
CHUNK_REACH * 16.0 * 2,
|
||||||
), CHUNK_REACH * 16.0 * 2, 1000.0, CHUNK_REACH * 16.0 * 2)
|
1000.0,
|
||||||
|
CHUNK_REACH * 16.0 * 2
|
||||||
|
)
|
||||||
|
|
||||||
if (!constrainedArea.world.isBoxLoaded(areaBox)) {
|
if (!constrainedArea.world.isBoxLoaded(areaBox)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -142,7 +145,7 @@ abstract class AreaSpawner(
|
|||||||
break
|
break
|
||||||
} else if (isValidStartPoint(area.world, chunk, basePos.setY(originalY - offset))) {
|
} else if (isValidStartPoint(area.world, chunk, basePos.setY(originalY - offset))) {
|
||||||
valid = true
|
valid = true
|
||||||
basePos.y = originalY + offset
|
basePos.y = originalY - offset
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
offset++
|
offset++
|
||||||
|
|||||||
+1
-2
@@ -14,7 +14,6 @@ import com.cobblemon.mod.common.api.spawning.SpawnerManager
|
|||||||
import com.cobblemon.mod.common.api.spawning.detail.SpawnPool
|
import com.cobblemon.mod.common.api.spawning.detail.SpawnPool
|
||||||
import com.cobblemon.mod.common.api.spawning.influence.PlayerLevelRangeInfluence
|
import com.cobblemon.mod.common.api.spawning.influence.PlayerLevelRangeInfluence
|
||||||
import com.cobblemon.mod.common.api.spawning.influence.PlayerLevelRangeInfluence.Companion.TYPICAL_VARIATION
|
import com.cobblemon.mod.common.api.spawning.influence.PlayerLevelRangeInfluence.Companion.TYPICAL_VARIATION
|
||||||
import com.cobblemon.mod.common.api.spawning.influence.RestrictedSpawnBlocksInfluence
|
|
||||||
import com.cobblemon.mod.common.api.spawning.influence.SpawningInfluence
|
import com.cobblemon.mod.common.api.spawning.influence.SpawningInfluence
|
||||||
import com.cobblemon.mod.common.api.spawning.rules.SpawnRule
|
import com.cobblemon.mod.common.api.spawning.rules.SpawnRule
|
||||||
import com.cobblemon.mod.common.util.mutableLazy
|
import com.cobblemon.mod.common.util.mutableLazy
|
||||||
@@ -45,7 +44,7 @@ object PlayerSpawnerFactory {
|
|||||||
it,
|
it,
|
||||||
variation = TYPICAL_VARIATION
|
variation = TYPICAL_VARIATION
|
||||||
)
|
)
|
||||||
}, { RestrictedSpawnBlocksInfluence() })
|
})
|
||||||
|
|
||||||
fun create(spawnerManager: SpawnerManager, player: ServerPlayer): PlayerSpawner {
|
fun create(spawnerManager: SpawnerManager, player: ServerPlayer): PlayerSpawner {
|
||||||
val influences = influenceBuilders.mapNotNull { it(player) }
|
val influences = influenceBuilders.mapNotNull { it(player) }
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ open class BottomlessStore(override val uuid: UUID) : PokemonStore<BottomlessPos
|
|||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
pokemon.forEachIndexed { index, pokemon ->
|
pokemon.forEachIndexed { index, pokemon ->
|
||||||
pokemon.storeCoordinates.set(StoreCoordinates(this, BottomlessPosition(index)))
|
pokemon.storeCoordinates.set(StoreCoordinates(this, BottomlessPosition(index)))
|
||||||
pokemon.getChangeObservable().pipe(
|
pokemon.changeObservable.pipe(
|
||||||
stopAfter { it.storeCoordinates.get()?.store != this }
|
stopAfter { pokemon.storeCoordinates.get()?.store != this }
|
||||||
).subscribe { storeChangeObservable.emit(Unit) }
|
).subscribe { storeChangeObservable.emit(Unit) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ open class BottomlessStore(override val uuid: UUID) : PokemonStore<BottomlessPos
|
|||||||
} else {
|
} else {
|
||||||
this.pokemon.removeAt(position.currentIndex)
|
this.pokemon.removeAt(position.currentIndex)
|
||||||
}
|
}
|
||||||
for(i in startIndex until this.pokemon.size) {
|
for (i in startIndex until this.pokemon.size) {
|
||||||
this.pokemon[i].storeCoordinates.set(StoreCoordinates(this, BottomlessPosition(i)))
|
this.pokemon[i].storeCoordinates.set(StoreCoordinates(this, BottomlessPosition(i)))
|
||||||
}
|
}
|
||||||
storeChangeObservable.emit(Unit)
|
storeChangeObservable.emit(Unit)
|
||||||
|
|||||||
Loaded 100 of 874 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user