版本信息
你使用的系统:Windows 10,64位系统
你是用的JDK:1.8.0_162 ,64位
你使用的IDE:IntelliJ IDEA
你使用的IDE版本:2019.3.2.0
Forge版本: forge-31.1.0
Minecraft版本:1.15.2
出错图
错误情况简述
我之前按照教程,尝试添加了一个投掷物的实体,并且确定弄好了材质,但是我在游戏中测试的时候,发现该物品可以进行投掷,并且会产生效果,但是投掷出去变成实体后,却看不到材质了,我也不知道应该如何解决。(说明:原版投掷物可正常显示材质)
相关代码
实体主文件:GasolineCan.java
package com.specialitem.specialitem.entity.GasolineCan;
import com.specialitem.specialitem.items.ModItems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.monster.BlazeEntity;
import net.minecraft.entity.projectile.ProjectileItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class ThrownGasolineCan extends ProjectileItemEntity {
public ThrownGasolineCan(World worldIn, LivingEntity throwerIn) {
super(GasolineCanHelper.THROWN_GASOLINE_CAN, throwerIn, worldIn);
}
public ThrownGasolineCan(World world) {
super(GasolineCanHelper.THROWN_GASOLINE_CAN, world);
}
public Item func_213885_i() {
return ModItems.gasolineCan;
}
@Override
public void tick() {
if (this.world.isRemote && this.isAlive()) {
for(int i = 0; i < 2; ++i) {
this.world.addParticle(ParticleTypes.FLAME,
this.func_226282_d_(0.5D),
this.func_226279_cv_() - 0.25D,
this.func_226287_g_(0.5D),
(this.rand.nextDouble() - 0.5D) * 2.0D,
-this.rand.nextDouble(),
(this.rand.nextDouble() - 0.5D) * 2.0D);
}
}
super.tick();
}
@OnlyIn(Dist.CLIENT)
private IParticleData func_213887_n() {
ItemStack itemstack = this.func_213882_k();
return itemstack.isEmpty() ? ParticleTypes.FLAME : new ItemParticleData(ParticleTypes.ITEM, itemstack);
}
@OnlyIn(Dist.CLIENT)
public void handleStatusUpdate(byte id) {
if (id == 3) {
IParticleData iparticledata = this.func_213887_n();
for(int i = 0; i < 8; ++i) {
this.world.addParticle(iparticledata, this.func_226277_ct_(), this.func_226278_cu_(), this.func_226281_cx_(), 0.0D, 0.0D, 0.0D);
}
}
}
protected void onImpact(RayTraceResult result) {
if (result.getType() == RayTraceResult.Type.ENTITY) {
Entity entity = ((EntityRayTraceResult)result).getEntity();
int i = entity instanceof BlazeEntity ? 3 : 0;
entity.attackEntityFrom(DamageSource.netherBedExplosion(), (float)i);
entity.world.createExplosion(null,DamageSource.netherBedExplosion(),
entity.getPosition().getX(),entity.getPosition().getY(),entity.getPosition().getZ(),
3.0F,true, Explosion.Mode.NONE);
}
if (!this.world.isRemote) {
world.createExplosion(null,DamageSource.netherBedExplosion(),
getPosition().getX(),getPosition().getY(),getPosition().getZ(),
3.0F,true, Explosion.Mode.NONE);
this.world.setEntityState(this, (byte)3);
this.remove();
}
}
}
实体渲染文件:GasolineCanRenderer.java
package com.specialitem.specialitem.entity.GasolineCan;
import com.specialitem.specialitem.SpecialItem;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class GasolineCanRenderer extends EntityRenderer<ThrownGasolineCan> {
private static final ResourceLocation TEXTURES = new ResourceLocation(SpecialItem.MODID,"textures/entity/thrown_gasoline_can.png");
public GasolineCanRenderer(EntityRendererManager renderManager) {
super(renderManager);
}
@Override
public ResourceLocation getEntityTexture(ThrownGasolineCan entity) {
return TEXTURES;
}
}
RegistryHandler.java里的相关的注册信息:
Event.getRegistry().register(EntityType.Builder.create((entityEntityType, world) -> new ThrownGasolineCan(world), EntityClassification.MISC)
.size(0.5F, 0.5F)
.build("thrown_gasoline_can")
.setRegistryName(SpecialItem.MODID, "thrown_gasoline_can"));
随便一个原版投掷物的代码(这个是雪球的代码):
package net.minecraft.entity.projectile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.monster.BlazeEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class SnowballEntity extends ProjectileItemEntity {
public SnowballEntity(EntityType<? extends SnowballEntity> p_i50159_1_, World p_i50159_2_) {
super(p_i50159_1_, p_i50159_2_);
}
public SnowballEntity(World worldIn, LivingEntity throwerIn) {
super(EntityType.SNOWBALL, throwerIn, worldIn);
}
public SnowballEntity(World worldIn, double x, double y, double z) {
super(EntityType.SNOWBALL, x, y, z, worldIn);
}
protected Item func_213885_i() {
return Items.SNOWBALL;
}
@OnlyIn(Dist.CLIENT)
private IParticleData func_213887_n() {
ItemStack itemstack = this.func_213882_k();
return (IParticleData)(itemstack.isEmpty() ? ParticleTypes.ITEM_SNOWBALL : new ItemParticleData(ParticleTypes.ITEM, itemstack));
}
/**
* Handler for {@link World#setEntityState}
*/
@OnlyIn(Dist.CLIENT)
public void handleStatusUpdate(byte id) {
if (id == 3) {
IParticleData iparticledata = this.func_213887_n();
for(int i = 0; i < 8; ++i) {
this.world.addParticle(iparticledata, this.func_226277_ct_(), this.func_226278_cu_(), this.func_226281_cx_(), 0.0D, 0.0D, 0.0D);
}
}
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(RayTraceResult result) {
if (result.getType() == RayTraceResult.Type.ENTITY) {
Entity entity = ((EntityRayTraceResult)result).getEntity();
int i = entity instanceof BlazeEntity ? 3 : 0;
entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
}
if (!this.world.isRemote) {
this.world.setEntityState(this, (byte)3);
this.remove();
}
}
}