feat(TU31): add Depth Strider enchantment

This commit is contained in:
George V.
2026-04-28 09:37:17 +03:00
parent e776c55a2b
commit 2a86a93971
11 changed files with 109 additions and 7 deletions

View File

@@ -8013,6 +8013,10 @@ Would you like to install the mash-up pack or texture pack now?</value>
<data name="IDS_ENCHANTMENT_WATER_WORKER">
<value>Aqua Affinity</value>
</data>
<data name="IDS_ENCHANTMENT_WATER_WALKER">
<value>Depth Strider</value>
</data>
<data name="IDS_ENCHANTMENT_DIGGING">
<value>Efficiency</value>

View File

@@ -0,0 +1,26 @@
using Minecraft.Server.FourKit.Inventory;
namespace Minecraft.Server.FourKit.Enchantments;
public class DepthStriderEnchantment : Enchantment
{
static readonly Material[] supportedItems = {
Material.LEATHER_BOOTS, Material.CHAINMAIL_BOOTS, Material.GOLD_BOOTS, Material.IRON_BOOTS, Material.DIAMOND_BOOTS,
};
static readonly EnchantmentType[] conflictedEnchants = { };
public override bool canEnchantItem(ItemStack item) => supportedItems.Contains(item.getType());
public override bool conflictsWith(Enchantment other) => conflictedEnchants.Contains(other.getEnchantType());
public override EnchantmentTarget getItemTarget() => EnchantmentTarget.ARMOR_FEET;
public override EnchantmentType getEnchantType() => EnchantmentType.WATER_WALKER;
public override int getMaxLevel() => 1;
public override string getName() => "depthstrider";
public override int getStartLevel() => 1;
}

View File

@@ -140,6 +140,10 @@ public enum EnchantmentType
/// Increases the speed at which a player may mine underwater
/// </summary>
WATER_WORKER = 6,
///<summary>
/// Increases the speed at which a player may walk/swim underwater
/// </summary>
WATER_WALKER = 8,
/// <summary>
/// Increases the rate at which fish bite the hook while fishing
/// </summary>
@@ -176,7 +180,7 @@ public abstract class Enchantment
public static Enchantment AquaAffinityEnchantment => _registry[EnchantmentType.WATER_WORKER];
public static Enchantment LureEnchantment => _registry[EnchantmentType.LURE];
public static Enchantment LuckOfTheSeaEnchantment => _registry[EnchantmentType.LUCK_OF_THE_SEA];
public static Enchantment DepthStriderEnchantment => _registry[EnchantmentType.WATER_WALKER];
private static Dictionary<EnchantmentType, Enchantment> _registry = new Dictionary<EnchantmentType, Enchantment>()
{
@@ -204,6 +208,7 @@ public abstract class Enchantment
{ EnchantmentType.WATER_WORKER, new AquaAffinityEnchantment() },
{ EnchantmentType.LURE, new LureEnchantment() },
{ EnchantmentType.LUCK_OF_THE_SEA, new LuckOfTheSeaEnchantment() },
{ EnchantmentType.WATER_WALKER, new DepthStriderEnchantment() },
};
/// <summary>

View File

@@ -3,6 +3,7 @@
#include "net.minecraft.world.item.h"
#include "Enchantment.h"
#include "WaterWalkerEnchantment.h"
#include "LuckOfTheSeaEnchantment.h"
#include "LureEnchantment.h"
@@ -17,6 +18,7 @@ Enchantment *Enchantment::explosionProtection = nullptr;
Enchantment *Enchantment::projectileProtection = nullptr;
Enchantment *Enchantment::drownProtection = nullptr;
Enchantment *Enchantment::waterWorker = nullptr;
Enchantment *Enchantment::waterWalker = nullptr;
Enchantment *Enchantment::thorns = nullptr;
// weapon
@@ -52,6 +54,7 @@ void Enchantment::staticCtor()
projectileProtection = new ProtectionEnchantment(4, FREQ_UNCOMMON, ProtectionEnchantment::PROJECTILE);
drownProtection = new OxygenEnchantment(5, FREQ_RARE);
waterWorker = new WaterWorkerEnchantment(6, FREQ_RARE);
waterWalker = new WaterWalkerEnchantment(8, FREQ_RARE);
thorns = new ThornsEnchantment(7, FREQ_VERY_RARE);
// weapon

View File

@@ -25,6 +25,7 @@ public :
static Enchantment *projectileProtection;
static Enchantment *drownProtection;
static Enchantment *waterWorker;
static Enchantment *waterWalker;
static Enchantment *thorns;
// weapon

