diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/world/BlockPosition.java b/src/main/java/de/bixilon/minosoft/game/datatypes/world/BlockPosition.java index 38a470d89..8e7b191bf 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/world/BlockPosition.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/world/BlockPosition.java @@ -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 diff --git a/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java b/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java index 6764bdc18..6aad82746 100644 --- a/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java +++ b/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java @@ -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 } diff --git a/src/main/java/de/bixilon/minosoft/render/texture/TextureLoader.java b/src/main/java/de/bixilon/minosoft/render/texture/TextureLoader.java index 724ed84c2..d91bbb325 100644 --- a/src/main/java/de/bixilon/minosoft/render/texture/TextureLoader.java +++ b/src/main/java/de/bixilon/minosoft/render/texture/TextureLoader.java @@ -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 rgbValues = getRGBTriplet(rgb); + float brightness = getBrightness(rgbValues); + rgbValues = multiply(new Triplet<>(94f / 255f, 157f / 255f, 52f / 255f), brightness); + return getRGBInt(rgbValues); + } + + private static Triplet multiply(Triplet rgbValues, float value) { + rgbValues.item1 *= value; + rgbValues.item2 *= value; + rgbValues.item3 *= value; + return rgbValues; + } + + private static int getRGBInt(Triplet 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 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 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 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);