Skip to content

Commit

Permalink
Fix #62 & #63
Browse files Browse the repository at this point in the history
Seems that interface mixins are still buggy, works in the IDE but not in practice!
Sadly this makes the fix less compatible for new bucketable mobs currently, so I do want to look into it.
  • Loading branch information
FxMorin committed May 9, 2022
1 parent b48f2a6 commit a14280f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package carpetfixes.mixins.entityFixes;
/*package carpetfixes.mixins.entityFixes;
import carpetfixes.CFSettings;
import net.minecraft.entity.Bucketable;
Expand All @@ -17,6 +17,7 @@
@Mixin(Bucketable.class)
public interface Bucketable_leashDetachMixin {
// TODO: Figure out why this seems to crash when used outside of the IDE
@Inject(
method = "tryBucket",
Expand All @@ -29,4 +30,4 @@ private static <T extends LivingEntity & Bucketable> void tryBucket(PlayerEntity
if (CFSettings.bucketableMobsNotDetachingLeashesFix && entity instanceof MobEntity mobEntity)
mobEntity.detachLeash(false,true);
}
}
}*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package carpetfixes.mixins.entityFixes.bucketableLeashDetach;

import carpetfixes.CFSettings;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.AxolotlEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(AxolotlEntity.class)
public abstract class AxolotlEntity_leashDetachMixin extends AnimalEntity {

protected AxolotlEntity_leashDetachMixin(EntityType<? extends AnimalEntity> entityType, World world) {
super(entityType, world);
}


@Inject(
method = "interactMob",
at = @At("RETURN")
)
private void interactMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (CFSettings.bucketableMobsNotDetachingLeashesFix && this.isLeashed() && cir.getReturnValue().isAccepted())
this.detachLeash(false,true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package carpetfixes.mixins.entityFixes.bucketableLeashDetach;

import carpetfixes.CFSettings;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.WaterCreatureEntity;
import net.minecraft.entity.passive.FishEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(FishEntity.class)
public abstract class FishEntity_leashDetachMixin extends WaterCreatureEntity {

protected FishEntity_leashDetachMixin(EntityType<? extends WaterCreatureEntity> entityType, World world) {
super(entityType, world);
}

// Added to fish in-case some mod makes it possible to leash fish


@Inject(
method = "interactMob",
at = @At("RETURN")
)
private void interactMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (CFSettings.bucketableMobsNotDetachingLeashesFix && this.isLeashed() && cir.getReturnValue().isAccepted())
this.detachLeash(false,true);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/carpet-fixes.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
"entityFixes.BeeEntity_voidMixin",
"entityFixes.BoatEntity_armorStandMixin",
"entityFixes.BoatEntity_fallDamageMixin",
"entityFixes.Bucketable_leashDetachMixin",
"entityFixes.CatSpawner_incorrectCatMixin",
"entityFixes.CreeperEntity_fuseMixin",
"entityFixes.DrownedEntity_enchantedTridentMixin",
Expand Down Expand Up @@ -195,6 +194,8 @@
"entityFixes.ZombieEntity_reinforcementMixin",
"entityFixes.ZombieVillagerEntity_convertingMixin",
"entityFixes.ZombieVillagerEntity_offlinePlayerMixin",
"entityFixes.bucketableLeashDetach.AxolotlEntity_leashDetachMixin",
"entityFixes.bucketableLeashDetach.FishEntity_leashDetachMixin",
"entityFixes.convertingFixes.SkeletonEntity_convertingMixin",
"entityFixes.convertingFixes.ZombieEntity_convertingMixin",
"entityFixes.growUpCollisionFix.Entity_dimensionsMixin",
Expand Down

0 comments on commit a14280f

Please sign in to comment.