fix bug in neighbour face detection, render grass_block_top texture as a nice jumbled mess.

This commit is contained in:
Lukas 2020-07-14 18:49:54 +02:00
parent 4f6b34711a
commit 6ec0b76d33
3 changed files with 49 additions and 4 deletions

View File

@ -47,7 +47,15 @@ public class BlockPosition {
}
public ChunkLocation getChunkLocation() {
return new ChunkLocation(getX() / 16, getZ() / 16);
int x = getX() / 16;
int z = getZ() / 16;
if (getX() < 0) {
x--;
}
if (getZ() < 0) {
z--;
}
return new ChunkLocation(x, z);
}
@Override

View File

@ -75,9 +75,9 @@ public class WorldRenderer {
if (neighbourPos.getY() >= 0) {
Blocks neighbourBlock = MainWindow.getConnection().getPlayer().getWorld().getBlock(neighbourPos);
if (!(neighbourBlock == Blocks.AIR || neighbourBlock == null)) //!modelLoader.isFull(neighbourBlock))
// if there is a block next to the current block
// if there is a block next to the current block, don't draw the face
continue;
//TODO: fix buggy behavior
//TODO: fix buggy behavior, not always working correctly, probably a problem in the World or BlockPosition class
}

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.render.texture;
import de.bixilon.minosoft.Config;
import de.bixilon.minosoft.render.utility.Triplet;
import de.matthiasmann.twl.utils.PNGDecoder;
import javafx.util.Pair;
@ -58,6 +59,39 @@ public class TextureLoader {
}
private static int makeGreen(int rgb) {
// this method has some bugs but it looks cool so let's just say it is an intended mechanic
Triplet<Float, Float, Float> rgbValues = getRGBTriplet(rgb);
float brightness = getBrightness(rgbValues);
rgbValues = multiply(new Triplet<>(94f / 255f, 157f / 255f, 52f / 255f), brightness);
return getRGBInt(rgbValues);
}
private static Triplet<Float, Float, Float> multiply(Triplet<Float, Float, Float> rgbValues, float value) {
rgbValues.item1 *= value;
rgbValues.item2 *= value;
rgbValues.item3 *= value;
return rgbValues;
}
private static int getRGBInt(Triplet<Float, Float, Float> rgbValues) {
int red = (int) (rgbValues.item1 * 255);
int green = (int) (rgbValues.item2 * 255);
int blue = (int) (rgbValues.item3 * 255);
return ((red << 16) | (green << 8) | blue);
}
static Triplet<Float, Float, Float> getRGBTriplet(int rgb) {
float red = (float) ((rgb >>> 16) & 0xFF) / 16f;
float green = (float) ((rgb >> 8) & 0xFF) / 16f;
float blue = (float) ((rgb) & 0xFF) / 16f;
return new Triplet<>(red, green, blue);
}
private static float getBrightness(Triplet<Float, Float, Float> rgbValues) {
return .2126f * rgbValues.item1 + .7152f * rgbValues.item2 + .0722f * rgbValues.item3;
}
private void loadTextures(String textureFolder) throws IOException {
// Any animated block will be stationary
File[] textureFiles = new File(textureFolder).listFiles();
@ -92,6 +126,9 @@ public class TextureLoader {
for (int y = 0; y < TEXTURE_PACK_RES; y++) {
for (int xPixel = 0; xPixel < TEXTURE_PACK_RES; xPixel++) {
int rgb = img.getRGB(xPixel, y);
if (allTextures.get(xPos).getValue().equals("grass_block_top")) {
rgb = makeGreen(rgb);
}
totalImage.setRGB(xPos * TEXTURE_PACK_RES + xPixel, y, rgb);
}
}
@ -123,7 +160,7 @@ public class TextureLoader {
}
public Pair<Float, Float> getTexture(String name) {
// returns the start and end u-coordinate of a specific texture to access it
// returns the start and end u-coordinatea of a specific texture to access it
String textureName = name;
if (textureName.contains("block/"))
textureName = textureName.substring(textureName.lastIndexOf('/') + 1);