Posted March 22, 20178 yr This is quite an interesting issue. I have a throwable entity (shuriken) that functionally works. BUT the shuriken seems to only render when I'm looking down, moving side-to-side, or moving backwards. If I'm standing still or moving forward the shuriken doesn't render. Note the entity is definitely there (though invisible) since I can see it damage the environment. Thank you for any and all help I will post the code for the shuriken item, entity, and render classes below. I do NOT believe the issue is in RenderShuriken.java since I still had this issue when I instantiated the shuriken render off of the RenderSnowball class. Here is a video demonstrating the rendering issue ItemShuriken.java package com.puresalvation.test.items; import com.puresalvation.test.Reference; import com.puresalvation.test.TestMod; import com.puresalvation.test.entity.EntityShuriken; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntitySnowball; import net.minecraft.init.SoundEvents; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.stats.StatList; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.SoundCategory; import net.minecraft.world.World; public class ItemShuriken extends Item { // [CONSTRUCTOR] public ItemShuriken() { setUnlocalizedName(Reference.TestItems.SHURIKEN.getUnlocalizedName()); setRegistryName(Reference.TestItems.SHURIKEN.getRegistryName()); setCreativeTab(TestMod.modTab); } // [METHODS] /* * Item is NOT repairable in an anvil */ @Override public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { return false; } /* * When right-clicked... * (1) Decrement the stack size (if in Survival Mode) * (2) Perform any animation and play sound * (3) Create and Spawn the corresponding entity into the world */ @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { // Create an ItemStack from the item being held in the Main/Offhand of player (Main/Offhand determined by "handIn") ItemStack itemstack = playerIn.getHeldItem(handIn); // (1) Decrement the stack size if NOT in creative mode if (!playerIn.capabilities.isCreativeMode) { itemstack.shrink(1); } // (2) Play the sound worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_ENDERPEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); // (3) Create and Spawn the shuriken entity into the world if (!worldIn.isRemote) { EntityShuriken shuriken = new EntityShuriken(worldIn, playerIn); // Set the entity's direction, velocity, inaccuracy, rotation, etc. shuriken.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F); worldIn.spawnEntity(shuriken); // spawn the entity into the world } playerIn.addStat(StatList.getObjectUseStats(this)); return new ActionResult(EnumActionResult.SUCCESS, itemstack); } } EntityShuriken.java package com.puresalvation.test.entity; import java.util.Arrays; import com.puresalvation.test.Reference; import com.puresalvation.test.TestMod; import com.puresalvation.test.init.ModItems; import com.puresalvation.test.render.RenderShuriken; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraftforge.fml.client.registry.IRenderFactory; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.registry.EntityRegistry; public class EntityShuriken extends EntityThrowable { public static final float GRAVITY = 0.03F; public static final Block[] SHURIKEN_BREAKS_THROUGH = {Blocks.TALLGRASS, Blocks.VINE, Blocks.RED_FLOWER, Blocks.YELLOW_FLOWER, Blocks.BROWN_MUSHROOM_BLOCK, Blocks.BROWN_MUSHROOM, Blocks.RED_MUSHROOM_BLOCK, Blocks.RED_MUSHROOM, Blocks.REEDS, Blocks.DOUBLE_PLANT, Blocks.DEADBUSH, Blocks.WHEAT, Blocks.WATERLILY, Blocks.CARROTS, Blocks.POTATOES, Blocks.SNOW_LAYER}; // [CONSTRUCTORS] public EntityShuriken(World worldIn) { super(worldIn); } public EntityShuriken(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } public EntityShuriken(World worldIn, EntityLivingBase throwerIn) { super(worldIn, throwerIn); } // [METHODS] public static void registerEntity() { EntityRegistry.registerModEntity(new ResourceLocation(Reference.MOD_ID, "textures/items/shuriken.png"), EntityShuriken.class, Reference.TestItems.SHURIKEN.getUnlocalizedName(), 0, TestMod.instance, 64, 10, true); } /* Custom Helper Method * * Inflict damage on the entity hit by the shuriken */ private void inflictDamage(RayTraceResult result) { // Get the entity that was hit by the shuriken and inflict damage result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 4); } /* Custom Helper Method * * Destroy the shuriken entity once it hits another entity or a block. Also add a little animation too */ private void destroySelf() { // A little smoke animation this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]); // Destroy the shuriken entity and remove it from the world (inherited from the entity class) this.setDead(); } /* * When the shuriken entity hits something... */ @Override protected void onImpact(RayTraceResult result) { if (result.typeOfHit == RayTraceResult.Type.BLOCK) // Shuriken hits a block { // Get the block that the shuriken hit Block block = this.world.getBlockState(result.getBlockPos()).getBlock(); // If the shuriken collides with vegetation and other "quasi" blocks, destroy the thing and continue on its path if (Arrays.asList(SHURIKEN_BREAKS_THROUGH).contains(block)) { // Get info relevant so the broken vegetation block is harvestable BlockPos blockpos = result.getBlockPos(); IBlockState blockstate = this.world.getBlockState(blockpos); TileEntity te = this.world.getTileEntity(blockpos); if (this.getThrower() instanceof EntityPlayer) // if thrower is a player { // Destroy the block but make sure it's harvestable EntityPlayer player = (EntityPlayer)this.getThrower(); this.world.destroyBlock(blockpos, false); block.harvestBlock(this.world, player, blockpos, blockstate, te, new ItemStack(ModItems.shuriken)); // TODO: Verify the last parameter is correct (making a guess on this one) } } // Otherwise it hit a block or entity and can be destroyed else { this.destroySelf(); } } else { if (result.entityHit != null) { this.inflictDamage(result); } this.destroySelf(); } } /* * Override impact of gravity to be minimal */ @Override protected float getGravityVelocity() { return this.GRAVITY; } } RenderShuriken.java package com.puresalvation.test.render; import org.lwjgl.opengl.GL11; import com.puresalvation.test.Reference; import com.puresalvation.test.entity.EntityShuriken; import com.puresalvation.test.init.ModItems; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderSnowball; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.client.registry.IRenderFactory; import net.minecraftforge.fml.client.registry.RenderingRegistry; public class RenderShuriken extends Render<EntityShuriken> { // Location of the texture private static final ResourceLocation shurikenTexture = new ResourceLocation(Reference.MOD_ID, "textures/items/shuriken.png"); protected final Item item; private final RenderItem itemRenderer; // [CONSTRUCTORS] public RenderShuriken(RenderManager renderManager) { super(renderManager); this.item = ModItems.shuriken; this.itemRenderer = Minecraft.getMinecraft().getRenderItem(); } // [METHODS] public static void registerRender() { RenderingRegistry.registerEntityRenderingHandler(EntityShuriken.class, new IRenderFactory() { @Override public Render createRenderFor(RenderManager manager) { return new RenderShuriken(manager); } }); } /* Custom Helper Method * * Return the texture of the shuriken */ @Override protected ResourceLocation getEntityTexture(EntityShuriken shuriken) { return this.shurikenTexture; } public ItemStack getStackToRender(EntityShuriken entityIn) { return new ItemStack(this.item); } @Override public void doRender(EntityShuriken shuriken, double x, double y, double z, float entityYaw, float partialTicks) { GlStateManager.pushMatrix(); GlStateManager.translate((float)x, (float)y, (float)z); GlStateManager.enableRescaleNormal(); GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GlStateManager.rotate((float)(this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); this.bindEntityTexture(shuriken); if (this.renderOutlines) { GlStateManager.enableColorMaterial(); GlStateManager.enableOutlineMode(this.getTeamColor(shuriken)); } this.itemRenderer.renderItem(this.getStackToRender(shuriken), ItemCameraTransforms.TransformType.GROUND); if (this.renderOutlines) { GlStateManager.disableOutlineMode(); GlStateManager.disableColorMaterial(); } GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); super.doRender(shuriken, x, y, z, entityYaw, partialTicks); } } Edited March 22, 20178 yr by Sack Of Potatoes
March 30, 20178 yr Author Still haven't solved this issue, if anyone has any potential thoughts or ideas I'm open to suggestions
March 31, 20178 yr Is it just the rendering that's the problem, or is the entity hitting your player when you throw it? If it's the latter, it might have something to do with MC-88491.
April 1, 20178 yr Author 21 hours ago, TheMasterGabriel said: Is it just the rendering that's the problem, or is the entity hitting your player when you throw it? If it's the latter, it might have something to do with MC-88491. I'm not entirely sure, it would make sense if it's the latter but I can't see the entity even behind me
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.