View File

@@ -234,6 +234,11 @@ bool EnchantmentHelper::hasWaterWorkerBonus(shared_ptr<LivingEntity> source)
return getEnchantmentLevel(Enchantment::waterWorker->id, source->getEquipmentSlots() ) > 0;
}
int EnchantmentHelper::getWaterWalker(shared_ptr<LivingEntity> source)
{
return getEnchantmentLevel(Enchantment::waterWalker->id, source->getEquipmentSlots() );
}
int EnchantmentHelper::getArmorThorns(shared_ptr<LivingEntity> source)
{
return getEnchantmentLevel(Enchantment::thorns->id, source->getEquipmentSlots());

View File

@@ -80,6 +80,7 @@ public:
static int getDiggingLootBonus(shared_ptr<LivingEntity> source);
static int getKillingLootBonus(shared_ptr<LivingEntity> source);
static bool hasWaterWorkerBonus(shared_ptr<LivingEntity> source);
static int getWaterWalker(shared_ptr<LivingEntity> source);
static int getArmorThorns(shared_ptr<LivingEntity> source);
static shared_ptr<ItemInstance> getRandomItemWith(Enchantment *enchantment, shared_ptr<LivingEntity> source);

View File

@@ -1504,13 +1504,34 @@ void LivingEntity::travel(float xa, float ya)
if (isInWater() && !(thisPlayer && thisPlayer->abilities.flying) )
{
double yo = y;
moveRelative(xa, ya, useNewAi() ? 0.04f : 0.02f);
move(xd, yd, zd);
int waterWalkerLever = EnchantmentHelper::getWaterWalker(dynamic_pointer_cast<LivingEntity>(shared_from_this()));
if (waterWalkerLever > 3)
{
waterWalkerLever = 3;
}
float waterFriction = 0.8f;
float waterSpeed = useNewAi() ? 0.04f : 0.02f;
if (!onGround)
{
waterWalkerLever *= 0.5f;
}
if (waterWalkerLever > 0)
{
waterFriction += (0.5f - waterFriction) * waterWalkerLever / 3.0f;
waterSpeed += (getSpeed() * 1.0f - waterSpeed) * waterWalkerLever / 3.0f;
}
moveRelative(xa, ya, waterSpeed);
move(xd, yd, zd);
xd *= 0.80f;
yd *= 0.80f;
zd *= 0.80f;
yd -= 0.02;
xd *= waterFriction;
yd *= 0.8;
zd *= waterFriction;
yd -= 0.02;
if (horizontalCollision && isFree(xd, yd + 0.6f - y + yo, zd))
{

View File

@@ -0,0 +1,21 @@
#include "WaterWalkerEnchantment.h"
WaterWalkerEnchantment::WaterWalkerEnchantment(int id, int frequency) : Enchantment(id, frequency, EnchantmentCategory::armor_feet)
{
setDescriptionId(IDS_ENCHANTMENT_WATER_WALKER);
}
int WaterWalkerEnchantment::getMinCost(int level)
{
return 1 + (level - 1) * 10;
}
int WaterWalkerEnchantment::getMaxCost(int level)
{
return getMinCost(level) + 15;
}
int WaterWalkerEnchantment::getMaxLevel()
{
return 3;
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "Enchantment.h"
class WaterWalkerEnchantment : public Enchantment
{
public:
WaterWalkerEnchantment(int id, int freq);
virtual int getMinCost(int level);
virtual int getMaxCost(int level);
virtual int getMaxLevel();
};

View File

@@ -1267,6 +1267,8 @@ set(_MINECRAFT_WORLD_COMMON_NET_MINECRAFT_WORLD_ITEM_ENCHANTMENT
"${CMAKE_CURRENT_SOURCE_DIR}/UntouchingEnchantment.h"
"${CMAKE_CURRENT_SOURCE_DIR}/WaterWorkerEnchantment.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/WaterWorkerEnchantment.h"
"${CMAKE_CURRENT_SOURCE_DIR}/WaterWalkerEnchantment.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/WaterWalkerEnchantment.h"
"${CMAKE_CURRENT_SOURCE_DIR}/net.minecraft.world.item.enchantment.h"
)
source_group("net/minecraft/world/item/enchantment" FILES ${_MINECRAFT_WORLD_COMMON_NET_MINECRAFT_WORLD_ITEM_ENCHANTMENT})