2020-07-22 22:31:22 +00:00
|
|
|
package com.thebrokenrail.energonrelics.mixin;
|
|
|
|
|
|
|
|
import com.thebrokenrail.energonrelics.potion.CustomPotions;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.attribute.EntityAttribute;
|
|
|
|
import net.minecraft.entity.attribute.EntityAttributes;
|
|
|
|
import net.minecraft.entity.data.DataTracker;
|
|
|
|
import net.minecraft.entity.data.TrackedData;
|
|
|
|
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
|
|
|
import net.minecraft.entity.effect.StatusEffect;
|
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
|
|
import org.spongepowered.asm.mixin.Unique;
|
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
|
|
|
|
|
|
@Mixin(LivingEntity.class)
|
|
|
|
public abstract class MixinLivingEntity {
|
|
|
|
@Unique
|
2020-07-22 23:26:04 +00:00
|
|
|
private static final TrackedData<Boolean> HAS_VERIDIUM_POISON = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
|
2020-07-22 22:31:22 +00:00
|
|
|
|
|
|
|
@Shadow
|
|
|
|
public abstract boolean hasStatusEffect(StatusEffect effect);
|
|
|
|
|
|
|
|
@Shadow
|
|
|
|
public abstract void setHealth(float health);
|
|
|
|
|
|
|
|
@Shadow
|
|
|
|
public abstract float getHealth();
|
|
|
|
|
|
|
|
@Inject(at = @At("RETURN"), method = "initDataTracker")
|
|
|
|
public void initDataTracker(CallbackInfo info) {
|
2020-07-22 23:26:04 +00:00
|
|
|
((LivingEntity) (Object) this).getDataTracker().startTracking(HAS_VERIDIUM_POISON, false);
|
2020-07-22 22:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(at = @At("RETURN"), method = "onTrackedDataSet")
|
|
|
|
public void onTrackedDataSet(TrackedData<?> data, CallbackInfo info) {
|
2020-07-22 23:26:04 +00:00
|
|
|
if (HAS_VERIDIUM_POISON.equals(data)) {
|
2020-07-22 22:31:22 +00:00
|
|
|
setHealth(getHealth());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(at = @At("HEAD"), method = "tick")
|
|
|
|
public void tick(CallbackInfo info) {
|
|
|
|
if (!((LivingEntity) (Object) this).getEntityWorld().isClient()) {
|
2020-07-22 23:26:04 +00:00
|
|
|
boolean hasVeridiumPoison = hasStatusEffect(CustomPotions.VERIDIUM_POISON_EFFECT.statusEffect);
|
|
|
|
if (((LivingEntity) (Object) this).getDataTracker().get(HAS_VERIDIUM_POISON) != hasVeridiumPoison) {
|
|
|
|
((LivingEntity) (Object) this).getDataTracker().set(HAS_VERIDIUM_POISON, hasVeridiumPoison);
|
2020-07-22 22:31:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(at = @At("HEAD"), method = "getAttributeValue", cancellable = true)
|
|
|
|
public void getAttributeValue(EntityAttribute attribute, CallbackInfoReturnable<Double> info) {
|
2020-07-22 23:26:04 +00:00
|
|
|
if (EntityAttributes.GENERIC_MAX_HEALTH.equals(attribute) && ((LivingEntity) (Object) this).getDataTracker().get(HAS_VERIDIUM_POISON)) {
|
2020-07-22 22:31:22 +00:00
|
|
|
info.setReturnValue(0.5d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|