BliX5 Posted August 27, 2020 Posted August 27, 2020 New to modding, and I'm trying to make a climbing feature, so if you jump next to a certain block, you'll start climbing. The problem is: I don't know how to identify a block next to a player, only directly under. Any help would be appreciated. Thanks in advance. Quote
poopoodice Posted August 27, 2020 Posted August 27, 2020 BlockPos.offset() or pos.up/down/n/s/w/e Quote
BliX5 Posted August 27, 2020 Author Posted August 27, 2020 How would I use BlockPos.offset to find a Block value? Quote
Draco18s Posted August 27, 2020 Posted August 27, 2020 The player has a Position value. Use it. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
poopoodice Posted August 27, 2020 Posted August 27, 2020 it returns the new position. Through World.getBlockState(pos) you can get the blockstate, and then get the block from it. Quote
BliX5 Posted August 27, 2020 Author Posted August 27, 2020 @Mod.EventBusSubscriber(modid = main.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ModClientEvents { @SubscribeEvent public static void onJumpNearStone(LivingEvent.LivingJumpEvent event) { LivingEntity player = event.getEntityLiving(); World world = player.getEntityWorld(); BlockPos pos = player.func_233580_cy_(); if (world.getBlockState(pos.add(1, 0, 0)).getBlock() == Blocks.STONE) { main.LOGGER.info(pos.add(1, 0, 0)); } else if (world.getBlockState(pos.add(-1, 0, 0)).getBlock() == Blocks.STONE) { main.LOGGER.info(pos.add(-1, 0, 0)); } else if (world.getBlockState(pos.add(0, 0, 1)).getBlock() == Blocks.STONE) { main.LOGGER.info(pos.add(0, 0, 1)); } else if (world.getBlockState(pos.add(0, 0, -1)).getBlock() == Blocks.STONE) { main.LOGGER.info(pos.add(0, 0, -1)); } } } It's probably very inefficient, but it works (mostly). My only problem is I must've messed up some code with the player, so instead of tracking only the player, it tracks every entity. I noticed this when I kept getting random messages when I wasn't jumping, but turning off mob spawning fixed the issue. Help? Quote
poopoodice Posted August 27, 2020 Posted August 27, 2020 The event is called LivingJumpEvent, it is triggered whenever a LivingEntity jumps. You can use instanceof syntax to check if the entity is player. Quote
BliX5 Posted August 27, 2020 Author Posted August 27, 2020 I tested it and the code tracks all entities, not just the player. How can I make LivingJumpEvent only track the player? Quote
Draco18s Posted August 27, 2020 Posted August 27, 2020 Put in a if statement checking if it is the player? 8 hours ago, poopoodice said: The event is called LivingJumpEvent, it is triggered whenever a LivingEntity jumps. You can use instanceof syntax to check if the entity is player. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
BliX5 Posted August 27, 2020 Author Posted August 27, 2020 Nevermind, I'm dumb. It's fixed now. Thanks for the help! 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.