Implemented Windup enchantment and effect

Currently the cooldown visual doesn't seem to line up correctly. I'm not entirely sure what to make of this.
This commit is contained in:
patience 2026-02-16 01:20:14 +00:00
parent f9279ce127
commit 1bd3b116dc
No known key found for this signature in database
10 changed files with 168 additions and 4 deletions

View file

@ -0,0 +1,60 @@
package xyz.nearmisses.patience.mc_rebalance;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
import net.minecraft.world.item.enchantment.EnchantmentTarget;
import net.minecraft.world.item.enchantment.LevelBasedValue;
import org.jetbrains.annotations.NotNull;
import xyz.nearmisses.patience.mc_rebalance.enchantment.effect.WindupEffect;
import java.util.concurrent.CompletableFuture;
// So this is how Java likes to do data generation. Cool?
// I don't like this specific organisation, though.
public class EnchantGen extends FabricDynamicRegistryProvider {
public EnchantGen(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registriesFuture) {
super(output, registriesFuture);
System.out.println("Generating enchantments");
}
@Override
protected void configure(HolderLookup.Provider registries, Entries entries) {
// Our new enchantment
register(entries, ModEnchantments.Windup,
Enchantment.enchantment(
Enchantment.definition(
registries.lookupOrThrow(Registries.ITEM).getOrThrow(ItemTags.WEAPON_ENCHANTABLE), // Valid items
10, // Weight (irrelevant for us?)
1, // Max enchant level
Enchantment.dynamicCost(2, 10), // Base cost for level 1
Enchantment.dynamicCost(12, 20), // same but for max cost
5, // Anvil cost
EquipmentSlotGroup.HAND // Valid slots to work in
)
).withEffect(
EnchantmentEffectComponents.POST_ATTACK, // enchantment occurs POST_ATTACK
//EnchantmentEffectComponents.DAMAGE,
EnchantmentTarget.ATTACKER,
EnchantmentTarget.VICTIM,
new WindupEffect(LevelBasedValue.constant(0.8f)) //.perLevel(0.8f, 0.2f)) // scale the enchantment linearly (irrelevant).
)
);
}
private void register(Entries entries, ResourceKey<Enchantment> key, Enchantment.Builder builder, ResourceCondition... resourceConditions) {
entries.add(key, builder.build(key.location()), resourceConditions);
}
@Override
public @NotNull String getName() {
return "MCRebalanceEnchantGen";
}
}

View file

@ -18,6 +18,7 @@ public class MCRebalance implements ModInitializer {
ModItems.init(); // Initialise: load all static values
ModBlocks.init();
ModEffects.init();
LOGGER.info("Hello Fabric world!");
ModEnchantments.registerModEnchantmentEffects();
LOGGER.info("Thanks for trying out our stuff!");
}
}

View file

@ -0,0 +1,13 @@
package xyz.nearmisses.patience.mc_rebalance;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
// More to practice than for actual use.
public class MCRebalanceDataGen implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
FabricDataGenerator.Pack pack = fabricDataGenerator.createPack();
pack.addProvider(EnchantGen::new);
}
}

View file

@ -0,0 +1,35 @@
package xyz.nearmisses.patience.mc_rebalance;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
import xyz.nearmisses.patience.mc_rebalance.enchantment.effect.WindupEffect;
// Copied off the Fabric wiki. I don't think I like this code.
public class ModEnchantments {
public static final ResourceKey<Enchantment> Windup = of("windup");
public static MapCodec<WindupEffect> Effect_Windup = register("windup_effect", WindupEffect.CODEC);
private static ResourceKey<Enchantment> of(String path) {
ResourceLocation id = ResourceLocation.fromNamespaceAndPath(MCRebalance.MOD_ID, path);
return ResourceKey.create(Registries.ENCHANTMENT, id);
}
private static <T extends EnchantmentEntityEffect> MapCodec<T> register(String id, MapCodec<T> codec) {
return Registry.register(
BuiltInRegistries.ENCHANTMENT_ENTITY_EFFECT_TYPE,
ResourceLocation.fromNamespaceAndPath(MCRebalance.MOD_ID, id),
codec
);
}
public static void registerModEnchantmentEffects() {
MCRebalance.LOGGER.info("Registering EnchantmentEffects for " + MCRebalance.MOD_ID);
}
}

View file

@ -0,0 +1,32 @@
package xyz.nearmisses.patience.mc_rebalance.enchantment.effect;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
import net.minecraft.world.item.enchantment.LevelBasedValue;
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public record WindupEffect(LevelBasedValue amount) implements EnchantmentEntityEffect {
public static final MapCodec<WindupEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
LevelBasedValue.CODEC.fieldOf("amount").forGetter(WindupEffect::amount)
).apply(instance, WindupEffect::new)
);
@Override
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) {
if (context.owner() != null && context.owner() instanceof Player player) {
player.getCooldowns().addCooldown(context.itemStack().getItem(), (int)(20 / this.amount.calculate(level)) ); // Tick conversion
}
}
@Override
public @NotNull MapCodec<? extends EnchantmentEntityEffect> codec() {
return CODEC;
}
}

View file

@ -25,7 +25,7 @@ public class CreakingRework extends Monster {
private static void createAttributes(CallbackInfoReturnable<AttributeSupplier.Builder> cir) {
cir.setReturnValue( Monster.createMonsterAttributes()
.add(Attributes.MAX_HEALTH, 1.0)
.add(Attributes.MOVEMENT_SPEED, 0.6)
.add(Attributes.MOVEMENT_SPEED, 0.6) // Vanilla pathfinding causes enemies to 'overshoot' and backtrack on speeds ~0.8+. I don't know why that still happens.
.add(Attributes.ATTACK_DAMAGE, 15.0)
.add(Attributes.FOLLOW_RANGE, 38.0)
.add(Attributes.STEP_HEIGHT, 2.1) // Step over big fences

View file

@ -0,0 +1,21 @@
package xyz.nearmisses.patience.mc_rebalance.mixin;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DiggerItem;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
// Required for the Windup enchantment effect to work correctly. Why would this not happen by default?
@Mixin(DiggerItem.class)
public class DiggerItemHitCooldownsTweak {
@Inject(method = "hurtEnemy", at = @At("HEAD"), cancellable = true)
private static void hurtEnemy(ItemStack itemStack, LivingEntity owner, LivingEntity target, CallbackInfoReturnable<Boolean> cir){
if(owner instanceof Player && ((Player)owner).getCooldowns().isOnCooldown(itemStack.getItem())){
cir.setReturnValue(false);
}
}
}

View file

@ -14,5 +14,6 @@
"item.mc_rebalance.golden_paxel": "Golden Paxel",
"item.mc_rebalance.diamond_paxel": "Diamond Paxel",
"item.mc_rebalance.netherite_paxel": "Dendrite Paxel",
"effect.mc_rebalance.shattered": "Shattered"
"effect.mc_rebalance.shattered": "Shattered",
"enchantment.mc_rebalance.windup": "Windup"
}

View file

@ -23,7 +23,7 @@
"xyz.nearmisses.patience.mc_rebalance.MCRebalanceClient"
],
"fabric-datagen": [
"xyz.nearmisses.patience.mc_rebalance.MCRebalanceDataGenerator"
"xyz.nearmisses.patience.mc_rebalance.MCRebalanceDataGen"
]
},
"mixins": [

View file

@ -6,6 +6,7 @@
"BlazeAIRework",
"BlazeRework",
"CreakingRework",
"DiggerItemHitCooldownsTweak",
"ExperienceOrbRework",
"WardenRework",
"WitherSkeletonRework"