Jump to content

1.12 Manipulate BlockPos [SOLVED]


Blu_Nighttime

Recommended Posts

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 by Blu_Nighttime
Link to comment
Share on other sites

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

Link to comment
Share on other sites

For reference:

+X is East

+Y is Up

+Z is South

  • Like 1

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
    • Create a new instance and start with Embeddium/Oculus and Valkyrien Skies Try different builds of Embeddium/Valkyrien Skies until you find a working combination - then add the rest of your mods one by one or in groups
    • There are some mods missing Missing or unsupported mandatory dependencies: Mod ID: 'octolib', Requested by: 'ramcompat', Expected range: '[0.1,)', Actual version: '[MISSING]' Mod ID: 'forge', Requested by: 'tfc', Expected range: '[47.1.3,47.1.6),[47.1.81,47.2.0),[47.2.6,)', Actual version: '47.2.0' Mod ID: 'relics', Requested by: 'ramcompat', Expected range: '[0.6.5,)', Actual version: '[MISSING]' Add octolib and relics and update tfc to build 47.2.6
    • Make a test with adding LMFT https://www.curseforge.com/minecraft/mc-mods/lmft
  • Topics

×
×
  • Create New...

Important Information

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