Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am wanting to create an event to do something rather strange...

What I want is: when a player right clicks a gold block with a flint and steel I want it to spawn another gold block on top of it instead of fire

I tried using events but I just can't wrap my head around it.

Any help would be useful!

1 minute ago, Pppineeeee3 said:

I tried using events but I just can't wrap my head around it. 

Post what you tried.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
1 minute ago, Animefan8888 said:

Post what you tried.

That's the thing, I haven't got anything apart from a class, I'm not entirety sure how to check/cancel the event.

  • Author
11 minutes ago, Animefan8888 said:

You can read up about events here.

Okay, so I've managed to get this...

public class TestEvent
{
	public void exampleEvent(PlayerInteractEvent event)
	{
		World world = event.getWorld();
		EntityPlayer player = event.getEntityPlayer();
		ItemStack itemstack = player.getHeldItemMainhand();
		BlockPos pos = event.getPos();
		

		
		if(itemstack == new ItemStack(Items.FLINT_AND_STEEL))
		{
			
		}
		
	}

}

But I'm not sure where to go from it

1 minute ago, Pppineeeee3 said:

PlayerInteractEvent

There are several sub-events to this one, the one you want is called PlayerInteractEvent.RightClickBlock.

2 minutes ago, Pppineeeee3 said:

But I'm not sure where to go from it 

You have the BlockPos where the player right clicked(aka where the Block is in the World where they right clicked). That means you have access to which Block they right clicked. Check to make sure it was a Gold Block. If it was a Gold Block then use BlockPos#offset to offset in the UP direction and call World#setBlockState to put a Gold Block in the World at that offset position.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
1 minute ago, Animefan8888 said:

There are several sub-events to this one, the one you want is called PlayerInteractEvent.RightClickBlock.

You have the BlockPos where the player right clicked(aka where the Block is in the World where they right clicked). That means you have access to which Block they right clicked. Check to make sure it was a Gold Block. If it was a Gold Block then use BlockPos#offset to offset in the UP direction and call World#setBlockState to put a Gold Block in the World at that offset position.

Okay so I have this now...

public class TestEvent
{
	public void exampleEvent(RightClickBlock event)
	{
		World world = event.getWorld();
		EntityPlayer player = event.getEntityPlayer();
		ItemStack itemstack = player.getHeldItemMainhand();
		BlockPos pos = event.getPos();
		IBlockState state = world.getBlockState(pos);
		Block block = state.getBlock();
		

		
		if(itemstack == new ItemStack(Items.FLINT_AND_STEEL) && block.equals(Blocks.SOUL_SAND))
		{
			BlockPos fire = pos.offset(EnumFacing.UP);
			world.setBlockState(fire, Blocks.GOLD_BLOCK.getDefaultState());
		}
		
	}

}

But nothing seems to happen in game, it still places the fire :/

1 minute ago, Pppineeeee3 said:

But nothing seems to happen in game, it still places the fire

Is your event even being called? Where do you register it?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
3 minutes ago, Animefan8888 said:

Is your event even being called? Where do you register it?

I made a new class - EventHandler and added this to it:

public static void registerEvents()
	{
		TestEvent testEvent = new TestEvent();
	
		MinecraftForge.EVENT_BUS.register(testEvent);
	}

Then in my RegistryHandler (where the FMLInitialization events are) I have this in the preInit:

EventHandler.registerEvents();

 

  • Author
20 minutes ago, Animefan8888 said:

Is your event even being called? Where do you register it?

I'm guessing it has something to do with the fire being placed first?

 

  • Author
9 minutes ago, diesieben07 said:

@SubscribeEvent

So where does this exactly go? I'm confused by the wording in the docs

I was the blind one this time diesieben

2 minutes ago, Pppineeeee3 said:

So where does this exactly go? I'm confused by the wording in the docs

It goes right above your Event method.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
3 minutes ago, Animefan8888 said:

I was the blind one this time diesieben

It goes right above your Event method.

So:

	@SubscribeEvent
	public void exampleEvent(RightClickBlock event)
	{
		World world = event.getWorld();
		EntityPlayer player = event.getEntityPlayer();
		ItemStack itemstack = player.getHeldItemMainhand();
		BlockPos pos = event.getPos();
		IBlockState state = world.getBlockState(pos);
		Block block = state.getBlock();
		

		
		if(itemstack == new ItemStack(Items.FLINT_AND_STEEL) && block.equals(Blocks.SOUL_SAND))
		{
			BlockPos fire = pos.offset(EnumFacing.UP);
			world.setBlockState(fire, Blocks.GOLD_BLOCK.getDefaultState());
		}
	}

This still isn't doing anything

7 minutes ago, Pppineeeee3 said:

This still isn't doing anything

Can you confirm if the event is being fired. Put a print line there or better yet step through that method with your debugger.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
4 minutes ago, Animefan8888 said:

Put a print line there

I have added 2 print lines (Event Failed, and Event Success), every time I right click with a flint and steel, the Event Failed comes through, even if I am aimed at soul sand

44 minutes ago, Pppineeeee3 said:

itemstack == new ItemStack(Items.FLINT_AND_STEEL)

We were both blind diesieben...

The problem is that this will never be true. Use ItemStack#getItem and compare item instances instead.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
Just now, diesieben07 said:

Post updated code (with the debug message).

@SubscribeEvent
	public void exampleEvent(RightClickBlock event)
	{
		World world = event.getWorld();
		EntityPlayer player = event.getEntityPlayer();
		
		ItemStack itemstack = player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
		BlockPos pos = event.getPos();
		IBlockState state = world.getBlockState(pos);
		Block block = state.getBlock();
		

		if(itemstack == new ItemStack(Items.FLINT_AND_STEEL))
		{
			System.out.println("Tested and Found Flint And Steel");
			if(block == Blocks.SOUL_SAND.getDefaultState())
			{
				BlockPos fire = pos.offset(EnumFacing.UP);
				world.setBlockState(fire, Blocks.GOLD_BLOCK.getDefaultState());

				System.out.println("Event Success");
			}
		}
		else
		{
			System.out.println("Event Completely Failed");
		}
		
	}

And in the console: 

[19:17:54] [main/INFO] [STDOUT]: [club.mcmodding.netherupdate.events.TestEvent:exampleEvent:43]: Event Completely Failed
[19:17:54] [Server thread/INFO] [STDOUT]: [club.mcmodding.netherupdate.events.TestEvent:exampleEvent:43]: Event Completely Failed
 

  • Author
5 minutes ago, diesieben07 said:

Animefan is right.

Please learn basic Java (yes, the == operator is basic Java) before attempting to mod.

Yes, I see that now, however, there is still the problem with the block, as it is not being detected

8 minutes ago, Pppineeeee3 said:

block == Blocks.SOUL_SAND.getDefaultState()

Look at the return type of Block#getDefaultState... they aren't compatible.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.