goldodemon/most / LivingEntityMixin.json
goldodemon's picture
download
raw
1.63 kB
{
"path": "Minecraft/mc-Data/LivingEntityMixin.java",
"original_extension": "java",
"content": "package com.example.examplemod.mixin;\n\nimport net.minecraft.entity.LivingEntity;\nimport net.minecraft.entity.damage.DamageSource;\nimport net.minecraft.text.Text;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;\n\n/**\n * Mixin into LivingEntity to add a \"lucky dodge\" chance that cancels damage.\n * Mixins are version-sensitive at the bytecode level but this mixin target\n * (damage(DamageSource, float)) has been stable across 1.21.7 - 1.21.11.\n *\n * Register in examplemod.mixins.json under \"mixins\": [\"LivingEntityMixin\"].\n */\n@Mixin(LivingEntity.class)\npublic abstract class LivingEntityMixin {\n\n // Inject at HEAD of damage(), cancel the whole method if our condition is met.\n @Inject(method = \"damage\", at = @At(\"HEAD\"), cancellable = true)\n private void examplemod$onDamage(DamageSource source, float amount,\n CallbackInfoReturnable<Boolean> cir) {\n LivingEntity self = (LivingEntity) (Object) this;\n\n // 5% chance to completely dodge any damage\n if (self.getRandom().nextFloat() < 0.05f) {\n if (!self.getWorld().isClient) {\n self.sendMessage(Text.literal(\"You dodged the attack!\"));\n }\n cir.setReturnValue(false); // cancel damage, \"false\" = no damage applied\n }\n }\n}\n"
}

Xet Storage Details

Size:
1.63 kB
·
Xet hash:
88675e4c025b62bfa427924fee1581dedbba302ee2d7eae87358212167696794

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.