AsmHook.newBuilder()
.setTargetClass("net.minecraft.item.ItemSword")
.setTargetMethod("<init>") // модифицируем конструктор, обфусцированное имя не нужно
.addTargetMethodParameters(Type.INT_TYPE, TypeHelper.getType("net.minecraft.item.EnumToolMaterial"))
.setHookClass("gloomyfolken.hooklib.example.CommonHooks")
.setHookMethod("twiceDamage")
// нулевой параметр - это this
.addHookMethodParameter("net.minecraft.item.ItemSword", 0)
.setInjectorFactory(AsmHook.ON_EXIT_FACTORY) // вставляем хук в конец метода
.buildAndRegister();
Can not found target method of hook AsmHook: net.minecraft.item.ItemSword#<init> -> gloomyfolken.hooklib.example.CommonHooks#twiceDamage
Да,путь такой.В идеале все вот так:krok написал(а):А путь точно такой?gloomyfolken.hooklib.example.CommonHooks?
@Override
public boolean dealDamage(float damage, ToolCore ammo, NBTTagCompound tags, Entity entityHit)
{
boolean dealtDamage = false;
//Minecraft.getMinecraft().thePlayer.sendChatMessage("Damage/Weight: " + damage + " - " + tags.getFloat("Mass"));
// we take the weight, and shift the damage done towards armor piercing, the more weight the arrow/bolt has!
float shift = (tags.getFloat("Mass") - 0.7f)*armorPenetrationModifier();
if(shift < 0)
shift = 0;
if(shift > damage)
shift = damage;
damage -= shift;
// deal regular damage
if(damage > 0)
dealtDamage = super.dealDamage(damage, ammo, tags, entityHit);
// deal armor piercing damage
if(shift > 0) {
DamageSource damagesource;
if (this.shootingEntity == null)
damagesource = new PiercingArrowDamage("arrow", this, this);
else
damagesource = new PiercingArrowDamage("arrow", this, this.shootingEntity);
//Minecraft.getMinecraft().thePlayer.sendChatMessage("Piercing Damage: " + shift);
// piercing damage does not affect wether the entity was hit (return value), since it should go through always
entityHit.attackEntityFrom(damagesource, shift);
}
return dealtDamage;
}