版本信息
你使用的系统:Ubuntu 20.04.1 LTS x64
你是用的JDK: JDK8u252
你使用的IDE:IntelliJ IDEA
你使用的IDE版本: 202.6397.94(2020.2)
Forge版本: 31.2.0
Minecraft版本: 1.15.2
Mapping 文件版本: snapshot-20200730
出错图
(我认为无法用图片描述)
错误情况简述
我在MC中仿照鸡蛋的代码加入了一个投掷物,但我注册了实体、以及渲染之后,却发现投掷物没有渲染,我打开碰撞箱,发现该投掷物并没有碰撞箱,我已经确保了实体的注册、模型没有问题,但就是无法发现问题。
相关代码
DuckEggItem.java
public class DuckEggItem extends Item {
public DuckEggItem() {
super(new Properties().maxStackSize(16).group(ItemGroups.HAMBURGER));
}
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
if (!worldIn.isRemote) {
DuckEggEntity entityDuckEgg = new DuckEggEntity(playerIn, worldIn);
entityDuckEgg.setItem(itemstack);
entityDuckEgg.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
worldIn.addEntity(entityDuckEgg);
}
playerIn.addStat(Stats.ITEM_USED.get(this));
if (!playerIn.abilities.isCreativeMode) { // 检查玩家是否为创造模式
itemstack.shrink(1); // 如果不是创造模式,就减少一个DuckEgg
}
return ActionResult.resultSuccess(itemstack);
}
}
DuckEggEntity.java
public class DuckEggEntity extends ProjectileItemEntity {
public DuckEggEntity(EntityType<? extends ProjectileItemEntity> type, World worldIn) {
super(type, worldIn);
}
public DuckEggEntity(LivingEntity throwerIn, World worldIn) {
super(Entities.DUCK_EGG, throwerIn, worldIn); // TODO
}
public DuckEggEntity(EntityType<? extends ProjectileItemEntity> type, double x, double y, double z, World worldIn) {
super(type, x, y, z, worldIn);
}
@OnlyIn(Dist.CLIENT)
@Override
public void handleStatusUpdate(byte id) {
if (id == 3) {
for (int i = 0; i < 8; ++i) {
this.world.addParticle(new ItemParticleData(ParticleTypes.ITEM, this.getItem()), this.getPosX(), this.getPosY(), this.getPosZ(), ((double) this.rand.nextFloat() - 0.5D) * 0.08D, ((double) this.rand.nextFloat() - 0.5D) * 0.08D, ((double) this.rand.nextFloat() - 0.5D) * 0.08D);
}
}
}
protected void onImpact(RayTraceResult result) {
if (result.getType() == RayTraceResult.Type.ENTITY) {
((EntityRayTraceResult) result).getEntity().attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);
}
if (!this.world.isRemote) {
if (this.rand.nextInt(8) == 0) {
int i = 1;
if (this.rand.nextInt(32) == 0) {
i = 4;
}
for (int j = 0; j < i; ++j) {
DuckEntity entityDuck = Entities.DUCK.create(this.world);
entityDuck.setGrowingAge(-24000);
entityDuck.setLocationAndAngles(this.getPosX(), this.getPosY(), this.getPosZ(), this.rotationYaw, 0.0F);
this.world.addEntity(entityDuck);
}
}
this.world.setEntityState(this, (byte) 3);
this.remove();
}
}
@Nonnull
@Override
protected Item getDefaultItem() {
return Items.DUCK_EGG;
}
}
DuckEggRenderer.java
@OnlyIn(Dist.CLIENT)
public class DuckEggRenderer extends SpriteRenderer<DuckEggEntity> {
public DuckEggRenderer(EntityRendererManager renderManagerIn) {
super(renderManagerIn, Minecraft.getInstance().getItemRenderer());
}
}
注册Renderer的代码
RenderingRegistry.registerEntityRenderingHandler(Entities.DUCK_EGG, DuckEggRenderer::new);