Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.15.2] Throwable item not firing when used
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
NarwhelZhu

[1.15.2] Throwable item not firing when used

By NarwhelZhu, November 28, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

NarwhelZhu    0

NarwhelZhu

NarwhelZhu    0

  • Tree Puncher
  • NarwhelZhu
  • Members
  • 0
  • 12 posts
Posted November 28, 2020 (edited)

I'm trying to make a super basic throwable item that is essentially just a retextured snowball with virtually identical code just to understand the basics of thrown items, and almost everything works, except that the item won't appear when I right click it to throw it or be fired from a dispenser. The item and entity are registered, the rendering works just fine, I can summon the entity with /summon and it appears, and there are no errors in the console at any point. The problem seems to be that the onItemRightClick() method isn't even being called at all when I right click, as I put debug messages in the method that never get run. I'm guessing that there's just one little thing that I'm not adding that would solve the whole thing, but I have no idea what it might be. Most of the code for the item and entity is copied directly from the snowball class, so I'm not sure if it has anything to do with those classes. 

 

Edit: This problem has been solved. For any future readers who have the same problem, the code below is updated to be correct and can be used as a reference.

 

Here's the code for the mod.

 

Entity class:

public class RiceBulletEntity extends ProjectileItemEntity {
	
	public RiceBulletEntity(EntityType<? extends RiceBulletEntity> p_i50159_1_, World p_i50159_2_) {
		super(p_i50159_1_, p_i50159_2_);
	}
	
	public RiceBulletEntity(World worldIn, LivingEntity throwerIn) {
	    super(Registries.RICE_BULLET.get(), throwerIn, worldIn);
	}
	
	public RiceBulletEntity(World worldIn, double x, double y, double z) {
	      super(Registries.RICE_BULLET.get(), x, y, z, worldIn);
	}
	
	@Override
	protected Item getDefaultItem() {
		return Registries.RICE_BULLET_ITEM.get();
	}
	
	@Override
	public IPacket<?> createSpawnPacket() {
		return NetworkHooks.getEntitySpawningPacket(this);
	}

	@Override
	protected void onImpact(RayTraceResult result) {
		if (!this.world.isRemote) {
	         this.world.setEntityState(this, (byte)3);
	         this.remove();
	      }
	}
}

 

Item class:

public class RiceBulletItem extends Item {
	public RiceBulletItem(Item.Properties builder) {
	      super(builder);
	}

	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
		
		ItemStack itemstack = playerIn.getHeldItem(handIn);
		
	    if (!worldIn.isRemote) {
	        RiceBulletEntity riceBullet = new RiceBulletEntity(worldIn, playerIn);
	        riceBullet.setItem(itemstack);
	        riceBullet.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
	        worldIn.addEntity(riceBullet);
	    }

        playerIn.addStat(Stats.ITEM_USED.get(this));
        
        if (!playerIn.abilities.isCreativeMode) {
        	itemstack.shrink(1);
        }
        
        return ActionResult.resultSuccess(itemstack);
	}
}

 

Item and entity registries:

public class Registries {
	public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, Minesokyo.MOD_ID);

	public static final DeferredRegister<EntityType<?>> ENTITIES = new DeferredRegister<>(ForgeRegistries.ENTITIES,
			Minesokyo.MOD_ID);

	
	public static void init() {
		ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
        ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }
	
	
	public static final RegistryObject<Item> RICE_BULLET_ITEM = ITEMS.register("rice_bullet_item",
			() -> new RiceBulletItem(new Item.Properties().group(ItemGroup.COMBAT)));

	public static final RegistryObject<EntityType<RiceBulletEntity>> RICE_BULLET = ENTITIES.register("rice_bullet",
			() -> EntityType.Builder.<RiceBulletEntity>create(RiceBulletEntity::new, EntityClassification.MISC)
					.build("rice_bullet"));
}

 

Entity renderer:

public class RiceBulletRenderer extends SpriteRenderer<RiceBulletEntity> {

	public RiceBulletRenderer(EntityRendererManager renderManagerIn, ItemRenderer itemRendererIn) {
		super(renderManagerIn, itemRendererIn);
	}

	protected static final ResourceLocation TEXTURE = new ResourceLocation(Minesokyo.MOD_ID, "textures/items/rice_bullet.png");
	
	@Override
	public ResourceLocation getEntityTexture(RiceBulletEntity entity) {
		return TEXTURE;
	}



	public static class Factory implements IRenderFactory<RiceBulletEntity> {
		@Override
		public EntityRenderer<? super RiceBulletEntity> createRenderFor(EntityRendererManager manager) {
			return new RiceBulletRenderer(manager, Minecraft.getInstance().getItemRenderer());
		}	
	}
}

 

Renderer registries:

