Posted August 13, 20187 yr Hi I was wondering how to manipulate a BlockPos, i.e. add 1 to x or z But I'm not sure how to do this, I've got pos = pos.offset(facing); Inside onItemUse, which I know all works as this returns the x,y,z pos of the block. Say I have position BlockPos{x=20, y=40, z=-100}, how do I get this to say {x=20, y=40, z=101} for example. Thanks Edited August 14, 20187 yr by Blu_Nighttime
August 13, 20187 yr BlockPos has methods for every direction one without params which target the blockPos next to it and one with an int param which searches the BlockPos in int value blocks distance. Sorry if this is unclear I think they are called up, down, north, west, south ,east My Projects: Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming) Important: As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts
August 13, 20187 yr For reference: +X is East +Y is Up +Z is South 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.
August 14, 20187 yr Also, a block pos contains fields for each of x, y, z so if you can do any math you want. Although most common operations, like getting block beside or above already have dedicated methods as mentioned. But don't be confused by BlockPos -- it just contains x, y, and z which are directly accessible if you need it. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
August 14, 20187 yr Author Cheers guys! Got it working. I needed to use .add(x,y,z) in conjunction with .offset(facing) to achieve several blocks being placed at once. If anyone else sees this (and for clear clarification for what I was looking for) this is the code necessary to place multiple blocks. public static BlockPos pos1; //creates a variable for holding second BlockPos public EnumActionResult onItemUse(...){ //Standard setup pos = pos.offset(facing); //fetch the current BlockPos the player is facing pos1 = pos.add(1, 0, 0) //set BlockPos 1 to the right (east, x) worldIn.setBlockState(pos, ...); //set the block infront of player to whatever worldIn.setBlockSate(pos1, ...); //set the block to the new BlockPos position (i.e. 1 to the right) to whatever. Obviously use if(worldIn.isAirBlock(pos)){...} to test to see if the new location can have a block placed, otherwise without this a block will be replaced which is incorrect (unless that is what you're looking for). And do this every time you need to place a new block that is at offset to the original location. I hope this helps anyone else, I know it definitely did for me. Thanks.
August 14, 20187 yr Author Also while this topic is still open, how do I get the player facing direction so i can have something like if(player facing north or south){...} if(player facing east or west){...} I thought it was something to do with EnumFacing but that doesn't seem to be the case.
August 14, 20187 yr 8 minutes ago, Blu_Nighttime said: Also while this topic is still open, how do I get the player facing direction so i can have something like if(player facing north or south){...} if(player facing east or west){...} I thought it was something to do with EnumFacing but that doesn't seem to be the case. Entity(something)#getHorizontalFacing 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.
August 14, 20187 yr Author Great, I knew it had something to do with player and EnumFacing but wasn't sure what else is was missing. Looks something like this: if(player.getHorizontalFacing == EnumFacing.NORTH || player.getHorizonalFacing == EnumFacing.SOUTH){...} //Likewise with West and East (For other people's referencing). Thanks guys, I know all of this is already in Forge and the declaration can be viewed in eclipse but sometimes it's so hard to know exactly what you're looking for that a few quick points like this is all you need. Thanks.
August 14, 20187 yr 5 hours ago, Blu_Nighttime said: pos1 = pos.add(1, 0, 0) //set BlockPos 1 to the right (east, x) Usually you want to do something more like pos1 = pos.rotateY(); //North -> East -> South -> West -> North 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.
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.