Posted October 1, 20196 yr 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!
October 1, 20196 yr 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.
October 1, 20196 yr 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.
October 1, 20196 yr 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.
October 1, 20196 yr 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
October 1, 20196 yr 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.
October 1, 20196 yr 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
October 1, 20196 yr 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.
October 1, 20196 yr 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();
October 1, 20196 yr 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?
October 1, 20196 yr Author 9 minutes ago, diesieben07 said: @SubscribeEvent So where does this exactly go? I'm confused by the wording in the docs
October 1, 20196 yr 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.
October 1, 20196 yr 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
October 1, 20196 yr 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.
October 1, 20196 yr 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
October 1, 20196 yr 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.
October 1, 20196 yr 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
October 1, 20196 yr 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
October 1, 20196 yr 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.