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]; } }