Ir para conteúdo
  • 0

[Resolvido] Criar uma gaiola


Trow_Games

Pergunta

Olá a todos; minha dúvida é a seguinte:

Quero saber como posso criar uma gaiola em certo local, tipo; eu tenho um código aqui, e ele cria um cubo só que eu quero que crie um cubo ocô sabe?

 

Código:
 

	public void generateCube(Location loc, int length) {
		// Set one corner of the cube to the given location.
		// Uses getBlockN() instead of getN() to avoid casting to an int later.
		int x1 = loc.getBlockX(); 
		int y1 = loc.getBlockY();
		int z1 = loc.getBlockZ();
		
		// Figure out the opposite corner of the cube by taking the corner and adding length to all coordinates.
		int x2 = x1 + length;
		int y2 = y1 + length;
		int z2 = z1 + length;
		
		World world = loc.getWorld();
		
		// Loop over the cube in the x dimension.
		for (int xPoint = x1; xPoint <= x2; xPoint++) { 
			// Loop over the cube in the y dimension.
			for (int yPoint = y1; yPoint <= y2; yPoint++) {
				// Loop over the cube in the z dimension.
				for (int zPoint = z1; zPoint <= z2; zPoint++) {
					// Get the block that we are currently looping over.
					Block currentBlock = world.getBlockAt(xPoint, yPoint, zPoint);
					// Set the block to type 57 (Diamond block!)
					currentBlock.setType(Material.DIAMOND_BLOCK);
				}
			}
		}
	}

Vlw a quem souber ajudar ai! ;)

 

Link para o comentário
Compartilhar em outros sites

7 respostass a esta questão

Posts Recomendados

Não entendi se é exatamente isso.

 

(Obs.: se não quiser com teto nem piso, só tirar cb4 e cb5)

 

 

public void generate(Location location, int length) {
    int x1 = (int) location.getX();
    int y1 = (int) location.getY();
    int z1 = (int) location.getZ();
    int x2 = x1 + length;
    int y2 = y1 + length;
    int z2 = z1 + length;
    World world = location.getWorld();
    for(int xp = x1; xp <= x2; xp++) {
        for(int yp = y1; yp <= y2; yp++) {
            for(int zp = z1; zp <= z2; zp++) {
                Block cb0 = world.getBlockAt(xp, yp, z1);
                Block cb1 = world.getBlockAt(x1, yp, zp);
                Block cb2 = world.getBlockAt(x2, yp, zp);
                Block cb3 = world.getBlockAt(xp, yp, z2);
                Block cb4 = world.getBlockAt(xp, y2, zp);
                Block cb5 = world.getBlockAt(xp, y1, zp);
                cb0.setType(Material.STONE);
                cb1.setType(Material.STONE);
                cb2.setType(Material.STONE);
                cb3.setType(Material.STONE);
                cb4.setType(Material.STONE);
                cb5.setType(Material.STONE);
            }
        }
    }
}
Link para o comentário
Compartilhar em outros sites

Se pode só gerar as paredes, ou, quando x ou y ou z for o tamanho do cudo tu coloca o bloco como o material q tu escolheu, senao coloca como AR

 

Agora eu preciso estudar pra prova, se ninguem tiver resolvido na hora que eu terminar eu posto um exemplo

Editado por leonardosc
Link para o comentário
Compartilhar em outros sites

Tipo, assim da certo não?

for (int xPoint = x2; xPoint >= x1; xPoint-=x1) { 
			// Loop over the cube in the y dimension.
			for (int yPoint = y2; yPoint >= y1; yPoint-=y1) {
				// Loop over the cube in the z dimension.
				for (int zPoint = z2; zPoint >= z1; zPoint-=z1) {
					// Get the block that we are currently looping over.
					Block currentBlock = world.getBlockAt(xPoint, yPoint, zPoint);
					// Set the block to type 57 (Diamond block!)
					currentBlock.setType(Material.DIAMOND_BLOCK);
				}
			}
		}

?

Editado por Dery
Link para o comentário
Compartilhar em outros sites

Tipo, assim da certo não?

for (int xPoint = x2; xPoint >= x1; xPoint-=x1) { 
			// Loop over the cube in the y dimension.
			for (int yPoint = y2; yPoint >= y1; yPoint-=y1) {
				// Loop over the cube in the z dimension.
				for (int zPoint = z2; zPoint >= z1; zPoint-=z1) {
					// Get the block that we are currently looping over.
					Block currentBlock = world.getBlockAt(xPoint, yPoint, zPoint);
					// Set the block to type 57 (Diamond block!)
					currentBlock.setType(Material.DIAMOND_BLOCK);
				}
			}
		}

?

Não, não é assim...

Fazendo assim, o bloco é gerado distante do player (distancia=tamanho definido).

 

E é gerado apenas 1 bloco.

Link para o comentário
Compartilhar em outros sites

 

Não entendi se é exatamente isso.

 

(Obs.: se não quiser com teto nem piso, só tirar cb4 e cb5)

public void generate(Location location, int length) {
    int x1 = (int) location.getX();
    int y1 = (int) location.getY();
    int z1 = (int) location.getZ();
    int x2 = x1 + length;
    int y2 = y1 + length;
    int z2 = z1 + length;
    World world = location.getWorld();
    for(int xp = x1; xp <= x2; xp++) {
        for(int yp = y1; yp <= y2; yp++) {
            for(int zp = z1; zp <= z2; zp++) {
                Block cb0 = world.getBlockAt(xp, yp, z1);
                Block cb1 = world.getBlockAt(x1, yp, zp);
                Block cb2 = world.getBlockAt(x2, yp, zp);
                Block cb3 = world.getBlockAt(xp, yp, z2);
                Block cb4 = world.getBlockAt(xp, y2, zp);
                Block cb5 = world.getBlockAt(xp, y1, zp);
                cb0.setType(Material.STONE);
                cb1.setType(Material.STONE);
                cb2.setType(Material.STONE);
                cb3.setType(Material.STONE);
                cb4.setType(Material.STONE);
                cb5.setType(Material.STONE);
            }
        }
    }
}

Vlw :D

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...