import { registerEnchant, slots } from "../../enchantment";
// Register the Rage enchantment
const rageEnchant = registerEnchant("rage", "Rage", 1, slots.chest);
mc.world.afterEvents.entityHitEntity.subscribe((event) => {
try {
const damagingEntity = event.damagingEntity;
// Ensure the damaging entity is a player
if (!damagingEntity || damagingEntity.typeId !== "minecraft:player") {
return;
}
// Get the player's chestplate
const equipment = damagingEntity.getComponent("minecraft:equippable");
if (!equipment) {
console.log("[Rage] Player does not have equippable components.");
return;
}
const chestplate = equipment.getEquipment("chest");
if (!chestplate) {
console.log("[Rage] No chestplate equipped.");
return;
}
// Check if the chestplate has the Rage enchantment
const { valid } = rageEnchant.getItem(chestplate);
if (!valid) {
console.log("[Rage] No Rage enchantment on chestplate.");
return;
}
// Get the player's health component
const healthComponent = damagingEntity.getComponent("minecraft:health");
if (!healthComponent) {
console.log("[Rage] Player does not have a health component.");
return;
}
const currentHealth = healthComponent.currentValue;
const maxHealth = healthComponent.defaultValue;
// Calculate health percentage
const healthPercentage = (currentHealth / maxHealth) * 100;
// Determine damage multiplier
let damageMultiplier = 1;
if (healthPercentage <= 50) {
damageMultiplier = 1.5; // +50% at <= 50% health
}
if (healthPercentage <= 20) {
damageMultiplier = 1.75; // +75% at <= 20% health
}
// Apply bonus damage
if (event.hitEntity && typeof event.damage === "number") {
const bonusDamage = event.damage * (damageMultiplier - 1);
event.hitEntity.applyDamage(event.damage + bonusDamage, damagingEntity);
console.log(
`[Rage] Bonus damage: ${bonusDamage}, Total damage: ${
event.damage + bonusDamage
}.`
);
}
// Add visual feedback
damagingEntity.dimension.spawnParticle("minecraft:angry_villager", {
x: damagingEntity.location.x,
y: damagingEntity.location.y + 1.5,
z: damagingEntity.location.z,
});
damagingEntity.dimension.playSound("entity.blaze.shoot", {
x: damagingEntity.location.x,
y: damagingEntity.location.y,
z: damagingEntity.location.z,
});
} catch (error) {
console.error(`[Rage enchantment error]: ${error}`);
}
});
#I need help with this custom enchant im getting error
1 messages · Page 1 of 1 (latest)
import * as mc from "@minecraft/server";
import { registerEnchant, slots } from "../../enchantment";
// Register the Rage enchantment
const rageEnchant = registerEnchant("rage", "Rage", 1, slots.chest);
mc.world.afterEvents.entityHurt.subscribe((event) => {
try {
const damagingEntity = event.damageSource.damagingEntity;
// Ensure the damaging entity is a player
if (!damagingEntity || damagingEntity.typeId !== "minecraft:player") {
return;
}
// Get the player's chestplate
const equipment = damagingEntity.getComponent("minecraft:equippable");
if (!equipment) {
console.log("[Rage] Player does not have equippable components.");
return;
}
const chestplate = equipment.getEquipment("Chest");
if (!chestplate) {
console.log("[Rage] No chestplate equipped.");
return;
}
// Check if the chestplate has the Rage enchantment
const { valid } = rageEnchant.getItem(chestplate);
if (!valid) {
console.log("[Rage] No Rage enchantment on chestplate.");
return;
}
// Get the player's health component
const healthComponent = damagingEntity.getComponent("minecraft:health");
if (!healthComponent) {
console.log("[Rage] Player does not have a health component.");
return;
}
const currentHealth = healthComponent.currentValue;
const maxHealth = healthComponent.defaultValue;
// Calculate health percentage
const healthPercentage = (currentHealth / maxHealth) * 100;
// Determine damage multiplier
let damageMultiplier = 1;
if (healthPercentage <= 50) {
damageMultiplier = 1.5; // +50% at <= 50% health
}
if (healthPercentage <= 20) {
damageMultiplier = 1.75; // +75% at <= 20% health
}
// Apply bonus damage
if (event.hurtEntity && typeof event.damage === "number") {
const bonusDamage = event.damage * (damageMultiplier - 1);
event.hurtEntity.applyDamage(event.damage + bonusDamage, damagingEntity);
console.log(
`[Rage] Bonus damage: ${bonusDamage}, Total damage: ${
event.damage + bonusDamage
}.`
);
}
// Add visual feedback
damagingEntity.dimension.spawnParticle("minecraft:angry_villager", {
x: damagingEntity.location.x,
y: damagingEntity.location.y + 1.5,
z: damagingEntity.location.z,
});
damagingEntity.dimension.playSound("entity.blaze.shoot", damagingEntity.location);
} catch (error) {
console.error(`[Rage enchantment error]: ${error}`);
}
});
//Changes:
entityHurt.subscribe
event.damageSource.damagingEntity
equipment.getEquipment("Chest")
event.hurtEntity
Crazy how close ai is to getting to using the api properly
Nah that’s insane
mine was a meme it is edited
Ah
a little bit outdated events.beforeChat
Still unbelievable that it’s getting this close. And people are trying to use it entirely to code stuff for them with no JavaScript or api experience and then ask why an error is happening
it is becouse it learns what you give him
They stopped doing that. Each year they pick chats to train the models from. Pretty sure right now it’s updated to stuff globally around 2022
do chatGpt know about the low taper fade
Maybe 😭
no way
yes
Ericdoa mentioned 💔