Skip to content

Instantly share code, notes, and snippets.

@codestripper
Created July 26, 2020 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codestripper/05b5b35f93a1522cdd6eb30043a9201c to your computer and use it in GitHub Desktop.
Save codestripper/05b5b35f93a1522cdd6eb30043a9201c to your computer and use it in GitHub Desktop.
Mixin Issue with getting damage source player.
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(EntityLivingBase.class)
public abstract class MixinEntityLivingBase extends Entity {
@Final
@Shadow
private static Logger LOGGER;
public MixinEntityLivingBase(World worldIn) {
super(worldIn);
}
@Inject(method = "attackEntityFrom", at = @At(value = "HEAD"))
private void onAttackEntityFrom(DamageSource source, float damageAmount, CallbackInfoReturnable<Boolean> cir) {
Entity entity = source.getTrueSource();
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
LOGGER.info(player.getLastAttackedEntityTime());
LOGGER.info(player.getCooledAttackStrength(0));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment