forked from mirrors/cobblemon
Compare commits
87
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0dd0a78741 | ||
|
|
03ddc35d36 | ||
|
|
1b8e9b9b36 | ||
|
|
e52ac956f0 | ||
|
|
493664bef2 | ||
|
|
981e3e5efc | ||
|
|
c15350e647 | ||
|
|
f9e5784b10 | ||
|
|
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 | ||
|
|
3859eb574e | ||
|
|
b4a29214a7 | ||
|
|
ed0e0fc65a | ||
|
|
c5dcfc57ea | ||
|
|
9997a5c4b4 | ||
|
|
2b70e5614c | ||
|
|
589c5381e2 | ||
|
|
4539703497 | ||
|
|
0152bc2e32 | ||
|
|
e175c44118 |
+17
-12
@@ -1,16 +1,21 @@
|
||||
### Additions
|
||||
|
||||
- Added ability to rename PC Boxes by clicking on the name of a box
|
||||
- Added ability to set wallpapers per PC Box by clicking the button right to the box name
|
||||
- Added sorting by Name, Level and type by clicking the button left of the box name (shift reverses order)
|
||||
- Added filtering/search functionality in PC UI, which also supports pokemon properties (e.g. shiny=yes shows all shinies)
|
||||
- Added /changewallpaper <player> <boxNumber> <wallpaper> command to change a wallpaper through commands
|
||||
- Added /renamebox <player> <boxNumber> <name> command to rename a PC box through commands
|
||||
- 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.
|
||||
- The button on the right allows for changing the box wallpaper.
|
||||
- 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 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 box wallpaper through commands.
|
||||
- Added `/renamebox <player> <boxNumber> <name>` command to rename a PC box through commands.
|
||||
|
||||
### 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
|
||||
- Added ChangePCBoxWallpaperEvent.Pre/Post to prevent players from changing to a wallpaper or change their selection
|
||||
- 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)
|
||||
- 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
|
||||
- Renamed `SetPCBoxPokemonPacket` and the respective handler to `SetPCBoxPacket`
|
||||
### Addons
|
||||
- Added Flows for `player_tick_pre`, `player_tick_post`, `advancement_earned`, `right_clicked_entity`, `right_clicked_block`, `player_died`, `wallpaper_unlocked`.
|
||||
- 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.
|
||||
- Added `unlockable_pc_box_wallpapers` datapack folder for wallpapers that need to be unlocked before they're usable.
|
||||
- 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.
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
### 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.
|
||||
+19
-3
@@ -13,6 +13,10 @@
|
||||
|
||||
### Changes
|
||||
- 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.
|
||||
|
||||
### Fixes
|
||||
- Fixed Particles sometimes facing the wrong direction (looking at you, Swords Dance)
|
||||
@@ -34,6 +38,12 @@
|
||||
- Fixed owned Pokémon sometimes being un-interactable after the player relogs fast
|
||||
- Fixed field name in evolution requirements for Spewpa Pokeball.
|
||||
- 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
|
||||
- A finished battle now has winners and losers set inside of `PokemonBattle` instead of them always being empty.
|
||||
@@ -44,9 +54,13 @@
|
||||
- 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.
|
||||
- Various items now have a rarity value.
|
||||
|
||||
### Changes
|
||||
- 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.
|
||||
- Reworked observable handling in `Pokemon.kt` to cut down on RAM usage and clarify the file.
|
||||
- Note: This will break mods that used our observable functionality there or in MoveSet, IVs, EVs, or BenchedMoves.
|
||||
- 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
|
||||
- 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)
|
||||
@@ -55,6 +69,8 @@
|
||||
- The `fossils` for a fossil entry
|
||||
- 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.
|
||||
|
||||
## [1.6.1 (January 26th, 2025)](#1-6-1)
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
package com.cobblemon.mod.common;
|
||||
|
||||
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;
|
||||
@@ -117,8 +120,24 @@ public interface Rollable {
|
||||
return (float) Mth.wrapDegrees(-Math.toDegrees(getUpVector().angleSigned(UP, getForwardVector())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the angular velocity in degrees per second as a Vec3
|
||||
*/
|
||||
Vec3 angRollVel( double deltaTime );
|
||||
|
||||
public Vec3 rotationOnMouseXY(
|
||||
double yMouse,
|
||||
double xMouse,
|
||||
SmoothDouble yMouseSmoother,
|
||||
SmoothDouble xMouseSmoother,
|
||||
double sensitivity,
|
||||
double deltaTime
|
||||
);
|
||||
|
||||
boolean shouldRoll();
|
||||
|
||||
boolean useAngVelSmoothing();
|
||||
|
||||
void clearRotation();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 ride = (PokemonEntity) player.getVehicle();
|
||||
|
||||
//Use custom jump bar logic if the current ride does not jump using it.
|
||||
if( !ride.getRiding().canJump(ride, player))
|
||||
{
|
||||
cir.setReturnValue(ride.setRideBar());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.SmoothDouble;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@@ -47,6 +48,7 @@ import net.minecraft.world.food.FoodProperties;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix3f;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -55,6 +57,7 @@ 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.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@@ -271,6 +274,7 @@ public abstract class PlayerMixin extends LivingEntity implements Rollable, Scan
|
||||
|
||||
@Override
|
||||
public Rollable updateOrientation(Function<Matrix3f, Matrix3f> update) {
|
||||
//Disabled to allow non mouse inputs to modify roll
|
||||
if (!shouldRoll()) return this;
|
||||
|
||||
if (this.orientation == null) {
|
||||
@@ -296,6 +300,60 @@ public abstract class PlayerMixin extends LivingEntity implements Rollable, Scan
|
||||
return pokemonEntity.getRiding().shouldRoll(pokemonEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3 rotationOnMouseXY(
|
||||
double yMouse,
|
||||
double xMouse,
|
||||
SmoothDouble yMouseSmoother,
|
||||
SmoothDouble xMouseSmoother,
|
||||
double sensitivity,
|
||||
double deltaTime
|
||||
) {
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if (!this.equals(player)) return Vec3.ZERO;
|
||||
|
||||
var playerVehicle = player.getVehicle();
|
||||
if (playerVehicle == null) return Vec3.ZERO;
|
||||
if (!(playerVehicle instanceof PokemonEntity pokemonEntity)) return Vec3.ZERO;
|
||||
|
||||
return pokemonEntity.getRiding().rotationOnMouseXY(
|
||||
pokemonEntity,
|
||||
player,
|
||||
yMouse,
|
||||
xMouse,
|
||||
yMouseSmoother,
|
||||
xMouseSmoother,
|
||||
sensitivity,
|
||||
deltaTime
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAngVelSmoothing() {
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if (!this.equals(player)) return true;
|
||||
|
||||
var playerVehicle = player.getVehicle();
|
||||
if (playerVehicle == null) return true;
|
||||
if (!(playerVehicle instanceof PokemonEntity pokemonEntity)) return true;
|
||||
|
||||
return pokemonEntity.getRiding().useAngVelSmoothing(pokemonEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3 angRollVel( double deltaTime ) {
|
||||
var ret = new Vec3(0.0, 0.0, 0.0);
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if (!this.equals(player)) return ret;
|
||||
|
||||
var playerVehicle = player.getVehicle();
|
||||
if (playerVehicle == null) return ret;
|
||||
if (!(playerVehicle instanceof PokemonEntity pokemonEntity)) return ret;
|
||||
|
||||
return pokemonEntity.getRiding().angRollVel( pokemonEntity, player, deltaTime );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clearRotation() {
|
||||
this.orientation = null;
|
||||
|
||||
+10
@@ -9,8 +9,10 @@
|
||||
package com.cobblemon.mod.common.mixin.client;
|
||||
|
||||
import com.cobblemon.mod.common.client.CobblemonClient;
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
|
||||
import com.cobblemon.mod.common.pokedex.scanner.PokedexUsageContext;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -30,5 +32,13 @@ public class AbstractClientPlayerMixin {
|
||||
if (usageContext.getScanningGuiOpen()) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,13 @@ import com.cobblemon.mod.common.client.keybind.keybinds.PartySendBinding;
|
||||
import com.cobblemon.mod.common.pokedex.scanner.PokedexUsageContext;
|
||||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.mojang.blaze3d.Blaze3D;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.SmoothDouble;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -33,8 +35,11 @@ public class MouseHandlerMixin {
|
||||
@Shadow private double accumulatedScrollY;
|
||||
@Shadow @Final private Minecraft minecraft;
|
||||
|
||||
@Unique SmoothDouble xMouseSmoother = new SmoothDouble();
|
||||
@Unique SmoothDouble yMouseSmoother = new SmoothDouble();
|
||||
@Unique SmoothDouble pitchSmoother = new SmoothDouble();
|
||||
@Unique SmoothDouble rollSmoother = new SmoothDouble();
|
||||
@Unique SmoothDouble yawSmoother = new SmoothDouble();
|
||||
|
||||
@Shadow @Final private SmoothDouble smoothTurnY;
|
||||
|
||||
@@ -44,6 +49,8 @@ public class MouseHandlerMixin {
|
||||
|
||||
@Shadow private double accumulatedDY;
|
||||
|
||||
@Shadow private double accumulatedScrollX;
|
||||
|
||||
@Inject(
|
||||
method = "onScroll",
|
||||
at = @At(
|
||||
@@ -95,7 +102,13 @@ public class MouseHandlerMixin {
|
||||
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();
|
||||
if (usageContext.getScanningGuiOpen()) {
|
||||
this.smoothTurnY.reset();
|
||||
@@ -109,16 +122,66 @@ public class MouseHandlerMixin {
|
||||
}
|
||||
|
||||
if (!(player instanceof Rollable rollable)) return true;
|
||||
|
||||
if (!rollable.shouldRoll()) {
|
||||
xMouseSmoother.reset();
|
||||
yMouseSmoother.reset();
|
||||
pitchSmoother.reset();
|
||||
rollSmoother.reset();
|
||||
yawSmoother.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
var pitch = pitchSmoother.getNewDeltaValue(cursorDeltaY * 0.15f, d);
|
||||
var roll = rollSmoother.getNewDeltaValue(cursorDeltaX * 0.15f, d);
|
||||
rollable.rotate(0.0F, (float)pitch, (float)roll);
|
||||
var defaultSensitivity = this.minecraft.options.sensitivity().get() * 0.6000000238418579 + 0.20000000298023224;
|
||||
var ridingSensitivity = Math.pow(defaultSensitivity, 3);
|
||||
|
||||
//Send mouse input to be interpreted into rotation
|
||||
//deltas by the ride controller
|
||||
Vec3 angVecMouse = rollable.rotationOnMouseXY(
|
||||
cursorDeltaY,
|
||||
cursorDeltaX ,
|
||||
yMouseSmoother,
|
||||
xMouseSmoother,
|
||||
ridingSensitivity,
|
||||
movementTime
|
||||
);
|
||||
|
||||
//Perform Rotation using mouse influenced rotation deltas.
|
||||
rollable.rotate(
|
||||
(float) angVecMouse.x,
|
||||
(float) angVecMouse.y,
|
||||
(float) angVecMouse.z
|
||||
);
|
||||
|
||||
|
||||
//Gather and apply the current rotation deltas
|
||||
var angRot = rollable.angRollVel(movementTime);
|
||||
|
||||
//Apply smoothing if requested by the controller.
|
||||
//This Might be best if done by the controller itself?
|
||||
if( rollable.useAngVelSmoothing() )
|
||||
{
|
||||
if( angRot != null ) {
|
||||
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);
|
||||
rollable.rotate((float) yaw, (float) pitch, (float) roll);
|
||||
}
|
||||
}
|
||||
//Otherwise simply apply the smoothing
|
||||
else
|
||||
{
|
||||
if( angRot != null ) {
|
||||
rollable.rotate((float) (
|
||||
angRot.x * 10 * d),
|
||||
(float) (angRot.y * 10 * d),
|
||||
(float) (angRot.z * 10 * d)
|
||||
);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Inject(method = "handleAccumulatedMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MouseHandler;isMouseGrabbed()Z", ordinal = 0))
|
||||
|
||||
@@ -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.DATA_SYNCHRONIZED
|
||||
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.pokeball.catching.calculators.CaptureCalculator
|
||||
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.tags.CobblemonEntityTypeTags
|
||||
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.pokemon.BattlePokemon
|
||||
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.feature.TagSeasonResolver
|
||||
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.stat.CobblemonStatProvider
|
||||
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.ore.CobblemonOrePlacedFeatures
|
||||
import com.cobblemon.mod.common.world.gamerules.CobblemonGameRules
|
||||
@@ -98,27 +115,29 @@ import com.mongodb.ConnectionString
|
||||
import com.mongodb.MongoClientSettings
|
||||
import com.mongodb.client.MongoClient
|
||||
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.commands.synchronization.SingletonArgumentInfo
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.server.packs.PackType
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.item.NameTagItem
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.level.storage.LevelResource
|
||||
import org.apache.logging.log4j.LogManager
|
||||
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 {
|
||||
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 statProvider: StatProvider = CobblemonStatProvider
|
||||
var seasonResolver: SeasonResolver = TagSeasonResolver
|
||||
var wallpapers = mapOf<UUID, List<ResourceLocation>>()
|
||||
var wallpapers = mutableMapOf<UUID, Set<ResourceLocation>>()
|
||||
|
||||
val serverPlayerStructs = mutableMapOf<UUID, ObjectValue<Player>>()
|
||||
|
||||
@JvmStatic
|
||||
val builtinPacks = listOf<CobblemonPack>(
|
||||
@@ -218,6 +239,7 @@ object Cobblemon {
|
||||
storage.onPlayerDisconnect(it.player)
|
||||
playerDataManager.onPlayerDisconnect(it.player)
|
||||
RequestManager.onLogoff(it.player)
|
||||
serverPlayerStructs.remove(it.player.uuid)
|
||||
}
|
||||
PlatformEvents.PLAYER_DEATH.subscribe {
|
||||
PCLinkManager.removeLink(it.player.uuid)
|
||||
@@ -387,9 +409,11 @@ object Cobblemon {
|
||||
PlatformEvents.SERVER_STOPPED.subscribe {
|
||||
storage.unregisterAll(it.server.registryAccess())
|
||||
playerDataManager.saveAllStores()
|
||||
playerDataManager.saveExecutor.shutdown()
|
||||
playerDataManager.saveExecutor.awaitTermination(30L, TimeUnit.SECONDS)
|
||||
}
|
||||
PlatformEvents.SERVER_STARTED.subscribe {
|
||||
bestSpawner.onServerStarted()
|
||||
PlatformEvents.SERVER_STARTED.subscribe { event ->
|
||||
bestSpawner.onServerStarted(event.server)
|
||||
battleRegistry.onServerStarted()
|
||||
}
|
||||
PlatformEvents.SERVER_TICK_POST.subscribe { ServerTickHandler.onTick(it.server) }
|
||||
@@ -537,6 +561,7 @@ object Cobblemon {
|
||||
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("npc_class"), NPCClassArgumentType::class, SingletonArgumentInfo.contextFree(NPCClassArgumentType::npcClass))
|
||||
this.implementation.registerCommandArgument(cobblemonResource("wallpaper"), UnlockablePCBoxWallpaperArgumentType::class, SingletonArgumentInfo.contextFree(UnlockablePCBoxWallpaperArgumentType::wallpaper))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,9 +61,11 @@ object CobblemonCommands {
|
||||
ChangeBoxWallpaperCommand.register(dispatcher)
|
||||
RunMolangScriptCommand.register(dispatcher)
|
||||
CobblemonConfigCommand.register(dispatcher)
|
||||
UnlockPCBoxWallpaperCommand.register(dispatcher)
|
||||
|
||||
// Possibly lock down registration if and only if under dev environment or running in an environment
|
||||
// with a certain system environment variable set
|
||||
CobblemonInfoCommand.register(dispatcher)
|
||||
CalculateSeatPositionCommand.register(dispatcher)
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,9 @@ object CobblemonFlows : DataRegistry {
|
||||
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) }
|
||||
|
||||
flows[eventResourceLocation]?.forEach {
|
||||
|
||||
@@ -1278,6 +1278,7 @@ object CobblemonItems : PlatformRegistry<Registry<Item>, ResourceKey<Registry<It
|
||||
CobblemonHeldItemManager.registerRemap(it, remappedName)
|
||||
CobblemonHeldItemManager.registerRemap(Items.BONE, "thickclub")
|
||||
CobblemonHeldItemManager.registerRemap(Items.SNOWBALL, "snowball")
|
||||
CobblemonHeldItemManager.registerRemap(Items.GOLD_BLOCK, "bignugget")
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package com.cobblemon.mod.common
|
||||
|
||||
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.SetClientPlayerDataHandler
|
||||
import com.cobblemon.mod.common.client.net.animation.PlayPosableAnimationHandler
|
||||
@@ -56,6 +57,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.TradeUpdatedHandler
|
||||
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.SetClientPlayerDataPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.animation.PlayPosableAnimationPacket
|
||||
@@ -104,6 +106,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.RequestPCBoxWallpapersPacket
|
||||
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.trade.TradeAcceptanceChangedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeCancelledPacket
|
||||
@@ -287,6 +290,7 @@ object CobblemonNetwork {
|
||||
list.add(PacketRegisterInfo(RequestPCBoxWallpapersPacket.ID, RequestPCBoxWallpapersPacket::decode, RequestPCBoxWallpapersHandler))
|
||||
list.add(PacketRegisterInfo(SetPCBoxWallpapersPacket.ID, SetPCBoxWallpapersPacket::decode, SetPCBoxWallpapersHandler))
|
||||
list.add(PacketRegisterInfo(ChangePCBoxWallpaperPacket.ID, ChangePCBoxWallpaperPacket::decode, ChangePCBoxWallpaperHandler))
|
||||
list.add(PacketRegisterInfo(UnlockPCBoxWallpaperPacket.ID, UnlockPCBoxWallpaperPacket::decode, UnlockPCBoxWallpaperHandler))
|
||||
|
||||
// UI Packets
|
||||
list.add(PacketRegisterInfo(SummaryUIPacket.ID, SummaryUIPacket::decode, SummaryUIPacketHandler))
|
||||
@@ -405,6 +409,10 @@ object CobblemonNetwork {
|
||||
|
||||
// Pokédex scanning
|
||||
list.add(PacketRegisterInfo(ServerConfirmedRegisterPacket.ID, ServerConfirmedRegisterPacket::decode, ServerConfirmedRegisterHandler))
|
||||
|
||||
// Debug / cheats
|
||||
list.add(PacketRegisterInfo(CalculateSeatPositionsPacket.ID, CalculateSeatPositionsPacket::decode, CalculateSeatPositionsHandler))
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
@@ -440,6 +448,7 @@ object CobblemonNetwork {
|
||||
list.add(PacketRegisterInfo(RequestRenamePCBoxPacket.Companion.ID, RequestRenamePCBoxPacket.Companion::decode, RequestRenamePCBoxHandler))
|
||||
list.add(PacketRegisterInfo(PCBoxWallpapersPacket.ID, PCBoxWallpapersPacket::decode, PCBoxWallpapersHandler))
|
||||
list.add(PacketRegisterInfo(RequestChangePCBoxWallpaperPacket.ID, RequestChangePCBoxWallpaperPacket::decode, RequestChangePCBoxWallpaperHandler))
|
||||
list.add(PacketRegisterInfo(MarkPCBoxWallpapersSeenPacket.ID, MarkPCBoxWallpapersSeenPacket::decode, MarkPCBoxWallpapersSeenHandler))
|
||||
|
||||
// Starter packets
|
||||
list.add(PacketRegisterInfo(SelectStarterPacket.ID, SelectStarterPacket::decode, SelectStarterPacketHandler))
|
||||
|
||||
@@ -40,6 +40,8 @@ object CobblemonSounds : PlatformRegistry<Registry<SoundEvent>, ResourceKey<Regi
|
||||
val PC_RELEASE = this.create("pc.release")
|
||||
@JvmField
|
||||
val PC_CLICK = this.create("pc.click")
|
||||
@JvmField
|
||||
val PC_WALLPAPER_UNLOCK = this.create("pc.wallpaper.unlock")
|
||||
|
||||
@JvmField
|
||||
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(
|
||||
ContextAwarePredicate.CODEC.optionalFieldOf("player").forGetter(BattleCountableCriterion::playerCtx),
|
||||
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) }
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -8,6 +8,7 @@
|
||||
|
||||
package com.cobblemon.mod.common.api.conditional
|
||||
|
||||
import net.minecraft.core.Holder
|
||||
import net.minecraft.core.Registry
|
||||
|
||||
/**
|
||||
@@ -17,5 +18,10 @@ import net.minecraft.core.Registry
|
||||
* @since July 16th, 2022
|
||||
*/
|
||||
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
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.Holder
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
|
||||
/**
|
||||
@@ -24,5 +24,6 @@ open class RegistryLikeIdentifierCondition<T : Any>(val identifier: ResourceLoca
|
||||
constructor: (ResourceLocation) -> RegistryLikeIdentifierCondition<T>
|
||||
): (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
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import net.minecraft.core.Holder
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.resources.ResourceKey
|
||||
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 {
|
||||
// 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)
|
||||
}
|
||||
override fun fits(t: Holder<T>) = t.`is`(tag)
|
||||
}
|
||||
@@ -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.RenamePCBoxEvent
|
||||
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.reactive.CancelableObservable
|
||||
import com.cobblemon.mod.common.api.reactive.EventObservable
|
||||
@@ -179,6 +180,8 @@ object CobblemonEvents {
|
||||
|
||||
@JvmField
|
||||
val WALLPAPER_COLLECTION_EVENT = EventObservable<WallpaperCollectionEvent>()
|
||||
@JvmField
|
||||
val WALLPAPER_UNLOCKED_EVENT = CancelableObservable<WallpaperUnlockedEvent>()
|
||||
|
||||
@JvmField
|
||||
val CHANGE_PC_BOX_WALLPAPER_EVENT_PRE = CancelableObservable<ChangePCBoxWallpaperEvent.Pre>()
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ data class PokemonInteractionGUICreationEvent(
|
||||
|
||||
private fun getNextFreeOrientation(): Orientation {
|
||||
var largest = Orientation.TOP_LEFT
|
||||
for(orientation in Orientation.values()) {
|
||||
for (orientation in Orientation.entries) {
|
||||
if(!options.containsKey(orientation)) {
|
||||
return orientation
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -22,5 +22,5 @@ import net.minecraft.server.level.ServerPlayer
|
||||
*/
|
||||
data class WallpaperCollectionEvent(
|
||||
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 org.joml.Matrix4f
|
||||
import org.joml.Vector3f
|
||||
import org.lwjgl.opengl.GL30
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
@JvmOverloads
|
||||
fun blitk(
|
||||
@@ -364,4 +366,26 @@ fun renderSprite(matrixStack: PoseStack, sprite: ResourceLocation) {
|
||||
buffer.addVertex(matrix, 2f, 2f, 0.0f).setUv(1f, 1f)
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.CobblemonActivities
|
||||
import com.cobblemon.mod.common.CobblemonBlockEntities
|
||||
import com.cobblemon.mod.common.CobblemonMemories
|
||||
import com.cobblemon.mod.common.CobblemonUnlockableWallpapers
|
||||
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.BattleActor
|
||||
@@ -39,6 +40,8 @@ import com.cobblemon.mod.common.api.pokedex.SeenPercent
|
||||
import com.cobblemon.mod.common.api.pokemon.PokemonProperties
|
||||
import com.cobblemon.mod.common.api.pokemon.evolution.Evolution
|
||||
import com.cobblemon.mod.common.api.pokemon.stats.Stats
|
||||
import com.cobblemon.mod.common.api.riding.RidingStyle
|
||||
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||
import com.cobblemon.mod.common.api.scripting.CobblemonScripts
|
||||
import com.cobblemon.mod.common.api.spawning.context.SpawningContext
|
||||
import com.cobblemon.mod.common.api.storage.PokemonStore
|
||||
@@ -77,6 +80,7 @@ import net.minecraft.commands.arguments.EntityAnchorArgument
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Holder
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.RegistryAccess
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
@@ -92,6 +96,7 @@ import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.tags.TagKey
|
||||
import net.minecraft.world.damagesource.DamageSource
|
||||
import net.minecraft.world.damagesource.DamageTypes
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.entity.EntityType
|
||||
import net.minecraft.world.entity.LightningBolt
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
@@ -101,6 +106,7 @@ import net.minecraft.world.entity.ai.memory.MemoryModuleType
|
||||
import net.minecraft.world.entity.ai.memory.MemoryStatus
|
||||
import net.minecraft.world.entity.ai.memory.WalkTarget
|
||||
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.ExplosionInteraction
|
||||
import net.minecraft.world.level.biome.Biome
|
||||
@@ -306,6 +312,11 @@ object MoLangFunctions {
|
||||
.map { it.asMostSpecificMoLangValue() }
|
||||
.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
|
||||
}
|
||||
@@ -317,8 +328,8 @@ object MoLangFunctions {
|
||||
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||
map.put("username") { _ -> StringValue(player.gameProfile.name) }
|
||||
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("off_held_item") { _ -> player.level().itemRegistry.wrapAsHolder(player.offhandItem.item).asMoLangValue(Registries.ITEM) }
|
||||
map.put("main_held_item") { _ -> player.mainHandItem.asMoLangValue(player.registryAccess()) }
|
||||
map.put("off_held_item") { _ -> player.offhandItem.asMoLangValue(player.registryAccess()) }
|
||||
map.put("face") { params -> ObjectValue(PlayerDialogueFaceProvider(player.uuid, params.getBooleanOrNull(0) != false)) }
|
||||
map.put("swing_hand") { _ -> player.swing(player.usedItemHand) }
|
||||
map.put("food_level") { _ -> DoubleValue(player.foodData.foodLevel) }
|
||||
@@ -412,11 +423,39 @@ object MoLangFunctions {
|
||||
return@put DoubleValue.ONE
|
||||
}
|
||||
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
|
||||
}
|
||||
)
|
||||
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 ->
|
||||
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||
map.put("uuid") { _ -> StringValue(entity.uuid.toString()) }
|
||||
@@ -425,31 +464,8 @@ object MoLangFunctions {
|
||||
val source = DamageSource(entity.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolder(DamageTypes.GENERIC).get())
|
||||
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_sprinting") { _ -> DoubleValue(entity.isSprinting) }
|
||||
map.put("is_flying") { _ -> DoubleValue(entity.isFallFlying) }
|
||||
map.put("is_in_water") { _ -> DoubleValue(entity.isUnderWater) }
|
||||
map.put("is_touching_water_or_rain") { _ -> DoubleValue(entity.isInWaterRainOrBubble) }
|
||||
map.put("is_touching_water") { _ -> DoubleValue(entity.isInWater) }
|
||||
@@ -457,16 +473,13 @@ object MoLangFunctions {
|
||||
map.put("is_in_lava") { _ -> DoubleValue(entity.isInLava) }
|
||||
map.put("is_on_fire") { _ -> DoubleValue(entity.isOnFire) }
|
||||
map.put("is_invisible") { _ -> DoubleValue(entity.isInvisible) }
|
||||
map.put("is_sleeping") { _ -> DoubleValue(entity.isSleeping) }
|
||||
map.put("is_riding") { _ -> DoubleValue(entity.isPassenger) }
|
||||
map.put("health") { _ -> DoubleValue(entity.health) }
|
||||
map.put("distance_to_pos") { params ->
|
||||
val x = params.getDouble(0)
|
||||
val y = params.getDouble(1)
|
||||
val z = params.getDouble(2)
|
||||
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("type") { _ ->
|
||||
entity.registryAccess().registry(Registries.ENTITY_TYPE).get().getKey(entity.type)?.toString()?.let {
|
||||
@@ -493,11 +506,6 @@ object MoLangFunctions {
|
||||
map.put("world") { _ -> entity.level().worldRegistry.wrapAsHolder(entity.level()).asWorldMoLangValue() }
|
||||
map.put("biome") { _ -> entity.level().getBiome(entity.blockPosition()).asBiomeMoLangValue() }
|
||||
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 ->
|
||||
val type = params.getString(0).asIdentifierDefaultingNamespace(namespace = "minecraft")
|
||||
val isTag = type.path.startsWith("#")
|
||||
@@ -516,7 +524,7 @@ object MoLangFunctions {
|
||||
val distance = params.getDouble(0)
|
||||
val entities = entity.level().getEntities(entity, AABB.ofSize(entity.position(), distance, distance, distance))
|
||||
return@put entities
|
||||
.filterIsInstance<LivingEntity>()
|
||||
.filterIsInstance<Entity>()
|
||||
.map { it.asMostSpecificMoLangValue() }
|
||||
.asArrayValue()
|
||||
}
|
||||
@@ -573,6 +581,45 @@ object MoLangFunctions {
|
||||
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
|
||||
}
|
||||
)
|
||||
@@ -741,6 +788,7 @@ object MoLangFunctions {
|
||||
map.put("is_flying") { DoubleValue(pokemonEntity.getBehaviourFlag(PokemonBehaviourFlag.FLYING)) }
|
||||
map.put("has_aspect") { DoubleValue(it.getString(0) in pokemonEntity.aspects) }
|
||||
map.put("is_pokemon") { DoubleValue.ONE }
|
||||
map.put("is_holding_item") { DoubleValue(!pokemonEntity.entityData.get(PokemonEntity.SHOWN_HELD_ITEM).isEmpty) }
|
||||
map
|
||||
}
|
||||
)
|
||||
@@ -748,6 +796,7 @@ object MoLangFunctions {
|
||||
val pokemonStoreFunctions = mutableListOf<(PokemonStore<*>) -> HashMap<String, java.util.function.Function<MoParams, Any>>>(
|
||||
{ store ->
|
||||
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||
map.put("uuid") { StringValue(store.uuid.toString()) }
|
||||
map.put("add") { params ->
|
||||
val pokemon = params.get<ObjectValue<Pokemon>>(0)
|
||||
return@put DoubleValue(store.add(pokemon.obj))
|
||||
@@ -848,6 +897,17 @@ object MoLangFunctions {
|
||||
return@put DoubleValue.ONE
|
||||
}
|
||||
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
|
||||
}
|
||||
)
|
||||
@@ -856,7 +916,7 @@ object MoLangFunctions {
|
||||
{ spawningContext ->
|
||||
val map = hashMapOf<String, java.util.function.Function<MoParams, Any>>()
|
||||
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("world") { _ -> worldValue }
|
||||
map.put("light") { _ -> DoubleValue(spawningContext.light.toDouble()) }
|
||||
@@ -1084,18 +1144,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<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 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 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(
|
||||
obj = this,
|
||||
stringify = { it.effectiveName().string }
|
||||
)
|
||||
|
||||
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())
|
||||
|
||||
if (this is ServerPlayer) {
|
||||
Cobblemon.serverPlayerStructs[uuid] = value
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -1150,6 +1227,7 @@ object MoLangFunctions {
|
||||
stringify = { it.name.string }
|
||||
)
|
||||
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())
|
||||
return value
|
||||
}
|
||||
@@ -1160,6 +1238,7 @@ object MoLangFunctions {
|
||||
stringify = { it.pokemon.uuid.toString() }
|
||||
)
|
||||
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(pokemonEntityFunctions.flatMap { it(this).entries.map { it.key to it.value } }.toMap())
|
||||
return value
|
||||
@@ -1195,12 +1274,18 @@ object MoLangFunctions {
|
||||
/**
|
||||
* Different functions exist depending on
|
||||
*/
|
||||
fun LivingEntity.asMostSpecificMoLangValue(): ObjectValue<out LivingEntity> {
|
||||
fun Entity.asMostSpecificMoLangValue(): ObjectValue<out Entity> {
|
||||
return when (this) {
|
||||
is Player -> asMoLangValue()
|
||||
is PokemonEntity -> 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 +1310,7 @@ object MoLangFunctions {
|
||||
return this
|
||||
}
|
||||
|
||||
fun QueryStruct.addEntityFunctions(entity: LivingEntity): QueryStruct {
|
||||
fun QueryStruct.addEntityFunctions(entity: Entity): QueryStruct {
|
||||
val addedFunctions = entityFunctions
|
||||
.flatMap { it.invoke(entity).entries }
|
||||
.associate { it.key to it.value }
|
||||
@@ -1233,6 +1318,14 @@ object MoLangFunctions {
|
||||
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 {
|
||||
val addedFunctions = pokedexFunctions
|
||||
.flatMap { it.invoke(pokedexManager).entries }
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
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.util.DataKeys
|
||||
import com.cobblemon.mod.common.util.readSizedInt
|
||||
@@ -24,7 +23,7 @@ import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||
|
||||
class BenchedMoves : Iterable<BenchedMove> {
|
||||
val observable = SimpleObservable<BenchedMoves>()
|
||||
var changeFunction: ((BenchedMoves) -> Unit) = {}
|
||||
private var emit = true
|
||||
private val benchedMoves = mutableListOf<BenchedMove>()
|
||||
|
||||
@@ -50,7 +49,7 @@ class BenchedMoves : Iterable<BenchedMove> {
|
||||
|
||||
fun update() {
|
||||
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.value.DoubleValue
|
||||
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
||||
import com.cobblemon.mod.common.net.IntSize
|
||||
import com.cobblemon.mod.common.util.DataKeys
|
||||
import com.cobblemon.mod.common.util.readSizedInt
|
||||
@@ -24,7 +23,7 @@ import com.mojang.serialization.Codec
|
||||
import kotlin.math.min
|
||||
|
||||
class MoveSet : Iterable<Move> {
|
||||
val observable = SimpleObservable<MoveSet>()
|
||||
var changeFunction: (MoveSet) -> Unit = {}
|
||||
private var emit = true
|
||||
|
||||
private val moves = arrayOfNulls<Move>(MOVE_COUNT)
|
||||
@@ -153,7 +152,7 @@ class MoveSet : Iterable<Move> {
|
||||
|
||||
fun update() {
|
||||
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 weatherball, naturalgift, judgement, technoblast, terrainpulse, and terrablast
|
||||
if (this.elementalType == ElementalTypes.NORMAL) {
|
||||
if( this.damageCategory != DamageCategories.STATUS) {
|
||||
if (this.damageCategory != DamageCategories.STATUS) {
|
||||
return when (pokemon.ability.name) {
|
||||
"pixilate" -> ElementalTypes.FAIRY
|
||||
"aerilate" -> ElementalTypes.FLYING
|
||||
|
||||
+35
-18
@@ -7,27 +7,31 @@
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.api.npc.partyproviders
|
||||
|
||||
import com.bedrockk.molang.Expression
|
||||
import com.bedrockk.molang.runtime.MoLangRuntime
|
||||
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.setup
|
||||
import com.cobblemon.mod.common.api.npc.NPCPartyProvider
|
||||
import com.cobblemon.mod.common.api.pokemon.PokemonProperties
|
||||
import com.cobblemon.mod.common.api.storage.party.NPCPartyStore
|
||||
import com.cobblemon.mod.common.entity.npc.NPCEntity
|
||||
import com.cobblemon.mod.common.util.asArrayValue
|
||||
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.cobblemon.mod.common.util.*
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonPrimitive
|
||||
import kotlin.random.Random
|
||||
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
|
||||
@@ -60,9 +64,9 @@ class PoolPartyProvider : NPCPartyProvider {
|
||||
json as JsonObject
|
||||
this.minPokemon = json.getAsJsonPrimitive("minPokemon").asString?.asExpression() ?: "1".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) {
|
||||
return@map DynamicPokemon(
|
||||
return@mapNotNull DynamicPokemon(
|
||||
PokemonProperties.parse(it.asString),
|
||||
"0".asExpression(),
|
||||
null,
|
||||
@@ -73,17 +77,26 @@ class PoolPartyProvider : NPCPartyProvider {
|
||||
}
|
||||
|
||||
it as JsonObject
|
||||
DynamicPokemon(
|
||||
PokemonProperties.parse(it.get("pokemon").asString),
|
||||
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()
|
||||
)
|
||||
val properties = 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.
|
||||
if (properties.species == null) {
|
||||
LOGGER.warn("Error making NPC pokemon pool. ${it.get("pokemon").asString.substringBefore(" ")} is not a valid species, ignoring")
|
||||
null
|
||||
}
|
||||
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()
|
||||
isStatic = json.get("isStatic").asBoolean
|
||||
json.get("useFixedRandom")?.asBoolean?.let { useFixedRandom = it }
|
||||
|
||||
}
|
||||
|
||||
class DynamicPokemon(
|
||||
@@ -137,6 +150,10 @@ class PoolPartyProvider : NPCPartyProvider {
|
||||
val instance = selected.pokemon.copy().also { it.level = it.level ?: dictatedLevel ?: randomLevel }.create()
|
||||
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 {
|
||||
|
||||
+54
-11
@@ -13,81 +13,124 @@ object CobblemonPermissions {
|
||||
private const val COMMAND_PREFIX = "command."
|
||||
private val permissions = arrayListOf<Permission>()
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
@JvmStatic
|
||||
val CHANGE_WALK_SPEED = this.create("${COMMAND_PREFIX}changewalkspeed", PermissionLevel.ALL_COMMANDS)
|
||||
@JvmStatic
|
||||
val CHANGE_JOINT_SCALE = this.create("${COMMAND_PREFIX}changejointscale", PermissionLevel.ALL_COMMANDS)
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
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)
|
||||
@JvmStatic
|
||||
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"
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
@JvmStatic
|
||||
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)
|
||||
@JvmStatic
|
||||
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)
|
||||
@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"
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
@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)
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
@JvmStatic
|
||||
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)
|
||||
@JvmStatic
|
||||
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)
|
||||
@JvmStatic
|
||||
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)
|
||||
@JvmStatic
|
||||
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)
|
||||
|
||||
@JvmStatic
|
||||
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 CALCULATE_SEAT_POSITIONS = this.create("${COMMAND_PREFIX}calculateseatpositions", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||
|
||||
fun all(): Iterable<Permission> = this.permissions
|
||||
|
||||
private fun create(node: String, level: PermissionLevel): Permission {
|
||||
|
||||
@@ -722,8 +722,8 @@ open class PokemonProperties {
|
||||
nature = json.get(DataKeys.POKEMON_NATURE)?.asString
|
||||
ability = json.get(DataKeys.POKEMON_ABILITY)?.asString
|
||||
status = json.get(DataKeys.POKEMON_STATUS_NAME)?.asString
|
||||
ivs = json.getAsJsonObject(DataKeys.POKEMON_IVS)?.let { IVs().loadFromJSON(it) } as IVs
|
||||
evs = json.getAsJsonObject(DataKeys.POKEMON_EVS)?.let { EVs().loadFromJSON(it) } as EVs
|
||||
ivs = json.getAsJsonObject(DataKeys.POKEMON_IVS)?.let { IVs().loadFromJSON(it) } as? IVs
|
||||
evs = json.getAsJsonObject(DataKeys.POKEMON_EVS)?.let { EVs().loadFromJSON(it) } as? EVs
|
||||
type = json.get(DataKeys.ELEMENTAL_TYPE)?.asString
|
||||
teraType = json.get(DataKeys.POKEMON_TERA_TYPE)?.asString
|
||||
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
|
||||
|
||||
enum class PokemonSortMode(val comparator: Comparator<Pokemon?>, val reverseComparator: Comparator<Pokemon?>) {
|
||||
NAME( { it?.getDisplayName()?.string } ),
|
||||
LEVEL( { it?.level } ),
|
||||
TYPE( { it?.primaryType?.name } );
|
||||
NAME({ it?.getDisplayName()?.string }),
|
||||
LEVEL({ it?.level }),
|
||||
TYPE({ it?.primaryType?.name }),
|
||||
POKEDEX_NUMBER({ it?.species?.nationalPokedexNumber }),
|
||||
GENDER({ it?.gender });
|
||||
|
||||
constructor(mapper: (Pokemon?) -> Comparable<*>?) : this(compareBy({ it == null }, mapper),
|
||||
compareBy<Pokemon?> { it == null }.thenComparing(compareBy(mapper).reversed()))
|
||||
|
||||
@@ -128,6 +128,11 @@ object PokemonSpecies : JsonDataRegistry<Species> {
|
||||
init {
|
||||
SpeciesAdditions.observable.subscribe {
|
||||
this.species.forEach(Species::initialize)
|
||||
this.species.forEach {
|
||||
if (it.implemented) {
|
||||
this.implemented.add(it)
|
||||
}
|
||||
}
|
||||
this.species.forEach(Species::resolveEvolutionMoves)
|
||||
Cobblemon.showdownThread.queue {
|
||||
it.registerSpecies()
|
||||
@@ -206,9 +211,6 @@ object PokemonSpecies : JsonDataRegistry<Species> {
|
||||
this.speciesByDex.remove(old.resourceIdentifier.namespace, old.nationalPokedexNumber)
|
||||
}
|
||||
this.speciesByDex.put(species.resourceIdentifier.namespace, species.nationalPokedexNumber, species)
|
||||
if (species.implemented) {
|
||||
this.implemented.add(species)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ interface Evolution : EvolutionLike {
|
||||
pokemonEntity.after(11.2F) {
|
||||
evolutionMethod(pokemon)
|
||||
}
|
||||
pokemonEntity.after( seconds = 12F ) {
|
||||
pokemonEntity.after(seconds = 12F) {
|
||||
cryAnimation(pokemonEntity)
|
||||
pokemonEntity.entityData.set(PokemonEntity.EVOLUTION_STARTED, false)
|
||||
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)
|
||||
}
|
||||
|
||||
fun getCodeFeature(name: String) = resourceFeatures[name]
|
||||
fun getResourceFeature(name: String) = codeFeatures[name]
|
||||
fun getCodeFeature(name: String) = codeFeatures[name]
|
||||
fun getResourceFeature(name: String) = resourceFeatures[name]
|
||||
fun getFeature(name: String) = getCodeFeature(name) ?: getResourceFeature(name)
|
||||
fun loadOnClient(entries: Collection<Map.Entry<String, SpeciesFeatureProvider<*>>>) {
|
||||
codeFeatures.putAll(entries.map { it.toPair() })
|
||||
|
||||
@@ -10,15 +10,23 @@ 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.Rollable
|
||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.setup
|
||||
import com.cobblemon.mod.common.api.riding.controller.RideController
|
||||
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.util.toProperties
|
||||
import com.cobblemon.mod.common.util.withQueryValue
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.network.chat.Component
|
||||
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.sin
|
||||
import kotlin.math.sin
|
||||
|
||||
data class RidingManager(val entity: PokemonEntity) {
|
||||
var lastSpeed = 0F
|
||||
@@ -31,6 +39,17 @@ data class RidingManager(val entity: PokemonEntity) {
|
||||
.withQueryValue("entity", entity.struct)
|
||||
.also {
|
||||
it.environment.query.addFunction("passenger_count") { DoubleValue(entity.passengers.size.toDouble()) }
|
||||
it.environment.query.addFunction("get_ride_stats") { params ->
|
||||
val rideStat = RidingStat.valueOf(params.getString(0).uppercase())
|
||||
val rideStyle = RidingStyle.valueOf(params.getString(1).uppercase())
|
||||
val maxVal = params.getDouble(2)
|
||||
val minVal = params.getDouble(3)
|
||||
//TODO: Use the mons actual boost once implemented
|
||||
val normalizedStat = entity.rideProp.calculate(rideStat, rideStyle, 0) / 100.0f
|
||||
val trueStatVal = (normalizedStat * (maxVal - minVal)) + minVal
|
||||
|
||||
DoubleValue(trueStatVal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +77,12 @@ data class RidingManager(val entity: PokemonEntity) {
|
||||
|
||||
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)
|
||||
//val speedPlayer = driver.deltaMovement.horizontalDistance()
|
||||
//driver.displayClientMessage(Component.literal("Speed player: ").withStyle { it.withColor(ChatFormatting.GREEN) }.append(Component.literal("$speedPlayer b/t")), true)
|
||||
//val speedEntity = entity.deltaMovement.length() //* 20 * 60 * 60) / ( 1000 )
|
||||
//println(speedEntity)
|
||||
//driver.displayClientMessage(Component.literal("Speed: ").withStyle { it.withColor(ChatFormatting.GREEN) }.append(Component.literal("${String.format("%.2f", speedEntity)} km/h")), true)
|
||||
|
||||
}
|
||||
|
||||
fun speed(entity: PokemonEntity, driver: Player): Float {
|
||||
@@ -91,6 +114,16 @@ data class RidingManager(val entity: PokemonEntity) {
|
||||
return controller.velocity(entity, driver, input)
|
||||
}
|
||||
|
||||
fun setRideBar(entity: PokemonEntity, driver: Player): Float {
|
||||
val controller = getController(entity) ?: return 0.0f
|
||||
return controller.setRideBar(entity, driver)
|
||||
}
|
||||
|
||||
fun rideFovMult(entity: PokemonEntity, driver: Player): Float {
|
||||
val controller = getController(entity) ?: return 1.0f
|
||||
return controller.rideFovMult(entity, driver)
|
||||
}
|
||||
|
||||
fun canJump(entity: PokemonEntity, driver: Player): Boolean {
|
||||
val controller = getController(entity) ?: return false
|
||||
return controller.canJump(entity, driver)
|
||||
@@ -101,11 +134,23 @@ data class RidingManager(val entity: PokemonEntity) {
|
||||
return controller.jumpForce(entity, driver, jumpStrength)
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to supply the delta for the lerp() between velocity
|
||||
* vectors. Called inertia for now as the way it feels when
|
||||
* affecting the ride is somewhat akin to inertia.
|
||||
*/
|
||||
fun inertia(entity: PokemonEntity): Double {
|
||||
val controller = getController(entity) ?: return 0.5
|
||||
return controller.inertia(entity)
|
||||
}
|
||||
|
||||
fun gravity(entity: PokemonEntity, regularGravity: Double): Double? {
|
||||
val controller = getController(entity) ?: return null
|
||||
return controller.gravity(entity, regularGravity)
|
||||
}
|
||||
|
||||
//Maybe should be changed to be a function that conveys:
|
||||
// "turn on use our camera system function"
|
||||
fun shouldRoll(entity: PokemonEntity): Boolean {
|
||||
val controller = getController(entity) ?: return false
|
||||
return controller.shouldRoll(entity)
|
||||
@@ -121,8 +166,50 @@ data class RidingManager(val entity: PokemonEntity) {
|
||||
return controller.shouldRotatePokemonHead()
|
||||
}
|
||||
|
||||
//FIXME: Make this not just be false for all controllers lol
|
||||
fun rotationOnMouseXY(
|
||||
entity: PokemonEntity,
|
||||
driver: Player,
|
||||
yMouse: Double,
|
||||
xMouse: Double,
|
||||
yMouseSmoother: SmoothDouble,
|
||||
xMouseSmoother: SmoothDouble,
|
||||
sensitivity: Double,
|
||||
deltaTime: Double
|
||||
): Vec3 {
|
||||
val controller = getController(entity) ?: return Vec3.ZERO
|
||||
return controller.rotationOnMouseXY(
|
||||
entity,
|
||||
driver,
|
||||
yMouse,
|
||||
xMouse,
|
||||
yMouseSmoother,
|
||||
xMouseSmoother,
|
||||
sensitivity,
|
||||
deltaTime
|
||||
) }
|
||||
|
||||
/**
|
||||
* Determines whether mouse input will affect the rotation of
|
||||
* the rollable object. Need to remove this as it's not used anymore
|
||||
*/
|
||||
//I think this might better serve as a "use smoothing on angular velocity"
|
||||
fun useAngVelSmoothing(entity: PokemonEntity): Boolean {
|
||||
val controller = getController(entity) ?: return true
|
||||
return controller.useAngVelSmoothing(entity)
|
||||
}
|
||||
|
||||
fun turnOffOnGround(entity: PokemonEntity): Boolean {
|
||||
val controller = getController(entity) ?: return false
|
||||
return controller.turnOffOnGround(entity)
|
||||
}
|
||||
|
||||
fun angRollVel(entity: PokemonEntity, driver: Player, deltaTime: Double): Vec3 {
|
||||
val controller = getController(entity) ?: return Vec3(0.0, 0.0, 0.0)
|
||||
return controller.angRollVel(entity, driver, deltaTime)
|
||||
}
|
||||
|
||||
fun dismountOnShift(): Boolean {
|
||||
return false
|
||||
val controller = getController(entity) ?: return false
|
||||
return controller.dismountOnShift(entity)
|
||||
}
|
||||
}
|
||||
+52
-7
@@ -8,6 +8,8 @@
|
||||
|
||||
package com.cobblemon.mod.common.api.riding.controller
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.Rollable
|
||||
import com.cobblemon.mod.common.api.net.Decodable
|
||||
import com.cobblemon.mod.common.api.net.Encodable
|
||||
import com.cobblemon.mod.common.api.riding.RidingState
|
||||
@@ -17,6 +19,7 @@ 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.util.SmoothDouble
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.phys.Vec2
|
||||
@@ -56,20 +59,28 @@ interface RideController : Encodable, Decodable {
|
||||
* 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 {
|
||||
fun pose(entity: PokemonEntity): PoseType {
|
||||
return this.poseProvider.select(entity)
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the current speed of the mount.
|
||||
*/
|
||||
fun speed(entity: PokemonEntity, driver: Player) : Float
|
||||
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 rotation(entity: PokemonEntity, driver: LivingEntity): Vec2
|
||||
|
||||
/**
|
||||
* Sets the change current change in rotation for that tick in three
|
||||
* dimensions
|
||||
*/
|
||||
fun angRollVel(entity: PokemonEntity, driver: Player, deltaTime: Double): Vec3 {
|
||||
return Vec3(0.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
fun clampPassengerRotation(entity: PokemonEntity, driver: LivingEntity) {}
|
||||
|
||||
@@ -82,15 +93,49 @@ interface RideController : Encodable, Decodable {
|
||||
* 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 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 setRideBar(entity: PokemonEntity, driver: Player): Float = 0.0f
|
||||
|
||||
fun gravity(entity: PokemonEntity, regularGravity: Double) : Double? = null
|
||||
fun rideFovMult(entity: PokemonEntity, driver: Player): Float = 1.0f
|
||||
|
||||
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 inertia(entity: PokemonEntity): Double = 0.5
|
||||
|
||||
fun shouldRoll(entity: PokemonEntity): Boolean = false
|
||||
|
||||
fun useAngVelSmoothing(entity: PokemonEntity): Boolean = false
|
||||
|
||||
//If function is not overwritten by controllers then just perform the defualt
|
||||
//rolling function which is roll on mousex and pitch on mousey
|
||||
fun rotationOnMouseXY(
|
||||
entity: PokemonEntity,
|
||||
driver: Player,
|
||||
yMouse: Double,
|
||||
xMouse: Double,
|
||||
yMouseSmoother: SmoothDouble,
|
||||
xMouseSmoother: SmoothDouble,
|
||||
sensitivity: Double,
|
||||
deltaTime: Double
|
||||
): Vec3 {
|
||||
if (driver !is Rollable) return Vec3.ZERO
|
||||
|
||||
//Might need to add the smoothing here for default.
|
||||
val rollable = driver as Rollable
|
||||
val invertRoll = if (Cobblemon.config.invertRoll) -1 else 1
|
||||
val invertPitch = if (Cobblemon.config.invertPitch) -1 else 1
|
||||
return Vec3(0.0, yMouse * invertPitch, xMouse * invertRoll)
|
||||
}
|
||||
|
||||
fun turnOffOnGround(entity: PokemonEntity): Boolean = false
|
||||
|
||||
fun dismountOnShift(entity: PokemonEntity): Boolean = false
|
||||
|
||||
fun getRuntime(entity: PokemonEntity) = entity.riding.runtime
|
||||
|
||||
fun shouldRotatePokemonHead(): Boolean = false
|
||||
|
||||
@@ -10,7 +10,14 @@ package com.cobblemon.mod.common.api.spawning
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon.LOGGER
|
||||
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.FishingSpawningContext
|
||||
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.entity.pokemon.CobblemonAgingDespawner
|
||||
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
|
||||
@@ -130,7 +138,8 @@ object BestSpawner {
|
||||
spawnerManagers.forEach(SpawnerManager::onConfigReload)
|
||||
}
|
||||
|
||||
fun onServerStarted() {
|
||||
fun onServerStarted(server: MinecraftServer) {
|
||||
CobblemonSpawnPools.onServerLoad(server)
|
||||
spawnerManagers.forEach(SpawnerManager::onServerStarted)
|
||||
fishingSpawner = FishingSpawner()
|
||||
}
|
||||
|
||||
+16
-1
@@ -8,10 +8,13 @@
|
||||
|
||||
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.ContextPrecalculation
|
||||
import com.cobblemon.mod.common.api.spawning.detail.SpawnPool
|
||||
import com.cobblemon.mod.common.data.CobblemonDataProvider
|
||||
import net.minecraft.server.MinecraftServer
|
||||
|
||||
/**
|
||||
* A collection of all of Cobblemon's general-purpose [SpawnPool]s. These
|
||||
@@ -26,6 +29,18 @@ object CobblemonSpawnPools {
|
||||
lateinit var WORLD_SPAWN_POOL: SpawnPool
|
||||
|
||||
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
|
||||
} else if (maxHeight != null && ctx.height > maxHeight!!) {
|
||||
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
|
||||
} else {
|
||||
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.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.
|
||||
@@ -30,6 +32,15 @@ class CompositeSpawningCondition {
|
||||
var conditions = 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 {
|
||||
return if (conditions.isNotEmpty() && conditions.none { it.isSatisfiedBy(ctx) }) {
|
||||
false
|
||||
|
||||
+5
-1
@@ -30,7 +30,11 @@ abstract class GroundedTypeSpawningCondition<T : GroundedSpawningContext> : Area
|
||||
return false
|
||||
} else if (maxHeight != null && ctx.height > maxHeight!!) {
|
||||
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) {
|
||||
|
||||
+8
-4
@@ -30,10 +30,14 @@ abstract class SeafloorTypeSpawningCondition<T : SeafloorSpawningContext> : Area
|
||||
return if (!super.fits(ctx)) {
|
||||
false
|
||||
} else if (minHeight != null && ctx.height < minHeight!!) {
|
||||
return false
|
||||
false
|
||||
} else if (maxHeight != null && ctx.height > maxHeight!!) {
|
||||
return false
|
||||
} else !(neededBaseBlocks != null && neededBaseBlocks!!.none { it.fits(ctx.baseBlock.block, ctx.blockRegistry) })
|
||||
false
|
||||
} else if (neededBaseBlocks != null && neededBaseBlocks!!.none { it.fits(ctx.baseBlockHolder) }) {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
override fun copyFrom(other: SpawningCondition<*>, merger: Merger) {
|
||||
@@ -44,7 +48,7 @@ abstract class SeafloorTypeSpawningCondition<T : SeafloorSpawningContext> : Area
|
||||
}
|
||||
|
||||
override fun isValid(): Boolean {
|
||||
val containsNullValues = neededBaseBlocks != null && neededBaseBlocks!!.any {it == null}
|
||||
val containsNullValues = neededBaseBlocks != null && neededBaseBlocks!!.any { it == null }
|
||||
return super.isValid() && !containsNullValues
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -42,6 +42,7 @@ abstract class SpawningCondition<T : SpawningContext> {
|
||||
}
|
||||
|
||||
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 moonPhase: MoonPhaseRange? = null
|
||||
var canSeeSky: Boolean? = null
|
||||
@@ -98,7 +99,7 @@ abstract class SpawningCondition<T : SpawningContext> {
|
||||
return false
|
||||
} else if (dimensions != null && dimensions!!.isNotEmpty() && ctx.world.dimensionType().effectsLocation !in dimensions!!) {
|
||||
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
|
||||
} else if (appendages.any { !it.fits(ctx) }) {
|
||||
return false
|
||||
@@ -153,11 +154,11 @@ abstract class SpawningCondition<T : SpawningContext> {
|
||||
}
|
||||
|
||||
open fun isValid(): Boolean {
|
||||
if(biomes != null && biomes!!.any {it == null})
|
||||
if (biomes != null && biomes!!.any { it == null })
|
||||
return false
|
||||
if(dimensions != null && dimensions!!.any {it == null})
|
||||
if (dimensions != null && dimensions!!.any { it == null })
|
||||
return false
|
||||
if(structures != null && structures!!.any {it == null})
|
||||
if (structures != null && structures!!.any { it == null })
|
||||
return false
|
||||
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.detail.SpawnDetail
|
||||
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
|
||||
@@ -31,7 +32,7 @@ import com.cobblemon.mod.common.api.spawning.spawner.Spawner
|
||||
*/
|
||||
interface SpawningPrecalculation<T : Any> {
|
||||
/** 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. */
|
||||
fun select(ctx: SpawningContext): T?
|
||||
|
||||
@@ -71,7 +72,8 @@ interface SpawningPrecalculation<T : Any> {
|
||||
* @since January 31st, 2022
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
@@ -89,7 +91,15 @@ object ContextPrecalculation : SpawningPrecalculation<Class<out SpawningContext>
|
||||
object BucketPrecalculation : SpawningPrecalculation<SpawnBucket> {
|
||||
override fun select(detail: SpawnDetail) = listOf(detail.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.server.level.ServerLevel
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Holder
|
||||
|
||||
/**
|
||||
* A [SpawningContext] that is for a particular area, and therefore has spatial properties.
|
||||
@@ -39,6 +40,7 @@ open class AreaSpawningContext(
|
||||
val slice: WorldSlice
|
||||
) : SpawningContext() {
|
||||
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 {
|
||||
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.WorldSlice
|
||||
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.Holder
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.tags.FluidTags
|
||||
import net.minecraft.world.level.block.Block
|
||||
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) {
|
||||
/** The block that the spawning is occurring on. */
|
||||
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. */
|
||||
val moonPhase: Int by lazy { world.moonPhase }
|
||||
/** 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 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.context.SpawningContext
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.tags.BlockTags
|
||||
import net.minecraft.tags.FluidTags
|
||||
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> {
|
||||
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 isWaterCondition: (BlockState) -> Boolean = { it.fluidState.`is`(FluidTags.WATER) && 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.util.asArrayValue
|
||||
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
|
||||
@@ -56,6 +59,14 @@ abstract class SpawnDetail : ModDependant {
|
||||
|
||||
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(
|
||||
"weight" to { DoubleValue(weight) },
|
||||
"percentage" to { DoubleValue(percentage) },
|
||||
@@ -74,6 +85,23 @@ abstract class SpawnDetail : ModDependant {
|
||||
|
||||
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 {
|
||||
if (!ctx.preFilter(this)) {
|
||||
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.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.SpawnSet
|
||||
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.spawner.Spawner
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.util.server
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
@@ -48,6 +50,10 @@ class SpawnPool(val name: String) : JsonDataRegistry<SpawnSet>, Iterable<SpawnDe
|
||||
for (set in data.values) {
|
||||
details.addAll(set.filter { it.isValid() })
|
||||
}
|
||||
val server = server()
|
||||
if (server != null && server.isRunning) {
|
||||
CobblemonSpawnPools.onServerLoad(server)
|
||||
}
|
||||
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()
|
||||
}
|
||||
}
|
||||
@@ -66,9 +66,12 @@ abstract class AreaSpawner(
|
||||
if (constrainedArea != null) {
|
||||
|
||||
val areaBox = AABB.ofSize(
|
||||
Vec3(
|
||||
constrainedArea.getCenter().toVec3f()
|
||||
), CHUNK_REACH * 16.0 * 2, 1000.0, CHUNK_REACH * 16.0 * 2)
|
||||
Vec3(constrainedArea.getCenter().toVec3f()),
|
||||
CHUNK_REACH * 16.0 * 2,
|
||||
1000.0,
|
||||
CHUNK_REACH * 16.0 * 2
|
||||
)
|
||||
|
||||
if (!constrainedArea.world.isBoxLoaded(areaBox)) {
|
||||
return null
|
||||
}
|
||||
@@ -142,7 +145,7 @@ abstract class AreaSpawner(
|
||||
break
|
||||
} else if (isValidStartPoint(area.world, chunk, basePos.setY(originalY - offset))) {
|
||||
valid = true
|
||||
basePos.y = originalY + offset
|
||||
basePos.y = originalY - offset
|
||||
break
|
||||
}
|
||||
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.influence.PlayerLevelRangeInfluence
|
||||
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.rules.SpawnRule
|
||||
import com.cobblemon.mod.common.util.mutableLazy
|
||||
@@ -45,7 +44,7 @@ object PlayerSpawnerFactory {
|
||||
it,
|
||||
variation = TYPICAL_VARIATION
|
||||
)
|
||||
}, { RestrictedSpawnBlocksInfluence() })
|
||||
})
|
||||
|
||||
fun create(spawnerManager: SpawnerManager, player: ServerPlayer): PlayerSpawner {
|
||||
val influences = influenceBuilders.mapNotNull { it(player) }
|
||||
|
||||
@@ -45,8 +45,8 @@ open class BottomlessStore(override val uuid: UUID) : PokemonStore<BottomlessPos
|
||||
override fun initialize() {
|
||||
pokemon.forEachIndexed { index, pokemon ->
|
||||
pokemon.storeCoordinates.set(StoreCoordinates(this, BottomlessPosition(index)))
|
||||
pokemon.getChangeObservable().pipe(
|
||||
stopAfter { it.storeCoordinates.get()?.store != this }
|
||||
pokemon.changeObservable.pipe(
|
||||
stopAfter { pokemon.storeCoordinates.get()?.store != this }
|
||||
).subscribe { storeChangeObservable.emit(Unit) }
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ open class BottomlessStore(override val uuid: UUID) : PokemonStore<BottomlessPos
|
||||
} else {
|
||||
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)))
|
||||
}
|
||||
storeChangeObservable.emit(Unit)
|
||||
|
||||
+4
-3
@@ -18,10 +18,10 @@ import com.cobblemon.mod.common.api.storage.adapter.flatfile.FileStoreAdapter
|
||||
import com.cobblemon.mod.common.api.storage.party.PlayerPartyStore
|
||||
import com.cobblemon.mod.common.api.storage.pc.PCStore
|
||||
import com.cobblemon.mod.common.platform.events.PlatformEvents
|
||||
import com.cobblemon.mod.common.platform.events.ServerPlayerEvent
|
||||
import com.cobblemon.mod.common.util.subscribeOnServer
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
import net.minecraft.core.RegistryAccess
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
|
||||
@@ -97,7 +97,7 @@ open class FileBackedPokemonStoreFactory<S>(
|
||||
fun save(store: PokemonStore<*>, registryAccess: RegistryAccess) {
|
||||
val serialized = SerializedStore(store::class.java, store.uuid, adapter.serialize(store, registryAccess))
|
||||
dirtyStores.remove(store)
|
||||
saveExecutor.submit { adapter.save(serialized.storeClass, serialized.uuid, serialized.serializedForm) }
|
||||
saveExecutor.execute { adapter.save(serialized.storeClass, serialized.uuid, serialized.serializedForm) }
|
||||
}
|
||||
|
||||
fun saveAll(registryAccess: RegistryAccess) {
|
||||
@@ -105,7 +105,7 @@ open class FileBackedPokemonStoreFactory<S>(
|
||||
val serializedStores = dirtyStores.map { SerializedStore(it::class.java, it.uuid, adapter.serialize(it, registryAccess)) }
|
||||
dirtyStores.clear()
|
||||
LOGGER.debug("Queueing save.")
|
||||
saveExecutor.submit {
|
||||
saveExecutor.execute {
|
||||
serializedStores.forEach { adapter.save(it.storeClass, it.uuid, it.serializedForm) }
|
||||
LOGGER.debug("Saved ${serializedStores.size} Pokémon stores.")
|
||||
}
|
||||
@@ -123,6 +123,7 @@ open class FileBackedPokemonStoreFactory<S>(
|
||||
saveSubscription.unsubscribe()
|
||||
saveAll(registryAccess)
|
||||
saveExecutor.shutdown()
|
||||
saveExecutor.awaitTermination(30L, TimeUnit.SECONDS)
|
||||
}
|
||||
|
||||
override fun onPlayerDisconnect(player: ServerPlayer) {
|
||||
|
||||
@@ -73,7 +73,7 @@ open class PartyStore(override val uuid: UUID) : PokemonStore<PartyPosition>() {
|
||||
}
|
||||
|
||||
fun trackPokemon(pokemon: Pokemon) {
|
||||
pokemon.getChangeObservable()
|
||||
pokemon.changeObservable
|
||||
.pipe(stopAfter { pokemon.storeCoordinates.get()?.store != this })
|
||||
.subscribe { anyChangeObservable.emit(Unit) }
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ open class PCBox(val pc: PCStore) : Iterable<Pokemon> {
|
||||
}
|
||||
|
||||
fun trackPokemon(pokemon: Pokemon) {
|
||||
pokemon.getChangeObservable()
|
||||
pokemon.changeObservable
|
||||
.pipe(
|
||||
stopAfter {
|
||||
val coordinates = it.storeCoordinates.get() ?: return@stopAfter true
|
||||
|
||||
@@ -9,26 +9,43 @@
|
||||
package com.cobblemon.mod.common.api.storage.pc
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.CobblemonItems
|
||||
import com.cobblemon.mod.common.CobblemonNetwork.sendPacket
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.CobblemonUnlockableWallpapers
|
||||
import com.cobblemon.mod.common.api.events.CobblemonEvents
|
||||
import com.cobblemon.mod.common.api.events.storage.WallpaperUnlockedEvent
|
||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.asMoLangValue
|
||||
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
||||
import com.cobblemon.mod.common.api.storage.BottomlessStore
|
||||
import com.cobblemon.mod.common.api.storage.PokemonStore
|
||||
import com.cobblemon.mod.common.api.storage.StoreCoordinates
|
||||
import com.cobblemon.mod.common.api.text.add
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.api.toast.Toast
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.RemoveClientPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.SwapClientPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.InitializePCPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.MoveClientPCPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.SetPCPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.UnlockPCBoxWallpaperPacket
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import com.cobblemon.mod.common.util.DataKeys
|
||||
import com.cobblemon.mod.common.util.getPlayer
|
||||
import com.cobblemon.mod.common.util.lang
|
||||
import com.cobblemon.mod.common.util.toJsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.RegistryAccess
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.nbt.StringTag
|
||||
import net.minecraft.nbt.Tag
|
||||
import net.minecraft.network.chat.MutableComponent
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.world.item.ItemStack
|
||||
|
||||
/**
|
||||
* The store used for PCs. It is divided into some number of [PCBox]es, and can
|
||||
@@ -52,6 +69,8 @@ open class PCStore(
|
||||
protected var lockedSize = false
|
||||
val backupStore = BottomlessStore(UUID(0L, 0L))
|
||||
val observingUUIDs = mutableSetOf(uuid)
|
||||
val unlockedWallpapers = mutableSetOf<ResourceLocation>()
|
||||
val unseenWallpapers = mutableSetOf<ResourceLocation>()
|
||||
|
||||
override fun iterator() = boxes.flatMap { it.toList() }.iterator()
|
||||
override fun getObservingPlayers() = observingUUIDs.mapNotNull { it.getPlayer() }
|
||||
@@ -135,6 +154,8 @@ open class PCStore(
|
||||
nbt.put(DataKeys.STORE_BOX + index, box.saveToNBT(CompoundTag(), registryAccess))
|
||||
}
|
||||
nbt.put(DataKeys.STORE_BACKUP, backupStore.saveToNBT(CompoundTag(), registryAccess))
|
||||
nbt.put(DataKeys.STORE_UNLOCKED_WALLPAPERS, ListTag().also { it.addAll(unlockedWallpapers.map { StringTag.valueOf(it.toString()) }) })
|
||||
nbt.put(DataKeys.STORE_UNSEEN_WALLPAPERS, ListTag().also { it.addAll(unseenWallpapers.map { StringTag.valueOf(it.toString()) }) })
|
||||
return nbt
|
||||
}
|
||||
|
||||
@@ -152,6 +173,8 @@ open class PCStore(
|
||||
|
||||
removeDuplicates()
|
||||
|
||||
unlockedWallpapers.addAll(nbt.getList(DataKeys.STORE_UNLOCKED_WALLPAPERS, Tag.TAG_STRING.toInt()).map { ResourceLocation.parse(it.asString) })
|
||||
unseenWallpapers.addAll(nbt.getList(DataKeys.STORE_UNSEEN_WALLPAPERS, Tag.TAG_STRING.toInt()).map { ResourceLocation.parse(it.asString) })
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -177,6 +200,8 @@ open class PCStore(
|
||||
json.add(DataKeys.STORE_BOX + index, box.saveToJSON(JsonObject(), registryAccess))
|
||||
}
|
||||
json.add(DataKeys.STORE_BACKUP, backupStore.saveToJSON(JsonObject(), registryAccess))
|
||||
json.add(DataKeys.STORE_UNLOCKED_WALLPAPERS, unlockedWallpapers.map(ResourceLocation::toString).toJsonArray())
|
||||
json.add(DataKeys.STORE_UNSEEN_WALLPAPERS, unseenWallpapers.map(ResourceLocation::toString).toJsonArray())
|
||||
return json
|
||||
}
|
||||
|
||||
@@ -194,6 +219,9 @@ open class PCStore(
|
||||
|
||||
removeDuplicates()
|
||||
|
||||
unlockedWallpapers.addAll(json.getAsJsonArray(DataKeys.STORE_UNLOCKED_WALLPAPERS).map { ResourceLocation.parse(it.asString) })
|
||||
unseenWallpapers.addAll(json.getAsJsonArray(DataKeys.STORE_UNSEEN_WALLPAPERS).map { ResourceLocation.parse(it.asString) })
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -257,4 +285,47 @@ open class PCStore(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun markWallpapersSeen(textures: Set<ResourceLocation>) {
|
||||
// This first step cleans out any that were unseen but were removed from the datapack side before they were seen.
|
||||
val currentlyUnseen = unseenWallpapers.mapNotNull { CobblemonUnlockableWallpapers.unlockableWallpapers[it] }
|
||||
|
||||
val remainingUnseen = currentlyUnseen.filter { it.texture !in textures }
|
||||
this.unseenWallpapers.clear()
|
||||
this.unseenWallpapers.addAll(remainingUnseen.map { it.id })
|
||||
pcChangeObservable.emit(Unit)
|
||||
}
|
||||
|
||||
fun unlockWallpaper(wallpaper: ResourceLocation, playSound: Boolean = true): Boolean {
|
||||
val unlockableWallpaper = CobblemonUnlockableWallpapers.unlockableWallpapers[wallpaper]
|
||||
var succeeded = false
|
||||
if (unlockableWallpaper != null && unlockableWallpaper.enabled) {
|
||||
val event = WallpaperUnlockedEvent(pc = this, wallpaper = unlockableWallpaper, shouldNotify = playSound)
|
||||
CobblemonEvents.WALLPAPER_UNLOCKED_EVENT.postThen(
|
||||
event = event,
|
||||
ifSucceeded = {
|
||||
if (unlockedWallpapers.add(wallpaper)) {
|
||||
unseenWallpapers.add(unlockableWallpaper.texture)
|
||||
pcChangeObservable.emit(Unit)
|
||||
getObservingPlayers().forEach { player ->
|
||||
player.sendPacket(UnlockPCBoxWallpaperPacket(unlockableWallpaper.texture))
|
||||
if (event.shouldNotify) {
|
||||
val toast = Toast(
|
||||
title = lang("wallpaper_unlocked"),
|
||||
description = unlockableWallpaper.displayName?.let { "\"".text().add(it).add("\"") } ?: lang("unknown_wallpaper") ,
|
||||
icon = ItemStack(CobblemonItems.PC)
|
||||
)
|
||||
toast.addListeners(player)
|
||||
toast.expireAfter(5F)
|
||||
player.playNotifySound(CobblemonSounds.PC_WALLPAPER_UNLOCK, SoundSource.MASTER, 1F, 1F)
|
||||
}
|
||||
}
|
||||
succeeded = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return succeeded
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.storage.pc
|
||||
|
||||
import com.bedrockk.molang.runtime.value.DoubleValue
|
||||
import com.bedrockk.molang.runtime.value.StringValue
|
||||
import com.cobblemon.mod.common.api.molang.ObjectValue
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
|
||||
/**
|
||||
* A server-defined wallpaper for PC boxes that are not immediately usable. Typically a command
|
||||
* or a code action is required to add the wallpaper to the unlock list.
|
||||
*
|
||||
* @author Hiroku
|
||||
* @since February 9th, 2025
|
||||
*/
|
||||
class UnlockablePCWallpaper {
|
||||
@Transient
|
||||
lateinit var id: ResourceLocation
|
||||
/** This is for when we provide a wallpaper but some server wants to remove it from the unlockables. */
|
||||
var enabled = true
|
||||
/** If unlocked with a notification toast, this is the name displayed in the toast. If blank, ??? will be used. */
|
||||
var displayName: Component? = null
|
||||
var texture: ResourceLocation = cobblemonResource("dummy.png")
|
||||
// I feel like there's more that could be added to this. Things like whether it displays when still locked, and if so what kind of hint to provide.
|
||||
// That requires client side changes which means it requires The Expert which is why I'm not committing to it right this second.
|
||||
|
||||
@Transient
|
||||
val struct = ObjectValue(this).also {
|
||||
it.addFunction("texture") { StringValue(texture.toString()) }
|
||||
it.addFunction("id") { StringValue(id.toString()) }
|
||||
it.addFunction("enabled") { DoubleValue(enabled) }
|
||||
}
|
||||
}
|
||||
@@ -37,9 +37,9 @@ class Search(
|
||||
if (inverted) {
|
||||
filter = filter.substring(1)
|
||||
}
|
||||
|
||||
|
||||
val pokemonFilter: PokemonFilter = when (filter) {
|
||||
"holding" -> PokemonFilter { pokemon -> !pokemon.heldItem().isEmpty }
|
||||
"holding", "helditem", "held_item" -> PokemonFilter { pokemon -> !pokemon.heldItem().isEmpty }
|
||||
"fainted" -> PokemonFilter { pokemon -> pokemon.isFainted() }
|
||||
"legendary" -> PokemonFilter { pokemon -> pokemon.isLegendary() }
|
||||
"mythical" -> PokemonFilter { pokemon -> pokemon.isMythical() }
|
||||
|
||||
+11
@@ -8,10 +8,14 @@
|
||||
|
||||
package com.cobblemon.mod.common.api.storage.player
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon.MODID
|
||||
import com.cobblemon.mod.common.api.pokedex.PokedexManager
|
||||
import com.cobblemon.mod.common.api.scheduling.ScheduledTask
|
||||
import com.cobblemon.mod.common.api.scheduling.ServerTaskTracker
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.world.entity.player.Player
|
||||
@@ -28,6 +32,13 @@ import net.minecraft.world.entity.player.Player
|
||||
*/
|
||||
|
||||
open class PlayerInstancedDataStoreManager {
|
||||
val saveExecutor = Executors.newSingleThreadExecutor(
|
||||
ThreadFactoryBuilder()
|
||||
.setNameFormat("$MODID Player Data Save Executor")
|
||||
.setDaemon(true)
|
||||
.setPriority(1)
|
||||
.build()
|
||||
)
|
||||
val factories = mutableMapOf<PlayerInstancedDataStoreType, PlayerInstancedDataFactory<*>>()
|
||||
val saveTasks = mutableMapOf<PlayerInstancedDataStoreType, ScheduledTask>()
|
||||
open fun setFactory(factory: PlayerInstancedDataFactory<*>, dataType: PlayerInstancedDataStoreType) {
|
||||
|
||||
+4
-4
@@ -37,10 +37,10 @@ abstract class FileBasedPlayerDataStoreBackend<T : InstancedPlayerData>(
|
||||
savePath = server.getWorldPath(LevelResource.PLAYER_DATA_DIR).parent
|
||||
}
|
||||
|
||||
protected fun postSaveFileMoving(playerData: T) {
|
||||
val tempFile = filePath(playerData.uuid, TEMPORARY_FILE_EXTENSION)
|
||||
val oldFile = filePath(playerData.uuid, OLD_FILE_EXTENSION)
|
||||
val file = filePath(playerData.uuid)
|
||||
protected fun postSaveFileMoving(uuid: UUID) {
|
||||
val tempFile = filePath(uuid, TEMPORARY_FILE_EXTENSION)
|
||||
val oldFile = filePath(uuid, OLD_FILE_EXTENSION)
|
||||
val file = filePath(uuid)
|
||||
if (file.exists()) {
|
||||
file.copyTo(oldFile, overwrite = true)
|
||||
}
|
||||
|
||||
+5
-6
@@ -8,13 +8,11 @@
|
||||
|
||||
package com.cobblemon.mod.common.api.storage.player.adapter
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.api.storage.player.InstancedPlayerData
|
||||
import com.cobblemon.mod.common.api.storage.player.PlayerInstancedDataStoreType
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import java.io.BufferedReader
|
||||
import java.io.FileReader
|
||||
import java.io.PrintWriter
|
||||
import java.util.UUID
|
||||
import kotlin.reflect.KMutableProperty
|
||||
import kotlin.reflect.full.memberProperties
|
||||
@@ -30,10 +28,11 @@ abstract class JsonBackedPlayerDataStoreBackend<T : InstancedPlayerData>(
|
||||
override fun save(playerData: T) {
|
||||
val fileTmp = filePath(playerData.uuid, TEMPORARY_FILE_EXTENSION)
|
||||
fileTmp.parentFile.mkdirs()
|
||||
fileTmp.printWriter().use { pw ->
|
||||
pw.write(gson.toJson(playerData))
|
||||
val json = gson.toJson(playerData)
|
||||
Cobblemon.playerDataManager.saveExecutor.execute {
|
||||
fileTmp.printWriter().use { pw -> pw.write(json) }
|
||||
postSaveFileMoving(playerData.uuid)
|
||||
}
|
||||
postSaveFileMoving(playerData)
|
||||
}
|
||||
|
||||
override fun load(uuid: UUID): T {
|
||||
|
||||
+10
-9
@@ -8,19 +8,17 @@
|
||||
|
||||
package com.cobblemon.mod.common.api.storage.player.adapter
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.api.storage.player.InstancedPlayerData
|
||||
import com.cobblemon.mod.common.api.storage.player.PlayerInstancedDataStoreType
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.mongodb.client.MongoClient
|
||||
import com.mongodb.client.model.ReplaceOptions
|
||||
import org.bson.Document
|
||||
import java.io.BufferedReader
|
||||
import java.io.FileReader
|
||||
import java.io.PrintWriter
|
||||
import java.util.UUID
|
||||
import kotlin.reflect.KMutableProperty
|
||||
import kotlin.reflect.full.memberProperties
|
||||
import org.bson.Document
|
||||
|
||||
abstract class MongoBackedPlayerDataStoreBackend<T : InstancedPlayerData>(
|
||||
mongoClient: MongoClient, databaseName: String, collectionName: String, type: PlayerInstancedDataStoreType
|
||||
@@ -31,11 +29,14 @@ abstract class MongoBackedPlayerDataStoreBackend<T : InstancedPlayerData>(
|
||||
abstract val classToken: TypeToken<T>
|
||||
|
||||
override fun save(playerData: T) {
|
||||
collection.replaceOne(
|
||||
Document("uuid", playerData.uuid.toString()),
|
||||
Document.parse(gson.toJson(playerData)),
|
||||
ReplaceOptions().upsert(true)
|
||||
)
|
||||
val json = gson.toJson(playerData)
|
||||
Cobblemon.playerDataManager.saveExecutor.execute {
|
||||
collection.replaceOne(
|
||||
Document("uuid", playerData.uuid.toString()),
|
||||
Document.parse(json),
|
||||
ReplaceOptions().upsert(true)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun load(uuid: UUID): T {
|
||||
|
||||
+5
-2
@@ -29,8 +29,11 @@ abstract class NbtBackedPlayerData<T : InstancedPlayerData>(
|
||||
val fileTmp = filePath(playerData.uuid, TEMPORARY_FILE_EXTENSION)
|
||||
fileTmp.parentFile.mkdirs()
|
||||
val encodeResult = codec.encodeStart(NbtOps.INSTANCE, playerData)
|
||||
NbtIo.write(encodeResult.result().get() as CompoundTag, fileTmp.toPath())
|
||||
postSaveFileMoving(playerData)
|
||||
val tag = encodeResult.result().get() as CompoundTag
|
||||
Cobblemon.playerDataManager.saveExecutor.submit {
|
||||
NbtIo.write(tag, fileTmp.toPath())
|
||||
postSaveFileMoving(playerData.uuid)
|
||||
}
|
||||
}
|
||||
|
||||
override fun load(uuid: UUID): T {
|
||||
|
||||
@@ -10,17 +10,17 @@ package com.cobblemon.mod.common.api.toast
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.api.scheduling.afterOnServer
|
||||
import com.cobblemon.mod.common.api.toast.Toast.Companion.VANILLA_FRAME
|
||||
import com.cobblemon.mod.common.api.toast.Toast.Companion.VANILLA_PROGRESS_COLOR
|
||||
import com.cobblemon.mod.common.net.messages.client.toast.ToastPacket
|
||||
import com.cobblemon.mod.common.platform.events.PlatformEvents
|
||||
import java.util.UUID
|
||||
import kotlin.properties.Delegates
|
||||
import net.minecraft.client.gui.components.toasts.AdvancementToast
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import java.util.*
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
/**
|
||||
* Represents a toast that can be shown to multiple clients.
|
||||
@@ -40,7 +40,7 @@ class Toast(
|
||||
title: Component,
|
||||
description: Component,
|
||||
icon: ItemStack,
|
||||
frameTexture: ResourceLocation = VANILLA_FRAME,
|
||||
frameTexture: ResourceLocation = AdvancementToast.BACKGROUND_SPRITE,
|
||||
progress: Float = -1F,
|
||||
progressColor: Int = VANILLA_PROGRESS_COLOR
|
||||
) {
|
||||
@@ -195,12 +195,6 @@ class Toast(
|
||||
)
|
||||
|
||||
companion object {
|
||||
|
||||
/**
|
||||
* The default Minecraft toast frame texture.
|
||||
*/
|
||||
val VANILLA_FRAME = ResourceLocation.fromNamespaceAndPath("minecraft", "textures/gui/toasts.png")
|
||||
|
||||
const val VANILLA_PROGRESS_COLOR = -1675545
|
||||
|
||||
}
|
||||
|
||||
@@ -785,7 +785,7 @@ class StrongBattleAI(skill: Int) : BattleAI {
|
||||
/*availableSwitches.forEach {
|
||||
estimateMatchup(request, battle, it.effectedPokemon)
|
||||
}*/
|
||||
val bestEstimation = if ( 1 == 1 /* todo if player is in bad matchup and switches out a lot and has a better matchup in revealed party */) {
|
||||
val bestEstimation = if (1 == 1 /* todo if player is in bad matchup and switches out a lot and has a better matchup in revealed party */) {
|
||||
// todo make it so that bestEstimation is actually in comparison to that potential pokemon instead and be sure to switch to that instead
|
||||
|
||||
availableSwitches.maxOfOrNull { estimateMatchup(activeBattlePokemon, request, battle, it.effectedPokemon) }
|
||||
|
||||
+4
-1
@@ -13,6 +13,7 @@ import com.cobblemon.mod.common.api.battles.interpreter.BattleMessage
|
||||
import com.cobblemon.mod.common.api.battles.model.PokemonBattle
|
||||
import com.cobblemon.mod.common.api.moves.Moves
|
||||
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.UsersProvider
|
||||
import com.cobblemon.mod.common.api.pokemon.status.Statuses
|
||||
import com.cobblemon.mod.common.battles.ShowdownInterpreter
|
||||
@@ -56,7 +57,9 @@ class ActivateInstruction(val instructionSet: InstructionSet, val message: Battl
|
||||
battle.dispatch {
|
||||
val effect = message.effectAt(1) ?: return@dispatch GO
|
||||
val status = Statuses.getStatus(effect.id)
|
||||
val actionEffect = status?.getActionEffect() ?: return@dispatch GO
|
||||
val actionEffect = status?.getActionEffect() ?: let {
|
||||
ActionEffects.actionEffects[cobblemonResource("activate_${effect.id}")] ?: return@dispatch GO
|
||||
}
|
||||
val providers = mutableListOf<Any>(battle)
|
||||
val pokemon = message.battlePokemon(0, battle) ?: return@dispatch GO
|
||||
pokemon.effectedPokemon.entity?.let { UsersProvider(it) }?.let(providers::add)
|
||||
|
||||
+111
-87
@@ -10,6 +10,7 @@ package com.cobblemon.mod.common.battles.interpreter.instructions
|
||||
|
||||
import com.bedrockk.molang.runtime.MoLangRuntime
|
||||
import com.cobblemon.mod.common.api.battles.interpreter.BattleMessage
|
||||
import com.cobblemon.mod.common.api.battles.interpreter.Effect
|
||||
import com.cobblemon.mod.common.api.battles.model.PokemonBattle
|
||||
import com.cobblemon.mod.common.api.battles.model.actor.BattleActor
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
@@ -23,11 +24,13 @@ import com.cobblemon.mod.common.battles.dispatch.GO
|
||||
import com.cobblemon.mod.common.battles.dispatch.InstructionSet
|
||||
import com.cobblemon.mod.common.battles.dispatch.UntilDispatch
|
||||
import com.cobblemon.mod.common.battles.pokemon.BattlePokemon
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.net.messages.client.animation.PlayPosableAnimationPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.battle.BattleHealthChangePacket
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.RunPosableMoLangPacket
|
||||
import com.cobblemon.mod.common.pokemon.evolution.progress.DamageTakenEvolutionProgress
|
||||
import com.cobblemon.mod.common.pokemon.evolution.progress.RecoilEvolutionProgress
|
||||
import com.cobblemon.mod.common.pokemon.status.statuses.persistent.PoisonBadlyStatus
|
||||
import com.cobblemon.mod.common.pokemon.status.statuses.persistent.PoisonStatus
|
||||
import com.cobblemon.mod.common.util.asIdentifierDefaultingNamespace
|
||||
import com.cobblemon.mod.common.util.battleLang
|
||||
@@ -67,49 +70,40 @@ class DamageInstruction(
|
||||
}
|
||||
}
|
||||
}
|
||||
val newHealth = privateMessage.argumentAt(1)?.split(" ")?.get(0) ?: return
|
||||
val effect = privateMessage.effect()
|
||||
val source = privateMessage.battlePokemonFromOptional(battle)
|
||||
source?.let { ShowdownInterpreter.broadcastOptionalAbility(battle, effect, it) }
|
||||
}
|
||||
|
||||
private fun doRecoilEvoChecks(battlePokemon: BattlePokemon) {
|
||||
battlePokemon.effectedPokemon.let { pokemon ->
|
||||
if (RecoilEvolutionProgress.supports(pokemon)) {
|
||||
val healthStr = privateMessage.argumentAt(1) ?: throw UnsupportedOperationException(
|
||||
"Cant get recoil string"
|
||||
)
|
||||
val newHealth =
|
||||
"([0-9]+).*".toRegex().find(healthStr)?.groups?.get(1)?.value?.toIntOrNull()
|
||||
?: throw UnsupportedOperationException("Cant get recoil string")
|
||||
val difference = pokemon.currentHealth - newHealth
|
||||
if (difference > 0) {
|
||||
val progress = pokemon.evolutionProxy.current()
|
||||
.progressFirstOrCreate({ it is RecoilEvolutionProgress }) { RecoilEvolutionProgress() }
|
||||
progress.updateProgress(RecoilEvolutionProgress.Progress(progress.currentProgress().recoil + difference))
|
||||
}
|
||||
}
|
||||
if (source != null) {
|
||||
ShowdownInterpreter.broadcastOptionalAbility(battle, effect, source)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun runActionEffect(battle: PokemonBattle, runtime: MoLangRuntime) {
|
||||
val effect = privateMessage.effect()
|
||||
val battlePokemon = publicMessage.battlePokemon(0, actor.battle) ?: return
|
||||
val publicPokemon = publicMessage.battlePokemon(0, actor.battle) ?: return
|
||||
var status = effect?.id?.let { Statuses.getStatus(it) }
|
||||
battle.dispatch {
|
||||
val pokemon = privateMessage.battlePokemon(0, battle) ?: return@dispatch GO
|
||||
//Showdown doesnt tell us on damage if its poison or toxic so we gotta consult the entity
|
||||
if (status is PoisonStatus) {
|
||||
status = pokemon.effectedPokemon.status?.status ?: status
|
||||
val isToxic = publicPokemon.effectedPokemon.status?.status is PoisonBadlyStatus
|
||||
val realStatus = if (isToxic) PoisonBadlyStatus() else status
|
||||
// Damage effects without a action effect receive the generic damage effect
|
||||
val actionEffect = if (realStatus != null) {
|
||||
realStatus.getActionEffect()
|
||||
} else if (effect != null) {
|
||||
ActionEffects.actionEffects[cobblemonResource("generic_damage")]
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
// Damage effects without a action effect receive the generic damage effect
|
||||
val actionEffect = status?.getActionEffect() ?: effect?.let {
|
||||
ActionEffects.actionEffects["generic_damage".asIdentifierDefaultingNamespace()]
|
||||
} ?: return@dispatch GO
|
||||
if (actionEffect == null) {
|
||||
return@dispatch GO
|
||||
}
|
||||
|
||||
val providers = mutableListOf<Any>(battle)
|
||||
battlePokemon.effectedPokemon.entity?.let { UsersProvider(it) }?.let(providers::add)
|
||||
val pokemonEntity = publicPokemon.effectedPokemon.entity
|
||||
if (pokemonEntity != null) {
|
||||
providers.add(UsersProvider(pokemonEntity))
|
||||
}
|
||||
|
||||
val context = ActionEffectContext(
|
||||
actionEffect = actionEffect,
|
||||
@@ -125,72 +119,24 @@ class DamageInstruction(
|
||||
}
|
||||
|
||||
override fun postActionEffect(battle: PokemonBattle) {
|
||||
val newHealth = privateMessage.argumentAt(1)?.split(" ")?.get(0) ?: return
|
||||
val hpStatus = privateMessage.argumentAt(1)?.split(" ")?.get(0)!!
|
||||
var causedFaint = hpStatus == "0"
|
||||
val remainingHealth = hpStatus.split("/")[0].toFloat()
|
||||
val maxHealth = hpStatus.split("/").getOrNull(1)?.toFloat()
|
||||
val battlePokemon = publicMessage.battlePokemon(0, actor.battle) ?: return
|
||||
var causedFaint = newHealth == "0"
|
||||
val effect = privateMessage.effect()
|
||||
val source = privateMessage.battlePokemonFromOptional(battle)
|
||||
val lastCauser = instructionSet.getMostRecentCauser(comparedTo = this)
|
||||
val pokemonName = battlePokemon.getName()
|
||||
val pokemonEntity = battlePokemon.entity
|
||||
|
||||
battle.dispatch {
|
||||
val pokemonName = battlePokemon.getName()
|
||||
val pokemonEntity = battlePokemon.entity
|
||||
//Play recoil animation if the pokemon recoiling isnt dead
|
||||
if (!causedFaint && pokemonEntity != null) {
|
||||
val pkt = PlayPosableAnimationPacket(pokemonEntity.id, setOf("recoil"), emptyList())
|
||||
pkt.sendToPlayersAround(
|
||||
x = pokemonEntity.x,
|
||||
y = pokemonEntity.y,
|
||||
z = pokemonEntity.z,
|
||||
worldKey = pokemonEntity.level().dimension(),
|
||||
distance = 50.0
|
||||
)
|
||||
}
|
||||
|
||||
val newHealthRatio: Float
|
||||
val remainingHealth = newHealth.split("/")[0].toInt()
|
||||
|
||||
playRecoilAnim(pokemonEntity, causedFaint)
|
||||
if (effect != null) {
|
||||
val lang = when (effect.id) {
|
||||
"blacksludge", "stickybarb", "jabocaberry", "rowapberry" -> battleLang("damage.item", pokemonName, effect.typelessData)
|
||||
"brn", "psn", "tox" -> {
|
||||
val status = Statuses.getStatus(effect.id)?.name?.path ?: return@dispatch GO
|
||||
lang("status.$status.hurt", pokemonName)
|
||||
}
|
||||
"aftermath", "innardsout" -> battleLang("damage.generic", pokemonName)
|
||||
"chloroblast", "steelbeam" -> battleLang("damage.mindblown", pokemonName)
|
||||
"jumpkick" -> battleLang("damage.highjumpkick", pokemonName)
|
||||
else -> battleLang("damage.${effect.id}", pokemonName, source?.getName() ?: Component.literal("UNKOWN"))
|
||||
}
|
||||
battle.broadcastChatMessage(lang.red())
|
||||
sendStatusMessage(battle, effect, pokemonName, source)
|
||||
}
|
||||
|
||||
if (causedFaint) {
|
||||
newHealthRatio = 0F
|
||||
battle.dispatch {
|
||||
battlePokemon.effectedPokemon.currentHealth = 0
|
||||
battlePokemon.sendUpdate()
|
||||
GO
|
||||
}
|
||||
causedFaint = true
|
||||
} else {
|
||||
val maxHealth = newHealth.split("/")[1].toInt()
|
||||
val difference = maxHealth - remainingHealth
|
||||
newHealthRatio = remainingHealth.toFloat() / maxHealth
|
||||
battle.dispatchToFront {
|
||||
battlePokemon.effectedPokemon.currentHealth = remainingHealth
|
||||
if (difference > 0) {
|
||||
battlePokemon.effectedPokemon.let { pokemon ->
|
||||
if (DamageTakenEvolutionProgress.supports(pokemon)) {
|
||||
val progress = pokemon.evolutionProxy.current().progressFirstOrCreate({ it is DamageTakenEvolutionProgress }) { DamageTakenEvolutionProgress() }
|
||||
progress.updateProgress(DamageTakenEvolutionProgress.Progress(progress.currentProgress().amount + difference))
|
||||
}
|
||||
}
|
||||
}
|
||||
battlePokemon.sendUpdate()
|
||||
GO
|
||||
}
|
||||
}
|
||||
privateMessage.pnxAndUuid(0)?.let { (pnx, _) -> battle.sendSidedUpdate(actor, BattleHealthChangePacket(pnx, remainingHealth.toFloat()), BattleHealthChangePacket(pnx, newHealthRatio)) }
|
||||
updateHealth(battle, battlePokemon, remainingHealth, maxHealth)
|
||||
|
||||
battle.minorBattleActions[battlePokemon.uuid] = privateMessage
|
||||
if (lastCauser is MoveInstruction) {
|
||||
@@ -215,4 +161,82 @@ class DamageInstruction(
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateHealth(battle: PokemonBattle, battlePokemon: BattlePokemon, remainingHealth: Float, maxHealth: Float?) {
|
||||
val causedFaint = maxHealth == null
|
||||
val newHealthRatio = if (maxHealth == null) 0F else remainingHealth / maxHealth
|
||||
if (causedFaint) {
|
||||
battle.dispatch {
|
||||
battlePokemon.effectedPokemon.currentHealth = 0
|
||||
battlePokemon.sendUpdate()
|
||||
GO
|
||||
}
|
||||
}
|
||||
else {
|
||||
val difference = maxHealth - remainingHealth
|
||||
battle.dispatchToFront {
|
||||
battlePokemon.effectedPokemon.currentHealth = remainingHealth.toInt()
|
||||
updateDamageTakenEvo(battlePokemon, difference.toInt())
|
||||
battlePokemon.sendUpdate()
|
||||
GO
|
||||
}
|
||||
}
|
||||
privateMessage.pnxAndUuid(0)?.let { (pnx, _ ) ->
|
||||
battle.sendSidedUpdate(actor, BattleHealthChangePacket(pnx, remainingHealth), BattleHealthChangePacket(pnx, newHealthRatio))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun doRecoilEvoChecks(battlePokemon: BattlePokemon) {
|
||||
battlePokemon.effectedPokemon.let { pokemon ->
|
||||
if (RecoilEvolutionProgress.supports(pokemon)) {
|
||||
val healthStr = privateMessage.argumentAt(1) ?: throw UnsupportedOperationException("Cant get recoil string")
|
||||
val newHealth =
|
||||
"([0-9]+).*".toRegex().find(healthStr)?.groups?.get(1)?.value?.toIntOrNull()
|
||||
?: throw UnsupportedOperationException("Cant get recoil string")
|
||||
val difference = pokemon.currentHealth - newHealth
|
||||
if (difference > 0) {
|
||||
val progress = pokemon.evolutionProxy.current()
|
||||
.progressFirstOrCreate({ it is RecoilEvolutionProgress }) { RecoilEvolutionProgress() }
|
||||
progress.updateProgress(RecoilEvolutionProgress.Progress(progress.currentProgress().recoil + difference))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendStatusMessage(battle: PokemonBattle, effect: Effect, pokemonName: Component, source: BattlePokemon?) {
|
||||
val lang = when (effect.id) {
|
||||
"blacksludge", "stickybarb", "jabocaberry", "rowapberry" -> battleLang("damage.item", pokemonName, effect.typelessData)
|
||||
"brn", "psn", "tox" -> {
|
||||
val status = Statuses.getStatus(effect.id)?.name?.path
|
||||
lang("status.$status.hurt", pokemonName)
|
||||
}
|
||||
"aftermath", "innardsout" -> battleLang("damage.generic", pokemonName)
|
||||
"chloroblast", "steelbeam" -> battleLang("damage.mindblown", pokemonName)
|
||||
"jumpkick" -> battleLang("damage.highjumpkick", pokemonName)
|
||||
else -> battleLang("damage.${effect.id}", pokemonName, source?.getName() ?: Component.literal("UNKOWN"))
|
||||
}
|
||||
battle.broadcastChatMessage(lang.red())
|
||||
}
|
||||
|
||||
private fun playRecoilAnim(pokemonEntity: PokemonEntity?, causedFaint: Boolean) {
|
||||
if (!causedFaint && pokemonEntity != null) {
|
||||
val pkt = PlayPosableAnimationPacket(pokemonEntity.id, setOf("recoil"), emptyList())
|
||||
pkt.sendToPlayersAround(
|
||||
x = pokemonEntity.x,
|
||||
y = pokemonEntity.y,
|
||||
z = pokemonEntity.z,
|
||||
worldKey = pokemonEntity.level().dimension(),
|
||||
distance = 50.0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateDamageTakenEvo(battlePokemon: BattlePokemon, damageTaken: Int) {
|
||||
battlePokemon.effectedPokemon.let { pokemon ->
|
||||
if (DamageTakenEvolutionProgress.supports(pokemon)) {
|
||||
val progress = pokemon.evolutionProxy.current().progressFirstOrCreate({ it is DamageTakenEvolutionProgress }) { DamageTakenEvolutionProgress() }
|
||||
progress.updateProgress(DamageTakenEvolutionProgress.Progress(progress.currentProgress().amount + damageTaken))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -90,7 +90,7 @@ class MoveInstruction(
|
||||
val providers = mutableListOf<Any>(battle)
|
||||
userPokemon.effectedPokemon.entity?.let { UsersProvider(it) }?.let(providers::add)
|
||||
if (spreadTargetPokemon.isNotEmpty()) {
|
||||
providers.add(TargetsProvider( spreadTargetPokemon.filter { it?.effectedPokemon?.entity != null}.mapNotNull { spreadTarget -> spreadTarget?.effectedPokemon?.entity } ))
|
||||
providers.add(TargetsProvider(spreadTargetPokemon.filter { it?.effectedPokemon?.entity != null}.mapNotNull { spreadTarget -> spreadTarget?.effectedPokemon?.entity }))
|
||||
} else {
|
||||
targetPokemon?.effectedPokemon?.entity?.let { TargetsProvider(it) }?.let(providers::add)
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import com.cobblemon.mod.common.util.asTranslated
|
||||
* @author Hiroku
|
||||
* @since October 3rd, 2022
|
||||
*/
|
||||
class StatusInstruction( val message: BattleMessage): InterpreterInstruction {
|
||||
class StatusInstruction(val message: BattleMessage): InterpreterInstruction {
|
||||
|
||||
override fun invoke(battle: PokemonBattle) {
|
||||
val (pnx, _) = message.pnxAndUuid(0) ?: return
|
||||
|
||||
@@ -285,7 +285,7 @@ class PCBlock(properties: Properties): BaseEntityBlock(properties), SimpleWaterl
|
||||
val pc = Cobblemon.storage.getPCForPlayer(player, baseEntity) ?: return InteractionResult.SUCCESS
|
||||
// TODO add event to check if they can open this PC? (answer: the getPCForPlayer should be where we do that)
|
||||
PCLinkManager.addLink(ProximityPCLink(pc, player.uuid, baseEntity))
|
||||
OpenPCPacket(pc.uuid).sendToPlayer(player)
|
||||
OpenPCPacket(pc).sendToPlayer(player)
|
||||
world.playSoundServer(
|
||||
position = blockPos.toVec3d(),
|
||||
sound = CobblemonSounds.PC_ON,
|
||||
|
||||
@@ -114,8 +114,8 @@ class RevivalHerbBlock(settings: Properties) : CropBlock(settings), Mulchable {
|
||||
var growthSpeed = 1.0F
|
||||
var ground = pos.below()
|
||||
|
||||
for(x in -1..1) {
|
||||
for(z in -1..1) {
|
||||
for (x in -1..1) {
|
||||
for (z in -1..1) {
|
||||
var nearbyFarmLandBoost = 0.0F
|
||||
var blockState = level.getBlockState(ground.offset(x, 0, z))
|
||||
if (blockState.`is`(Blocks.FARMLAND)) {
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ class FossilAnalyzerBlockEntity(
|
||||
return stack?.let { Fossils.isFossilIngredient(it) } == true
|
||||
&& structure.fossilInventory.size < Cobblemon.config.maxInsertedFossilItems
|
||||
&& structure.isRunning() == false && structure.resultingFossil == null
|
||||
&& Fossils.getSubFossilByItemStacks( structure.fossilInventory + mutableListOf(stack) ) != null
|
||||
&& Fossils.getSubFossilByItemStacks(structure.fossilInventory + mutableListOf(stack)) != null
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.cobblemon.mod.common.CobblemonClientImplementation
|
||||
import com.cobblemon.mod.common.CobblemonEntities
|
||||
import com.cobblemon.mod.common.CobblemonItems
|
||||
import com.cobblemon.mod.common.api.berry.Berries
|
||||
import com.cobblemon.mod.common.api.molang.ObjectValue
|
||||
import com.cobblemon.mod.common.api.scheduling.ClientTaskTracker
|
||||
import com.cobblemon.mod.common.api.storage.player.client.ClientGeneralPlayerData
|
||||
import com.cobblemon.mod.common.api.storage.player.client.ClientPokedexManager
|
||||
@@ -78,6 +79,8 @@ import net.minecraft.world.InteractionHand
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.phys.AABB
|
||||
import java.util.UUID
|
||||
import net.minecraft.client.player.AbstractClientPlayer
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
|
||||
object CobblemonClient {
|
||||
|
||||
@@ -144,7 +147,7 @@ object CobblemonClient {
|
||||
PlatformEvents.CLIENT_ENTITY_UNLOAD.subscribe { event -> EntitySoundTracker.clear(event.entity.id) }
|
||||
PlatformEvents.CLIENT_TICK_POST.subscribe { event ->
|
||||
val player = event.client.player
|
||||
if (player !== null) {
|
||||
if (player != null) {
|
||||
var selectedItem = player.inventory.getItem(player.inventory.selected)
|
||||
if (pokedexUsageContext.scanningGuiOpen &&
|
||||
!(selectedItem.`is`(CobblemonItemTags.POKEDEX)) &&
|
||||
@@ -156,13 +159,14 @@ object CobblemonClient {
|
||||
// Stop using Pokédex in main hand if player switches to a different slot in hotbar
|
||||
pokedexUsageContext.stopUsing(PokedexUsageContext.OPEN_SCANNER_BUFFER_TICKS + 1)
|
||||
}
|
||||
if(event.client.isPaused) {
|
||||
if (event.client.isPaused) {
|
||||
return@subscribe
|
||||
}
|
||||
val nearbyShinies = player?.level()?.getEntities(player, AABB.ofSize(player.position(), 16.0, 16.0, 16.0)) { (it is PokemonEntity) && it.pokemon.shiny }
|
||||
val nearbyShinies = player.level().getEntities(player, AABB.ofSize(player.position(), 16.0, 16.0, 16.0)) { it is PokemonEntity && it.pokemon.shiny && !it.isSilent }
|
||||
nearbyShinies?.firstOrNull { player.isLookingAt(it) && !player.isSpectator }.let {
|
||||
if(it is PokemonEntity)
|
||||
it.delegate.spawnShinyParticle(player!!)
|
||||
if (it is PokemonEntity) {
|
||||
it.delegate.spawnShinyParticle(player)
|
||||
}
|
||||
}
|
||||
}
|
||||
ClientPlayerIcon.onTick()
|
||||
|
||||
+2
-2
@@ -382,7 +382,7 @@ class PokemonClientDelegate : PosableState(), PokemonSideDelegate {
|
||||
val player = Minecraft.getInstance().player ?: return
|
||||
val isWithinRange = player.position().distanceTo(currentEntity.position()) <= Cobblemon.config.shinyNoticeParticlesDistance
|
||||
|
||||
if (currentEntity.pokemon.shiny && currentEntity.ownerUUID == null) {
|
||||
if (currentEntity.pokemon.shiny && currentEntity.ownerUUID == null && !currentEntity.isSilent) {
|
||||
if (isWithinRange) {
|
||||
if (secondsSinceLastShinyParticle > SHINY_PARTICLE_COOLDOWN && !currentEntity.isBattling) {
|
||||
playShinyEffect("cobblemon:shiny_sparkle_ambient_wild")
|
||||
@@ -420,7 +420,7 @@ class PokemonClientDelegate : PosableState(), PokemonSideDelegate {
|
||||
}
|
||||
|
||||
override fun spawnShinyParticle(player: Player) {
|
||||
if(secondsSinceLastShinyParticle > SHINY_PARTICLE_COOLDOWN) {
|
||||
if (secondsSinceLastShinyParticle > SHINY_PARTICLE_COOLDOWN) {
|
||||
playShinyEffect("cobblemon:ambient_shiny_sparkle")
|
||||
lastShinyParticle = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ class PasturePokemonScrollList(
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = "${children().count { it.isOwned() }}/${config.permissions.maxPokemon.takeIf { it >= 0 } ?: config.limit }".text().bold(),
|
||||
x = x + (WIDTH / 2),
|
||||
y = y - 9,
|
||||
y = y - 7,
|
||||
centered = true
|
||||
)
|
||||
}
|
||||
|
||||
@@ -15,67 +15,60 @@ import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.storage.ClientBox
|
||||
import com.cobblemon.mod.common.net.messages.server.storage.pc.RequestRenamePCBoxPacket
|
||||
import com.mojang.blaze3d.platform.InputConstants
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.EditBox
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.network.chat.MutableComponent
|
||||
|
||||
class BoxNameWidget(
|
||||
private val pX: Int,
|
||||
pX: Int,
|
||||
pY: Int,
|
||||
text: Component = "BoxNameWidget".text(),
|
||||
private val pcGui: PCGUI,
|
||||
private val storageWidget: StorageWidget,
|
||||
): EditBox(Minecraft.getInstance().font, pX, pY, 0, HEIGHT, text) {
|
||||
|
||||
companion object {
|
||||
const val HEIGHT = 14
|
||||
}
|
||||
|
||||
init {
|
||||
setMaxLength(21)
|
||||
update()
|
||||
setResponder { update() }
|
||||
}
|
||||
private val storageWidget: StorageWidget
|
||||
): TextWidget(pX, pY, text = text, update = {}) {
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
if (cursorPosition != value.length) moveCursorToEnd(false)
|
||||
val label = getBox().name?: defaultBoxLabel()
|
||||
val input = applyTextCursor(value, label).bold()
|
||||
val textWidth = Minecraft.getInstance().font.width((if (isFocused) value.text() else label).bold().font(CobblemonResources.DEFAULT_LARGE))
|
||||
val centerX = x + (width / 2) - (textWidth / 2)
|
||||
if (startPosX != centerX) startPosX = centerX
|
||||
|
||||
drawScaledText(
|
||||
context = context,
|
||||
text = text(),
|
||||
x = x,
|
||||
y = y
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
x = startPosX,
|
||||
y = y + 3,
|
||||
text = input,
|
||||
)
|
||||
|
||||
renderCursor(context, label)
|
||||
}
|
||||
|
||||
override fun setFocused(focused: Boolean) {
|
||||
super.setFocused(focused)
|
||||
update()
|
||||
if (!focused) {
|
||||
RequestRenamePCBoxPacket(pcGui.pc.uuid, storageWidget.box, value).sendToServer()
|
||||
pcGui.pc.boxes[storageWidget.box].name = if (value.isBlank()) null else Component.literal(value).bold()
|
||||
value = ""
|
||||
// Set text value to box's saved name if applicable on focus
|
||||
if (focused && value.isEmpty() && getBox().name != null) {
|
||||
value = getBox().name?.string ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
private fun text(): MutableComponent {
|
||||
return (if (isFocused) {
|
||||
"${value}_".text()
|
||||
} else if (value.isEmpty()) {
|
||||
getBox().name?: Component.translatable("cobblemon.ui.pc.box.title", storageWidget.box + 1)
|
||||
} else {
|
||||
value.text()
|
||||
}).bold().font(CobblemonResources.DEFAULT_LARGE)
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
// Reset box name
|
||||
if (isFocused && keyCode == InputConstants.KEY_ESCAPE) value = getBox().name?.string ?: ""
|
||||
return super.keyPressed(keyCode, scanCode, modifiers)
|
||||
}
|
||||
|
||||
fun getBox(): ClientBox {
|
||||
return pcGui.pc.boxes[storageWidget.box]
|
||||
override fun unfocused() {
|
||||
super.unfocused()
|
||||
RequestRenamePCBoxPacket(pcGui.pc.uuid, storageWidget.box, value).sendToServer()
|
||||
getBox().name = if (value.isBlank()) null else Component.literal(value).bold()
|
||||
value = ""
|
||||
}
|
||||
|
||||
fun update() {
|
||||
width = Minecraft.getInstance().font.width(text())
|
||||
x = pX - width / 2
|
||||
}
|
||||
}
|
||||
fun getBox(): ClientBox = pcGui.pc.boxes[storageWidget.box]
|
||||
|
||||
fun defaultBoxLabel(): MutableComponent = Component.translatable("cobblemon.ui.pc.box.title", storageWidget.box + 1)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.client.gui.pc
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.api.text.font
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.util.lang
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.Component
|
||||
|
||||
class FilterWidget(
|
||||
private var pX: Int,
|
||||
private var pY: Int,
|
||||
text: Component = "FilterWidget".text(),
|
||||
update: () -> (Unit)
|
||||
): TextWidget(pX, pY, text = text, update = update) {
|
||||
|
||||
companion object {
|
||||
const val ICON_SIZE = 16
|
||||
const val SCALE = 0.5F
|
||||
|
||||
private val iconFilterResource = cobblemonResource("textures/gui/pc/pc_icon_filter.png")
|
||||
private val labelFilter = Component.translatable("cobblemon.ui.pc.filter")
|
||||
}
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
blitk(
|
||||
matrixStack = context.pose(),
|
||||
x = (x - 9) / SCALE,
|
||||
y = (y + 3) / SCALE,
|
||||
texture = iconFilterResource,
|
||||
width = ICON_SIZE,
|
||||
height = ICON_SIZE,
|
||||
vOffset = if (isFocused || !value.isEmpty() || iconHovered(mouseX, mouseY)) ICON_SIZE else 0,
|
||||
textureHeight = ICON_SIZE * 2,
|
||||
scale = SCALE
|
||||
)
|
||||
|
||||
val input = applyTextCursor(value, labelFilter)
|
||||
val textWidth = Minecraft.getInstance().font.width((if (!isFocused && value.isEmpty()) labelFilter else value.text()).bold().font(CobblemonResources.DEFAULT_LARGE))
|
||||
val centerX = x + (width / 2) - (textWidth / 2)
|
||||
if (startPosX != centerX) startPosX = centerX
|
||||
|
||||
drawScaledText(
|
||||
context = context,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = input.bold(),
|
||||
x = startPosX,
|
||||
y = pY + 2
|
||||
)
|
||||
|
||||
renderCursor(context, input)
|
||||
|
||||
if (iconHovered(mouseX, mouseY)) {
|
||||
context.renderTooltip(Minecraft.getInstance().font, lang("ui.pc.filter.tooltip"), mouseX, mouseY)
|
||||
}
|
||||
}
|
||||
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
if (iconHovered(mouseX.toInt(), mouseY.toInt())) {
|
||||
Minecraft.getInstance().soundManager.play(SimpleSoundInstance.forUI(CobblemonSounds.PC_CLICK, 1.0F, 0.25F))
|
||||
// Simulate clicking on text area if icon is clicked
|
||||
if (!isFocused) return super.mouseClicked(x + (width / 2.0), y + (height / 2.0), button)
|
||||
}
|
||||
return super.mouseClicked(mouseX, mouseY, button)
|
||||
}
|
||||
|
||||
fun iconHovered(mouseX: Int, mouseY: Int): Boolean = mouseX >= (x - 9) && mouseY >= (y + 3)
|
||||
&& mouseX <= ((x - 9) + (ICON_SIZE * SCALE)) && mouseY <= ((y + 3) + (ICON_SIZE * SCALE))
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.client.gui.pc
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.util.lang
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.client.sounds.SoundManager
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
|
||||
class IconButton(
|
||||
pX: Int, pY: Int,
|
||||
val buttonWidth: Int,
|
||||
val buttonHeight: Int,
|
||||
val resource: ResourceLocation,
|
||||
val altResource: ResourceLocation? = null,
|
||||
val tooltipKey: String? = null,
|
||||
label: String,
|
||||
onPress: OnPress,
|
||||
): Button(pX, pY, (buttonWidth * SCALE).toInt(), (buttonHeight * SCALE).toInt(), Component.literal(label), onPress, DEFAULT_NARRATION), CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
private const val SCALE = 0.5F
|
||||
}
|
||||
|
||||
var highlighted = false
|
||||
var showAlt = false
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, partialTicks: Float) {
|
||||
|
||||
blitk(
|
||||
matrixStack = context.pose(),
|
||||
x = x / SCALE,
|
||||
y = y / SCALE,
|
||||
texture = if (altResource != null && showAlt) altResource else resource,
|
||||
width = buttonWidth,
|
||||
height = buttonHeight,
|
||||
vOffset = if (isHovered() || highlighted) buttonHeight else 0,
|
||||
textureHeight = buttonHeight * 2,
|
||||
scale = SCALE
|
||||
)
|
||||
|
||||
if (isHovered()) {
|
||||
tooltipKey?.let {
|
||||
context.renderTooltip(Minecraft.getInstance().font, lang(it), mouseX, mouseY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun playDownSound(soundManager: SoundManager) {
|
||||
soundManager.play(SimpleSoundInstance.forUI(CobblemonSounds.PC_CLICK, 1.0F))
|
||||
}
|
||||
}
|
||||
@@ -22,11 +22,10 @@ class NavigationButton(
|
||||
pX: Int, pY: Int,
|
||||
private val forward: Boolean,
|
||||
onPress: OnPress
|
||||
): Button(pX, pY, (WIDTH * SCALE).toInt(), (HEIGHT * SCALE).toInt(), Component.literal("Navigation"), onPress, DEFAULT_NARRATION), CobblemonRenderable {
|
||||
): Button(pX, pY, (SIZE * SCALE).toInt(), (SIZE * SCALE).toInt(), Component.literal("Navigation"), onPress, DEFAULT_NARRATION), CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
private const val WIDTH = 8F
|
||||
private const val HEIGHT = 10F
|
||||
private const val SIZE = 14
|
||||
private const val SCALE = 0.5F
|
||||
private val forwardButtonResource = cobblemonResource("textures/gui/pc/pc_arrow_next.png")
|
||||
private val backwardsButtonResource = cobblemonResource("textures/gui/pc/pc_arrow_previous.png")
|
||||
@@ -38,10 +37,10 @@ class NavigationButton(
|
||||
x = x / SCALE,
|
||||
y = y / SCALE,
|
||||
texture = if (forward) forwardButtonResource else backwardsButtonResource,
|
||||
width = WIDTH,
|
||||
height = HEIGHT,
|
||||
vOffset = if (isHovered()) HEIGHT else 0,
|
||||
textureHeight = HEIGHT * 2,
|
||||
width = SIZE,
|
||||
height = SIZE,
|
||||
vOffset = if (isHovered()) SIZE else 0,
|
||||
textureHeight = SIZE * 2,
|
||||
scale = SCALE
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ package com.cobblemon.mod.common.client.gui.pc
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.pokemon.PokemonSortMode
|
||||
import com.cobblemon.mod.common.api.storage.pc.search.Search
|
||||
import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
@@ -23,6 +24,7 @@ import com.cobblemon.mod.common.client.gui.summary.widgets.common.reformatNature
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.storage.ClientPC
|
||||
import com.cobblemon.mod.common.client.storage.ClientParty
|
||||
import com.cobblemon.mod.common.net.messages.server.storage.pc.MarkPCBoxWallpapersSeenPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.storage.pc.SortPCBoxPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.storage.pc.UnlinkPlayerFromPCPacket
|
||||
import com.cobblemon.mod.common.pokemon.Gender
|
||||
@@ -39,12 +41,14 @@ import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import kotlin.isInitialized
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
|
||||
class PCGUI(
|
||||
val pc: ClientPC,
|
||||
val party: ClientParty,
|
||||
val configuration: PCGUIConfiguration,
|
||||
val openOnBox: Int = 0
|
||||
val openOnBox: Int = 0,
|
||||
val unseenWallpapers: MutableSet<ResourceLocation> = mutableSetOf()
|
||||
) : Screen(Component.translatable("cobblemon.ui.pc.title")), CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
@@ -61,6 +65,10 @@ class PCGUI(
|
||||
|
||||
private val baseResource = cobblemonResource("textures/gui/pc/pc_base.png")
|
||||
private val portraitBackgroundResource = cobblemonResource("textures/gui/pc/portrait_background.png")
|
||||
|
||||
private val buttonOptionsResource = cobblemonResource("textures/gui/pc/pc_icon_options.png")
|
||||
private val buttonWallpaperResource = cobblemonResource("textures/gui/pc/pc_button_set_wallpaper.png")
|
||||
|
||||
private val topSpacerResource = cobblemonResource("textures/gui/pc/pc_spacer_top.png")
|
||||
private val bottomSpacerResource = cobblemonResource("textures/gui/pc/pc_spacer_bottom.png")
|
||||
private val rightSpacerResource = cobblemonResource("textures/gui/pc/pc_spacer_right.png")
|
||||
@@ -71,17 +79,21 @@ class PCGUI(
|
||||
|
||||
private lateinit var storageWidget: StorageWidget
|
||||
private lateinit var boxNameWidget: BoxNameWidget
|
||||
private lateinit var searchWidget: SearchWidget
|
||||
private lateinit var filterWidget: FilterWidget
|
||||
private lateinit var wallpaperWidget: WallpapersScrollingWidget
|
||||
|
||||
private var modelWidget: ModelWidget? = null
|
||||
internal var previewPokemon: Pokemon? = null
|
||||
|
||||
private val optionButtons: MutableList<IconButton> = mutableListOf()
|
||||
|
||||
var search: Search = Search.DEFAULT
|
||||
var ticksElapsed = 0
|
||||
var selectPointerOffsetY = 0
|
||||
var selectPointerOffsetIncrement = false
|
||||
var displayOptions = false
|
||||
|
||||
override fun renderBlurredBackground(delta: Float) { }
|
||||
override fun renderBlurredBackground(delta: Float) {}
|
||||
|
||||
override fun renderMenuBackground(context: GuiGraphics) {}
|
||||
|
||||
@@ -90,40 +102,44 @@ class PCGUI(
|
||||
val y = (height - BASE_HEIGHT) / 2
|
||||
|
||||
// Add Exit Button
|
||||
this.addRenderableWidget(ExitButton(pX = x + 320, pY = y + 186) { configuration.exitFunction(this) })
|
||||
this.addRenderableWidget(
|
||||
ExitButton(pX = x + 320, pY = y + 186) {
|
||||
if (::wallpaperWidget.isInitialized && wallpaperWidget.visible) {
|
||||
wallpaperWidget.visible = false
|
||||
configuration.showParty = true
|
||||
for (button in optionButtons) button.highlighted = false
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
} else {
|
||||
configuration.exitFunction(this)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// Add Forward Button
|
||||
this.addRenderableWidget(
|
||||
NavigationButton(
|
||||
pX = x + 221,
|
||||
pY = y + 17,
|
||||
pX = x + 220,
|
||||
pY = y + 16,
|
||||
forward = true
|
||||
) {
|
||||
storageWidget.box += 1
|
||||
}
|
||||
) { storageWidget.box += 1 }
|
||||
)
|
||||
|
||||
// Add Backwards Button
|
||||
this.addRenderableWidget(
|
||||
NavigationButton(
|
||||
pX = x + 119,
|
||||
pY = y + 17,
|
||||
pX = x + 117,
|
||||
pY = y + 16,
|
||||
forward = false
|
||||
) {
|
||||
storageWidget.box -= 1
|
||||
}
|
||||
) { storageWidget.box -= 1 }
|
||||
)
|
||||
|
||||
// Add Sort Button
|
||||
addRenderableWidget(
|
||||
SortButton(
|
||||
pX = x + 85,
|
||||
pY = y + 12,
|
||||
onPress = { it as SortButton
|
||||
SortPCBoxPacket(pc.uuid, storageWidget.box, it.sortMode, hasShiftDown()).sendToServer()
|
||||
}
|
||||
)
|
||||
// Add Filter Widget
|
||||
this.filterWidget = FilterWidget(
|
||||
pX = x + 126,
|
||||
pY = y + 183,
|
||||
update = { search = Search.of(filterWidget.value) }
|
||||
)
|
||||
this.addRenderableWidget(filterWidget)
|
||||
|
||||
// Add Storage
|
||||
this.storageWidget = StorageWidget(
|
||||
@@ -134,48 +150,97 @@ class PCGUI(
|
||||
party = party
|
||||
)
|
||||
this.storageWidget.box = openOnBox
|
||||
this.addRenderableWidget(storageWidget)
|
||||
|
||||
// Add Box Name
|
||||
this.boxNameWidget = BoxNameWidget(
|
||||
pX = x + 172,
|
||||
pY = y + 15,
|
||||
pX = x + 126,
|
||||
pY = y + 12,
|
||||
pcGui = this,
|
||||
storageWidget = storageWidget
|
||||
)
|
||||
this.addRenderableWidget(boxNameWidget)
|
||||
|
||||
// Add Search Widget
|
||||
this.searchWidget = SearchWidget(
|
||||
pX = x + 117,
|
||||
pY = y + 183,
|
||||
update = { search = Search.of(searchWidget.value) }
|
||||
)
|
||||
|
||||
// Add Wallpaper Button
|
||||
this.addRenderableWidget(
|
||||
WallpaperButton(
|
||||
pX = x + 235,
|
||||
pY = y + 12,
|
||||
onPress = {
|
||||
configuration.showParty = wallpaperWidget.visible
|
||||
wallpaperWidget.visible = !wallpaperWidget.visible
|
||||
},
|
||||
pcGui = this
|
||||
// Initialise box options if not pasture
|
||||
if (storageWidget.pastureWidget == null) {
|
||||
optionButtons.clear()
|
||||
addRenderableWidget(
|
||||
IconButton(
|
||||
pX = x + 218,
|
||||
pY = y + 186,
|
||||
buttonWidth = 16,
|
||||
buttonHeight = 16,
|
||||
resource = buttonOptionsResource,
|
||||
label = "options"
|
||||
) {
|
||||
displayOptions = !displayOptions
|
||||
if (!displayOptions && wallpaperWidget.visible) {
|
||||
configuration.showParty = true
|
||||
wallpaperWidget.visible = false
|
||||
}
|
||||
(it as IconButton).highlighted = displayOptions
|
||||
storageWidget.setupStorageSlots()
|
||||
for (button in optionButtons) {
|
||||
button.visible = displayOptions
|
||||
button.highlighted = false
|
||||
}
|
||||
}.also { it.highlighted = displayOptions }
|
||||
)
|
||||
)
|
||||
|
||||
// Add Wallpaper Widget
|
||||
this.wallpaperWidget = WallpapersScrollingWidget(
|
||||
pX = x + 275,
|
||||
pY = y + 30,
|
||||
pcGui = this,
|
||||
storageWidget = storageWidget
|
||||
)
|
||||
// Add Wallpaper Widget
|
||||
this.wallpaperWidget = WallpapersScrollingWidget(
|
||||
pX = x + 274,
|
||||
pY = y + 29,
|
||||
pcGui = this,
|
||||
storageWidget = storageWidget
|
||||
).also {
|
||||
// Set default component visibility
|
||||
it.visible = false
|
||||
configuration.showParty = true
|
||||
}
|
||||
this.addRenderableWidget(wallpaperWidget)
|
||||
|
||||
// Add Wallpaper Settings Button
|
||||
this.addRenderableWidget(IconButton(
|
||||
pX = x + 242,
|
||||
pY = y + 31,
|
||||
buttonWidth = 20,
|
||||
buttonHeight = 20,
|
||||
resource = buttonWallpaperResource,
|
||||
label = "open_wallpaper_settings"
|
||||
) {
|
||||
val isVisible = wallpaperWidget.visible
|
||||
configuration.showParty = isVisible
|
||||
wallpaperWidget.visible = !isVisible
|
||||
(it as IconButton).highlighted = !isVisible
|
||||
if (!unseenWallpapers.isEmpty()) MarkPCBoxWallpapersSeenPacket(unseenWallpapers).sendToServer()
|
||||
}.also {
|
||||
it.visible = displayOptions
|
||||
optionButtons.add(it)
|
||||
})
|
||||
|
||||
PokemonSortMode.entries.forEachIndexed { index, sortType ->
|
||||
val typeName = sortType.name.lowercase()
|
||||
this.addRenderableWidget(IconButton(
|
||||
pX = x + 92 + (12 * index),
|
||||
pY = y + 31,
|
||||
buttonWidth = 20,
|
||||
buttonHeight = 20,
|
||||
resource = cobblemonResource("textures/gui/pc/pc_button_sort_${typeName}.png"),
|
||||
altResource = cobblemonResource("textures/gui/pc/pc_button_sort_${typeName}_reverse.png"),
|
||||
tooltipKey = "ui.sort.${typeName}",
|
||||
label = "sort_${typeName}"
|
||||
) {
|
||||
SortPCBoxPacket(pc.uuid, storageWidget.box, sortType, hasShiftDown()).sendToServer()
|
||||
}.also {
|
||||
it.visible = displayOptions
|
||||
optionButtons.add(it)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.setPreviewPokemon(null)
|
||||
this.addRenderableWidget(storageWidget)
|
||||
this.addRenderableWidget(boxNameWidget)
|
||||
this.addRenderableWidget(searchWidget)
|
||||
this.addRenderableWidget(wallpaperWidget)
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
@@ -460,6 +525,10 @@ class PCGUI(
|
||||
scale = SCALE
|
||||
)
|
||||
|
||||
if (!optionButtons.isEmpty() && displayOptions) {
|
||||
for (button in optionButtons) button.showAlt = hasShiftDown()
|
||||
}
|
||||
|
||||
super.render(context, mouseX, mouseY, delta)
|
||||
|
||||
// Item Tooltip
|
||||
@@ -485,60 +554,59 @@ class PCGUI(
|
||||
}
|
||||
}
|
||||
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
// Trigger child component function as they will need to check the entire screen click area
|
||||
if (::boxNameWidget.isInitialized) boxNameWidget.mouseClicked(mouseX, mouseY, button)
|
||||
return super.mouseClicked(mouseX, mouseY, button)
|
||||
}
|
||||
|
||||
override fun mouseScrolled(mouseX: Double, mouseY: Double, amount: Double, verticalAmount: Double): Boolean {
|
||||
if (storageWidget.pastureWidget != null) storageWidget.pastureWidget!!.pastureScrollList.mouseScrolled(
|
||||
mouseX,
|
||||
mouseY,
|
||||
amount,
|
||||
verticalAmount
|
||||
)
|
||||
if (storageWidget.pastureWidget != null) storageWidget.pastureWidget!!.pastureScrollList.mouseScrolled(mouseX, mouseY, amount, verticalAmount)
|
||||
return children().any { it.mouseScrolled(mouseX, mouseY, amount, verticalAmount) }
|
||||
}
|
||||
|
||||
override fun mouseDragged(mouseX: Double, mouseY: Double, button: Int, deltaX: Double, deltaY: Double): Boolean {
|
||||
if (storageWidget.pastureWidget != null) storageWidget.pastureWidget!!.pastureScrollList.mouseDragged(
|
||||
mouseX,
|
||||
mouseY,
|
||||
button,
|
||||
deltaX,
|
||||
deltaY
|
||||
)
|
||||
if (storageWidget.pastureWidget != null) storageWidget.pastureWidget!!.pastureScrollList.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)
|
||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)
|
||||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
val boxNameSelected = this::boxNameWidget.isInitialized && boxNameWidget.isFocused
|
||||
val searchSelected = this::searchWidget.isInitialized && searchWidget.isFocused
|
||||
if (isInventoryKeyPressed(minecraft, keyCode, scanCode) && !boxNameSelected && !searchSelected) {
|
||||
val boxNameFocused = this::boxNameWidget.isInitialized && boxNameWidget.isFocused
|
||||
val filterFocused = this::filterWidget.isInitialized && filterWidget.isFocused
|
||||
|
||||
if (isInventoryKeyPressed(minecraft, keyCode, scanCode) && !boxNameFocused && !filterFocused) {
|
||||
playSound(CobblemonSounds.PC_OFF)
|
||||
UnlinkPlayerFromPCPacket().sendToServer()
|
||||
Minecraft.getInstance().setScreen(null)
|
||||
return true
|
||||
}
|
||||
|
||||
if ((keyCode == InputConstants.KEY_RETURN || keyCode == InputConstants.KEY_NUMPADENTER)
|
||||
&& (boxNameSelected || searchSelected)) {
|
||||
if (!filterFocused && !boxNameFocused) {
|
||||
when (keyCode) {
|
||||
InputConstants.KEY_ESCAPE -> {
|
||||
playSound(CobblemonSounds.PC_OFF)
|
||||
UnlinkPlayerFromPCPacket().sendToServer()
|
||||
onClose()
|
||||
return true
|
||||
}
|
||||
InputConstants.KEY_RIGHT -> {
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
this.storageWidget.box += 1
|
||||
return true
|
||||
}
|
||||
InputConstants.KEY_LEFT -> {
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
this.storageWidget.box -= 1
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else if (keyCode == InputConstants.KEY_ESCAPE) {
|
||||
// Escape from text box
|
||||
if (::boxNameWidget.isInitialized) boxNameWidget.keyPressed(keyCode, scanCode, modifiers)
|
||||
this.focused = null
|
||||
return true
|
||||
}
|
||||
|
||||
when (keyCode) {
|
||||
InputConstants.KEY_ESCAPE -> {
|
||||
playSound(CobblemonSounds.PC_OFF)
|
||||
UnlinkPlayerFromPCPacket().sendToServer()
|
||||
onClose()
|
||||
return true
|
||||
}
|
||||
InputConstants.KEY_RIGHT -> {
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
this.storageWidget.box += 1
|
||||
return true
|
||||
}
|
||||
InputConstants.KEY_LEFT -> {
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
this.storageWidget.box -= 1
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, modifiers)
|
||||
}
|
||||
|
||||
@@ -581,10 +649,4 @@ class PCGUI(
|
||||
modelWidget = null
|
||||
}
|
||||
}
|
||||
|
||||
fun updateBoxName() {
|
||||
if (this::boxNameWidget.isInitialized) {
|
||||
boxNameWidget.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +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.client.gui.pc
|
||||
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.EditBox
|
||||
import net.minecraft.network.chat.Component
|
||||
|
||||
class SearchWidget(
|
||||
private var pX: Int,
|
||||
private var pY: Int,
|
||||
text: Component = "SearchWidget".text(),
|
||||
update: () -> (Unit)
|
||||
): EditBox(Minecraft.getInstance().font, pX, pY, WIDTH, HEIGHT, text) {
|
||||
|
||||
companion object {
|
||||
const val WIDTH = 110
|
||||
const val HEIGHT = 14
|
||||
const val HINT_COLOUR = 0x8D8D8D
|
||||
private val hint = Component.translatable("cobblemon.ui.pc.search")
|
||||
private val searchIcon = cobblemonResource("textures/gui/pc/pc_search_icon.png")
|
||||
}
|
||||
|
||||
init {
|
||||
setMaxLength(21)
|
||||
setResponder { update() }
|
||||
}
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
if (cursorPosition != value.length) moveCursorToEnd(false)
|
||||
val input = if (isFocused) "${value}_".text() else value.text()
|
||||
val useHint = !isFocused && value.isEmpty()
|
||||
|
||||
blitk(
|
||||
matrixStack = context.pose(),
|
||||
texture = searchIcon,
|
||||
x = pX + 1,
|
||||
y = pY + 3,
|
||||
width = 8,
|
||||
height = 8
|
||||
)
|
||||
|
||||
drawScaledText(
|
||||
context = context,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = if (useHint) hint.bold() else input.bold(),
|
||||
x = pX + if (useHint) 55 else 14,
|
||||
y = pY + 2,
|
||||
colour = if (useHint) HINT_COLOUR else 0xFFFFFF,
|
||||
centered = useHint
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,78 +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.client.gui.pc
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.pokemon.PokemonSortMode
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.client.sounds.SoundManager
|
||||
import net.minecraft.network.chat.Component
|
||||
import kotlin.math.abs
|
||||
|
||||
class SortButton(
|
||||
pX: Int, pY: Int,
|
||||
onPress: OnPress,
|
||||
) : Button(pX, pY, WIDTH, HEIGHT, Component.literal("SortButton"), onPress, DEFAULT_NARRATION) {
|
||||
|
||||
var sortMode = PokemonSortMode.NAME
|
||||
|
||||
companion object {
|
||||
const val WIDTH = 24
|
||||
const val HEIGHT = 11
|
||||
|
||||
private val modeResources = PokemonSortMode.entries.map { cobblemonResource("textures/gui/pc/pc_sort_${it.name.lowercase()}.png") }
|
||||
private val buttonResource = cobblemonResource("textures/gui/pc/pc_sort_button.png")
|
||||
}
|
||||
|
||||
override fun renderWidget(context: net.minecraft.client.gui.GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
blitk(
|
||||
matrixStack = context.pose(),
|
||||
texture = buttonResource,
|
||||
x = x,
|
||||
y = y,
|
||||
width = WIDTH,
|
||||
height = HEIGHT,
|
||||
vOffset = if (isHovered()) HEIGHT else 0,
|
||||
textureHeight = HEIGHT * 2
|
||||
)
|
||||
|
||||
blitk(
|
||||
matrixStack = context.pose(),
|
||||
texture = modeResources[sortMode.ordinal],
|
||||
x = x,
|
||||
y = y,
|
||||
width = WIDTH,
|
||||
height = HEIGHT
|
||||
)
|
||||
}
|
||||
|
||||
override fun mouseScrolled(
|
||||
mouseX: Double,
|
||||
mouseY: Double,
|
||||
scrollX: Double,
|
||||
scrollY: Double
|
||||
): Boolean {
|
||||
if (abs(scrollY) >= .5 && isMouseOver(mouseX, mouseY)) {
|
||||
val modes = PokemonSortMode.entries
|
||||
var mode = sortMode.ordinal + if (scrollY > 0) 1 else -1
|
||||
if (mode < 0) mode = modes.size - 1
|
||||
if (mode >= modes.size) mode = 0
|
||||
sortMode = modes[mode]
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun playDownSound(soundManager: SoundManager) {
|
||||
soundManager.play(SimpleSoundInstance.forUI(CobblemonSounds.PC_CLICK, 1.0F))
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ package com.cobblemon.mod.common.client.gui.pc
|
||||
import com.cobblemon.mod.common.CobblemonNetwork
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.gui.getPixelRGB
|
||||
import com.cobblemon.mod.common.api.storage.StorePosition
|
||||
import com.cobblemon.mod.common.api.storage.party.PartyPosition
|
||||
import com.cobblemon.mod.common.api.storage.pc.PCPosition
|
||||
@@ -20,6 +21,7 @@ import com.cobblemon.mod.common.client.gui.pasture.PasturePCGUIConfiguration
|
||||
import com.cobblemon.mod.common.client.gui.pasture.PastureWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.SoundlessWidget
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.render.gui.PCBoxWallpaperRepository
|
||||
import com.cobblemon.mod.common.client.settings.ServerSettings
|
||||
import com.cobblemon.mod.common.client.storage.ClientPC
|
||||
import com.cobblemon.mod.common.client.storage.ClientParty
|
||||
@@ -37,6 +39,7 @@ import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
|
||||
class StorageWidget(
|
||||
@@ -49,6 +52,8 @@ class StorageWidget(
|
||||
companion object {
|
||||
const val WIDTH = 263
|
||||
const val HEIGHT = 155
|
||||
const val SCREEN_WIDTH = 174
|
||||
const val SCREEN_HEIGHT = 155
|
||||
const val BOX_SLOT_START_OFFSET_X = 7
|
||||
const val BOX_SLOT_START_OFFSET_Y = 11
|
||||
const val PARTY_SLOT_START_OFFSET_X = 193
|
||||
@@ -57,6 +62,9 @@ class StorageWidget(
|
||||
const val PARTY_SLOT_PADDING = 6
|
||||
|
||||
private val partyPanelResource = cobblemonResource("textures/gui/pc/party_panel.png")
|
||||
private val screenOverlayResource = cobblemonResource("textures/gui/pc/pc_screen_overlay.png")
|
||||
private val screenGridResource = cobblemonResource("textures/gui/pc/pc_screen_grid.png")
|
||||
private val screenGlowResource = cobblemonResource("textures/gui/pc/pc_screen_glow.png")
|
||||
}
|
||||
|
||||
private val partySlots = arrayListOf<PartyStorageSlot>()
|
||||
@@ -81,7 +89,6 @@ class StorageWidget(
|
||||
// Else it's greater than max, wrap around to start
|
||||
else 0
|
||||
this.setupStorageSlots()
|
||||
this.pcGui.updateBoxName()
|
||||
}
|
||||
|
||||
init {
|
||||
@@ -147,13 +154,13 @@ class StorageWidget(
|
||||
&& grabbedSlot != null
|
||||
}
|
||||
|
||||
private fun setupStorageSlots() {
|
||||
fun setupStorageSlots() {
|
||||
this.resetStorageSlots()
|
||||
var index = 0
|
||||
|
||||
// Box Slots
|
||||
val boxStartX = x + BOX_SLOT_START_OFFSET_X
|
||||
val boxStartY = y + BOX_SLOT_START_OFFSET_Y
|
||||
val boxStartY = y + BOX_SLOT_START_OFFSET_Y + (if (pcGui.displayOptions) 5 else 0)
|
||||
|
||||
for (row in 1..5) {
|
||||
for (col in 1..6) {
|
||||
@@ -173,32 +180,30 @@ class StorageWidget(
|
||||
}
|
||||
|
||||
// Party Slots
|
||||
if (pcGui.configuration.showParty) {
|
||||
for (partyIndex in 0..5) {
|
||||
var partyX = x + PARTY_SLOT_START_OFFSET_X
|
||||
var partyY = y + PARTY_SLOT_START_OFFSET_Y
|
||||
for (partyIndex in 0..5) {
|
||||
var partyX = x + PARTY_SLOT_START_OFFSET_X
|
||||
var partyY = y + PARTY_SLOT_START_OFFSET_Y
|
||||
|
||||
if (partyIndex > 0) {
|
||||
val isEven = partyIndex % 2 == 0
|
||||
val offsetIndex = (partyIndex - (if (isEven) 0 else 1)) / 2
|
||||
val offsetX = if (isEven) 0 else (StorageSlot.SIZE + PARTY_SLOT_PADDING)
|
||||
val offsetY = if (isEven) 0 else 8
|
||||
if (partyIndex > 0) {
|
||||
val isEven = partyIndex % 2 == 0
|
||||
val offsetIndex = (partyIndex - (if (isEven) 0 else 1)) / 2
|
||||
val offsetX = if (isEven) 0 else (StorageSlot.SIZE + PARTY_SLOT_PADDING)
|
||||
val offsetY = if (isEven) 0 else 8
|
||||
|
||||
partyX += offsetX
|
||||
partyY += ((StorageSlot.SIZE + PARTY_SLOT_PADDING) * offsetIndex) + offsetY
|
||||
}
|
||||
partyX += offsetX
|
||||
partyY += ((StorageSlot.SIZE + PARTY_SLOT_PADDING) * offsetIndex) + offsetY
|
||||
}
|
||||
|
||||
PartyStorageSlot(
|
||||
x = partyX,
|
||||
y = partyY,
|
||||
parent = this,
|
||||
party = party,
|
||||
position = PartyPosition(partyIndex),
|
||||
onPress = { this.onStorageSlotClicked(it) }
|
||||
).also { widget ->
|
||||
this.addWidget(widget)
|
||||
this.partySlots.add(widget)
|
||||
}
|
||||
PartyStorageSlot(
|
||||
x = partyX,
|
||||
y = partyY,
|
||||
parent = this,
|
||||
party = party,
|
||||
position = PartyPosition(partyIndex),
|
||||
onPress = { this.onStorageSlotClicked(it) }
|
||||
).also { widget ->
|
||||
this.addWidget(widget)
|
||||
this.partySlots.add(widget)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +240,6 @@ class StorageWidget(
|
||||
shadow = true
|
||||
)
|
||||
|
||||
|
||||
if (canDeleteSelected() && displayConfirmRelease) {
|
||||
drawScaledText(
|
||||
context = context,
|
||||
@@ -252,17 +256,66 @@ class StorageWidget(
|
||||
this.releaseNoButton.render(context, mouseX, mouseY, delta)
|
||||
}
|
||||
|
||||
// Screen Overlay
|
||||
val boxWallpaper = pc.boxes[box].wallpaper
|
||||
val screenResource: Pair<ResourceLocation, ResourceLocation?> =
|
||||
PCBoxWallpaperRepository.allWallpapers.find { it.first == boxWallpaper }
|
||||
?: PCBoxWallpaperRepository.allWallpapers.find { it.first == PCBoxWallpaperRepository.defaultWallpaper }
|
||||
?: Pair(PCBoxWallpaperRepository.defaultWallpaper, null)
|
||||
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = pc.boxes[box].wallpaper,
|
||||
x = x - 17,
|
||||
y = y - 17,
|
||||
width = 208,
|
||||
height = 189,
|
||||
texture = screenResource.first,
|
||||
x = x,
|
||||
y = y,
|
||||
width = SCREEN_WIDTH,
|
||||
height = SCREEN_HEIGHT,
|
||||
alpha = if (screenLoaded) 1F else ((pcGui.ticksElapsed).toFloat() / 10F).coerceIn(0F, 1F)
|
||||
)
|
||||
|
||||
if (screenResource.second !== null) {
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = screenResource.second,
|
||||
x = x - 17,
|
||||
y = y - 17,
|
||||
width = 208,
|
||||
height = 189,
|
||||
alpha = if (screenLoaded) 1F else ((pcGui.ticksElapsed).toFloat() / 10F).coerceIn(0F, 1F)
|
||||
)
|
||||
} else {
|
||||
val rgb = getPixelRGB(x + (SCREEN_WIDTH / 2), y + (SCREEN_HEIGHT / 2))
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = screenGlowResource,
|
||||
x = x - 17,
|
||||
y = y - 17,
|
||||
width = 208,
|
||||
height = 189,
|
||||
red = rgb.first / 255F,
|
||||
green = rgb.second / 255F,
|
||||
blue = rgb.third / 255F,
|
||||
alpha = if (screenLoaded) 1F else ((pcGui.ticksElapsed).toFloat() / 10F).coerceIn(0F, 1F)
|
||||
)
|
||||
}
|
||||
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = screenGridResource,
|
||||
x = x + 7,
|
||||
y = y + if (pcGui.displayOptions) 16 else 11,
|
||||
width = 160,
|
||||
height = 133
|
||||
)
|
||||
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = screenOverlayResource,
|
||||
x = x,
|
||||
y = y,
|
||||
width = SCREEN_WIDTH,
|
||||
height = SCREEN_HEIGHT
|
||||
)
|
||||
|
||||
if (screenLoaded) {
|
||||
this.boxSlots.forEach { slot ->
|
||||
slot.render(context, mouseX, mouseY, delta)
|
||||
@@ -435,4 +488,4 @@ class StorageWidget(
|
||||
grabbedSlot = null
|
||||
pcGui.setPreviewPokemon(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.client.gui.pc
|
||||
|
||||
import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.api.text.font
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.mojang.blaze3d.platform.InputConstants
|
||||
import net.minecraft.Util
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.EditBox
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.renderer.RenderType
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.network.chat.MutableComponent
|
||||
|
||||
abstract class TextWidget(
|
||||
pX: Int,
|
||||
pY: Int,
|
||||
width: Int = 91,
|
||||
height: Int = 14,
|
||||
maxLength: Int = 19,
|
||||
text: Component = "TextWidget".text(),
|
||||
update: () -> (Unit)
|
||||
): EditBox(Minecraft.getInstance().font, pX, pY, width, height, text), CobblemonRenderable {
|
||||
|
||||
var focusedTime: Long = 0
|
||||
var showCursor: Boolean = false
|
||||
var startPosX: Int = 0
|
||||
|
||||
init {
|
||||
setMaxLength(maxLength)
|
||||
setResponder { update() }
|
||||
focusedTime = Util.getMillis()
|
||||
startPosX = x
|
||||
}
|
||||
|
||||
fun applyTextCursor(string: String, placeholder: MutableComponent): MutableComponent {
|
||||
showCursor = isFocused && ((Util.getMillis() - this.focusedTime) / 300L % 2L == 0L)
|
||||
return if (isFocused) "${string}${if ((cursorPosition == string.length) && showCursor) "_" else ""}".text()
|
||||
else (if(string.isEmpty()) placeholder else string.text())
|
||||
}
|
||||
|
||||
fun renderCursor(context: GuiGraphics, text: MutableComponent) {
|
||||
if (showCursor && !value.isEmpty() && cursorPosition != value.length) {
|
||||
val startToCursorWidth = Minecraft.getInstance().font.width((text.getString(cursorPosition).text().bold()).font(CobblemonResources.DEFAULT_LARGE))
|
||||
context.fill(
|
||||
RenderType.guiTextHighlight(),
|
||||
startPosX + startToCursorWidth - 1,
|
||||
y + 2,
|
||||
startPosX + startToCursorWidth,
|
||||
y + 11,
|
||||
-3092272
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
open fun unfocused() {
|
||||
isFocused = false
|
||||
}
|
||||
|
||||
override fun setFocused(focused: Boolean) {
|
||||
if (focused) focusedTime = Util.getMillis()
|
||||
super.setFocused(focused)
|
||||
}
|
||||
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
if (isFocused && !isMouseOver(mouseX, mouseY)) unfocused()
|
||||
|
||||
val result = super.mouseClicked(mouseX, mouseY, button)
|
||||
|
||||
if (mouseX > startPosX + Minecraft.getInstance().font.width(value.text().bold().font(CobblemonResources.DEFAULT_LARGE))) {
|
||||
moveCursorToEnd(false)
|
||||
} else {
|
||||
var lineSubstring = ""
|
||||
for (char in value) {
|
||||
lineSubstring += char
|
||||
val startToLineWidth = Minecraft.getInstance().font.width(lineSubstring.text().bold().font(CobblemonResources.DEFAULT_LARGE))
|
||||
if ((mouseX - startPosX) <= startToLineWidth) break
|
||||
}
|
||||
moveCursorTo(maxOf(0, lineSubstring.length - 1), Screen.hasShiftDown())
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
if (isFocused && (keyCode == InputConstants.KEY_RETURN || keyCode == InputConstants.KEY_NUMPADENTER)) unfocused()
|
||||
return super.keyPressed(keyCode, scanCode, modifiers)
|
||||
}
|
||||
}
|
||||
@@ -1,48 +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.client.gui.pc
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.client.sounds.SoundManager
|
||||
import net.minecraft.network.chat.Component
|
||||
|
||||
class WallpaperButton(
|
||||
pX: Int, pY: Int,
|
||||
onPress: OnPress,
|
||||
private val pcGui: PCGUI
|
||||
) : Button(pX, pY, WIDTH, HEIGHT, Component.literal("WallpaperButton"), onPress, DEFAULT_NARRATION) {
|
||||
|
||||
companion object {
|
||||
const val WIDTH = 24
|
||||
const val HEIGHT = 11
|
||||
|
||||
private val buttonResource = cobblemonResource("textures/gui/pc/pc_wallpaper_button.png")
|
||||
}
|
||||
|
||||
override fun renderWidget(context: net.minecraft.client.gui.GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
blitk(
|
||||
matrixStack = context.pose(),
|
||||
texture = buttonResource,
|
||||
x = x,
|
||||
y = y,
|
||||
width = WIDTH,
|
||||
height = HEIGHT,
|
||||
vOffset = if (isHovered() || !pcGui.configuration.showParty) HEIGHT else 0,
|
||||
textureHeight = HEIGHT * 2
|
||||
)
|
||||
}
|
||||
|
||||
override fun playDownSound(soundManager: SoundManager) {
|
||||
soundManager.play(SimpleSoundInstance.forUI(CobblemonSounds.PC_CLICK, 1.0F))
|
||||
}
|
||||
}
|
||||
+39
-38
@@ -34,18 +34,18 @@ class WallpapersScrollingWidget(
|
||||
height = HEIGHT,
|
||||
left = pX,
|
||||
top = 0,
|
||||
slotHeight = SLOT_HEIGHT + SLOT_PADDING,
|
||||
scrollBarWidth = SCROLL_BAR_WIDTH
|
||||
slotHeight = SLOT_HEIGHT + SLOT_PADDING
|
||||
) {
|
||||
companion object {
|
||||
const val WIDTH = 67
|
||||
const val HEIGHT = 147
|
||||
const val SLOT_WIDTH = 58
|
||||
const val SLOT_HEIGHT = 53
|
||||
const val SLOT_PADDING = 3
|
||||
const val SCROLL_BAR_WIDTH = 3
|
||||
val ENTRY_HOVERED = cobblemonResource("textures/gui/pc/wallpaper_entry_hover.png")
|
||||
val BACKGROUND = cobblemonResource("textures/gui/pc/wallpaper_widget_background.png")
|
||||
const val WIDTH = 68
|
||||
const val HEIGHT = 146
|
||||
const val SLOT_WIDTH = 56
|
||||
const val SLOT_HEIGHT = 50
|
||||
const val SLOT_PADDING = 4
|
||||
|
||||
val previewOverlayResource = cobblemonResource("textures/gui/pc/pc_screen_overlay_preview.png")
|
||||
val previewOverlayNewResource = cobblemonResource("textures/gui/pc/pc_screen_overlay_preview_new.png")
|
||||
val backgroundResource = cobblemonResource("textures/gui/pc/wallpaper_scroll_background.png")
|
||||
}
|
||||
|
||||
init {
|
||||
@@ -54,38 +54,37 @@ class WallpapersScrollingWidget(
|
||||
createEntries()
|
||||
}
|
||||
|
||||
override fun renderWidget(
|
||||
context: GuiGraphics,
|
||||
mouseX: Int,
|
||||
mouseY: Int,
|
||||
delta: Float
|
||||
) {
|
||||
override fun getScrollbarPosition(): Int = x + width - 3
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
blitk(
|
||||
matrixStack = context.pose(),
|
||||
texture = BACKGROUND,
|
||||
x = x - 1,
|
||||
texture = backgroundResource,
|
||||
x = x,
|
||||
y = y - 1,
|
||||
width = width + 1,
|
||||
width = width,
|
||||
height = height + 2
|
||||
)
|
||||
|
||||
drawScaledText(
|
||||
context = context,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = lang("ui.wallpapers").bold(),
|
||||
text = lang("ui.pc.wallpaper").bold(),
|
||||
x = x + 23,
|
||||
y = y - 18.5,
|
||||
y = y - 18,
|
||||
centered = true,
|
||||
shadow = true
|
||||
)
|
||||
|
||||
context.enableScissor(x, y, x + width, y + height)
|
||||
super.renderWidget(context, mouseX, mouseY, delta)
|
||||
context.disableScissor()
|
||||
}
|
||||
|
||||
private fun createEntries() {
|
||||
clearEntries()
|
||||
for (wallpaper in PCBoxWallpaperRepository.wallpapers) {
|
||||
addEntry(WallpaperEntry(wallpaper))
|
||||
for (wallpaper in PCBoxWallpaperRepository.availableWallpapers) {
|
||||
addEntry(WallpaperEntry(wallpaper, pcGui.unseenWallpapers.contains(wallpaper)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +100,7 @@ class WallpapersScrollingWidget(
|
||||
return this.rowLeft + SLOT_WIDTH
|
||||
}
|
||||
|
||||
inner class WallpaperEntry(val wallpaper: ResourceLocation) : Slot<WallpaperEntry>() {
|
||||
inner class WallpaperEntry(val wallpaper: ResourceLocation, var isNew: Boolean) : Slot<WallpaperEntry>() {
|
||||
override fun render(
|
||||
guiGraphics: GuiGraphics,
|
||||
index: Int,
|
||||
@@ -118,28 +117,30 @@ class WallpapersScrollingWidget(
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = wallpaper,
|
||||
x = left,
|
||||
y = top,
|
||||
width = width,
|
||||
height = height,
|
||||
x = left + 1,
|
||||
y = top + SLOT_PADDING + 1,
|
||||
width = width - 2,
|
||||
height = SLOT_HEIGHT - 2,
|
||||
)
|
||||
|
||||
if (hovering) {
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = ENTRY_HOVERED,
|
||||
x = left,
|
||||
y = top,
|
||||
width = width,
|
||||
height = height
|
||||
)
|
||||
}
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = if (isNew) previewOverlayNewResource else previewOverlayResource,
|
||||
x = left,
|
||||
y = top + SLOT_PADDING,
|
||||
width = width,
|
||||
height = SLOT_HEIGHT,
|
||||
vOffset = if (hovering) SLOT_HEIGHT else 0,
|
||||
textureHeight = SLOT_HEIGHT * 2
|
||||
)
|
||||
}
|
||||
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
if (this@WallpapersScrollingWidget.visible && isMouseOver(mouseX, mouseY)) {
|
||||
RequestChangePCBoxWallpaperPacket(pcGui.pc.uuid, storageWidget.box, wallpaper).sendToServer()
|
||||
pcGui.pc.boxes[storageWidget.box].wallpaper = wallpaper
|
||||
pcGui.unseenWallpapers.remove(wallpaper)
|
||||
isNew = false
|
||||
minecraft.soundManager.play(SimpleSoundInstance.forUI(CobblemonSounds.PC_CLICK, 1.0F))
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -491,16 +491,16 @@ class PokedexGUI private constructor(
|
||||
|
||||
when (tabIndex) {
|
||||
TAB_DESCRIPTION -> {
|
||||
tabInfoElement = DescriptionWidget( x + 180, y + 135)
|
||||
tabInfoElement = DescriptionWidget(x + 180, y + 135)
|
||||
}
|
||||
TAB_ABILITIES -> {
|
||||
tabInfoElement = AbilitiesWidget( x + 180, y + 135)
|
||||
tabInfoElement = AbilitiesWidget(x + 180, y + 135)
|
||||
}
|
||||
TAB_SIZE -> {
|
||||
tabInfoElement = SizeWidget( x + 180, y + 135)
|
||||
tabInfoElement = SizeWidget(x + 180, y + 135)
|
||||
}
|
||||
TAB_STATS -> {
|
||||
tabInfoElement = StatsWidget( x + 180, y + 135)
|
||||
tabInfoElement = StatsWidget(x + 180, y + 135)
|
||||
}
|
||||
TAB_DROPS -> {
|
||||
tabInfoElement = DropsScrollingWidget(x + 189, y + 135)
|
||||
|
||||
-1
@@ -9,7 +9,6 @@
|
||||
package com.cobblemon.mod.common.client.gui.pokedex.widgets
|
||||
|
||||
import com.bedrockk.molang.runtime.MoLangRuntime
|
||||
import com.cobblemon.mod.common.api.gui.ParentWidget
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.pokedex.entry.PokedexEntry
|
||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.setup
|
||||
|
||||
@@ -13,9 +13,6 @@ import com.cobblemon.mod.common.CobblemonNetwork.sendToServer
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.moves.Move
|
||||
import com.cobblemon.mod.common.api.moves.MoveSet
|
||||
import com.cobblemon.mod.common.api.reactive.Observable.Companion.emitWhile
|
||||
import com.cobblemon.mod.common.api.reactive.ObservableSubscription
|
||||
import com.cobblemon.mod.common.api.scheduling.Schedulable
|
||||
import com.cobblemon.mod.common.api.scheduling.SchedulingTracker
|
||||
import com.cobblemon.mod.common.api.storage.party.PartyPosition
|
||||
@@ -317,8 +314,8 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
* Switches the selected PKM
|
||||
*/
|
||||
fun switchSelection(newSelection: Int) {
|
||||
this.selectedPokemon.moveSet.changeFunction = {}
|
||||
this.party.getOrNull(newSelection)?.let { this.selectedPokemon = it }
|
||||
moveSetSubscription?.unsubscribe()
|
||||
listenToMoveSet()
|
||||
displayMainScreen(mainScreenIndex)
|
||||
children().find { it is EvolutionSelectScreen }?.let(this::removeWidget)
|
||||
@@ -333,18 +330,15 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
}
|
||||
}
|
||||
|
||||
private var moveSetSubscription: ObservableSubscription<MoveSet>? = null
|
||||
|
||||
/**
|
||||
* Start observing the MoveSet of the current PKM for changes
|
||||
*/
|
||||
private fun listenToMoveSet() {
|
||||
moveSetSubscription = selectedPokemon.moveSet.observable
|
||||
.pipe(emitWhile { isOpen() })
|
||||
.subscribe {
|
||||
if (mainScreen is MovesWidget)
|
||||
displayMainScreen(MOVES)
|
||||
}
|
||||
selectedPokemon.moveSet.changeFunction = {
|
||||
if (mainScreen is MovesWidget) {
|
||||
displayMainScreen(MOVES)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
@@ -113,6 +113,7 @@ class ModelWidget(
|
||||
)
|
||||
|
||||
heldItemRenderer.renderOnModel(
|
||||
state.currentModel!!,
|
||||
heldItem?: ItemStack.EMPTY,
|
||||
state.locatorStates,
|
||||
matrices,
|
||||
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.client.net
|
||||
|
||||
import com.cobblemon.mod.common.api.net.ClientNetworkPacketHandler
|
||||
import com.cobblemon.mod.common.api.pokemon.PokemonSpecies
|
||||
import com.cobblemon.mod.common.api.text.green
|
||||
import com.cobblemon.mod.common.api.text.plus
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.FloatingState
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.repository.RenderContext
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.repository.VaryingModelRepository
|
||||
import com.cobblemon.mod.common.net.messages.client.CalculateSeatPositionsPacket
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.network.chat.ClickEvent
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object CalculateSeatPositionsHandler : ClientNetworkPacketHandler<CalculateSeatPositionsPacket> {
|
||||
private const val FORMAT = "%.2f"
|
||||
private const val SEAT_PREFIX = "seat"
|
||||
private const val SIMULATION_PERIOD_TICKS = 15 * 20F
|
||||
|
||||
class SeatRanges(
|
||||
var minX: Float = 9999F,
|
||||
var minY: Float = 9999F,
|
||||
var minZ: Float = 9999F,
|
||||
var maxX: Float = -9999F,
|
||||
var maxY: Float = -9999F,
|
||||
var maxZ: Float = -9999F
|
||||
)
|
||||
|
||||
override fun handle(packet: CalculateSeatPositionsPacket, client: Minecraft) {
|
||||
val state = FloatingState()
|
||||
state.currentAspects = packet.aspects
|
||||
val model = VaryingModelRepository.getPoser(packet.speciesIdentifier, state)
|
||||
model.context = RenderContext()
|
||||
model.context.put(RenderContext.SPECIES, packet.speciesIdentifier)
|
||||
model.context.put(RenderContext.ASPECTS, packet.aspects)
|
||||
model.context.put(RenderContext.POSABLE_STATE, state)
|
||||
model.context.put(RenderContext.RENDER_STATE, RenderContext.RenderState.WORLD)
|
||||
|
||||
|
||||
state.setPoseToFirstSuitable(packet.poseType)
|
||||
|
||||
val seatData = mutableMapOf<Int, SeatRanges>()
|
||||
|
||||
var ticks = 0F
|
||||
|
||||
// This will loop through the animation and find the extremes of the seat positions so we can later find the avg.
|
||||
// Most animations are going to loop in like 3 seconds but we can't know that, so just run through 15s to be safe.
|
||||
while (ticks < SIMULATION_PERIOD_TICKS) {
|
||||
state.updatePartialTicks(ticks)
|
||||
|
||||
model.applyAnimations(null, state, 0F, 0F, 0F, 0F, 0F)
|
||||
model.updateLocators(null, state)
|
||||
|
||||
for ((key, locatorState) in state.locatorStates.entries.filter { it.key.startsWith(SEAT_PREFIX) }.sortedBy { it.key }) {
|
||||
val index = key.replace(SEAT_PREFIX, "").toInt()
|
||||
val seatPosition = locatorState.transformPosition(Vec3.ZERO)
|
||||
val seatRanges = seatData.getOrPut(index, ::SeatRanges)
|
||||
if (seatPosition.x < seatRanges.minX) seatRanges.minX = seatPosition.x.toFloat()
|
||||
if (seatPosition.y < seatRanges.minY) seatRanges.minY = seatPosition.y.toFloat()
|
||||
if (seatPosition.z < seatRanges.minZ) seatRanges.minZ = seatPosition.z.toFloat()
|
||||
if (seatPosition.x > seatRanges.maxX) seatRanges.maxX = seatPosition.x.toFloat()
|
||||
if (seatPosition.y > seatRanges.maxY) seatRanges.maxY = seatPosition.y.toFloat()
|
||||
if (seatPosition.z > seatRanges.maxZ) seatRanges.maxZ = seatPosition.z.toFloat()
|
||||
}
|
||||
|
||||
ticks++
|
||||
}
|
||||
|
||||
val species = PokemonSpecies.getByIdentifier(packet.speciesIdentifier)!!
|
||||
val form = species.getForm(packet.aspects)
|
||||
val scale = form.baseScale
|
||||
|
||||
var text = "Seats:".text()
|
||||
for ((index, seatRanges) in seatData) {
|
||||
val x = String.format(FORMAT, ((seatRanges.minX + seatRanges.maxX) / 2 * scale))
|
||||
val y = String.format(FORMAT, ((seatRanges.minY + seatRanges.maxY) / 2 * -1 * scale)) // Y is inverted between model and world
|
||||
val z = String.format(FORMAT, ((seatRanges.minZ + seatRanges.maxZ) / 2 * scale))
|
||||
|
||||
val str = """
|
||||
{
|
||||
"x": $x,
|
||||
"y": $y,
|
||||
"z": $z
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
text.plus(" [$index]".green().also {
|
||||
it.style = it.style.withClickEvent(ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, str))
|
||||
})
|
||||
}
|
||||
Minecraft.getInstance().player!!.sendSystemMessage(text)
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -18,6 +18,14 @@ import net.minecraft.client.Minecraft
|
||||
object OpenPCHandler : ClientNetworkPacketHandler<OpenPCPacket> {
|
||||
override fun handle(packet: OpenPCPacket, client: Minecraft) {
|
||||
val pc = CobblemonClient.storage.pcStores[packet.storeID] ?: return
|
||||
Minecraft.getInstance().setScreen(PCGUI(pc, CobblemonClient.storage.myParty, PCGUIConfiguration(), packet.box))
|
||||
Minecraft.getInstance().setScreen(
|
||||
PCGUI(
|
||||
pc = pc,
|
||||
party = CobblemonClient.storage.myParty,
|
||||
configuration = PCGUIConfiguration(),
|
||||
openOnBox = packet.box,
|
||||
unseenWallpapers = packet.unseenWallpapers.toMutableSet()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -17,6 +17,6 @@ import net.minecraft.client.Minecraft
|
||||
object RequestPCBoxWallpapersHandler : ClientNetworkPacketHandler<RequestPCBoxWallpapersPacket> {
|
||||
override fun handle(packet: RequestPCBoxWallpapersPacket, client: Minecraft) {
|
||||
PCBoxWallpaperRepository.findWallpapers(client.resourceManager)
|
||||
PCBoxWallpapersPacket(PCBoxWallpaperRepository.wallpapers).sendToServer()
|
||||
PCBoxWallpapersPacket(PCBoxWallpaperRepository.availableWallpapers).sendToServer()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -15,6 +15,6 @@ import net.minecraft.client.Minecraft
|
||||
|
||||
object SetPCBoxWallpapersHandler : ClientNetworkPacketHandler<SetPCBoxWallpapersPacket> {
|
||||
override fun handle(packet: SetPCBoxWallpapersPacket, client: Minecraft) {
|
||||
PCBoxWallpaperRepository.wallpapers = packet.wallpapers
|
||||
PCBoxWallpaperRepository.availableWallpapers = packet.wallpapers.toMutableSet()
|
||||
}
|
||||
}
|
||||
+20
@@ -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.client.net.storage.pc
|
||||
|
||||
import com.cobblemon.mod.common.api.net.ClientNetworkPacketHandler
|
||||
import com.cobblemon.mod.common.client.render.gui.PCBoxWallpaperRepository
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.UnlockPCBoxWallpaperPacket
|
||||
import net.minecraft.client.Minecraft
|
||||
|
||||
object UnlockPCBoxWallpaperHandler : ClientNetworkPacketHandler<UnlockPCBoxWallpaperPacket> {
|
||||
override fun handle(packet: UnlockPCBoxWallpaperPacket, client: Minecraft) {
|
||||
PCBoxWallpaperRepository.availableWallpapers.add(packet.texture)
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,8 @@ import com.cobblemon.mod.common.client.render.models.blockbench.PosableState
|
||||
import com.cobblemon.mod.common.entity.PosableEntity
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.particle.SnowstormParticleOptions
|
||||
import com.cobblemon.mod.common.util.asExpressionLike
|
||||
import com.cobblemon.mod.common.util.math.geometry.transformDirection
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import com.cobblemon.mod.common.util.resolve
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.multiplayer.ClientLevel
|
||||
import net.minecraft.client.particle.NoRenderParticle
|
||||
@@ -35,7 +33,6 @@ import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import kotlin.random.Random
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.level.Level
|
||||
|
||||
/**
|
||||
* An instance of a bedrock particle effect.
|
||||
@@ -187,7 +184,7 @@ class ParticleStorm(
|
||||
val matrixWrapper = MatrixWrapper()
|
||||
matrixWrapper.updateFunction = { it.updatePosition(entity.position()) }
|
||||
val particleRuntime = MoLangRuntime().setup().setupClient()
|
||||
particleRuntime.environment.query.addFunction("entity") { params -> MoLangFunctions.entityFunctions.flatMap { it(entity).map { it.key to it.value } } }
|
||||
particleRuntime.environment.query.addFunction("entity") { params -> MoLangFunctions.livingEntityFunctions.flatMap { it(entity).map { it.key to it.value } } }
|
||||
return listOf(
|
||||
ParticleStorm(
|
||||
effect = effect,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user