SciPunk Posted February 19, 2020 Posted February 19, 2020 I have my throwable item, which I want it to spin when it is in the air and stick to the surface when it hits a block but I can´t figure out, my item uses a sprite renderer, here´s my code Item class Spoiler public class ItemBatarang extends Item{ public ItemBatarang(Properties properties) { super(properties); setRegistryName("item_batarang"); } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { ItemStack stack = playerIn.getHeldItem(handIn); Vec3d look = playerIn.getLookVec(); EntityBatarang batarang = new EntityBatarang(1.0D,1.0D,1.0D,worldIn); batarang.setPosition(playerIn.getPosX() + look.x , playerIn.getPosY() + look.y + 1, playerIn.getPosZ() + look.z); batarang.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F,1.5F,0.0F); if (!worldIn.isRemote) { worldIn.addEntity(batarang); } worldIn.playSound(null,playerIn.getPosition(), SoundEvents.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS,1.0f,1.0f); return new ActionResult<ItemStack>(ActionResultType.SUCCESS, stack); } } Entity class Spoiler public class EntityBatarang extends ProjectileItemEntity { public EntityBatarang(double x, double y, double z, World worldIn) { super(EntitiesHolder.BATARANG, x, y, z, worldIn); } public EntityBatarang( LivingEntity livingEntityIn, World worldIn) { super(EntitiesHolder.BATARANG, livingEntityIn, worldIn); } public EntityBatarang(EntityType<EntityBatarang> entityBatarangEntityType, World world) { super(EntitiesHolder.BATARANG, world); } @Override public IPacket<?> createSpawnPacket() { return NetworkHooks.getEntitySpawningPacket(this); } @Override protected Item getDefaultItem() { return ItemHolder.BATARANG; } @Override protected void onImpact(RayTraceResult result) { if (result.getType() == RayTraceResult.Type.ENTITY) { ((EntityRayTraceResult)result).getEntity().attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 5.0F); } if (result instanceof EntityRayTraceResult) { EntityRayTraceResult entityRayTraceResult = (EntityRayTraceResult) result; if(entityRayTraceResult.getEntity() instanceof MobEntity) { MobEntity entity = (MobEntity) entityRayTraceResult.getEntity(); double d0 = (double)entity.getPosX() ; double d1 = (double)entity.getPosY() + 1D; double d2 = (double)entity.getPosZ(); entity.addPotionEffect(new EffectInstance(Effects.SLOWNESS,120,2)); this.world.playSound(entity.getPosX(),entity.getPosY(),entity.getPosZ(), SoundEvents.BLOCK_ANVIL_HIT, SoundCategory.AMBIENT,1,1,true); //3400 this.remove(); } else if(entityRayTraceResult.getEntity() instanceof PlayerEntity) { PlayerEntity entity = (PlayerEntity) entityRayTraceResult.getEntity(); entity.addPotionEffect(new EffectInstance(Effects.SLOWNESS,120,2)); } } else if (result instanceof BlockRayTraceResult) { BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) result; double x = this.getPosX(); double y = this.getPosY(); double z = this.getPosZ(); this.setMotion(x,y,z); } } public static EntityType register() { return EntityType.Builder.<EntityBatarang>create(EntityBatarang::new, EntityClassification.MISC).size(0.8F, 0.8F).build("batarang").setRegistryName(ComicUniverse.MODID,"batarang"); } @Override public void tick() { super.tick(); this.motionMultiplier.rotatePitch(5); } } ClientProxy class (where it renders) Spoiler public class ClientProxy implements IProxy { @Override public void init() { ScreenManager.registerFactory(BlockHolder.BLOCKGENERATOR_CONTAINER, GUIGenerator::new); ScreenManager.registerFactory(BlockHolder.SUITFABRICATOR_CONTAINER, GUISuitfabricator::new); RenderingRegistry.registerEntityRenderingHandler(EntitiesHolder.RADIOACTIVE_SPIDER, RadioactiveSpiderRenderer::new); RenderingRegistry.registerEntityRenderingHandler(EntitiesHolder.SMOKE_PELLET, renderManager -> new SpriteRenderer<EntitySmokePellet>(renderManager, Minecraft.getInstance().getItemRenderer())); RenderingRegistry.registerEntityRenderingHandler(EntitiesHolder.BATARANG, renderManager -> new SpriteRenderer<EntityBatarang>(renderManager, Minecraft.getInstance().getItemRenderer())); } Quote
DragonITA Posted February 19, 2020 Posted February 19, 2020 @SciPunk What is your Problem? Quote New in Modding? == Still learning!
SciPunk Posted February 19, 2020 Author Posted February 19, 2020 27 minutes ago, DragonITA said: @SciPunk What is your Problem? My projectile item, I want it to spin when in the air and stuck to surface, but I don't know how Quote
Cadiboo Posted February 19, 2020 Posted February 19, 2020 Read this: https://cadiboo.github.io/tutorials/1.15.1/forge/1.4-proxies You’re better off extending the Arrow and adding the spin in your renderer (similar time the arrow shake) as it already sticks into stuff 1 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
SciPunk Posted February 21, 2020 Author Posted February 21, 2020 On 2/19/2020 at 4:08 PM, Cadiboo said: Read this: https://cadiboo.github.io/tutorials/1.15.1/forge/1.4-proxies You’re better off extending the Arrow and adding the spin in your renderer (similar time the arrow shake) as it already sticks into stuff Got it to stick, now I'll figure out the shake thing, thanks Quote
Recommended Posts
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.