下面的代码片段是我在网上找到的教程中使用的:
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'
有多种方法:
- 使用实体
您可以通过扩展Entity
而不是ItemEntity
来修复它。
- 使用特定实体类型
例如,AnimalEntity
可以解决您的问题。
最后,例如,如果您需要获取实体的堆栈,您可以这样做:
public ItemStack getStack(){
return ((ItemEntity) this).getStack();
}