Added wood walls, fixed some collision detection, added lines and tile

break indicators for the user, added an indicator to tell the user when
they can use a certain tile.
This commit is contained in:
jsrobson10 2020-10-20 10:36:00 +11:00
parent 6ef6277148
commit 51c5e52057
29 changed files with 404 additions and 124 deletions

View File

@ -47,6 +47,7 @@ public class DisplayWindow implements IMainloopTask
public int glsl_discard_coords;
public int glsl_do_discard_coords;
public int glsl_do_lighting;
public int glsl_do_texture;
public int glsl_model;
public int glsl_camera;
public int glsl_projection;
@ -144,6 +145,7 @@ public class DisplayWindow implements IMainloopTask
glsl_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "discard_coords");
glsl_do_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "do_discard_coords");
glsl_do_lighting = GL33.glGetUniformLocation(environmentRenderer.program, "do_lighting");
glsl_do_texture = GL33.glGetUniformLocation(environmentRenderer.program, "do_texture");
glsl_color = GL33.glGetUniformLocation(environmentRenderer.program, "color");
glsl_contrast = GL33.glGetUniformLocation(environmentRenderer.program, "contrast");
glsl_billboard = GL33.glGetUniformLocation(environmentRenderer.program, "billboard");
@ -214,7 +216,8 @@ public class DisplayWindow implements IMainloopTask
environmentRenderer.use();
DisplayLighting.updateLighting();
GL33.glUniform1f(glsl_mist, 0);
GL33.glUniform1f(glsl_mist, 0.0078125f);
GL33.glUniform1i(glsl_do_texture, 1);
if(Main.player.getHydration() < 0.2) {
GL33.glUniform1f(glsl_contrast, (float)(0.2 - Main.player.getHydration()) * 1.6f);

View File

@ -320,47 +320,60 @@ public abstract class Entity implements ClassBdf
private boolean moveIsLegal(Vec2d pos)
{
Vec2i t_pos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
Chunk chunk = Main.world.getLayer().getChunk(pos);
tile_back = chunk.getBackTile(t_pos);
tile_front = chunk.getFrontTile(t_pos);
Layer layer = Main.world.getLayer();
// Is this entity solid
if(isSolid)
{
// Check the tile the player is standing on
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
final Vec2i[] positions = {
new Vec2i(-1, -1),
new Vec2i(1, -1),
new Vec2i(1, 1),
new Vec2i(-1, 1),
new Vec2i(1, 0),
new Vec2i(0, 1),
new Vec2i(-1, 0),
new Vec2i(0, -1),
new Vec2i(0, 0),
};
for(Vec2i tpos_offset : positions)
{
// Get the tile
Tile t = tile_back.tile;
// Check the tile the player is standing on
Vec2i tpos = new Vec2i(
MathHelpers.floor(pos.x) + tpos_offset.x,
MathHelpers.floor(pos.y) + tpos_offset.y);
TileState tile_back = layer.getBackTile(tpos);
TileState tile_front = layer.getFrontTile(tpos);
// Check the tiles hitbox if the tile is solid
if(t.tileSolid)
{
// Is the entity in the tiles hitbox
Vec2d check = pos.subtract(new Vec2d(tpos.x + 0.5, tpos.y + 0.5));
if(Math.max(Math.abs(check.x), Math.abs(check.y)) <= t.tileHitbox)
// Get the tile
Tile t = tile_back.tile;
// Check the tiles hitbox if the tile is solid
if(t.tileSolid)
{
// Send back false
return false;
// Is the entity in the tiles hitbox
Vec2d check = pos.subtract(tpos.toDouble());
if(t.inHitbox(tile_back, check)) {
return false;
}
}
}
}
{
// Get the front tile
Tile t = tile_front.tile;
// Check the tiles hitbox if the tile is solid
if(t.tileSolid)
{
// Is the entity in the tiles hitbox
Vec2d check = pos.subtract(new Vec2d(tpos.x + 0.5, tpos.y + 0.5));
if(Math.max(Math.abs(check.x), Math.abs(check.y)) <= t.tileHitbox)
// Get the front tile
Tile t = tile_front.tile;
// Check the tiles hitbox if the tile is solid
if(t.tileSolid)
{
// Send back false
return false;
// Is the entity in the tiles hitbox
Vec2d check = pos.subtract(tpos.toDouble());
if(t.inHitbox(tile_front, check)) {
return false;
}
}
}
}

View File

@ -61,6 +61,7 @@ public class EntityPlayer extends Entity implements
public boolean dead = false;
public boolean in_animation = false;
public int attackedCooldown = 0;
private int particle_spawn_cooldown = 0;
private ArrayList<Task> tasks;
private Inventory inventory;
@ -285,7 +286,7 @@ public class EntityPlayer extends Entity implements
if(is.isEmpty() || !is.item.onPlayerLeftClick(is, Main.world.getLayer(), this, place_pos))
{
boolean isTool = is.item instanceof ItemTool;
boolean isTool = !is.isEmpty() && is.item instanceof ItemTool;
ItemTool tool = isTool ? (ItemTool) is.item : null;
double speed = isTool ? ((ItemTool) is.item).toolSpeed(is) : 1;
Vec2i pos = place_pos.toInt();
@ -309,6 +310,16 @@ public class EntityPlayer extends Entity implements
break_pos = pos;
}
particle_spawn_cooldown += 1;
if(particle_spawn_cooldown > 10) {
particle_spawn_cooldown -= 10;
layer.spawnEntity(new ParticleBreak(
new Vec3d(pos.x + 0.5, 0, pos.y + 0.5),
new Vec3d(0, 0, 0), ts.tile.getModel(ts.meta), 2));
}
if(break_progress > ts.tile.hardness)
{
ItemStack[] stacks = ts.tile.getTileDrops(ts);
@ -431,11 +442,37 @@ public class EntityPlayer extends Entity implements
model.render();
ItemStack holding = inventory.getItem(inventory_hand);
Vec2d place_pos = getPos().xz().add(MathHelpers.moveTowards2(0.5, Math.toRadians(angle)));
Vec3d ppos = getPos();
{
boolean isTool = !holding.isEmpty() && holding.item instanceof ItemTool;
ItemTool tool = isTool ? (ItemTool) holding.item : null;
Vec2i pos = place_pos.toInt();
for(int ti=0;ti<2;ti++)
{
TileState ts;
if(ti == 0) {
ts = layer.getFrontTile(pos);
} else {
ts = layer.getBackTile(pos);
}
if(ts.tile.canTileBreak(ts, holding, tool) || ts.tile.canUse(ts))
{
Models.TILE_BORDER.setModel(Matrix4.translate(
new Vec3d(pos.x + 0.5 - ppos.x, 0, pos.y + 0.5 - ppos.z)));
Models.TILE_BORDER.render();
break;
}
}
}
if(holding != null && !holding.isEmpty())
{
Vec3d ppos = getPos();
Model model_place = holding.item.getPlaceModel(holding);
Model model_spawn = holding.item.getSpawnModel(holding);
Vec2d pos = ppos.xz().add(MathHelpers.moveTowards2(1, Math.toRadians(angle)));
@ -449,13 +486,15 @@ public class EntityPlayer extends Entity implements
if(render_place_model)
{
model_place.setModel(Matrix4.translate(Math.floor(pos.x) - ppos.x + 0.5, 0.001, Math.floor(pos.y) - ppos.z + 0.5));
model_place.setModel(Matrix4.translate(new Vec3d(
MathHelpers.floor(pos.x) + 0.5 - ppos.x, 0.00390625,
MathHelpers.floor(pos.y) + 0.5 - ppos.z)));
model_place.render();
}
if(model_spawn != null)
{
model_spawn.setModel(Matrix4.translate(pos.x - ppos.x, 0.001, pos.y - ppos.z));
model_spawn.setModel(Matrix4.translate(pos.x - ppos.x, 0, pos.y - ppos.z));
model_spawn.render();
}

View File

@ -15,6 +15,7 @@ import projectzombie.model.ModelRandom;
import projectzombie.model.ModelRock;
import projectzombie.model.ModelTallGrass;
import projectzombie.model.ModelTile;
import projectzombie.model.ModelTileBorder;
import projectzombie.model.ModelTree;
import projectzombie.model.ModelTreeSnow;
import projectzombie.model.ModelVertical;
@ -24,6 +25,7 @@ public class Models
{
public static final Model EMPTY = new ModelEmpty();
public static final Model TILE_MISSING = new ModelTile(Resources.TEX_EMPTY);
public static final Model TILE_BORDER = new ModelTileBorder();
public static final Model TILE_TALL_GRASS = new ModelTallGrass();
public static final Model TILE_GRASS = new ModelGrass();

View File

@ -37,6 +37,7 @@ import projectzombie.tiles.TileVoid;
import projectzombie.tiles.TileWall;
import projectzombie.tiles.TileWater;
import projectzombie.tiles.TileWoodFloor;
import projectzombie.tiles.TileWoodWall;
import projectzombie.tiles.TileWorkbench;
public class Tiles
@ -90,6 +91,7 @@ public class Tiles
register(ORE);
register(COAL);
register(WOOD_FLOOR);
register(WOOD_WALL);
}
public static final Tile GRASS = new TileGrass();
@ -127,4 +129,5 @@ public class Tiles
public static final Tile ORE = new TileOre();
public static final Tile COAL = new TileCoal();
public static final Tile WOOD_FLOOR = new TileWoodFloor();
public static final Tile WOOD_WALL = new TileWoodWall();
}

View File

@ -1,11 +1,18 @@
package projectzombie.items;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import projectzombie.Main;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Models;
import projectzombie.init.Tiles;
import projectzombie.items.modifier.ItemModifierMeta;
import projectzombie.model.Model;
import projectzombie.model.ModelItem;
import projectzombie.util.ItemStack;
import projectzombie.util.TileState;
import projectzombie.world.layer.Layer;
public class ItemWoodWall extends Item
{
@ -22,6 +29,28 @@ public class ItemWoodWall extends Item
return Models.ITEM_WOOD_WALL;
}
@Override
public boolean showPlaceModel(Layer layer, Vec2i pos, ItemStack stack) {
return layer.getFrontTile(pos).tile.isNaturalFloorItem;
}
@Override
public boolean onPlayerRightClick(ItemStack stack, Layer layer, EntityPlayer player, Vec2d place_pos)
{
Vec2i pos = place_pos.toInt();
if(!showPlaceModel(layer, pos, stack)) {
return false;
}
int angle = (int)MathHelpers.mod(Main.player.angle / 90 + 0.5, 4);
stack.count -= 1;
layer.setFrontTile(new TileState(Tiles.WOOD_WALL, ItemModifierMeta.getStackMeta(stack) * 4 + angle), pos);
return true;
}
@Override
public String getName(ItemStack stack) {
return "Wood Wall";

View File

@ -1,7 +1,10 @@
package projectzombie.model;
import org.lwjgl.opengl.GL33;
import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.init.Resources;
public class ModelChunkBorder extends Model
@ -10,61 +13,58 @@ public class ModelChunkBorder extends Model
@Override
public int getSize() {
return 16;
return 8;
}
@Override
public int getIndexSize() {
return 24;
return 8;
}
@Override
public void render()
{
if(bound != this) {
bind();
}
GL33.glUniform1i(Main.window.glsl_do_texture, 0);
GL33.glDrawElements(GL33.GL_LINES, getIndexSize(), GL33.GL_UNSIGNED_INT, 0);
GL33.glUniform1i(Main.window.glsl_do_texture, 1);
}
@Override
public float[] getVerticies()
{
float w = 16;
float h = 0.0625f;
float h = 0.03125f;
float f = 0b10;
float c = 0b000000111111111111;
float o = 0.5f;
return new float[]
{
0-o, 0, 0-o, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
w-o, 0, 0-o, 0, 0, 0, 0, 1, 0, 0,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 0, 1, 1, 1, c, f,
w-o, h, w-o, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
};
}
@Override
public int[] getIndicies() {
return new int[] {
0, 1, 2,
2, 3, 0,
4, 5, 6,
6, 7, 4,
8, 9, 10,
10, 11, 8,
12, 13, 14,
14, 15, 12,
0, 1,
2, 3,
4, 5,
6, 7,
};
}
@ -74,8 +74,6 @@ public class ModelChunkBorder extends Model
return new TextureRef3D[] {
ref, ref, ref, ref,
ref, ref, ref, ref,
ref, ref, ref, ref,
ref, ref, ref, ref,
};
}

View File

@ -0,0 +1,87 @@
package projectzombie.model;
import org.lwjgl.opengl.GL33;
import gl_engine.texture.TextureRef3D;
import projectzombie.Main;
import projectzombie.init.Resources;
public class ModelTileBorder extends Model
{
private static final TextureRef3D ref = Resources.ATLAS.get("/gui/pixel_white.png");
@Override
public int getSize() {
return 8;
}
@Override
public int getIndexSize() {
return 8;
}
@Override
public void render()
{
if(bound != this) {
bind();
}
GL33.glUniform1i(Main.window.glsl_do_texture, 0);
GL33.glDrawElements(GL33.GL_LINES, getIndexSize(), GL33.GL_UNSIGNED_INT, 0);
GL33.glUniform1i(Main.window.glsl_do_texture, 1);
}
@Override
public float[] getVerticies()
{
float h = 0.03125f;
float f = 0b10;
float c = 0b101111101111101111;
float o = 0.5f;
return new float[]
{
0-o, h, 0-o, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
1-o, h, 0-o, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
0-o, h, 1-o, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
1-o, h, 1-o, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
0-o, h, 0-o, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
0-o, h, 1-o, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
1-o, h, 0-o, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
1-o, h, 1-o, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, c, f,
};
}
@Override
public int[] getIndicies() {
return new int[] {
0, 1,
2, 3,
4, 5,
6, 7,
};
}
@Override
public TextureRef3D[] getTextures()
{
return new TextureRef3D[] {
ref, ref, ref, ref,
ref, ref, ref, ref,
};
}
@Override
public double getHeight() {
return 1;
}
@Override
public double getWidth() {
return 16;
}
}

View File

@ -48,90 +48,109 @@ public class ModelWall extends Model
@Override
public float[] getVerticies()
{
float x1=0, x2=0, x3=0, x4=0, z1=0, z2=0, z3=0, z4=0;
float x1=0, x2=0, x3=0, x4=0, x5=0, x6=0, z1=0, z2=0, z3=0, z4=0, z5=0, z6=0;
switch(rotation)
{
case 0:
z1 = -0.5f;
z2 = -0.5f;
z3 = -0.25f;
z4 = -0.25f;
z1 = 0.5f;
z2 = 0.25f;
x1 = 0.5f;
x2 = 0.5f;
x3 = -0.5f;
x4 = -0.5f;
x2 = -0.5f;
break;
case 1:
x1 = -0.5f;
x2 = -0.5f;
x3 = -0.25f;
x4 = -0.25f;
x1 = 0.5f;
x2 = 0.25f;
z1 = 0.5f;
z2 = 0.5f;
z3 = -0.5f;
z4 = -0.5f;
z2 = -0.5f;
break;
case 2:
z1 = 0.5f;
z2 = 0.5f;
z3 = 0.25f;
z4 = 0.25f;
z1 = -0.5f;
z2 = -0.25f;
x1 = 0.5f;
x2 = 0.5f;
x3 = -0.5f;
x4 = -0.5f;
x2 = -0.5f;
break;
case 3:
x1 = 0.5f;
x2 = 0.5f;
x3 = 0.25f;
x4 = 0.25f;
x1 = -0.5f;
x2 = -0.25f;
z1 = 0.5f;
z2 = 0.5f;
z3 = -0.5f;
z4 = -0.5f;
z2 = -0.5f;
break;
}
if(rotation % 2 == 0) {
x3 = x1;
x4 = x2;
x5 = x2;
x6 = x1;
z3 = z1;
z4 = z1;
z5 = z2;
z6 = z2;
}
else {
x3 = x1;
x4 = x1;
x5 = x2;
x6 = x2;
z3 = z1;
z4 = z2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0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x3, 0, z4, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x3, 1, z4, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z3, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 0, z2, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 0, z2, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x2, 1, z2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z2, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x3, 1, z1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x3, 1, z3, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x1, 1, z3, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x3, 1, z3, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x4, 1, z4, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x5, 1, z5, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
x6, 1, z6, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,
};
}
@Override
public TextureRef3D[] getTextures() {
return new TextureRef3D[] {
front, front, front, front,
front, front, front, front,
side, side, side, side,
side, side, side, side,
top, top, top, top,
};
public TextureRef3D[] getTextures()
{
if(rotation % 2 == 0) {
return new TextureRef3D[] {
side, side, side, side,
side, side, side, side,
front, front, front, front,
front, front, front, front,
top, top, top, top,
};
}
else {
return new TextureRef3D[] {
front, front, front, front,
front, front, front, front,
side, side, side, side,
side, side, side, side,
top, top, top, top,
};
}
}
@Override

View File

@ -1,5 +1,6 @@
package projectzombie.tiles;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import projectzombie.entity.Entity;
import projectzombie.items.ItemTool;
@ -23,6 +24,17 @@ public abstract class Tile
public boolean isNaturalFloorItem = false;
public int hardness = -1;
public boolean inHitbox(TileState state, Vec2d pos) {
return (pos.x > 0.5 - tileHitbox &&
pos.x < 0.5 + tileHitbox &&
pos.y > 0.5 - tileHitbox &&
pos.y < 0.5 + tileHitbox);
}
public boolean canUse(TileState state) {
return false;
}
public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, TileState state) {
}

View File

@ -0,0 +1,25 @@
package projectzombie.tiles;
import gl_engine.vec.Vec2d;
import projectzombie.util.TileState;
public abstract class TileAbstractWall extends Tile
{
public TileAbstractWall() {
tileSolid = true;
}
@Override
public boolean inHitbox(TileState state, Vec2d pos)
{
switch(state.meta % 4)
{
case 0: return pos.x > -0.125 && pos.x < 1.125 && pos.y > 0.5 && pos.y < 1.125;
case 1: return pos.y > -0.125 && pos.y < 1.125 && pos.x > 0.5 && pos.x < 1.125;
case 2: return pos.x > -0.125 && pos.x < 1.125 && pos.y > -0.125 && pos.y < 0.5;
case 3: return pos.y > -0.125 && pos.y < 1.125 && pos.x > -0.125 && pos.x < 0.5;
}
return false;
}
}

View File

@ -38,6 +38,11 @@ public class TileBlastFurnace extends Tile
return Models.TILE_BLAST_FURNACE;
}
@Override
public boolean canUse(TileState state) {
return true;
}
@Override
public boolean onActivated(Layer layer, Vec2i tpos, Entity entity, TileState state) {
super.onActivated(layer, tpos, entity, state);

View File

@ -30,6 +30,11 @@ public class TileBossPortal extends Tile
this.unbreakable = true;
}
@Override
public boolean canUse(TileState state) {
return true;
}
@Override
public double getLightLevel(TileState state, Vec2i pos) {
return 0.6;

View File

@ -27,6 +27,11 @@ public class TileCampfire extends Tile
this.hardness = 800;
}
@Override
public boolean canUse(TileState state) {
return true;
}
@Override
public double getLightLevel(TileState state, Vec2i pos) {
return 1 - MathHelpers.squared(1 - state.meta / 16.0);

View File

@ -29,6 +29,11 @@ public class TileChest extends Tile implements TileBulletBreakable
}
@Override
public boolean canUse(TileState state) {
return true;
}
private void spawnItem(Chunk chunk, Vec2i pos, ItemStack stack) {
chunk.spawnEntity(new EntityItem(pos.xny().toDouble(), new Vec3d(0, 0, 0), stack));
}

View File

@ -27,6 +27,11 @@ public class TileClayPot extends Tile
hardness = 100;
}
@Override
public boolean canUse(TileState state) {
return true;
}
@Override
public Model getModel(byte meta)
{

View File

@ -20,6 +20,11 @@ public class TileHemp extends Tile
this.hardness = 5000;
}
@Override
public boolean canUse(TileState state) {
return state.meta > 3;
}
@Override
public void tickRandomly(Layer layer, Chunk chunk, TileState state, Vec2i pos) {
super.tickRandomly(layer, chunk, state, pos);

View File

@ -19,6 +19,11 @@ public class TileLadderUp extends Tile
this.unbreakable = true;
}
@Override
public boolean canUse(TileState state) {
return true;
}
@Override
public boolean onActivated(Layer layer, Vec2i pos, Entity entity, TileState state)
{

View File

@ -18,6 +18,11 @@ public class TilePortalDown extends Tile
this.unbreakable = true;
}
@Override
public boolean canUse(TileState state) {
return true;
}
@Override
public boolean onActivated(Layer layer, Vec2i pos, Entity entity, TileState state)
{

View File

@ -22,7 +22,11 @@ public class TileWater extends Tile
this.slowness = 0.5;
this.unbreakable = true;
this.hardness = 800;
this.isNaturalFloorItem = true;
}
@Override
public boolean canUse(TileState state) {
return true;
}
@Override

View File

@ -9,17 +9,17 @@ import projectzombie.model.Model;
import projectzombie.util.ItemStack;
import projectzombie.util.TileState;
public class TileWoodWall extends Tile
public class TileWoodWall extends TileAbstractWall
{
public TileWoodWall()
{
tileSolid = true;
light_dissipation = 0.5;
hardness = 800;
}
@Override
public boolean canTileBreak(TileState state, ItemStack stack, ItemTool tool) {
return tool.toolType(stack) == ItemToolType.HATCHET;
return tool != null && tool.toolType(stack) == ItemToolType.HATCHET;
}
@Override

View File

@ -21,6 +21,11 @@ public class TileWorkbench extends Tile
hardness = 200;
}
@Override
public boolean canUse(TileState state) {
return true;
}
@Override
public Model getModel(byte meta) {
return Models.TILE_WORKBENCH;

View File

@ -25,6 +25,7 @@ uniform vec2 lightmap_size;
uniform int do_lighting;
uniform int do_discard_coords;
uniform int do_texture;
uniform vec4 discard_coords;
uniform vec4 color;
@ -70,7 +71,7 @@ vec3 interpolate2RGB(float x, float y, vec3 v00, vec3 v01, vec3 v10, vec3 v11) {
void main()
{
vec4 textureRGB = texture(atlas, pTexture);
vec4 textureRGB = do_texture == 0 ? vec4(1) : texture(atlas, pTexture);
if(mode == 0)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB