Jump to content

Recommended Posts

Posted

Hello everyone!

 

I'm trying to make a multiblock structure but I have some problems...

The metadata is wrong and I cant figure it out what I did wrong so for fixing the texture I replaced this line of code:

if(world.getBlockMetadata(x1, y1, z1) > 0) world.setBlockMetadataWithNotify(x1, y1, z1, 0, 3);

 

To:

if(world.getBlockMetadata(x1, y1, z1) > 0) world.setBlockMetadataWithNotify(x1, y1, z1, 9, 3);

 

But the texture is only showing after I removed 1 block of the structure.

 

Block Class:

package com.poonkje.optical.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import com.poonkje.optical.TileEntity.TileEntityWindmillFloor;
import com.poonkje.optical.common.MainClass;

public class WindmillFloor extends BlockContainer {

public WindmillFloor(Material material) {
	super(material);

	this.setBlockBounds(0, 0, 0, 1, (1F/16F)*14, 1);
}

public int getRenderType() {
	return -1;
}

public boolean renderAsNormalBlock() {
	return false;
}

public boolean isOpaqueCube() {
	return false;
}

public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) {
	updateMultiBlockStructure(world, x, y, z);
}

public void onBlockAdded(World world, int x, int y, int z) {
	updateMultiBlockStructure(world, x, y, z);
}

public void updateMultiBlockStructure(World world, int x, int y, int z) {
	isMultiBlockStructure(world, x, y, z);
}

public boolean isMultiBlockStructure(World world, int x1, int y1, int z1) {
	boolean mStructure = false;

	boolean currentCheckStructure = true;

	for(int x2 = 0; x2 < 3; x2++){
		for(int z2=0; z2 < 3; z2++){
			if(!mStructure){
				currentCheckStructure = true;

				for(int x3 = 0; x3 < 3; x3++){
					for(int z3 = 0; z3 < 3; z3++) {
						if(currentCheckStructure && !world.getBlock(x1+x2-x3, y1, z1+z2-z3).equals(MainClass.WindmillFloor)){
							currentCheckStructure = false;
						}
					}
				}
				if(currentCheckStructure){
					for(int x3 = 0; x3 <3; x3++){
						for(int z3 = 0; z3 < 3; z3++){
							world.setBlockMetadataWithNotify(x1+x2-x3, y1, z1+z2-z3, x3*3+z3, 2);
						}
					}
				}
			}

			mStructure = currentCheckStructure;
		}
	}
	if(mStructure) return true;

	if(world.getBlockMetadata(x1, y1, z1) > 0) world.setBlockMetadataWithNotify(x1, y1, z1, 9, 3);

	return false;
}

public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityWindmillFloor();
}

}

 

TileEntityRenderWindmillFloor class:

package com.poonkje.optical.TileEntity.Renderer;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

