Flandre923
180 words
1 minutes
20 让玩家可以像蜘蛛一样可以爬墙

20 让玩家可以像蜘蛛一样可以爬墙#

package com.mafuyu33.neomafishmod.mixin.effectMixin.canclimb;

import com.mafuyu33.neomafishmod.effect.ModEffects;
import net.minecraft.core.Holder;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
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(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity {

    @Shadow public abstract boolean hasEffect(Holder<MobEffect> effect);

    public LivingEntityMixin(EntityType<?> entityType, Level level) {
        super(entityType, level);
    }

    @Inject(at=@At("HEAD"),method = "onClimbable",cancellable = true)
    private void init(CallbackInfoReturnable<Boolean> cir) {
        if(this.hasEffect(ModEffects.SPIDER_EFFECT)) { // 有药水效果
            if (this.horizontalCollision) { // 在横向发生了碰撞
                cir.setReturnValue(true); // 将onClimbable的返回值设置为true,表示可以爬.
            }
        }
    }
}

还需要给生物加一个爬墙的寻路器


@Mixin(Mob.class)
public abstract class MobEntityMixin extends LivingEntity implements Targeting {
    protected MobEntityMixin(EntityType<? extends LivingEntity> entityType, Level level) {
        super(entityType, level);
    }

    @Inject(at = @At("HEAD"),method = "createNavigation",cancellable = true)
    private void init1(Level level, CallbackInfoReturnable<PathNavigation> cir){ // 给实体加上一个爬墙的寻路器.
        cir.setReturnValue(new WallClimberNavigation((Mob) (Object)this,level));
    }
}

20 让玩家可以像蜘蛛一样可以爬墙
https://fuwari.vercel.app/posts/minecraft1_21_0/20_让玩家可以像蜘蛛一样可以爬墙/
Author
Flandre923
Published at
2024-08-24