WebCraft icon indicating copy to clipboard operation
WebCraft copied to clipboard

Destroying blocks past 255

Open Klem3n opened this issue 7 years ago • 5 comments

Does anyone know how to fix the bug where it only allows you to destroy blocks up to x and y of 255?

I know this is the problem: var pixel = new Uint8Array( 4 ); gl.readPixels( mx/gl.viewportWidth*512, (1-my/gl.viewportHeight)*512, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel );

as its assigned to a byte array so the highest value is 255, I tried to change it to UNSIGNED_SHORT_4_4_4_4 and even a float with no luck. It kept returning 0,0,0,0 to the array

Klem3n avatar Jan 21 '18 18:01 Klem3n

RESOLVED THE ISSUE:

SOLUTION: Find this in renderer.java: var whiteTexture = this.texWhite = gl.createTexture(); change parameter gl.UNSIGNED_BYTE of gl.texImage2D to gl.FLOAT

Then find: var bt = gl.createTexture(); and do the same for`gl.texImage2D`` under that

Then change var pixels = new UInt8Array... and the line under that to this.

to var pixel = new Float32Array( 4 ); gl.readPixels( mx/gl.viewportWidth*512, (1-my/gl.viewportHeight)*512, 1, 1, gl.RGBA, gl.FLOAT, pixel );

And finnaly add this to beginning;

	var floatTextures = gl.getExtension('OES_texture_float');
	if (!floatTextures) {
    	alert('no floating point texture support');
    	return;
	}

change if ( pixel[0] != 255 ) to if ( pixel[0] != 1)

Result: https://i.gyazo.com/f7e3733264cdf60d625716e9e2bf4173.gif

PS

If you'd like to work with me on this project for fun, post your skype down bellow or message me or something. Now working on making the world infinite. Already coded chunks.

Klem3n avatar Jan 21 '18 18:01 Klem3n

Hi! well im only understand a bit javascript. I want to make the webcraft like you. can i learn from you or get the code from you? here's my webcraft https://ficopangz.herokuapp.com/multiplayer.html. here's my skype account: fico_pang

ficopang avatar Jan 22 '18 10:01 ficopang

oh, i already chat you. it's ok if your priority is singleplayer.

ficopang avatar Jan 22 '18 10:01 ficopang

RESOLVED THE ISSUE:

SOLUTION: Find this in renderer.java: var whiteTexture = this.texWhite = gl.createTexture(); change parameter gl.UNSIGNED_BYTE of gl.texImage2D to gl.FLOAT

Then find: var bt = gl.createTexture(); and do the same for`gl.texImage2D`` under that

Then change var pixels = new UInt8Array... and the line under that to this.

to var pixel = new Float32Array( 4 ); gl.readPixels( mx/gl.viewportWidth*512, (1-my/gl.viewportHeight)*512, 1, 1, gl.RGBA, gl.FLOAT, pixel );

And finnaly add this to beginning;

	var floatTextures = gl.getExtension('OES_texture_float');
	if (!floatTextures) {
    	alert('no floating point texture support');
    	return;
	}

change if ( pixel[0] != 255 ) to if ( pixel[0] != 1)

Result: https://i.gyazo.com/f7e3733264cdf60d625716e9e2bf4173.gif

PS

If you'd like to work with me on this project for fun, post your skype down bellow or message me or something. Now working on making the world infinite. Already coded chunks.

You seem to know what you're doing, do you have a way to increase the build height for multiplayer? I've been poking around render.js, world.js and blocks.js and can't seem to find the solution. I'm also not very good at programming, so that's another issue.

Alotario avatar Jan 26 '22 08:01 Alotario

@Klem3n I am interested in your work on this. Would you mind sharing your code?

p3rlphr33k avatar May 16 '22 16:05 p3rlphr33k