Jump to content

A block that can have 12 possible orientations [SOLVED FOR NOW] [1.7.10]


Recommended Posts

Posted

Hello everyone.

 

So I am trying to create a block that can have 12 different orientations, now, I can make a block face in 4 different directions, but what I am trying to achieve is hard to explain. Just a note, I am not trying to achieve a diagonal block, I can look at the the sign to see this.

 

So, I am making a block, it has a model, the model is pretty much just a slab on its side. Now, I want this block to be able to do the following:

 

When the player places this block, if the player clicks on the top side of a block, my block will face upward, and the bottom of the model will face the player, so there is now 4 possible orientations from placing it on top of a block, I want the same to happen if the player clicks on the bottom of a block, the only difference being that my model now faces down, so, there is now 8 possible orientations from placing it on the bottom or top of a block. Now as for placing this block on the north south east or west side of a block, the bottom of the model will always face down, so there is no rotation other than the direction. So this adds up to 12 possible orientations. So, 4 orientations for placing this block flat on top of a block, 4 orientations for placing this block facing down on the bottom of a block, and 4 more orientations depending on the if the block is placed on the north, south, east or west side of a block..

 

I really hope this makes sense, as it is really hard to explain what I am trying to achieve here.

 

Thanks.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

You might need to play a little bit with the player's jaw to determine if the player is facing down or up, and with the player's pitch to determine the rotation of the Block.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Okay, I also have another question, how do I get what side of a block the player clicks to place a block? or can I? because, I could make a method that determines what to do depending on if the player clicks on side 1 (top), side 0 (bottom) or sides 2 to 5 (the rest of the sides). So, I need a way to get that information. I also want it so if the player shift clicks on the top or bottom, it will place the block up right.

 

I know this is quite complicated, also, before it is mentioned, I have looked at the stairs class, and the BlockRotatedPillar class, but it is confusing because most of the methods are named stupid things, such as func_150162_k (from blockrotatedpillar), and there are loads of methods like this in the stairs class.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

use

	@Override
	public void onBlockPlacedBy(World w, int x, int y, int z, EntityLivingBase e, ItemStack s){
		calculate metadate value based on e.rotationYaw and e.rotationPitch
		w.setBlockMetadataWithNotify(x, y, z, meta, 3);
	}

or if you prefer to orientate the block based on the where the click was use

@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float hitx, float hity, float hitz, int metadata) {
   do stuff here
    return metadata
}

Posted

Okay, thanks, I have used the onBlockAdded method, and the onBlockPlacedBy method, but I forgot about the onBlockPlaced method. Isn't the onBlockPlaced method the method that is called by things like block placers? if so, how will it handle orientating the block then?

 

I haven't actually used the onBlockPlaced method before, do I have to return the metadata? also, how would I use the onBlockPlaced method and the onBlockPlacedBy method at the same time? in the onBlockPlaced method, I would handle things like figuring out what direction the block should face (north south east west up or down), and in the onBlockPlacedBy method, I would handle the rotation of the block (what direction the bottom of the model is facing) if it was placed on the bottom or top of the block. So, which of these two methods would get called first?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Actually, it might be easier to use the yaw and pitch rotation of the player, would this work?

 

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
	int l = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
	int k = MathHelper.floor_double((double)(entityLiving.rotationPitch * 4.0F / 360.0F) + 0.5D) & 3;

	if (k == 0) { //If the player is looking down
		if (l == 0) {
			world.setBlockMetadataWithNotify(x, y, z, 0, 2);
		} if (l == 1) {
			world.setBlockMetadataWithNotify(x, y, z, 1, 2);
		} if (l == 2) {
			world.setBlockMetadataWithNotify(x, y, z, 2, 2);
		} if (l == 3) {
			world.setBlockMetadataWithNotify(x, y, z, 3, 2);
		}
	} if (k == 1) { //If the player is looking up
		if (l == 0) {
			world.setBlockMetadataWithNotify(x, y, z, 4, 2);
		} if (l == 1) {
			world.setBlockMetadataWithNotify(x, y, z, 5, 2);
		} if (l == 2) {
			world.setBlockMetadataWithNotify(x, y, z, 6, 2);
		} if (l == 3) {
			world.setBlockMetadataWithNotify(x, y, z, 7, 2);
		}
	} if ((k != 1) && (k != 0)) { //If the player is looking forwards (not down or up)
		if (l == 0) {
			world.setBlockMetadataWithNotify(x, y, z, 8, 2);
		} if (l == 1) {
			world.setBlockMetadataWithNotify(x, y, z, 9, 2);
		} if (l == 2) {
			world.setBlockMetadataWithNotify(x, y, z, 10, 2);
		} if (l == 3) {
			world.setBlockMetadataWithNotify(x, y, z, 11, 2);
		}
	}
}

 

