diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/Minecraft/Scene/Objects')
4 files changed, 257 insertions, 0 deletions
diff --git a/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/Entity.java b/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/Entity.java new file mode 100755 index 0000000..b2e69f4 --- /dev/null +++ b/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/Entity.java @@ -0,0 +1,105 @@ +package net.tylermurphy.Minecraft.Scene.Objects;
+
+import java.io.Serializable;
+
+import net.tylermurphy.Minecraft.Scene.World;
+import org.joml.Vector3f;
+
+import net.tylermurphy.Minecraft.Chunk.Cube;
+
+public class Entity extends Renderable implements Serializable{
+
+ private static final long serialVersionUID = -1273546184611580473L;
+
+ protected static final float RUN_SPEED = 4;
+ protected static final float JUMP_POWER = 6;
+ protected static final float GRAVITY = -15;
+
+ protected float currentForwardSpeed = 0;
+ protected float currentSideSpeed = 0;
+ protected float upwardsSpeed = 0;
+
+ public boolean isInAir = true;
+ public boolean isFlying = false;
+ public boolean isSwimming = false;
+ public boolean isBobbing = false;
+ public boolean isFalling = false;
+ public boolean wasFalling = false;
+ public boolean isDead = false;
+
+ public Entity(Transform transform) {
+ super(null,transform,0);
+ }
+
+ public boolean willCollide(float dx, float dy, float dz) {
+ float px = getTransform().getPosition().x;
+ float py = getTransform().getPosition().y;
+ float pz = getTransform().getPosition().z;
+ if(getTransform().getPosition().x<0)
+ px--;
+ if(getTransform().getPosition().z<0)
+ pz--;
+ int[] nbc = {
+ (int) (px+dx+.25f),
+ (int) (py+dy),
+ (int) (pz+dz+.25f),
+ (int) (px+dx+.75f),
+ (int) (py+dy+1.9f),
+ (int) (pz+dz+.75f)
+ };
+
+ for(int x = nbc[0]; x<=nbc[3]; x++) {
+ for(int y = nbc[1]; y<=nbc[4]; y++) {
+ for(int z = nbc[2]; z<=nbc[5]; z++) {
+ byte block_head = World.getBlock(x,y,z);
+ byte block_current_feet = World.getBlock(x,(int)(py),z);
+ byte block_current_upper = World.getBlock(x,(int)(py+1f),z);
+ byte block_current_lower = World.getBlock(x,(int)(py+.75f),z);
+ if(block_current_feet == 17 ) {
+ isSwimming = true;
+ isBobbing = false;
+ }
+ if(block_current_feet == 17 && block_current_lower == 17 && block_current_upper == Cube.AIR){
+ isSwimming = false;
+ isBobbing = true;
+ }
+ if(block_current_feet != 17) {
+ isSwimming = false;
+ isBobbing = false;
+ }
+ if(dy != 0) {
+ if(block_head != Cube.AIR && block_head != 17) {
+ isInAir = !(y <= getTransform().getGlobalPosition().y);
+ return false;
+ } else isInAir = true;
+ }else {
+ if(block_head != Cube.AIR && block_head != 17) return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ public boolean collides(float x, float y, float z) {
+ float px = getTransform().getPosition().x;
+ float py = getTransform().getPosition().y;
+ float pz = getTransform().getPosition().z;
+ if(getTransform().getPosition().x<0)
+ px--;
+ if(getTransform().getPosition().z<0)
+ pz--;
+ int[] nbc = {
+ (int) (px+.25f),
+ (int) (py),
+ (int) (pz+.25f),
+ (int) (px+.75f),
+ (int) (py+1.9f),
+ (int) (pz+.75f)
+ };
+ return x >= nbc[0] && x <= nbc[3] &&
+ y >= nbc[1] && y <= nbc[4] &&
+ z >= nbc[2] && z <= nbc[5];
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/Renderable.java b/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/Renderable.java new file mode 100755 index 0000000..476e2c6 --- /dev/null +++ b/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/Renderable.java @@ -0,0 +1,46 @@ +package net.tylermurphy.Minecraft.Scene.Objects;
+
+import java.io.Serializable;
+
+import net.tylermurphy.Minecraft.Render.Data.Mesh;
+
+public class Renderable implements Serializable {
+
+ private static final long serialVersionUID = -5017401455504595815L;
+
+ public Renderable(Mesh mesh, Transform transform, int texture) {
+ this.mesh = mesh;
+ this.transform = transform;
+ this.texture = texture;
+ }
+
+ private Transform transform;
+ private Mesh mesh;
+ private int texture;
+
+ public Mesh getMesh() {
+ return mesh;
+ }
+
+ public void setMesh(Mesh mesh) {
+ this.mesh = mesh;
+ }
+
+ public int getTexture(){
+ return texture;
+ }
+
+ public void setTexture(int texture){
+ this.texture = texture;
+ }
+
+ public Transform getTransform(){
+ if(transform == null) this.transform = new Transform();
+ return transform;
+ }
+
+ public void setTransform(Transform transform){
+ this.transform = transform;
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/Transform.java b/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/Transform.java new file mode 100755 index 0000000..2da820f --- /dev/null +++ b/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/Transform.java @@ -0,0 +1,59 @@ +package net.tylermurphy.Minecraft.Scene.Objects;
+
+import net.tylermurphy.Minecraft.Scene.World;
+import org.joml.Vector3f;
+
+public class Transform {
+
+ private Vector3f position = new Vector3f(0f, 0f, 0f);
+ private Vector3f rotation = new Vector3f(0f, 0f, 0f);
+ private float scale = 1.0f;
+
+ public Transform setPosition(Vector3f position){
+ this.position = position;
+ return this;
+ }
+
+ public Transform setGlobalPosition(Vector3f position) {
+ this.position = new Vector3f(
+ position.x - World.world_origin.x(),
+ position.y,
+ position.z - World.world_origin.z()
+ );
+ return this;
+ }
+
+ public Transform increasePosition(float dx, float dy, float dz) {
+ this.position.x += dx;
+ this.position.y += dy;
+ this.position.z += dz;
+ return this;
+ }
+
+ public Transform setRotation(Vector3f rotation){
+ this.rotation = rotation;
+ return this;
+ }
+
+ public Transform setScale(float scale){
+ this.scale = scale;
+ return this;
+ }
+
+ public Vector3f getPosition(){
+ return position;
+ }
+
+ public Vector3f getGlobalPosition() {
+ return new Vector3f(position.x+ World.world_origin.x(),position.y,position.z+ World.world_origin.z());
+ }
+
+ public Vector3f getRotation(){
+ return rotation;
+ }
+
+ public float getScale(){
+ return scale;
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/WorldOrigin.java b/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/WorldOrigin.java new file mode 100755 index 0000000..a5fa73e --- /dev/null +++ b/src/main/java/net/tylermurphy/Minecraft/Scene/Objects/WorldOrigin.java @@ -0,0 +1,47 @@ +package net.tylermurphy.Minecraft.Scene.Objects;
+
+import net.tylermurphy.Minecraft.Scene.World;
+import org.joml.Vector3f;
+
+public class WorldOrigin {
+
+ private int x;
+ private int z;
+
+ public WorldOrigin(int x, int z){
+ this.x = x;
+ this.z = z;
+ }
+
+ public int x(){
+ return x;
+ }
+
+ public int z(){
+ return z;
+ }
+
+ public void recalculateOrigin(){
+ Vector3f position = World.player.getTransform().getPosition();
+ if((int)position.x>=256) {
+ int changes = (int) (position.x / 256);
+ x += 256*changes;
+ World.player.getTransform().setPosition(new Vector3f(position.x - 256*changes ,position.y,position.z));
+ } else if((int)position.x<=-256) {
+ int changes = (int) (position.x / 256);
+ x += 256*changes;
+ World.player.getTransform().setPosition(new Vector3f(position.x - 256*changes ,position.y,position.z));
+ }
+
+ if((int)position.z>=256) {
+ int changes = (int) (position.z / 256);
+ z += 256*changes;
+ World.player.getTransform().setPosition(new Vector3f(position.x,position.y,position.z - 256*changes));
+ } else if((int)position.z<=-256) {
+ int changes = (int) (position.z / 256);
+ z += 256*changes;
+ World.player.getTransform().setPosition(new Vector3f(position.x,position.y,position.z - 256*changes));
+ }
+ }
+
+}
|