Overv / WebCraft

Minecraft clone written in Javascript.
zlib License
387 stars 186 forks source link

Destroying blocks past 255 #25

Open Klem3n opened 6 years ago

Klem3n commented 6 years ago

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.viewportWidth512, (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 commented 6 years ago

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.viewportWidth512, (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.

ficopang commented 6 years ago

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 commented 6 years ago

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

Alotario commented 2 years ago

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.viewportWidth512, (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.

p3rlphr33k commented 2 years ago

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