One thing to note, I don't actually understand how int l or k work, I don't understand the bitwise operator (& 3), so really, I don't know what I need to change here other than rotationYaw to rotationPitch. I also don't know why * 4, I'm guessing because there is 4 orientations for yaw, so would I need to change the * 4 on the pitch to * 3? because the player can look up, down and forward? also, why + 0.5D?

 

If I understand how these integers work, I would probable have no trouble with this whole 12 orientations block thing.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Okay, so, I have got it working (still without understanding the maths behind l, and k) using trial and error.

 

This does still have all my debugging System.out.printlns

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
	int l = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
	int k = MathHelper.floor_double((double)(entityLiving.rotationPitch * 3.0F / 360.0F) + 0.5D) & 3;

	System.out.println("Players Rotation Yaw: " + l);
	System.out.println("Players Rotation Pitch: " + k);
	if (k == 3) { //If the player is looking up
		if (l == 0) { //South
			world.setBlockMetadataWithNotify(x, y, z, 0, 2);
			System.out.println("Faceing South");
		} if (l == 1) { //West
			world.setBlockMetadataWithNotify(x, y, z, 1, 2);
			System.out.println("Faceing West");
		} if (l == 2) { //North
			world.setBlockMetadataWithNotify(x, y, z, 2, 2);
			System.out.println("Faceing North");
		} if (l == 3) { //East
			world.setBlockMetadataWithNotify(x, y, z, 3, 2);
			System.out.println("Faceing East");
		}
		System.out.println("Player Is Looking Up");
	} if (k == 1) { //If the player is looking Down
		if (l == 0) { //South
			world.setBlockMetadataWithNotify(x, y, z, 4, 2);
			System.out.println("Faceing South");
		} if (l == 1) { //West
			world.setBlockMetadataWithNotify(x, y, z, 5, 2);
			System.out.println("Faceing West");
		} if (l == 2) { //North
			world.setBlockMetadataWithNotify(x, y, z, 6, 2);
			System.out.println("Faceing North");
		} if (l == 3) { //East
			world.setBlockMetadataWithNotify(x, y, z, 7, 2);
			System.out.println("Faceing East");
		}
		System.out.println("Player Is Looking Down");
	} if ((k != 1) && (k != 3)) { //If the player is looking forwards (not down or up)
		if (l == 0) { //South
			world.setBlockMetadataWithNotify(x, y, z, 8, 2);
			System.out.println("Faceing South");
		} if (l == 1) { //West
			world.setBlockMetadataWithNotify(x, y, z, 9, 2);
			System.out.println("Faceing West");
		} if (l == 2) { //North
			world.setBlockMetadataWithNotify(x, y, z, 10, 2);
			System.out.println("Faceing North");
		} if (l == 3) { //East
			world.setBlockMetadataWithNotify(x, y, z, 11, 2);
			System.out.println("Faceing East");
		}
		System.out.println("Player Is Looking Forwards");
	}

	System.out.println("Metadata: " + world.getBlockMetadata(x, y, z));
}

 

So, this seems to work, and know what metadata to assign the block. Now all I have to do is make the model rotate with GL11 in the renderer depending on the metadata.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

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



×
×
  • Create New...

Important Information

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