Skip to content

Commit

Permalink
Fix potential issues from overrides in mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
dhyces committed Apr 3, 2024
1 parent 3b0f826 commit fe461c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
37 changes: 31 additions & 6 deletions src/main/java/moriyashiine/aylyth/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package moriyashiine.aylyth.mixin;

import moriyashiine.aylyth.api.interfaces.ProlongedDeath;
import moriyashiine.aylyth.common.entity.mob.BoneflyEntity;
import moriyashiine.aylyth.common.item.YmpeEffigyItem;
import moriyashiine.aylyth.common.registry.ModComponents;
import moriyashiine.aylyth.common.registry.ModItems;
Expand All @@ -10,6 +11,7 @@
import moriyashiine.aylyth.common.util.AylythUtil;
import net.fabricmc.fabric.api.tag.convention.v1.TagUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributes;
Expand All @@ -19,6 +21,8 @@
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.tag.BiomeTags;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.util.ItemScatterer;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -37,7 +41,7 @@ public LivingEntityMixin(EntityType<?> type, World world) {
}

@ModifyVariable(method = "damage", at = @At("HEAD"), argsOnly = true)
float aylyth$damage(float value, DamageSource source) {
private float applySpecialDamage(float value, DamageSource source) {
if (source.getAttacker() instanceof LivingEntity entity && !source.getAttacker().getWorld().isClient) {
double attkDMG = entity.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
ItemStack stack = entity.getMainHandStack();
Expand All @@ -62,14 +66,14 @@ private void preventHeal(float amount, CallbackInfo callbackInfo) {
}

@Inject(method = "drop", at = @At("HEAD"), cancellable = true)
private void aylyth_shuckLogic(DamageSource source, CallbackInfo ci) {
private void shuckLogic(DamageSource source, CallbackInfo ci) {
if ((LivingEntity) (Object) this instanceof MobEntity mob && ModComponents.PREVENT_DROPS.get(mob).getPreventsDrops()) {
ci.cancel();
}
}

@Inject(method = "eatFood", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;applyFoodEffects(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;)V"))
private void aylyth_decreaseYmpeInfestationStage(World world, ItemStack stack, CallbackInfoReturnable<ItemStack> cir) {
private void decreaseYmpeInfestationStage(World world, ItemStack stack, CallbackInfoReturnable<ItemStack> cir) {
if ((LivingEntity) (Object) this instanceof PlayerEntity player && stack.isIn(ModItemTags.DECREASES_BRANCHES)) {
ModComponents.YMPE_INFESTATION.maybeGet(player).ifPresent(ympeInfestationComponent -> {
if (ympeInfestationComponent.getStage() > 0) {
Expand All @@ -82,22 +86,43 @@ else if (ympeInfestationComponent.getInfestationTimer() > 0) {
}
}

@Inject(method = "stopRiding", at = @At("HEAD"))
private void dismountAllFromBonefly(CallbackInfo ci) {
if ((LivingEntity) (Object) this instanceof PlayerEntity && this.getVehicle() instanceof BoneflyEntity fly) {
fly.getPassengerList().forEach(Entity::dismountVehicle);
}
}

@Inject(method = "getGroup", at = @At("HEAD"), cancellable = true)
private void makeUndeadWithEffigy(CallbackInfoReturnable<EntityGroup> cir) {
if (YmpeEffigyItem.isEquipped((LivingEntity)(Object)this)) {
cir.setReturnValue(EntityGroup.UNDEAD);
}
}

@Inject(method = "hurtByWater", at = @At("HEAD"), cancellable = true)
private void waterHurtsWithEffigy(CallbackInfoReturnable<Boolean> cir) {
if (YmpeEffigyItem.isEquipped((LivingEntity)(Object)this) && (this.getWorld().getBiome(this.getBlockPos()).isIn(BiomeTags.IS_RIVER) || fluidHeight.getDouble(FluidTags.WATER) > 0)) {
cir.setReturnValue(true);
}
}

@ModifyConstant(method = "updatePostDeath", constant = @Constant(intValue = 20))
private int aylyth_updatePostDeath(int constant){
private int updatePostDeath(int constant){
LivingEntity living = (LivingEntity) (Object) this;
return ProlongedDeath.of(living).map(ProlongedDeath::getDeathAnimationTime).orElse(constant);
}

@Inject(method = "updatePostDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;sendEntityStatus(Lnet/minecraft/entity/Entity;B)V"))
private void aylyth_injectLootDrop(CallbackInfo ci){
private void injectLootDrop(CallbackInfo ci){
LivingEntity living = (LivingEntity) (Object) this;
if(living instanceof ProlongedDeath){
ItemScatterer.spawn(living.getWorld(), living.getX(), living.getY() + 1.5D, living.getZ(), ModItems.CORIC_SEED.getDefaultStack());
}
}

@Inject(method = "canHaveStatusEffect", at = @At("HEAD"), cancellable = true)
public void aylyth_canHaveStatusEffect(StatusEffectInstance effect, CallbackInfoReturnable<Boolean> cir) {
public void canHaveStatusEffect(StatusEffectInstance effect, CallbackInfoReturnable<Boolean> cir) {
if (this.isPlayer()) {
LivingEntity entity = ((LivingEntity) (Object) this);

Expand Down
34 changes: 6 additions & 28 deletions src/main/java/moriyashiine/aylyth/mixin/PlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

import static moriyashiine.aylyth.common.block.SoulHearthBlock.HALF;

@Debug(export = true, print = true)
@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin extends LivingEntity implements VitalHealthHolder, HindPledgeHolder {

Expand Down Expand Up @@ -124,21 +123,21 @@ private void addAylythTrackers(CallbackInfo info) {
}

@Inject(method = "findRespawnPosition", at = @At(value = "HEAD", target = "Lnet/minecraft/block/BlockState;getBlock()Lnet/minecraft/block/Block;"), cancellable = true)
private static void aylyth_injectSoulHeartRespawn(ServerWorld world, BlockPos pos, float angle, boolean forced, boolean alive, CallbackInfoReturnable<Optional<Vec3d>> cir){
private static void soulHearthRespawn(ServerWorld world, BlockPos pos, float angle, boolean forced, boolean alive, CallbackInfoReturnable<Optional<Vec3d>> cir){
BlockState blockState = world.getBlockState(pos);
Block block = blockState.getBlock();
if (block instanceof SoulHearthBlock && blockState.get(SoulHearthBlock.CHARGES) > 0 && blockState.get(HALF) == DoubleBlockHalf.LOWER && world.getRegistryKey() == ModDimensionKeys.AYLYTH) {
Optional<Vec3d> optional = SoulHearthBlock.findRespawnPosition(EntityType.PLAYER, world, pos);
if (!alive && optional.isPresent()) {
world.setBlockState(pos, blockState.with(SoulHearthBlock.CHARGES, blockState.get(SoulHearthBlock.CHARGES) - 1).with(HALF, DoubleBlockHalf.LOWER), Block.NOTIFY_ALL);
world.setBlockState(pos.up(), blockState.with(SoulHearthBlock.CHARGES, blockState.get(SoulHearthBlock.CHARGES) - 1).with(HALF, DoubleBlockHalf.UPPER), Block.NOTIFY_ALL);
world.setBlockState(pos, blockState.with(SoulHearthBlock.CHARGES, blockState.get(SoulHearthBlock.CHARGES) - 1).with(HALF, DoubleBlockHalf.LOWER));
world.setBlockState(pos.up(), blockState.with(SoulHearthBlock.CHARGES, blockState.get(SoulHearthBlock.CHARGES) - 1).with(HALF, DoubleBlockHalf.UPPER));
}
cir.setReturnValue(optional);
}
}

@Inject(method = "shouldDismount", at = {@At("HEAD")}, cancellable = true)
private void aylyth_webbingScuffedry(CallbackInfoReturnable<Boolean> cir) {
private void webbingScuffedry(CallbackInfoReturnable<Boolean> cir) {
Entity var3 = this.getVehicle();
if (var3 instanceof BoneflyEntity) {
if (!Objects.equals(this.getVehicle().getFirstPassenger(), this)) {
Expand All @@ -148,7 +147,7 @@ private void aylyth_webbingScuffedry(CallbackInfoReturnable<Boolean> cir) {
}

@ModifyVariable(method = "applyDamage", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/entity/player/PlayerEntity;getHealth()F"), ordinal = 0, argsOnly = true)
private float aylyth$modifyDamageForCuirass(float amount, DamageSource source) {
private float modifyDamageForCuirass(float amount, DamageSource source) {
if (!getWorld().isClient) {
PlayerEntity player = (PlayerEntity) (Object) this;
CuirassComponent component = ModComponents.CUIRASS_COMPONENT.get(player);
Expand Down Expand Up @@ -194,31 +193,10 @@ private void removePledgeASAP(CallbackInfo ci){
}
}

@Override
public void stopRiding() {
if (this.getVehicle() instanceof BoneflyEntity fly) {
fly.getPassengerList().forEach(Entity::dismountVehicle);
}
super.stopRiding();
}

@Override
public EntityGroup getGroup() {
return YmpeEffigyItem.isEquipped(this) ? EntityGroup.UNDEAD : super.getGroup();
}

@Override
public boolean hurtByWater() {
return YmpeEffigyItem.isEquipped(this) && (this.getWorld().getBiome(this.getBlockPos()).isIn(BiomeTags.IS_RIVER) || fluidHeight.getDouble(FluidTags.WATER) > 0) || super.hurtByWater();
}

@Inject(method = "onDeath", at = @At("TAIL"))
private void unpledgeHind(DamageSource damageSource, CallbackInfo ci) {
PlayerEntity thiz = (PlayerEntity) (Object) this;
if (damageSource.isOf(ModDamageTypeKeys.KILLING_BLOW)) {
HindPledgeHolder.of(thiz).ifPresent(hindPledgeHolder -> {
hindPledgeHolder.setHindUuid(null);
});
setHindUuid(null);
}
}
}

0 comments on commit fe461c4

Please sign in to comment.