Skip to content

Commit

Permalink
starting new entity system and fixed a few chunk issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilligans committed Jul 23, 2024
1 parent 95e0ca0 commit 0863d8b
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 77 deletions.
10 changes: 9 additions & 1 deletion src/main/java/dev/hilligans/ourcraft/ClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.hilligans.ourcraft.util.ArgumentContainer;
import dev.hilligans.ourcraft.util.Side;
import dev.hilligans.ourcraft.util.registry.Registry;
import org.joml.Intersectionf;

import java.io.IOException;
import java.util.concurrent.Semaphore;
Expand All @@ -22,7 +23,14 @@ public class ClientMain {

public static long startTime;
public static void main(String[] args) throws IOException {
startTime = System.currentTimeMillis();
for(int y = 0; y < 2; y++) {
startTime = System.currentTimeMillis();
for (int x = 0; x < 1000000; x++) {
Intersectionf.testObOb(x, x, x, 1, 1, x, 1, 1, y, 1, 1, 2 * x, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
}
System.out.println("Time to 1M:" + (System.currentTimeMillis() - startTime));
}

argumentContainer = new ArgumentContainer(args);

System.out.println(STR."Starting client with PID \{ProcessHandle.current().pid()}");
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/hilligans/ourcraft/GameInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import dev.hilligans.ourcraft.command.CommandHandler;
import dev.hilligans.ourcraft.container.Container;
import dev.hilligans.ourcraft.data.descriptors.Tag;
import dev.hilligans.ourcraft.entity.Entity;
import dev.hilligans.ourcraft.entity.EntityType;
import dev.hilligans.ourcraft.item.data.ToolLevel;
import dev.hilligans.ourcraft.item.data.ToolLevelList;
import dev.hilligans.ourcraft.item.Item;
Expand Down Expand Up @@ -147,6 +147,7 @@ public void cleanupGraphics(IGraphicsEngine<?,?,?> graphicsEngine, GraphicsConte
public Registry<Texture> TEXTURES;
public Registry<ShaderSource> SHADERS;
public Registry<ILayoutEngine<?>> LAYOUT_ENGINES;
public Registry<EntityType> ENTITY_TYPES;

public ArrayList<IBlockState> BLOCK_STATES;

Expand Down Expand Up @@ -177,6 +178,7 @@ public void copyRegistries() {
SHADERS = (Registry<ShaderSource>) REGISTRIES.getExcept("ourcraft:shader");
LAYOUT_ENGINES = (Registry<ILayoutEngine<?>>) REGISTRIES.getExcept("ourcraft:layout_engine");
SOUND_CATEGORIES = (Registry<SoundCategory>) REGISTRIES.getExcept("ourcraft:sound_category");
ENTITY_TYPES = (Registry<EntityType>) REGISTRIES.getExcept("ourcraft:entity_type");
}

public void finishBuild() {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/dev/hilligans/ourcraft/Ourcraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import dev.hilligans.ourcraft.data.descriptors.Tag;
import dev.hilligans.ourcraft.data.other.BlockProperties;
import dev.hilligans.ourcraft.data.primitives.Tuple;
import dev.hilligans.ourcraft.entity.Entities;
import dev.hilligans.ourcraft.entity.EntityType;
import dev.hilligans.ourcraft.item.Items;
import dev.hilligans.ourcraft.item.data.ToolLevel;
import dev.hilligans.ourcraft.mod.handler.ModClass;
Expand Down Expand Up @@ -135,7 +137,8 @@ public void registerRegistries(RegistryView view) {
new Tuple(Texture.class, "texture"),
new Tuple(ShaderSource.class, "shader"),
new Tuple(ILayoutEngine.class, "layout_engine"),
new Tuple(SoundCategory.class, "sound_category")
new Tuple(SoundCategory.class, "sound_category"),
new Tuple(EntityType.class, "entity_type")
};

for(Tuple<Class<? extends IRegistryElement>, String> element : elements) {
Expand Down Expand Up @@ -390,6 +393,9 @@ public void registerContent(ModContainer modContent) {
modContent.registerBlock(Blocks.WATER);
modContent.registerBiome(Biomes.PLAINS,Biomes.SANDY_HILLS,Biomes.DESERT,Biomes.FOREST);

modContent.registerEntityType(Entities.PLAYER);


for(int x = 0; x < 30000; x++) {
//modContent.registerBlock(new Block("x" + x, new BlockProperties()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.hilligans.ourcraft.data.other;

import org.joml.Intersectionf;
import org.joml.Vector2f;

public interface IBoundingBox {
Expand All @@ -19,5 +20,42 @@ default boolean intersects(IBoundingBox boundingBox) {
(maxZ() > boundingBox.minZ() && minZ() < boundingBox.maxZ());
}

float intersectsRay(float x, float y, float z, float dirX, float dirY, float dirZ, Vector2f vector2f);
default float intersectsRay(float x, float y, float z, float dirX, float dirY, float dirZ, Vector2f vector2f) {
if (!Intersectionf.intersectRayAab(x, y, z, dirX, dirY, dirZ, minX(), minY(), minZ(), maxX(), maxY(), maxZ(), vector2f)) {
return -1;
}
return vector2f.x;
}

public static final IBoundingBox EMPTY_BOX = new IBoundingBox() {
@Override
public float minX() {
return 0;
}

@Override
public float minY() {
return 0;
}

@Override
public float minZ() {
return 0;
}

@Override
public float maxX() {
return 0;
}

@Override
public float maxY() {
return 0;
}

@Override
public float maxZ() {
return 0;
}
};
}
7 changes: 7 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/entity/Entities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.hilligans.ourcraft.entity;

public class Entities {

public static final EntityType PLAYER = new EntityType("player", "ourcraft");

}
2 changes: 1 addition & 1 deletion src/main/java/dev/hilligans/ourcraft/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void writeData(IPacketByteArray packetData) {
packetData.writeInt(id);
}

public abstract void render(MatrixStack matrixStack);
public void render(MatrixStack matrixStack) {}

public void tick() {}

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/entity/EntityType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.hilligans.ourcraft.entity;

import dev.hilligans.ourcraft.util.registry.IRegistryElement;

public class EntityType implements IRegistryElement {

public String owner;
public String name;

public EntityType(String name, String modID) {
this.name = name;
this.owner = modID;
}

@Override
public String getResourceName() {
return name;
}

@Override
public String getResourceOwner() {
return owner;
}

@Override
public String getResourceType() {
return "entity_type";
}
}
6 changes: 5 additions & 1 deletion src/main/java/dev/hilligans/ourcraft/entity/IEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.hilligans.ourcraft.entity;

import dev.hilligans.ourcraft.data.other.IBoundingBox;
import dev.hilligans.ourcraft.world.newworldsystem.IWorld;

public interface IEntity {
Expand All @@ -12,8 +13,9 @@ public interface IEntity {
long getID();
void setID(long id);

EntityType getEntityType();


IBoundingBox getEntityBoundingBox();

float getPitch();
float getYaw();
Expand All @@ -29,4 +31,6 @@ public interface IEntity {
double getX();
double getY();
double getZ();

void tick();
}
14 changes: 14 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/entity/ILivingEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.hilligans.ourcraft.entity;

public interface ILivingEntity extends IEntity {

int getHealth();

void setHealth(int health);

void dealDamage(int dmg);

void heal(int amount);

boolean alive();
}
10 changes: 8 additions & 2 deletions src/main/java/dev/hilligans/ourcraft/entity/LivingEntity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package dev.hilligans.ourcraft.entity;

import dev.hilligans.ourcraft.data.other.IInventory;
import dev.hilligans.ourcraft.item.ItemStack;
import dev.hilligans.ourcraft.network.IPacketByteArray;

import java.util.List;

public abstract class LivingEntity extends Entity {

public int maxHealth;
Expand All @@ -22,10 +26,12 @@ public LivingEntity(IPacketByteArray packetData) {
super(packetData);
}

public List<ItemStack> getOnDeathLoot() {
return null;
}

public void hitGround(float vel) {
float amount = (int)(vel * 10);
health -= amount;
}


}
120 changes: 120 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/entity/NewEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package dev.hilligans.ourcraft.entity;

import dev.hilligans.ourcraft.data.other.IBoundingBox;
import dev.hilligans.ourcraft.world.newworldsystem.IWorld;

public class NewEntity implements IEntity {

public IWorld world;
public EntityType entityType;
public long entityID;

public float pitch, yaw, velX, velY, velZ;
public double x, y, z;

public IBoundingBox boundingBox = IBoundingBox.EMPTY_BOX;

public NewEntity(EntityType entityType) {
this.entityType = entityType;
}

@Override
public IWorld getWorld() {
return this.world;
}

@Override
public void setWorld(IWorld world) {
this.world = world;
}

@Override
public void setRot(float pitch, float yaw, float roll) {
this.pitch = pitch;
this.yaw = yaw;
}

@Override
public long getID() {
return entityID;
}

@Override
public void setID(long id) {
this.entityID = id;
}

@Override
public EntityType getEntityType() {
return entityType;
}

@Override
public IBoundingBox getEntityBoundingBox() {
return boundingBox;
}

@Override
public float getPitch() {
return pitch;
}

@Override
public float getYaw() {
return yaw;
}

@Override
public float getRoll() {
return 0;
}

@Override
public void setVel(float velX, float velY, float velZ) {
this.velX = velX;
this.velY = velY;
this.velZ = velZ;
}

@Override
public float getVelX() {
return velX;
}

@Override
public float getVelY() {
return velY;
}

@Override
public float getVelZ() {
return velZ;
}

@Override
public void setPosition(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}

@Override
public double getX() {
return x;
}

@Override
public double getY() {
return y;
}

@Override
public double getZ() {
return z;
}

@Override
public void tick() {

}
}
Loading

0 comments on commit 0863d8b

Please sign in to comment.