#magic protection enchant

67 messages · Page 1 of 1 (latest)

rugged breach
#

I tried Liopyu's magic protection code but it's not working for some reason.

acoustic apexBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

rugged breach
merry spadeBOT
#

Paste version of message.js from @rugged breach

rugged breach
#

im genuinely very stupid idk what i am doing

rugged breach
#

there is this but I am very new to javascript in general and the only things I know are consts and arrays

merry spadeBOT
#

Paste version of message.js from @rugged breach

rugged breach
#

wait no

merry spadeBOT
#

Paste version of message.txt from @rugged breach

rugged breach
#

is there also any way to resister attributes from damage types im not seeing much examples from it.

#

*register

rugged breach
#

@tiny zodiac can you please help me with this if you have the time bcs im very clueless about this

tiny zodiac
#

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'

rugged breach
merry spadeBOT
#

Paste version of message.js from @rugged breach

tiny zodiac
#

and to explain the script it looks like its a function to return a number that will give it the damage protection needed

rugged breach
#

ohh ok

tiny zodiac
#

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

rugged breach
#

for modded damage types dose "alexscaves:acid" work for example bcs I had problems with Kubejs not registering modded rarities before

tiny zodiac
#

it should, like i said before you can console log it in the hurt event

rugged breach
#

ok

tiny zodiac
#

then whatever it is just put it in your damage script

rugged breach
#

thanks!!!!

tiny zodiac
#

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

rugged breach
#

Im going to sleep now and tomorrow I would try the script, thanks!

rugged breach
#

I have a problem with the code as the protection dose not scale with the levels for some reason

rugged breach
#

@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

tiny zodiac
#

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"

rugged breach
#

im testing with and without magic and the damage that is protected by the magic protection enchant extends to jeg:bullet, thrown, and arrows

merry spadeBOT
#

Paste version of server.log from @rugged breach

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.

merry spadeBOT
#

Paste version of message.txt from @rugged breach

tiny zodiac
#

whatever you console logged would be what you'd compare against

tiny zodiac
#

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

rugged breach
#

hmm

rugged breach
#
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}`)
}
}
#

im comparing magic protection IV vs protection againts JEG bullet

rugged breach
#

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?

rugged breach
#

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))
}
}
rugged breach
#

]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)

tiny zodiac
# rugged breach oh im doing the livinghurt events now ```javascript if (source.getType() == "tri...

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) } }

rugged breach
merry spadeBOT
#

Paste version of message.txt from @rugged breach

rugged breach
#

it crashes bcs of this thing [ItemStackKJS.kjs$hasEnchantment(string)] even if i removed the array

rugged breach
#

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

tiny zodiac
#

instead of guessing what damage sources are named you can console log the source type

rugged breach
merry spadeBOT
#

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.