Hello,
Very new to minecraft modding, but I have been making good progress. I have created a custom throwable entity based mostly on EntitySnowBall that works perfectly. However, when I throw it, the model is always rendered in the same orientation with reference to the world. I would like for its rendered orientation to be based on the player so that its its always thrown on edge (its a throwing star) to look more realistic.
Here are what I believe to be the relevant portions of my code. Thank you all for your help!
ModelThrowingStar Class
@SideOnly(Side.CLIENT)
public class ModelThrowingStar extends ModelBase {
public ModelRenderer renderer;
public ModelThrowingStar() {
this.textureWidth = 16;
this.textureHeight = 16;
this.renderer = new ModelRenderer(this, 0, 0);
this.renderer.setRotationPoint(0.0F, 0.0F, 0.0F);
this.renderer.addBox(0.0F, 0.0F, 0.0F, 16, 16, 0);
}
@Override
public void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float rotationYaw, float rotationPitch, float scale) {
this.renderer.render(scale);
}
RenderThrowingStar Class
private final ModelThrowingStar model = new ModelThrowingStar();
@Override
public void doRender(EntityThrowingStar entity, double x, double y, double z, float entityYaw, float partialTicks)
{
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
this.bindEntityTexture(entity);
model.render(entity, partialTicks, 0f, -1f, 0f, 0f, 0.05f);
GlStateManager.popMatrix();
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
EntityThrowingStar Class
public class EntityThrowingStar extends EntityThrowable{
public EntityThrowingStar(World worldIn)
{
super(worldIn);
}
public EntityThrowingStar(World worldIn, EntityLivingBase throwerIn)
{
super(worldIn, throwerIn);
}
public EntityThrowingStar(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
/**
* Handler for {@link World#setEntityState}
*/
@SideOnly(Side.CLIENT)
@Override
public void handleStatusUpdate(byte id)
{
if (id == 3)
{
for (int i = 0; i < 8; ++i)
{
this.world.spawnParticle(EnumParticleTypes.CRIT, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
}
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
@Override
protected void onImpact(RayTraceResult result)
{
if (result.entityHit != null)
{
int i = 10;
result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
}
if (!this.world.isRemote)
{
this.world.setEntityState(this, (byte)3);
this.setDead();
}
}
}
ThrowingStar Class (Item Class with the right click action)
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
ItemStack itemstack = playerIn.getHeldItem(handIn);
if (!playerIn.capabilities.isCreativeMode)
{
itemstack.shrink(1);
}
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!worldIn.isRemote)
{
EntityThrowingStar entitythrowingstar = new EntityThrowingStar(worldIn, playerIn);
entitythrowingstar.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
worldIn.spawnEntity(entitythrowingstar);
}
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
Please let me know if there is other code I should have posted.