Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cubyz-client/assets/cubyz/shaders/default/fragment.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ vec4 calcLightColour(vec3 light_colour, float light_intensity, vec3 position, ve

// Diffuse Light
float diffuseFactor = max(dot(normal, to_light_dir), 0.0);
diffuseColour = diffuseC * vec4(light_colour, 1.0) * light_intensity * diffuseFactor;
diffuseColour = diffuseC * vec4(light_colour, 0) * light_intensity * diffuseFactor;

// Specular Light
vec3 camera_direction = normalize(-position);
vec3 from_light_dir = -to_light_dir;
vec3 reflected_light = normalize(reflect(from_light_dir , normal));
float specularFactor = max( dot(camera_direction, reflected_light), 0.0);
specularFactor = pow(specularFactor, specularPower);
specColour = speculrC * light_intensity * specularFactor * material.reflectance * vec4(light_colour, 1.0);
specColour = speculrC * light_intensity * specularFactor * material.reflectance * vec4(light_colour, 0);

return (diffuseColour + specColour);
}
Expand Down Expand Up @@ -155,6 +155,6 @@ void main()
}
fragColor = ambientC * vec4(ambientLight, 1) + diffuseSpecularComp;
if (outSelected > 0) {
fragColor = vec4(fragColor.x, fragColor.y, 1, 1);
fragColor = vec4(fragColor.x, fragColor.y, 0.8, fragColor.w);
}
}
1 change: 1 addition & 0 deletions cubyz-client/src/io/cubyz/client/Cubyz.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public void init(Window window) throws Exception {
gameUI.addOverlay(new DebugOverlay());

ClientOnly.createBlockMesh = (block) -> {
// TODO use new resource model
Resource rsc = block.getRegistryID();
try {
BlockModel bm = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import org.joml.Vector2f;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.jungle.Camera;
import org.jungle.renderers.IRenderer;
import io.cubyz.blocks.BlockInstance;
import io.cubyz.util.Vector3fi;
import io.cubyz.math.Vector3fi;
import io.cubyz.world.BlockSpatial;
import io.cubyz.world.Chunk;

Expand Down
17 changes: 14 additions & 3 deletions cubyz-common/src/io/cubyz/api/base/BaseMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@
import io.cubyz.blocks.SnowGrass;
import io.cubyz.blocks.Stone;
import io.cubyz.blocks.Water;
import io.cubyz.entity.EntityType;
import io.cubyz.entity.PlayerEntity;

/**
* Mod adding SpacyCubyd default content.
* @author zenith391
* Mod adding Cubyz default content.
*/
@Mod(id = "cubyz", name = "Cubyz")
public class BaseMod {

// Normal:
// Entities:
static PlayerEntity player;

// Blocks:
static Bedrock bedrock;
static Cactus cactus;
static CobbleStone cobblestone;
Expand Down Expand Up @@ -59,6 +63,13 @@ public void init() {
System.out.println("Init!");
}

@EventHandler(type = "entity/register")
public void registerEntities(Registry<EntityType> reg) {
player = new PlayerEntity();

reg.register(player);
}

@EventHandler(type = "block/register")
public void registerBlocks(Registry<Block> reg) {

Expand Down
26 changes: 13 additions & 13 deletions cubyz-common/src/io/cubyz/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import io.cubyz.IRenderablePair;
import io.cubyz.blocks.BlockInstance;
import io.cubyz.util.Vector3fi;
import io.cubyz.math.Vector3fi;
import io.cubyz.world.World;

public abstract class Entity {
Expand Down Expand Up @@ -86,20 +86,20 @@ protected float _getX(float x) {
}

if (relZ < 0.3) {
for (int i = 0; i < 3; i++) {
for (int i = 0; i < height; i++) {
if (checkBlock(absX - 1, absY + i, absZ - 1)) {
return 0.30001F - relX;
}
}
}
if (relZ > 0.7) {
for (int i = 0; i < 3; i++) {
for (int i = 0; i < height; i++) {
if (checkBlock(absX - 1, absY + i, absZ + 1)) {
return 0.30001F - relX;
}
}
}
for (int i = 0; i < 3; i++) {
for (int i = 0; i < height; i++) {
if (checkBlock(absX - 1, absY + i, absZ)) {
return 0.30001F - relX;
}
Expand All @@ -116,20 +116,20 @@ protected float _getX(float x) {
}

if (relZ < 0.3) {
for (int i = 0; i < 3; i++) {
for (int i = 0; i < height; i++) {
if (checkBlock(absX + 1, absY + i, absZ - 1)) {
return 0.69999F - relX;
}
}
}
if (relZ > 0.7) {
for (int i = 0; i < 3; i++) {
for (int i = 0; i < height; i++) {
if( checkBlock(absX + 1, absY + i, absZ + 1)) {
return 0.69999F - relX;
}
}
}
for (int i = 0; i < 3; i++) {
for (int i = 0; i < height; i++) {
if (checkBlock(absX + 1, absY + i, absZ)) {
return 0.69999F - relX;
}
Expand All @@ -153,20 +153,20 @@ protected float _getZ(float z) {
return z;
}
if(relX < 0.3) {
for(int i = 0; i < 3; i++) {
for(int i = 0; i < height; i++) {
if (checkBlock(absX - 1, absY + i, absZ - 1)) {
return 0.30001F - relZ;
}
}
}
if(relX > 0.7) {
for(int i = 0; i < 3; i++) {
for(int i = 0; i < height; i++) {
if(checkBlock(absX+1, absY+i, absZ-1)) {
return 0.30001F - relZ;
}
}
}
for(int i = 0; i < 3; i++) {
for(int i = 0; i < height; i++) {
if(checkBlock(absX, absY+i, absZ-1)) {
return 0.30001F - relZ;
}
Expand All @@ -181,20 +181,20 @@ protected float _getZ(float z) {
return z;
}
if(relX < 0.3) {
for(int i = 0; i < 3; i++) {
for(int i = 0; i < height; i++) {
if(checkBlock(absX-1, absY+i, absZ+1)) {
return 0.69999F - relZ;
}
}
}
if(relX > 0.7) {
for(int i = 0; i < 3; i++) {
for(int i = 0; i < height; i++) {
if(checkBlock(absX+1, absY+i, absZ+1)) {
return 0.69999F - relZ;
}
}
}
for(int i = 0; i < 3; i++) {
for(int i = 0; i < height; i++) {
if(checkBlock(absX, absY+i, absZ+1)) {
return 0.69999F - relZ;
}
Expand Down
118 changes: 16 additions & 102 deletions cubyz-common/src/io/cubyz/entity/Player.java
Original file line number Diff line number Diff line change
@@ -1,114 +1,28 @@
package io.cubyz.entity;

import org.joml.Vector3f;
import org.joml.Vector3i;

import io.cubyz.api.CubyzRegistries;
import io.cubyz.command.ICommandSource;

public class Player extends Entity implements ICommandSource {
/**
* Base class for both implementation and MP version of Player.
* @author zenith391
*
*/
public abstract class Player extends Entity {

private boolean local = false;
private boolean flying = false;

public boolean isFlying() {
return flying;
public Player() {
super(CubyzRegistries.ENTITY_REGISTRY.getByID("cubyz:player"));
}

public void setFlying(boolean fly) {
flying = fly;
}
public abstract boolean isFlying();
public abstract void setFlying(boolean fly);

public Player(boolean local) {
super(CubyzRegistries.ENTITY_REGISTRY.getByID("cubyz:"));
this.local = local;
// try {
// mesh = loadMesh("uglyplayer");
// Material mat = new Material(new Vector4f(0.1F, 0.5F, 0.5F, 0.0F), 1.0F);
// mesh.setBoundingRadius(10.0F);
// mesh.setMaterial(mat);
// } catch (Exception e) {
// e.printStackTrace();
// }
// spatial = new Spatial(mesh);
// spatial.setScale(0.5F);
}

public boolean isLocal() {
return local;
}

public void move(Vector3f inc, Vector3f rot) {
float deltaX = 0;
float deltaZ = 0;
if (inc.z != 0) {
deltaX += (float) Math.sin(Math.toRadians(rot.y)) * -1.0F * inc.z;
deltaZ += (float) Math.cos(Math.toRadians(rot.y)) * inc.z;
}
if (inc.x != 0) {
deltaX += (float) Math.sin(Math.toRadians(rot.y - 90)) * -1.0F * inc.x;
deltaZ += (float) Math.cos(Math.toRadians(rot.y - 90)) * inc.x;
}
if (inc.y != 0) {
vy = inc.y;
}
if(deltaX != 0)
deltaX = _getX(deltaX);
if(deltaZ != 0)
deltaZ = _getZ(deltaZ);
position.add(deltaX, 0, deltaZ);
}

@Override
public void update() {
super.update();
if (!flying) {
vy -= 0.015F;
}
// if(flying) {
// vy = 0;
// position.y = 200;
//}
if (vy < 0) {
Vector3i bp = new Vector3i(position.x + (int) Math.round(position.relX), (int) Math.floor(position.y), position.z + (int) Math.round(position.relZ));
float relX = position.relX +0.5F - Math.round(position.relX);
float relZ = position.relZ + 0.5F- Math.round(position.relZ);
if(checkBlock(bp.x, bp.y, bp.z)) {
vy = 0;
}
else if (relX < 0.3) {
if (checkBlock(bp.x - 1, bp.y, bp.z)) {
vy = 0;
}
else if (relZ < 0.3 && checkBlock(bp.x - 1, bp.y, bp.z - 1)) {
vy = 0;
}
else if (relZ > 0.7 && checkBlock(bp.x - 1, bp.y, bp.z + 1)) {
vy = 0;
}
}
else if (relX > 0.7) {
if (checkBlock(bp.x + 1, bp.y, bp.z)) {
vy = 0;
}
else if (relZ < 0.3 && checkBlock(bp.x + 1, bp.y, bp.z - 1)) {
vy = 0;
}
else if (relZ > 0.7 && checkBlock(bp.x + 1, bp.y, bp.z + 1)) {
vy = 0;
}
}
if (relZ < 0.3 && checkBlock(bp.x, bp.y, bp.z - 1)) {
vy = 0;
}
else if (relZ > 0.7 && checkBlock(bp.x, bp.y, bp.z + 1)) {
vy = 0;
}
}
position.add(0, vy, 0);
if (flying) {
vy = 0;
}
}
/**
* Throws an exception if being a multiplayer Player implementation.
* @param inc
* @param rot
*/
public abstract void move(Vector3f inc, Vector3f rot);

}
Loading