Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2] RightClickEvent


Pppineeeee3
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

1 minute ago, Pppineeeee3 said:

I'm not entirety sure how to check/cancel the event.

You can read up about events here.

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
 

Link to comment
Share on other sites

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.

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.