@Mod.EventBusSubscriber(modid = Minesokyo.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientEventBusSubscriber {
	
	@SubscribeEvent
	public static void onClientSetup(FMLClientSetupEvent event) {
		RenderingRegistry.registerEntityRenderingHandler(Registries.RICE_BULLET.get(), new RiceBulletRenderer.Factory());
	}

}

 

Edited November 28, 2020 by NarwhelZhu
  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted November 28, 2020
1 hour ago, NarwhelZhu said:

public static final RegistryObject<Item> RICE_BULLET_ITEM = ITEMS.register("rice_bullet_item", () -> new Item(new Item.Properties().group(ItemGroup.COMBAT)));

That would happen if you do not register the item using your extended item class.

  • Quote

Share this post


Link to post
Share on other sites

NarwhelZhu    0

NarwhelZhu

NarwhelZhu    0

  • Tree Puncher
  • NarwhelZhu
  • Members
  • 0
  • 12 posts
Posted November 28, 2020
57 minutes ago, ChampionAsh5357 said:

That would happen if you do not register the item using your extended item class.

Ah, thank you, I knew that it would be something really dumb like that. The entity does summon now, although it seems to be invisible. Is there some other obvious reason for that that I'm missing too?

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted November 28, 2020
8 minutes ago, NarwhelZhu said:

The entity does summon now, although it seems to be invisible. Is there some other obvious reason for that that I'm missing too?

This is more or less a guess, but try checking the output of ProjectileItemEntity#getItem and where the entity is initially placed. It's either due to the fact that the position of the entity spawn is too low so it dies immediately or the item is not synchronized to the client for rendering.

  • Quote

Share this post


Link to post
Share on other sites

NarwhelZhu    0

NarwhelZhu

NarwhelZhu    0

  • Tree Puncher
  • NarwhelZhu
  • Members
  • 0
  • 12 posts
Posted November 28, 2020 (edited)

Alright, I figured it out. Once again, an idiot mistake. I forgot to put throwerIn in the second entity constructor's super call. It appears now and I believe it's working fine. I'll update my code blocks to be correct for any future coders who have the same problem. Thank you for your help, even by just pointing out my own idiocy.

 

One last problem though: it doesn't fire from a dispenser like a snowball does. It doesn't look like the snowball classes even have code for that though.

Edited November 28, 2020 by NarwhelZhu
  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted November 28, 2020
11 minutes ago, NarwhelZhu said:

it doesn't fire from a dispenser like a snowball does. It doesn't look like the snowball classes even have code for that though.

You need to register the dispenser behavior using DispenserBlock::registerDispenseBehavior.

  • Quote

Share this post


Link to post
Share on other sites

NarwhelZhu    0

NarwhelZhu

NarwhelZhu    0

  • Tree Puncher
  • NarwhelZhu
  • Members
  • 0
  • 12 posts
Posted November 28, 2020
31 minutes ago, ChampionAsh5357 said:

You need to register the dispenser behavior using DispenserBlock::registerDispenseBehavior.

It works now, thanks. I think that will be all for this particular thread. It renders and fires from the dispenser now. Thanks for the help.

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • loordgek
      [1.16.5] Help with custom Event

      By loordgek · Posted 12 minutes ago

      yes  
    • Luis_ST
      [1.16.5] Help with custom Event

      By Luis_ST · Posted 35 minutes ago

      I've already found out that the bus is wrong   what do you mean by that? do you mean this: MinecraftForge.EVENT_BUS.post(event)  
    • loordgek
      [1.16.5] Help with custom Event

      By loordgek · Posted 44 minutes ago

      https://github.com/Luis-st/Forge-1.16.5-36.0.1-mdk/blob/main/forge-1.16.5-36.0.1-mdk/src/main/java/net/luis/cave/api/event/ModEventFactory.java you never post the event
    • Draco18s
      [1.16.5] Help with custom Event

      By Draco18s · Posted 56 minutes ago

      The error is caused by registering the event to the wrong bus. Change the bus, error goes away.
    • Luis_ST
      [1.16.5] Help with custom Event

      By Luis_ST · Posted 1 hour ago

      I already thought I wasn't sure   where is the error then? this is my enchanting table container (where i sue the event) https://github.com/Luis-st/Forge-1.16.5-36.0.1-mdk/blob/main/forge-1.16.5-36.0.1-mdk/src/main/java/net/luis/cave/common/inventory/container/ModEnchantingTableContainer.java
  • Topics

    • Luis_ST
      6
      [1.16.5] Help with custom Event

      By Luis_ST
      Started 4 hours ago

    • hammy3502
      1
      [1.16.4] Fluid Flowing Very Oddly

      By hammy3502
      Started 19 hours ago

    • <Gl33p_0r4nge>
      0
      [1.16.4] Screen Render

      By <Gl33p_0r4nge>
      Started 3 hours ago

    • forgnog
      0
      My Minecraft Forge Server Don't Start and I Don't Know Why

      By forgnog
      Started 4 hours ago

    • mikey3977
      4
      server won't start up

      By mikey3977
      Started December 4, 2020

  • Who's Online (See full list)

    • brok4d
    • Lucca_Lindup
    • a fellow friend
    • vemerion
    • Aviator737
    • Ezequiel052
    • S-Spirit
    • Astrow ( Astrow )
    • loordgek
    • diesieben07
    • HalternerJunge
    • forgnog
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.15.2] Throwable item not firing when used
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community