【问题标题】:Error when trying to extend a class using 'mixin'尝试使用“mixin”扩展类时出错
【发布时间】:2021-09-30 02:36:20
【问题描述】:

以下sn-p代码是我从网上找到的教程中使用的:

package com.jktech.minend.common.events;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(ItemEntity.class)
public abstract class itemevents extends ItemEntity {
    public itemevents(World world, double x, double y, double z, ItemStack stack, doublevelocityX, double velocityY, double velocityZ) {
        super(world, x, y, z, stack, velocityX, velocityY, velocityZ);
    }
}

虽然代码可以编译,但它在运行时仍然显示错误,但游戏并没有崩溃。但是,我的函数没有执行,也没有任何反应(好像一开始就没有应用它们)。

[14:16:45] [main/ERROR] (mixin) minend.mixins.json:itemevents: Super class 'net.minecraft.entity.ItemEntity' of itemevents was not found in the hierarchy of target class 'net/minecraft/entity/ItemEntity'

org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException: Super class 'net.minecraft.entity.ItemEntity' of itemevents was not found in the hierarchy of target class 'net/minecraft/entity/ItemEntity'

【问题讨论】:

    标签: java minecraft mixins minecraft-fabric


    【解决方案1】:

    有多种方法可以做到:

    1. 使用实体

    您可以通过扩展 Entity 而不是 ItemEntity 来修复它。

    1. 使用特定的实体类型

    例如,AnimalEntity 可以解决您的问题。

    最后,如果你需要获取实体的堆栈,你可以这样:

    public ItemStack getStack(){
       return ((ItemEntity) this).getStack();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-11
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      • 2013-09-12
      相关资源
      最近更新 更多