#magic protection enchant
67 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
blep
Paste version of message.js from @rugged breach
im genuinely very stupid idk what i am doing
there is this but I am very new to javascript in general and the only things I know are consts and arrays
Paste version of message.js from @rugged breach
Paste version of message.txt from @rugged breach
is there also any way to resister attributes from damage types im not seeing much examples from it.
*register
@tiny zodiac can you please help me with this if you have the time bcs im very clueless about this
try something like this js .damageProtection((level, source) => { return source.getType() == 'magic' ? 2 * level : 1 })
you might need to console log the damage type in an entity hurt event to make sure it's returning the string 'magic'
like this?
Paste version of message.js from @rugged breach
and to explain the script it looks like its a function to return a number that will give it the damage protection needed
ohh ok
so you're returning 2* level if the type is 'magic'
yea
and 1 if no magic
also what i meant was do it in the EntityEvents.hurt server script console.log(event.source.getType()) and then splash yourself with a harming pot or something
for modded damage types dose "alexscaves:acid" work for example bcs I had problems with Kubejs not registering modded rarities before
it should, like i said before you can console log it in the hurt event
ok
then whatever it is just put it in your damage script
thanks!!!!
then you can do something like this to set it as a list
.damageProtection((level, source) => {
let damagesources = [
'magic',
'someothertype'
]
return damagesources.includes(source.getType()) ? 2 * level : 1
})
er wait
there
we make an array with [] then use .includes so if the type is included in the array itll be true boolean
Im going to sleep now and tomorrow I would try the script, thanks!
I have a problem with the code as the protection dose not scale with the levels for some reason
@tiny zodiac I tested this like a week ago with retro damage indicator and the damage dose not scale for some reason but it works on the selected damage sources
^
like i said before you should console.log the damage type because chances are the type you're testing against isnt straight up called "magic"
im testing with and without magic and the damage that is protected by the magic protection enchant extends to jeg:bullet, thrown, and arrows
Paste version of server.log from @rugged breach
I bumped the numbers for 2 to 8 and the damage recived by tridents is 3.5 with the enchant being level 4-1 similar to protection 1. 2.5 with protection 1 or magic protection and 2.6 without any.
Paste version of message.txt from @rugged breach
what did you console log
whatever you console logged would be what you'd compare against
like if you console.log(event.source.getType()) and it logged "somesource" you'd copy it over like js if (source.getType() == "somesource") like you would any other javascript string object
i hope im making sense
hmm
StartupEvents.registry("enchantment", event => {
event.create("minecraft:magic_protection")
.minLevel(1)
.maxLevel(4)
.rarity('UNCOMMON')
.category(EnchantmentCategory.ARMOR)
.damageProtection((level, source) => {
let damagesources = [
'minecraft:magic',
'minecraft:indirect_magic',
'jeg:bullet'
]
return damagesources.includes(source.getType()) ? 8 * level : 1
})
.displayName("Magic Protection")
})
ForgeEvents.onEvent("net.minecraftforge.event.entity.living.LivingHurtEvent", event => global.hurt(event))
/**
*
* ${player.username}aram {Internal.LivingHurtEvent} event
*/
global.hurt = event => {
let { entity, source, amount } = event
// const { amount, source: { actual }, source } = event
let attacker = source.actual
if(entity.isAlive()){
Utils.server.runCommandSilent(`say ${source}`)
Utils.server.runCommandSilent(`say ${amount}`)
//Utils.server.runCommandSilent(`say ${source.actual}`)
Utils.server.runCommandSilent(`say ${source.actual.type}`)
}
}
@tiny zodiac im sorry i forgot about my ticket but here is the video evidence of the enchant not working
im comparing magic protection IV vs protection againts JEG bullet
I got the damage numbers to work but it's the same when hitting dummies :(
Also is it possible to edit an enchant this way?
oh im doing the livinghurt events now
if (source.getType() == "trident"){
let armor = [entity.HeadArmorItem, entity.ChestArmorItem, entity.LegsArmorItem, entity.FeetArmorItem]
let Protection = armor.getEnchantmentLevel("minecraft:unbreaking")
if (armor.getEnchantmentLevel("minecraft:unbreaking") > 0) {
let Protect = ((Protection * 0.08));
let Protect2 = ((1 - Protection));
event.setAmount((amount * Protect2))
}
}
]dev.latvian.mods.rhino.EcmaError: TypeError: Cannot find function getEnchantmentLevel in object TargetDummyEntity['Target Dummy'/262, l='ServerLevel[New World]', x=25.50, y=75.00, z=3.50]. (startup_scripts:Enchant.js#226)
your armor item is an array so you have to iterate through them to add up the collective full unbreaking enchantment level, your protection calculations are off as well, try this js if (source.getType() == "trident") { let armor = [entity.headArmorItem, entity.chestArmorItem, entity.legsArmorItem, entity.feetArmorItem] let totalLevel = 0 for (let piece of armor) { if (piece && piece.hasEnchantment("minecraft:unbreaking")) { totalLevel += piece.getEnchantmentLevel("minecraft:unbreaking") } } if (totalLevel > 0) { let reduction = totalLevel * 0.08 let finalDamage = amount * (1 - reduction) event.setAmount(finalDamage) } }
Dear lord it did not work
Paste version of message.txt from @rugged breach
it crashes bcs of this thing [ItemStackKJS.kjs$hasEnchantment(string)] even if i removed the array
OH JESUS IT WORKED
Now imma make an areay
Oh damn jeg:bullet won't do anything right
the bullets ignore my script???
ForgeEvents.onEvent("net.minecraftforge.event.entity.living.LivingHurtEvent", event => global.hurt(event))
/**
*
* ${Internal.LivingHurtEvent} event
*/
global.hurt = event => {
let { entity, source, amount } = event
let attacker = source.actual
let damagesources = [
"jeg:bullet",
"trident",
"player",
"arrow"
]
if (damagesources.includes(source.getType())) {
var unbreak = 0
let armorPieces = [
entity.getHeadArmorItem(),
entity.getChestArmorItem(),
entity.getLegsArmorItem(),
entity.getFeetArmorItem()
].forEach((piece) => {
if (piece.id != "minecraft:air") {
unbreak += piece.getEnchantments().get('minecraft:unbreaking')
}
})
if (unbreak > 0) {
let reduction = unbreak * 0.08
let finalDamage = amount * (1 - reduction)
event.setAmount(finalDamage)
}
}
}
MAGIC IS ALSO IGNORED
instead of guessing what damage sources are named you can console log the source type
Oh damn it actually worked , thanks!!!
Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue!
This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.
Do you have any other questions regarding your issue? Feel free to ask!
Note: You should create a new post for unrelated issues.