fix up
parent
06817492af
commit
202e0f1324
|
@ -40,7 +40,7 @@ public class Block
|
|||
private final boolean visible, fullCube;
|
||||
private final float caveCarveThreshold;
|
||||
public final String identifier;
|
||||
private String texture;
|
||||
public String texture;
|
||||
|
||||
public boolean isFullCube()
|
||||
{ return this.fullCube; }
|
||||
|
@ -67,11 +67,17 @@ public class Block
|
|||
this.fullCube = properties.fullCube;
|
||||
this.identifier = properties.identifier;
|
||||
this.caveCarveThreshold = properties.caveCarveThreshold;
|
||||
if(model != null) {
|
||||
this.texture = model.getTexture().getTexture().getLocation();
|
||||
}else {
|
||||
this.texture = "DONTLOAD";
|
||||
}
|
||||
IDENTIFIER_TO_BLOCK.put(this.identifier, this);
|
||||
Blocks.blocks.add(this);
|
||||
}
|
||||
|
||||
public void updateBlockModel() {
|
||||
public void updateBlockModelData() {
|
||||
System.out.println("Updating block with texture at block/"+texture);
|
||||
this.model = ModelLoader.loadGenericCube("block/"+texture);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.github.halotroop.litecraft.types.block.Block.Properties;
|
|||
public final class Blocks
|
||||
{
|
||||
|
||||
public static ArrayList<Block> blocks = new ArrayList<Block>();//real number is 256 //TODO: get all mods to say how many blocks they have and increace the number by that
|
||||
public static ArrayList<Block> blocks = new ArrayList<Block>();
|
||||
|
||||
public static final Block AIR = new Block(new Properties("air").visible(false).fullCube(false));
|
||||
public static final Block GRASS = new Block(new Properties("cubes/soil/grass/grass_top.png").caveCarveThreshold(0.04f));
|
||||
|
|
|
@ -71,6 +71,7 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
shader.loadFakeLightingVariable(true);
|
||||
shader.loadShine(1, 1);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, atlasID);
|
||||
enableWireframe();
|
||||
}
|
||||
|
||||
|
@ -85,7 +86,7 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
if (entity != null && entity.getModel() != null)
|
||||
{
|
||||
TexturedModel blockModel = entity.getModel();
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, atlasID);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockModel.getTexture().getTextureID());
|
||||
prepBlockInstance(entity);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, blockModel.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
|
|
@ -34,20 +34,22 @@ public class Image
|
|||
img = stbi_load_from_memory(imageBuffer, w, h, comp, 0);
|
||||
if (img == null)
|
||||
{ throw new RuntimeException("Failed to load image: " + stbi_failure_reason()); }
|
||||
return new Image(w.get(0), h.get(0), img, comp);
|
||||
return new Image(w.get(0), h.get(0), img, comp, imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
private ByteBuffer image;
|
||||
private int width, height;
|
||||
private IntBuffer comp;
|
||||
private String location;
|
||||
|
||||
Image(int width, int heigh, ByteBuffer image, IntBuffer comp)
|
||||
Image(int width, int heigh, ByteBuffer image, IntBuffer comp, String location)
|
||||
{
|
||||
this.image = image;
|
||||
this.height = heigh;
|
||||
this.width = width;
|
||||
this.comp = comp;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
|
@ -61,4 +63,8 @@ public class Image
|
|||
|
||||
public IntBuffer getComp()
|
||||
{ return comp; }
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
|
@ -120,25 +120,27 @@ public class Loader
|
|||
//Fill the image with blank image data
|
||||
GL40.glTexImage2D(GL40.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width*2, height*2, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
|
||||
|
||||
int maxX = (int) Math.sqrt(Blocks.blocks.size());//if the block list gets too big just increace the 2 by 4 or somthing to account for it
|
||||
long maxX = Math.round(Math.sqrt(Blocks.blocks.size()));
|
||||
int currentX = 0;
|
||||
int currentY = 0;
|
||||
for(Block block: Blocks.blocks) {
|
||||
//just in case
|
||||
|
||||
block.updateBlockModel();
|
||||
|
||||
if(currentX > maxX) {
|
||||
currentX = 0;
|
||||
currentY--;
|
||||
if(!block.texture.equals("DONTLOAD")) {
|
||||
block.updateBlockModelData();
|
||||
if(currentX > maxX) {
|
||||
currentX = 0;
|
||||
currentY--;
|
||||
}
|
||||
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0,
|
||||
currentX*width, currentY*height,
|
||||
width, height,
|
||||
GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,
|
||||
block.model.getTexture().getTexture().getImage()
|
||||
);
|
||||
currentX++;
|
||||
}
|
||||
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0,
|
||||
currentX*width, currentY*height,
|
||||
width, height,
|
||||
GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,
|
||||
block.model.getTexture().getTexture().getImage()
|
||||
);
|
||||
currentX++;
|
||||
|
||||
}
|
||||
return atlasId;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue