Removed lots of unused code

This commit is contained in:
josua 2020-07-01 12:37:04 +10:00
parent 55ea5e6c55
commit fe1f97f248
11 changed files with 39 additions and 82 deletions

View File

@ -308,10 +308,6 @@ public class DisplayLighting
(float)(lighting.y * 16 - Camera.camera.y - 0.5)); (float)(lighting.y * 16 - Camera.camera.y - 0.5));
} }
else {
System.out.println("CAMERA IS NULL");
}
} }
public static void clearLighting() public static void clearLighting()

View File

@ -14,6 +14,7 @@ import projectzombie.Main;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.util.math.ColorRange; import projectzombie.util.math.ColorRange;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.chunk.ChunkEventHandler;
public class DisplayRender public class DisplayRender
@ -42,7 +43,7 @@ public class DisplayRender
Camera.camera = camera; Camera.camera = camera;
// Create the projection matrix // Create the projection matrix
Matrix4 projection = Matrix4.projection((double)w / (double)h, 45, 0.1, 1000); Matrix4 projection = Matrix4.projection((double)w / (double)h, 45, 0.1, Chunk.RENDER_DISTANCE*16+32);
projection = Matrix4.multiply(camera.getMatrix(), projection); projection = Matrix4.multiply(camera.getMatrix(), projection);
Matrix4 rotated = Matrix4.rotate(-camera.angle, 0, 1, 0); Matrix4 rotated = Matrix4.rotate(-camera.angle, 0, 1, 0);

View File

