[SOLVED] Updating Block Textures (Joined Boxes?) [3D]

Hello JGO, today I’ve been messing around with cubes in a 3D application :slight_smile:
Basically what I’m trying to accomplish is shown in the images below, but I’ll also explain it:

Here is what I am starting with:

I’m trying to accomplish something around the lines of:

Now I have been experimenting with this for the past few hours and I can’t seem to write a method that “Dynamically” adjusts.

Here is the method at the moment (Clean restart, was WAY too long):


	/**
	 * Updating the blocks texture.
	 * @param parentChunk The chunk to iterate through.
	 */
	public void updateBlockTexture(Chunk parentChunk) {

		// obtain a instance of this block (class)
		final Block b1 = (Block) this;

		// iterate through the parent chunk's blocks.
		for (int i = 0; i < parentChunk.getBlockList().size(); i++) {

			// obtaining a block from the list.
			final Block b2 = parentChunk.getBlockList().get(i);

			// are the blocks identical?
			final boolean identical = Boolean.valueOf(b1 == b2 || b2 == b1);

			if (!identical) {

				// check if b1 is ontop of b2
				if (b1.isOntopOf(b2)) {

					// updateB2.texture -> solid block texture (Vice Verca)
				}
				
				// check if b2 is ontop of b1
				if (b2.isOntopOf(b1)) {
					
					// updateB1.texture -> solid block texture (Vice Verca)
				}

				// TODO: Check blocks on top of blocks.
			}
		}
	}

When I wrote a somewhat decent version of this earlier I managed to get it to do what I want, but when I changed the chunks size It wouldn’t function properly xD.

If somebody whose done this before could help me out with a explanation / pseudo code or if anybody could link me to a tutorial I’d be very grateful thanks JGO :slight_smile:

If you need anymore information, please ask :slight_smile:

Just use different blocks for the top and fill.

Almost sounds like you’re stating the obvious lol ::slight_smile: ::slight_smile: ::).

Or maybe I didn’t explain what I’m trying to accomplish well enough :slight_smile:

Of course I want to use a different block texture for the top one xD each block is independent in the world so it has to be dealt with (In the method) independently.

Great, I solved it :slight_smile:

Thread closed.


	/**
	 * Updating the blocks texture.
	 * @param parentChunk The chunk to iterate through.
	 */
	public void updateBlockTexture(Chunk parentChunk) {

		// iterate through the parent chunk's blocks.
		for (int i = 0; i < parentChunk.getBlockList().size(); i++) {
			// obtain a instance of this block (class)
			final Block b1 = (Block) this;
			// obtaining a block from the list.
			final Block b2 = parentChunk.getBlockList().get(i);

			// are the blocks identical?
			final boolean identical = Boolean.valueOf(b1 == b2 || b2 == b1);

			if (!identical) {

				// check if b1 is ontop of b2
				if (b1.isOntopOf(b2)) {
					b2.setSideTextures("Bottom");
					Game.debug(b1.toString() + " is on top of " + b2.toString());
					break;
					// updateB2.texture -> solid block texture (Vice Versa)
				}

				// check if b2 is ontop of b1
				if (b2.isOntopOf(b1)) {
					Game.debug(b2.toString() + " is on top of " + b1.toString());
					break;
					// updateB1.texture -> solid block texture (Vice Versa)
				}

				// TODO: Check blocks ontop of blocks.
			}
		}
	}

Minecraft used the “grass topped block”, but there’s really no reason to slavishly copy this design. How about implementing the ability to compose blocks out of a base block and decorations? Then you just draw all dirt blocks and “paint” decorations on top. Sure it’s more complex but I think you can see some advantages to this too.