Skip to content

Commit

Permalink
Create block subpackage and BlockFace class
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Jul 24, 2024
1 parent 526e4fb commit 7bffdfb
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.nixinova.world;
package com.nixinova.blocks;

import com.nixinova.coords.BlockCoord;
import com.nixinova.graphics.Render;
Expand All @@ -15,17 +15,17 @@ public class Block {
public static Block GRASS = new Block("blocks/grass");
public static Block DEBUG = new Block("debug");
public static Block MISSING = new Block("missing_texture");

private Render texture;

public Block(String texture) {
this.texture = texture == null ? null : Texture.loadTexture(texture);
}

public Render getTexture() {
return this.texture;
}

public static boolean isInsideWorld(BlockCoord coords) {
int x = coords.x;
int z = coords.z;
Expand Down
35 changes: 35 additions & 0 deletions src/com/nixinova/blocks/BlockFace.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.nixinova.blocks;

import com.nixinova.graphics.Texture;

public enum BlockFace {
TOP, BOTTOM, LEFT, RIGHT, FRONT, BACK;

public static BlockFace getFromTx(int txX, int txY, int txZ) {
final int size = Texture.SIZE;

// Get 0..7-ranged texel IDs
int texIdX = txX % size;
int texIdY = txY % size;
int texIdZ = txZ % size;

// Set block's face
BlockFace face = null;
if (texIdX == 0)
face = RIGHT;
else if (texIdX == size - 1)
face = LEFT;
else if (texIdY == 0)
face = BOTTOM;
else if (texIdY == size - 1)
face = TOP;
else if (texIdZ == 0)
face = BACK;
else if (texIdZ == size - 1)
face = FRONT;

return face;
}


}
2 changes: 2 additions & 0 deletions src/com/nixinova/graphics/BlocksRenderer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nixinova.graphics;

import com.nixinova.blocks.Block;
import com.nixinova.blocks.BlockFace;
import com.nixinova.coords.BlockCoord;
import com.nixinova.coords.Coord3;
import com.nixinova.coords.PxCoord;
Expand Down
2 changes: 1 addition & 1 deletion src/com/nixinova/graphics/HUD.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.nixinova.graphics;

import com.nixinova.blocks.Block;
import com.nixinova.player.Hotbar;
import com.nixinova.world.Block;

public class HUD {

Expand Down
2 changes: 1 addition & 1 deletion src/com/nixinova/input/Controller.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nixinova.input;

import com.nixinova.Vector3;
import com.nixinova.blocks.Block;
import com.nixinova.coords.BlockCoord;
import com.nixinova.coords.Coord1;
import com.nixinova.coords.Coord3;
Expand All @@ -9,7 +10,6 @@
import com.nixinova.options.Options;
import com.nixinova.player.Hotbar;
import com.nixinova.player.Player;
import com.nixinova.world.Block;

public class Controller {

Expand Down
2 changes: 1 addition & 1 deletion src/com/nixinova/player/Hotbar.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.nixinova.player;

import com.nixinova.blocks.Block;
import com.nixinova.input.Keys;
import com.nixinova.world.Block;

public class Hotbar {
public static final Block[] SLOTS = new Block[10];
Expand Down
1 change: 1 addition & 0 deletions src/com/nixinova/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Random;

import com.nixinova.blocks.Block;
import com.nixinova.coords.BlockCoord;
import com.nixinova.graphics.Render;
import com.nixinova.options.Options;
Expand Down

0 comments on commit 7bffdfb

Please sign in to comment.