@ -23,6 +23,10 @@ public class DisplayRenderUI
public static Matrix4 camera, projection; public static Matrix4 camera, projection;
private static float calculateGreen(double a) {
return (float)(-2 * a * (a - 1) + 0.25 * a * a);
}
public static void renderGameGui() public static void renderGameGui()
{ {
{ {
@ -85,12 +89,12 @@ public class DisplayRenderUI
model_health_f.render(); model_health_f.render();
double temperature = MathHelpers.smoothStep(Main.player.getTemperature()); double temperature = MathHelpers.smoothStep(Main.player.getTemperature());
double hydration = MathHelpers.squared(1 - Main.player.getHydration()); double hydration = MathHelpers.smoothStep(1 - Main.player.getHydration());
GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0); GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0);
GL33.glUniform4f(Main.window.glsl_color, GL33.glUniform4f(Main.window.glsl_color,
(float)temperature, (float)temperature * 0.25f, 1 - (float)temperature, 1); (float)temperature, calculateGreen(temperature), 1 - (float)temperature, 1);
matrix = Matrix4.translate(-(9 * 0.75) / 8, -9.5 + (1.5 * 17) / 16, 0); matrix = Matrix4.translate(-(9 * 0.75) / 8, -9.5 + (1.5 * 17) / 16, 0);
@ -98,7 +102,7 @@ public class DisplayRenderUI
model_temperature.render(); model_temperature.render();
GL33.glUniform4f(Main.window.glsl_color, GL33.glUniform4f(Main.window.glsl_color,
(float)hydration, (float)hydration * 0.25f, 1 - (float)hydration, 1); (float)hydration * 0.75f, calculateGreen(hydration), 1 - (float)hydration, 1);
matrix = Matrix4.translate((1 * 0.75) / 8, -9.5 + (1.5 * 17) / 16, 0); matrix = Matrix4.translate((1 * 0.75) / 8, -9.5 + (1.5 * 17) / 16, 0);

View File

@ -29,13 +29,10 @@ public abstract class Entity implements IBdfClassManager
public Chunk chunk; public Chunk chunk;
private TileState tile_front; private TileState tile_front;
private TileState tile_back; private TileState tile_back;
public boolean crossUnWalkable = true;
public boolean goThroughSolid = true;
protected static final Random rand = new Random(); protected static final Random rand = new Random();
public boolean emitsLight = false; public boolean emitsLight = false;
public int stepOnTileCooldown = 0; private boolean isDead = false;
private boolean dead = false; protected boolean hasGravity = true;
protected boolean gravity = true;
private Vec3d pos; private Vec3d pos;
private Vec3d velocity; private Vec3d velocity;
@ -43,7 +40,7 @@ public abstract class Entity implements IBdfClassManager
public abstract IModel getModel(); public abstract IModel getModel();
public boolean isDead() { public boolean isDead() {
return dead; return isDead;
} }
public Vec3d getPos() { public Vec3d getPos() {
@ -142,11 +139,8 @@ public abstract class Entity implements IBdfClassManager
velocity = new Vec3d(e.get(1)); velocity = new Vec3d(e.get(1));
hitbox = e.get(2).getDouble(); hitbox = e.get(2).getDouble();
isSolid = e.get(3).getBoolean(); isSolid = e.get(3).getBoolean();
crossUnWalkable = e.get(4).getBoolean();
goThroughSolid = e.get(5).getBoolean();
emitsLight = e.get(6).getBoolean(); emitsLight = e.get(6).getBoolean();
stepOnTileCooldown = e.get(7).getInteger(); hasGravity = e.get(8).getBoolean();
gravity = e.get(8).getBoolean();
} }
@Override @Override
@ -165,18 +159,12 @@ public abstract class Entity implements IBdfClassManager
BdfObject velocity_bdf = new BdfObject(); BdfObject velocity_bdf = new BdfObject();
velocity.BdfClassSave(velocity_bdf); velocity.BdfClassSave(velocity_bdf);
BdfArray e = new BdfArray(); nl.set("pos", pos_bdf);
nl.set("e", BdfObject.withArray(e)); nl.set("velocity", velocity_bdf);
nl.set("hitbox", BdfObject.withDouble(hitbox));
e.add(pos_bdf); nl.set("isSolid", BdfObject.withBoolean(isSolid));
e.add(velocity_bdf); nl.set("emitsLight", BdfObject.withBoolean(emitsLight));
e.add(BdfObject.withDouble(hitbox)); nl.set("hasGravity", BdfObject.withBoolean(hasGravity));
e.add(BdfObject.withBoolean(isSolid));
e.add(BdfObject.withBoolean(crossUnWalkable));
e.add(BdfObject.withBoolean(goThroughSolid));
e.add(BdfObject.withBoolean(emitsLight));
e.add(BdfObject.withInteger(stepOnTileCooldown));
e.add(BdfObject.withBoolean(gravity));
} }
public void tick(Chunk chunk, Layer layer) public void tick(Chunk chunk, Layer layer)
@ -189,10 +177,6 @@ public abstract class Entity implements IBdfClassManager
tile_back = chunk.getBackTile(tpos); tile_back = chunk.getBackTile(tpos);
tile_front = chunk.getFrontTile(tpos); tile_front = chunk.getFrontTile(tpos);
if(stepOnTileCooldown > 0) {
stepOnTileCooldown -= 1;
}
Vec3d new_pos = pos.add(velocity); Vec3d new_pos = pos.add(velocity);
if(isSolid) { if(isSolid) {
@ -221,7 +205,7 @@ public abstract class Entity implements IBdfClassManager
pos.y = 0; pos.y = 0;
} }
if(gravity) { if(hasGravity) {
velocity.y -= MathHelpers.FallSpeed; velocity.y -= MathHelpers.FallSpeed;
} }
@ -232,11 +216,11 @@ public abstract class Entity implements IBdfClassManager
protected void moveAwayFromSolidEntities(Layer layer) protected void moveAwayFromSolidEntities(Layer layer)
{ {
if(!goThroughSolid) if(isSolid)
{ {
for(Entity e : layer.getNearbyEntities(pos.xz(), hitbox)) for(Entity e : layer.getNearbyEntities(pos.xz(), hitbox))
{ {
if(e.isSolid && !e.goThroughSolid && e != this) if(e.isSolid && e != this)
{ {
double distance = pos.distance(e.pos); double distance = pos.distance(e.pos);
double angle = MathHelpers.atan2(e.pos.z - pos.z, e.pos.x - pos.x); double angle = MathHelpers.atan2(e.pos.z - pos.z, e.pos.x - pos.x);
@ -255,7 +239,7 @@ public abstract class Entity implements IBdfClassManager
public void kill() { public void kill() {
chunk.killEntity(this); chunk.killEntity(this);
dead = true; isDead = true;
} }
public void activateTile() public void activateTile()
@ -271,20 +255,13 @@ public abstract class Entity implements IBdfClassManager
public void activateSteppedOnTile() public void activateSteppedOnTile()
{ {
// Has the cooldown expired // Get the tile position and the layer
if(stepOnTileCooldown == 0) Layer layer = Main.world.getLayer();
{ Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.z)+0);
// Get the tile position and the layer
Layer layer = Main.world.getLayer();
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.z)+0);
// Activate both tiles
tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front);
tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back);
// Reset the cooldown // Activate both tiles
stepOnTileCooldown = 1; tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front);
} tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back);
} }
private boolean moveIsLegal(Vec2d pos) private boolean moveIsLegal(Vec2d pos)
@ -295,7 +272,7 @@ public abstract class Entity implements IBdfClassManager
tile_front = chunk.getFrontTile(t_pos); tile_front = chunk.getFrontTile(t_pos);
// Is this entity solid // Is this entity solid
if(!goThroughSolid || !crossUnWalkable) if(isSolid)
{ {
// Check the tile the player is standing on // Check the tile the player is standing on
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
@ -304,13 +281,8 @@ public abstract class Entity implements IBdfClassManager
// Get the tile // Get the tile
Tile t = tile_back.tile; Tile t = tile_back.tile;
// Send false if the tile isn't walkable
if((!t.tileWalkable) && (!crossUnWalkable)) {
return false;
}
// Check the tiles hitbox if the tile is solid // Check the tiles hitbox if the tile is solid
if((t.tileSolid) && (!goThroughSolid)) if(t.tileSolid)
{ {
// Is the entity in the tiles hitbox // Is the entity in the tiles hitbox
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox) if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox)
@ -325,13 +297,8 @@ public abstract class Entity implements IBdfClassManager
// Get the front tile // Get the front tile
Tile t = tile_front.tile; Tile t = tile_front.tile;
// Send false if the tile isn't walkable
if((!t.tileWalkable) && (!crossUnWalkable)) {
return false;
}
// Check the tiles hitbox if the tile is solid // Check the tiles hitbox if the tile is solid
if((t.tileSolid) && (!goThroughSolid)) if(t.tileSolid)
{ {
// Is the entity in the tiles hitbox // Is the entity in the tiles hitbox
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox) if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox)

View File

@ -54,8 +54,6 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic
spawn_frequency = nl.get("spawn_frq").getInteger(); spawn_frequency = nl.get("spawn_frq").getInteger();
this.isSolid = true; this.isSolid = true;
this.goThroughSolid = false;
this.crossUnWalkable = false;
this.hitbox = 2; this.hitbox = 2;
long seed = nl.get("seed").getLong(); long seed = nl.get("seed").getLong();
@ -84,8 +82,6 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic
super(pos, velocity); super(pos, velocity);
this.isSolid = true; this.isSolid = true;
this.goThroughSolid = false;
this.crossUnWalkable = false;
this.hitbox = 2; this.hitbox = 2;
long seed = rand.nextLong(); long seed = rand.nextLong();

View File

@ -52,7 +52,7 @@ public class EntityBullet extends EntityParticle
this.parent = parent; this.parent = parent;
this.damage = damage; this.damage = damage;
this.time = despawn_time; this.time = despawn_time;
this.gravity = false; this.hasGravity = false;
// Play the gun sound // Play the gun sound
Sounds.GUN.play(pos, 2); Sounds.GUN.play(pos, 2);

View File

@ -58,8 +58,6 @@ public class EntityTnt extends Entity implements EntityHoldsEntities
Vec2d v = MathHelpers.moveTowards2(0.05, Math.toRadians(angle)); Vec2d v = MathHelpers.moveTowards2(0.05, Math.toRadians(angle));
velocity = velocity.add(new Vec3d(v.x, v.y, 0.01)); velocity = velocity.add(new Vec3d(v.x, v.y, 0.01));
this.explode_radius = explode_radius; this.explode_radius = explode_radius;
this.crossUnWalkable = true;
this.goThroughSolid = false;
this.explode_damage = explode_damage; this.explode_damage = explode_damage;
this.smoke_particles = new ParticleSpark[100]; this.smoke_particles = new ParticleSpark[100];

View File

@ -36,6 +36,7 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP
private Vec3d walk_to; private Vec3d walk_to;
private int walk_scan_cooldown = 0; private int walk_scan_cooldown = 0;
private boolean can_see_player = false; private boolean can_see_player = false;
protected boolean crossUnwalkable = false;
private int walking_for = 0; private int walking_for = 0;
public EntityZombie(BdfObject bdf) { public EntityZombie(BdfObject bdf) {
@ -44,8 +45,6 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP
// Set some settings // Set some settings
hitbox = 0.5; hitbox = 0.5;
isSolid = true; isSolid = true;
goThroughSolid = false;
crossUnWalkable = false;
} }
@Override @Override
@ -99,8 +98,6 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP
// Set some settings // Set some settings
hitbox = 0.5; hitbox = 0.5;
isSolid = true; isSolid = true;
goThroughSolid = false;
crossUnWalkable = false;
} }
@Override @Override
@ -122,7 +119,7 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP
(walk_to != null && getPos().toInt().equal(walk_to.toInt()) && (walk_to != null && getPos().toInt().equal(walk_to.toInt()) &&
player_distance > 2) || walk_scan_cooldown < 1 || walking_for > 200) player_distance > 2) || walk_scan_cooldown < 1 || walking_for > 200)
{ {
AStar astar = new AStar(getPos().xz().toInt(), 16, new AStarSearcher(layer, crossUnWalkable)); AStar astar = new AStar(getPos().xz().toInt(), 16, new AStarSearcher(layer));
Vec2i path[] = astar.getPath(Main.player.getPos().xz().toInt()); Vec2i path[] = astar.getPath(Main.player.getPos().xz().toInt());
walk_scan_cooldown = 100; walk_scan_cooldown = 100;

View File

@ -18,7 +18,7 @@ public class EntityZombieArmored extends EntityZombie
this.health = this.health_max; this.health = this.health_max;
this.gun_level = 3; this.gun_level = 3;
this.crossUnWalkable = true; this.crossUnwalkable = true;
} }
@Override @Override

