Skip to content

Commit

Permalink
Add oak log and coal ore
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Aug 2, 2024
1 parent da75736 commit d6d91d0
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ A 3D sandbox game.

Math codes are from [JOML](https://github.com/JOML-CI/JOML).

Block textures are from [Squareful](https://www.curseforge.com/minecraft/texture-packs/xekr-square-pattern) by XeKr.
Block textures are from [Squareful](https://www.curseforge.com/minecraft/texture-packs/xekr-square-pattern) by XeKr redistributed under [CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh) License.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import org.slf4j.Logger;
import overrungl.opengl.GL10C;

import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* The game renderer.
Expand Down Expand Up @@ -80,7 +80,7 @@ public void init(GLStateMgr gl) {

initBlockAtlas(gl);

final TextureAtlas guiAtlas = TextureAtlas.load(gl, List.of(
final TextureAtlas guiAtlas = TextureAtlas.load(gl, Set.of(
HudRenderer.CROSSING_TEXTURE,
HudRenderer.HOT_BAR_TEXTURE,
HudRenderer.HOT_BAR_SELECTED_TEXTURE
Expand All @@ -101,17 +101,17 @@ private void initBlockAtlas(GLStateMgr gl) {
final var registry = client.blockModelManager().registry();

// scan textures
final List<Identifier> list = new ArrayList<>(registry.size());
final Set<Identifier> set = new HashSet<>(registry.size());
for (var e : registry) {
final BlockModel model = e.getValue();
for (BlockModelPart part : model.parts()) {
for (BlockModelFace face : part.faces().values()) {
list.add(model.textureDefinitions().get(face.textureKey()));
set.add(model.textureDefinitions().get(face.textureKey()));
}
}
}

final TextureAtlas blockAtlas = TextureAtlas.load(gl, list, 4);
final TextureAtlas blockAtlas = TextureAtlas.load(gl, set, 4);
textureManager.addTexture(TextureManager.BLOCK_ATLAS, blockAtlas);
logAtlas(blockAtlas, TextureManager.BLOCK_ATLAS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public void bootstrap() {
register(BlockTypes.DIRT, new CubeAllBlockModel(Identifier.ofBuiltin("block/dirt")));
register(BlockTypes.STONE, new CubeAllBlockModel(Identifier.ofBuiltin("block/stone")));
register(BlockTypes.STONE_SLAB, new SlabBlockModel(Identifier.ofBuiltin("block/stone"), Identifier.ofBuiltin("block/stone"), Identifier.ofBuiltin("block/stone")));
register(BlockTypes.OAK_LOG, new LogBlockModel(Identifier.ofBuiltin("block/oak_log_top"), Identifier.ofBuiltin("block/oak_log")));
register(BlockTypes.COAL_ORE, new CubeAllBlockModel(Identifier.ofBuiltin("block/coal_ore")));
}

public BlockModel get(Identifier identifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public CubeAllBlockModel(Identifier texture) {
static {
final Map<Direction, BlockModelFace> map = HashMap.newHashMap(6);
for (Direction direction : Direction.LIST) {
map.put(direction, new BlockModelFace(Vector2f.ZERO, new Vector2f(1.0f), TextureKeys.ALL, direction));
map.put(direction, new BlockModelFace(Vector2f.ZERO, Vector2f.ONE, TextureKeys.ALL, direction));
}
LIST = List.of(new BlockModelPart(Vector3f.ZERO, new Vector3f(1.0f), map));
LIST = List.of(new BlockModelPart(Vector3f.ZERO, Vector3f.ONE, map));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* freeworld - 3D sandbox game
* Copyright (C) 2024 XenFork Union
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* only version 2.1 of the License.
*/

package freeworld.client.render.model.block;

import freeworld.client.util.MapBuilder;
import freeworld.math.Vector3f;
import freeworld.util.Direction;
import freeworld.util.Identifier;

import java.util.List;
import java.util.Map;

import static freeworld.client.render.model.TextureKeys.*;
import static freeworld.math.Vector2f.ONE;
import static freeworld.math.Vector2f.ZERO;
import static freeworld.util.Direction.*;

/**
* @author squid233
* @since 0.1.0
*/
public final class LogBlockModel implements BlockModel {
private static final List<BlockModelPart> LIST = List.of(
new BlockModelPart(
Vector3f.ZERO,
Vector3f.ONE,
new MapBuilder<Direction, BlockModelFace>()
.entry(WEST, new BlockModelFace(ZERO, ONE, SIDE, WEST))
.entry(EAST, new BlockModelFace(ZERO, ONE, SIDE, EAST))
.entry(DOWN, new BlockModelFace(ZERO, ONE, TOP, DOWN))
.entry(UP, new BlockModelFace(ZERO, ONE, TOP, UP))
.entry(NORTH, new BlockModelFace(ZERO, ONE, SIDE, NORTH))
.entry(SOUTH, new BlockModelFace(ZERO, ONE, SIDE, SOUTH))
.build()
)
);
private final Map<Identifier, Identifier> map;

public LogBlockModel(Identifier topTexture, Identifier sideTexture) {
this.map = Map.of(TOP, topTexture, SIDE, sideTexture);
}

@Override
public Map<Identifier, Identifier> textureDefinitions() {
return map;
}

@Override
public List<BlockModelPart> parts() {
return LIST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.Map;

import static freeworld.client.render.model.TextureKeys.*;
import static freeworld.math.Vector2f.*;
import static freeworld.util.Direction.*;

/**
* @author squid233
Expand All @@ -30,12 +32,12 @@ public final class SlabBlockModel implements BlockModel {
Vector3f.ZERO,
new Vector3f(1.0f, 0.5f, 1.0f),
new MapBuilder<Direction, BlockModelFace>()
.entry(Direction.WEST, new BlockModelFace(new Vector2f(0.0f, 0.5f), new Vector2f(1.0f), SIDE, Direction.WEST))
.entry(Direction.EAST, new BlockModelFace(new Vector2f(0.0f, 0.5f), new Vector2f(1.0f), SIDE, Direction.EAST))
.entry(Direction.DOWN, new BlockModelFace(Vector2f.ZERO, new Vector2f(1.0f), BOTTOM, Direction.DOWN))
.entry(Direction.UP, new BlockModelFace(Vector2f.ZERO, new Vector2f(1.0f), TOP, null))
.entry(Direction.NORTH, new BlockModelFace(new Vector2f(0.0f, 0.5f), new Vector2f(1.0f), SIDE, Direction.NORTH))
.entry(Direction.SOUTH, new BlockModelFace(new Vector2f(0.0f, 0.5f), new Vector2f(1.0f), SIDE, Direction.SOUTH))
.entry(WEST, new BlockModelFace(new Vector2f(0.0f, 0.5f), ONE, SIDE, WEST))
.entry(EAST, new BlockModelFace(new Vector2f(0.0f, 0.5f), ONE, SIDE, EAST))
.entry(DOWN, new BlockModelFace(ZERO, ONE, BOTTOM, DOWN))
.entry(UP, new BlockModelFace(ZERO, ONE, TOP, null))
.entry(NORTH, new BlockModelFace(new Vector2f(0.0f, 0.5f), ONE, SIDE, NORTH))
.entry(SOUTH, new BlockModelFace(new Vector2f(0.0f, 0.5f), ONE, SIDE, SOUTH))
.build()
));
private final Map<Identifier, Identifier> textureDef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* @author squid233
Expand All @@ -43,7 +44,8 @@ private TextureAtlas(int id, int width, int height, int mipmapLevel, Map<Identif
this.aliasMap = new HashMap<>();
}

public static TextureAtlas load(GLStateMgr gl, List<Identifier> identifierList, int initMipmapLevel) {
public static TextureAtlas load(GLStateMgr gl, Set<Identifier> identifierSet, int initMipmapLevel) {
var identifierList = List.copyOf(identifierSet);
final int numIds = identifierList.size();
final STBRectPack stbrp = STBRectPack.INSTANCE;
try (Arena arena = Arena.ofConfined()) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public final class BlockTypes {
public static final BlockType DIRT = register("dirt", new BlockType(new BlockType.Settings()));
public static final BlockType STONE = register("stone", new BlockType(new BlockType.Settings()));
public static final BlockType STONE_SLAB = register("stone_slab", new SlabBlockType(new BlockType.Settings()));
public static final BlockType OAK_LOG = register("oak_log", new BlockType(new BlockType.Settings()));
public static final BlockType COAL_ORE = register("coal_ore", new BlockType(new BlockType.Settings()));

private BlockTypes() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class PlayerEntity extends Entity {
BlockTypes.DIRT,
BlockTypes.GRASS_BLOCK,
BlockTypes.STONE_SLAB,
BlockTypes.AIR,
BlockTypes.AIR,
BlockTypes.OAK_LOG,
BlockTypes.COAL_ORE,
BlockTypes.AIR,
BlockTypes.AIR,
BlockTypes.AIR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
public record Vector2f(float x, float y) {
public static final Vector2f ZERO = new Vector2f(0.0f);
public static final Vector2f ONE = new Vector2f(1.0f);

public Vector2f(float d) {
this(d, d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
public record Vector3f(float x, float y, float z) {
public static final Vector3f ZERO = new Vector3f(0.0f);
public static final Vector3f ONE = new Vector3f(1.0f);

public Vector3f(float d) {
this(d, d, d);
Expand Down

0 comments on commit d6d91d0

Please sign in to comment.