From 27fd83af6d4576ed95197c82906b5ebeb4e83d7b Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Mon, 8 Nov 2021 18:10:05 +0900 Subject: [PATCH] Fix a rounding error to remove gridlines that appear around blocks. --- src/sig/SigRenderer.java | 16 +++++++++++++++- src/sig/Texture.java | 6 +++--- src/sig/utils/DrawUtils.java | 8 ++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/sig/SigRenderer.java b/src/sig/SigRenderer.java index 40b7e74..0d76039 100644 --- a/src/sig/SigRenderer.java +++ b/src/sig/SigRenderer.java @@ -159,6 +159,19 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene for (int x=0;x<64;x++) { for (int z=0;z<64;z++) { addBlock(new Vector(x,0,z),BlockType.GRASS); + if (r.nextInt(2)<1) { + switch (r.nextInt(7)) { + case 1:{ + addBlock(new Vector(x,1,z),BlockType.FURNACE); + }break; + case 2:{ + addBlock(new Vector(x,1,z),BlockType.PUMPKIN); + }break; + case 3:{ + addBlock(new Vector(x,1,z),BlockType.CRAFTING_TABLE); + }break; + } + } /* if (Math.random()<=0.5) { addBlock(new Vector(x,y,z),BlockType.GLASS); @@ -170,11 +183,12 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene for (int x=0;x<64;x++) { for (int y=1;y<5;y++) { + /* if (x%8>2&&x%8<6&&y>1&&y<4) { addBlock(new Vector(x,y,16),BlockType.GLASS); } else { addBlock(new Vector(x,y,16),BlockType.FURNACE); - } + }*/ } } diff --git a/src/sig/Texture.java b/src/sig/Texture.java index e5fe24c..ebc3417 100644 --- a/src/sig/Texture.java +++ b/src/sig/Texture.java @@ -51,12 +51,12 @@ public class Texture{ } public int getColor(float u,float v,float mult) { - int sx = (int)(u*width-1f); - int sy = (int)(v*height-1f); + int sx = (int)Math.min(width-0.1f,(u*width-0.1f)); + int sy = (int)Math.min(height-0.1f,(v*height-0.1f)); if (sx<0||sx>=width||sy<0||sy>=height) { return 0; } else { - int indice = (int)(u*width-1)+(int)(v*height-1)*width; + int indice = sx+sy*width; //return tex[indice]; return (int)((tex[indice]&0xFF)*mult) + ((int)(((tex[indice]&0xFF00)>>>8)*mult)<<8) + ((int)(((tex[indice]&0xFF0000)>>>16)*mult)<<16) + ((((tex[indice]&0xFF000000)>>>24))<<24); /*Color newCol = new Color(tex.getRGB(sx,sy)); diff --git a/src/sig/utils/DrawUtils.java b/src/sig/utils/DrawUtils.java index ae9fa95..f9ea247 100644 --- a/src/sig/utils/DrawUtils.java +++ b/src/sig/utils/DrawUtils.java @@ -85,10 +85,10 @@ public class DrawUtils { tex_v=tex_sv; tex_w=tex_sw; - float tstep = 1.0f/((float)(bx-ax)); + float tstep = 1.0f/(float)(bx-ax); float t=0.0f; - for (int j=ax;j