View File

@ -54,7 +54,7 @@ public class ParticleBreak extends EntityParticle implements IModel
protected ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count, double velocity_up_multiplier) { protected ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count, double velocity_up_multiplier) {
super(pos, new Vec3d(0, 0, 0)); super(pos, new Vec3d(0, 0, 0));
this.gravity = false; this.hasGravity = false;
double model_height = model.getHeight(); double model_height = model.getHeight();
TextureRef3D[] textures = model.getTextures(); TextureRef3D[] textures = model.getTextures();

View File

@ -94,15 +94,13 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
} }
public EntityPlayer() { public EntityPlayer() {
super(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0)); super(new Vec3d(Math.pow(2, 30), 0, -Math.pow(2, 30)), new Vec3d(0, 0, 0));
this.angle = 45; this.angle = 45;
// Set some settings // Set some settings
hitbox = 0.5; hitbox = 0.5;
isSolid = true; isSolid = true;
goThroughSolid = false;
crossUnWalkable = false;
emitsLight = true; emitsLight = true;
// Create the inventory // Create the inventory
@ -190,7 +188,7 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature; chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature;
temperature += temp_diff / 1000; temperature += temp_diff / 1000;
hydration -= Math.sqrt(Math.abs(temperature - 0.5)) / 5000; hydration -= MathHelpers.smoothStep(Math.abs(temperature - 0.4) + 0.1) / 1000;
if(temperature < 0.3) { if(temperature < 0.3) {
health -= 0.3 - temperature; health -= 0.3 - temperature;