public class TileEntityRenderWindmillFloor extends TileEntitySpecialRenderer {

private final ResourceLocation res = new ResourceLocation("optical:textures/model/windmillFloor.png");

private int textureW = 32;
private int textureH = 32;

private float pixel = 1F/16F;
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {


	GL11.glPushMatrix();
		GL11.glTranslatef((float)x, (float)y, (float)z);

		Tessellator tes = Tessellator.instance;
		this.bindTexture(res);
		tes.startDrawingQuads(); // Starts the tes
		{				
			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 9){
				tes.addVertexWithUV(1, pixel*14, 1, 1F/textureW*(32), 1F/textureH*(32));
				tes.addVertexWithUV(1, pixel*14, 0, 1F/textureW*(32), 1F/textureH*(0));
				tes.addVertexWithUV(0, pixel*14, 0, 1F/textureW*(0), 1F/textureH*(0));
				tes.addVertexWithUV(0, pixel*14, 1, 1F/textureW*(0), 1F/textureH*(32));
			}

			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 1){
				tes.addVertexWithUV(0.5, pixel*14, 1.5, 1F/textureW*(32), 1F/textureH*(32));
				tes.addVertexWithUV(0.5, pixel*14, 1, 1F/textureW*(32), 1F/textureH*(8+16));
				tes.addVertexWithUV(0, pixel*14, 1, 1F/textureW*(8+16), 1F/textureH*(8+16));
				tes.addVertexWithUV(0, pixel*14, 1.5, 1F/textureW*(8+16), 1F/textureH*(32));
			}

			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 2){
				tes.addVertexWithUV(0.5, pixel*14, 2, 1F/textureW*(32), 1F/textureH*(8+16));
				tes.addVertexWithUV(0.5, pixel*14, 1, 1F/textureW*(32), 1F/textureH*();
				tes.addVertexWithUV(0, pixel*14, 1, 1F/textureW*(8+16), 1F/textureH*();
				tes.addVertexWithUV(0, pixel*14, 2, 1F/textureW*(8+16), 1F/textureH*(8+16));
			}
			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 3){
				tes.addVertexWithUV(1, pixel*14, 0.5, 1F/textureW*(8+16), 1F/textureH*(32));
				tes.addVertexWithUV(1, pixel*14, 0, 1F/textureW*(8+16), 1F/textureH*(8+16));
				tes.addVertexWithUV(0, pixel*14, 0, 1F/textureW*(, 1F/textureH*(8+16));
				tes.addVertexWithUV(0, pixel*14, 0.5, 1F/textureW*(, 1F/textureH*(32));
			}
			//4
			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 5){
				tes.addVertexWithUV(1, pixel*14, 1, 1F/textureW*(8+16), 1F/textureH*();
				tes.addVertexWithUV(1, pixel*14, 0.5, 1F/textureW*(8+16), 1F/textureH*(0));
				tes.addVertexWithUV(0, pixel*14, 0.5, 1F/textureW*(, 1F/textureH*(0));
				tes.addVertexWithUV(0, pixel*14, 1, 1F/textureW*(, 1F/textureH*();
			}
			//5 Middle Connected with 4! TODO
			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 5){
				tes.addVertexWithUV(0, pixel*14, 2, 1F/textureW*(8+16), 1F/textureH*(8+16));
				tes.addVertexWithUV(1, pixel*14, 2, 1F/textureW*(8+16), 1F/textureH*();
				tes.addVertexWithUV(1, pixel*14, 1, 1F/textureW*(, 1F/textureH*();
				tes.addVertexWithUV(0, pixel*14, 1, 1F/textureW*(, 1F/textureH*(8+16));
			}
			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 6){
				tes.addVertexWithUV(0.5, pixel*14, 0.5, 1F/textureW*(0), 1F/textureH*(32));
				tes.addVertexWithUV(1, pixel*14, 0.5, 1F/textureW*(0), 1F/textureH*(8+16));
				tes.addVertexWithUV(1, pixel*14, 0, 1F/textureW*(, 1F/textureH*(8+16));
				tes.addVertexWithUV(0.5, pixel*14, 0, 1F/textureW*(, 1F/textureH*(32));

			}

			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 7){
				tes.addVertexWithUV(0.5, pixel*14, 0, 1F/textureW*(, 1F/textureH*(32));
				tes.addVertexWithUV(0.5, pixel*14, 1, 1F/textureW*(8+16), 1F/textureH*(32));
				tes.addVertexWithUV(1, pixel*14, 1, 1F/textureW*(8+16), 1F/textureH*(8+16));
				tes.addVertexWithUV(1, pixel*14, 0, 1F/textureW*(, 1F/textureH*(8+16));

			}

			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == {
				tes.addVertexWithUV(0.5, pixel*14, 1, 1F/textureW*(, 1F/textureH*(32));
				tes.addVertexWithUV(1, pixel*14, 1, 1F/textureW*(, 1F/textureH*(8+16));
				tes.addVertexWithUV(1, pixel*14, 0.5, 1F/textureW*(0), 1F/textureH*(8+16));
				tes.addVertexWithUV(0.5, pixel*14, 0.5, 1F/textureW*(0), 1F/textureH*(32));
			}

			if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 5){
				tes.addVertexWithUV(1.5, pixel*14, 1, 1F/textureW*(0), 1F/textureH*(8+16));
				tes.addVertexWithUV(1.5, pixel*14, 0.5, 1F/textureW*(0), 1F/textureH*(32));
				tes.addVertexWithUV(1, pixel*14, 0.5, 1F/textureW*(, 1F/textureH*(32));
				tes.addVertexWithUV(1, pixel*14, 1, 1F/textureW*(, 1F/textureH*(8+16));
			}



		tes.draw(); //End of tes
	GL11.glPopMatrix();

}

}
}


 

This line of code sets the texture if the block is not a multiblock structure ( The texture is again only visible after you remove one block of the structure )

				if(tileentity.getWorldObj().getBlockMetadata(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord) == 9){
				tes.addVertexWithUV(1, pixel*14, 1, 1F/textureW*(32), 1F/textureH*(32));
				tes.addVertexWithUV(1, pixel*14, 0, 1F/textureW*(32), 1F/textureH*(0));
				tes.addVertexWithUV(0, pixel*14, 0, 1F/textureW*(0), 1F/textureH*(0));
				tes.addVertexWithUV(0, pixel*14, 1, 1F/textureW*(0), 1F/textureH*(32));
			}

And I don't know why but the textures are to dark and is only light on a specific perspective?

 

Images to get a better view of the

 

 

If I set 9 to 0 in the block and the render class then I get this:

Normal block ( Not a multiblock structure this is what I want to to look like if I place it ):

KFzCtKG.png

Multiblock structure:

JtImhIl.png

Texture dark and is only normal on a specific perspective:

Normal

lAzOnwG.png

Dark

ktHlkE0.png

 

 

 

Thanks already for the help!

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.