ginger...Player.java -> litecraft...PlayerEntity.java
parent
a2f712dc63
commit
77d3d14753
|
@ -5,6 +5,7 @@ import org.joml.*;
|
|||
import com.github.halotroop.litecraft.save.LitecraftSave;
|
||||
import com.github.halotroop.litecraft.screens.*;
|
||||
import com.github.halotroop.litecraft.types.block.Blocks;
|
||||
import com.github.halotroop.litecraft.types.entity.PlayerEntity;
|
||||
import com.github.halotroop.litecraft.util.RelativeDirection;
|
||||
import com.github.halotroop.litecraft.world.World;
|
||||
import com.github.hydos.ginger.engine.common.Constants;
|
||||
|
@ -29,7 +30,7 @@ public class Litecraft extends Game
|
|||
private World world;
|
||||
private LitecraftSave save;
|
||||
private GingerGL engine;
|
||||
public Player player;
|
||||
public PlayerEntity playerEntity;
|
||||
private Camera camera;
|
||||
public int fps, ups, tps;
|
||||
public Vector4i dbgStats = new Vector4i();
|
||||
|
@ -60,7 +61,7 @@ public class Litecraft extends Game
|
|||
System.out.println("Saving chunks...");
|
||||
long time = System.currentTimeMillis();
|
||||
this.world.unloadAllChunks();
|
||||
this.getSave().saveGlobalData(this.world.getSeed(), this.player);
|
||||
this.getSave().saveGlobalData(this.world.getSeed(), this.playerEntity);
|
||||
System.out.println("Saved world in " + (System.currentTimeMillis() - time) + " milliseconds");
|
||||
}
|
||||
engine.cleanup();
|
||||
|
@ -125,15 +126,15 @@ public class Litecraft extends Game
|
|||
Light sun = new Light(new Vector3f(0, 105, 0), new Vector3f(0.9765625f, 0.98828125f, 0.05859375f), new Vector3f(0.002f, 0.002f, 0.002f));
|
||||
FontType font = new FontType(GlLoader.loadFontAtlas("candara.png"), "candara.fnt");
|
||||
this.engine = new GingerGL();
|
||||
this.player = new Player(playerModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
this.camera = new FirstPersonCamera(player);
|
||||
this.player.setVisible(false);
|
||||
this.data = new GameData(this.player, this.camera, 20);
|
||||
this.playerEntity = new PlayerEntity(playerModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
this.camera = new FirstPersonCamera(playerEntity);
|
||||
this.playerEntity.setVisible(false);
|
||||
this.data = new GameData(this.playerEntity, this.camera, 20);
|
||||
this.data.handleGuis = false;
|
||||
this.engine.setup(new MasterRenderer(this.camera), INSTANCE);
|
||||
this.engine.setGlobalFont(font);
|
||||
this.data.lights.add(sun);
|
||||
this.data.entities.add(this.player);
|
||||
this.data.entities.add(this.playerEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,12 +143,12 @@ public class Litecraft extends Game
|
|||
Input.addPressCallback(Keybind.EXIT, this::exit);
|
||||
Input.addInitialPressCallback(Keybind.FULLSCREEN, Window::fullscreen);
|
||||
Input.addInitialPressCallback(Keybind.WIREFRAME, GingerRegister.getInstance()::toggleWireframe);
|
||||
Input.addPressCallback(Keybind.MOVE_FORWARD, () -> this.player.move(RelativeDirection.FORWARD));
|
||||
Input.addPressCallback(Keybind.MOVE_BACKWARD, () -> this.player.move(RelativeDirection.BACKWARD));
|
||||
Input.addPressCallback(Keybind.STRAFE_LEFT, () -> this.player.move(RelativeDirection.LEFT));
|
||||
Input.addPressCallback(Keybind.STRAFE_RIGHT, () -> this.player.move(RelativeDirection.RIGHT));
|
||||
Input.addPressCallback(Keybind.FLY_UP, () -> this.player.move(RelativeDirection.UP));
|
||||
Input.addPressCallback(Keybind.FLY_DOWN, () -> this.player.move(RelativeDirection.DOWN));
|
||||
Input.addPressCallback(Keybind.MOVE_FORWARD, () -> this.playerEntity.move(RelativeDirection.FORWARD));
|
||||
Input.addPressCallback(Keybind.MOVE_BACKWARD, () -> this.playerEntity.move(RelativeDirection.BACKWARD));
|
||||
Input.addPressCallback(Keybind.STRAFE_LEFT, () -> this.playerEntity.move(RelativeDirection.LEFT));
|
||||
Input.addPressCallback(Keybind.STRAFE_RIGHT, () -> this.playerEntity.move(RelativeDirection.RIGHT));
|
||||
Input.addPressCallback(Keybind.FLY_UP, () -> this.playerEntity.move(RelativeDirection.UP));
|
||||
Input.addPressCallback(Keybind.FLY_DOWN, () -> this.playerEntity.move(RelativeDirection.DOWN));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,9 +162,9 @@ public class Litecraft extends Game
|
|||
if (GingerRegister.getInstance().currentScreen == null && world == null)
|
||||
engine.openScreen(new TitleScreen());
|
||||
|
||||
if (data.player != null && data.camera != null)
|
||||
if (data.playerEntity != null && data.camera != null)
|
||||
{
|
||||
data.player.updateMovement();
|
||||
data.playerEntity.updateMovement();
|
||||
data.camera.updateMovement();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@ import java.util.Random;
|
|||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.halotroop.litecraft.Litecraft;
|
||||
import com.github.halotroop.litecraft.types.entity.PlayerEntity;
|
||||
import com.github.halotroop.litecraft.world.*;
|
||||
import com.github.halotroop.litecraft.world.dimension.Dimension;
|
||||
import com.github.hydos.ginger.engine.common.cameras.Camera;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.Player;
|
||||
|
||||
import tk.valoeghese.sod.*;
|
||||
|
||||
|
@ -125,13 +125,13 @@ public final class LitecraftSave
|
|||
}
|
||||
}
|
||||
|
||||
public void saveGlobalData(long seed, Player player)
|
||||
public void saveGlobalData(long seed, PlayerEntity playerEntity)
|
||||
{
|
||||
try
|
||||
{
|
||||
File globalDataFile = new File(this.file.getPath() + "/global_data.sod");
|
||||
globalDataFile.createNewFile(); // create world file if it doesn't exist.
|
||||
writeGlobalData(globalDataFile, seed, player.getPosition());
|
||||
writeGlobalData(globalDataFile, seed, playerEntity.getPosition());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ public class IngameHUD extends Screen
|
|||
long freeMemory = Runtime.getRuntime().freeMemory();
|
||||
long usedMemory = (totalMemory - freeMemory) / 1024 / 1024;
|
||||
Vector4i dbg = litecraft.dbgStats;
|
||||
Vector3f position = GingerRegister.getInstance().game.data.player.getPosition();
|
||||
Vector3f position = GingerRegister.getInstance().game.data.playerEntity.getPosition();
|
||||
debugText.setText("FPS: " + dbg.x() + " UPS: " + dbg.y() + " TPS: " + dbg.z() + " TWL: " + dbg.w() + " Mem: " + usedMemory + "MB");
|
||||
positionText.setText("Position: " + (int) position.x() + ", " + (int) position.y() + ", "+ (int) position.z() );
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class TitleScreen extends Screen
|
|||
{
|
||||
Litecraft.getInstance().setSave(new LitecraftSave("SegregatedOrdinalData", false));
|
||||
Litecraft.getInstance().changeWorld(Litecraft.getInstance().getSave().getWorldOrCreate(Dimensions.OVERWORLD));
|
||||
ginger3D.setGingerPlayer(Litecraft.getInstance().getWorld().player);
|
||||
ginger3D.setGingerPlayer(Litecraft.getInstance().getWorld().playerEntity);
|
||||
}
|
||||
if (Litecraft.getInstance().getWorld() != null)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.hydos.ginger.engine.common.elements.objects;
|
||||
package com.github.halotroop.litecraft.types.entity;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
|
@ -10,14 +10,14 @@ import com.github.hydos.ginger.engine.common.api.GingerRegister;
|
|||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.TexturedModel;
|
||||
|
||||
public class Player extends RenderObject implements WorldGenConstants
|
||||
public class PlayerEntity extends Entity implements WorldGenConstants
|
||||
{
|
||||
private boolean isInAir = false;
|
||||
private double upwardsSpeed;
|
||||
private boolean noWeight = true; // because the force of gravity on an object's mass is called WEIGHT, not gravity
|
||||
private boolean noWeight = true;
|
||||
private int chunkX, chunkY, chunkZ;
|
||||
|
||||
public Player(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale)
|
||||
public PlayerEntity(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale)
|
||||
{
|
||||
super(model, position, rotX, rotY, rotZ, scale);
|
||||
this.chunkX = (int) position.x >> POS_SHIFT;
|
|
@ -12,11 +12,11 @@ import org.joml.Vector3f;
|
|||
|
||||
import com.github.halotroop.litecraft.save.LitecraftSave;
|
||||
import com.github.halotroop.litecraft.types.block.*;
|
||||
import com.github.halotroop.litecraft.types.entity.PlayerEntity;
|
||||
import com.github.halotroop.litecraft.world.block.BlockRenderer;
|
||||
import com.github.halotroop.litecraft.world.dimension.Dimension;
|
||||
import com.github.halotroop.litecraft.world.gen.*;
|
||||
import com.github.halotroop.litecraft.world.gen.modifier.WorldModifier;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.Player;
|
||||
import com.github.hydos.ginger.engine.common.obj.ModelLoader;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.TexturedModel;
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
private final long seed;
|
||||
private final int dimension;
|
||||
private final ForkJoinPool threadPool;
|
||||
public Player player;
|
||||
public PlayerEntity playerEntity;
|
||||
int renderBound;
|
||||
int renderBoundVertical;
|
||||
// dummy block instance for retrieving the default block model
|
||||
|
@ -86,19 +86,19 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
this.spawnPlayer(0, y, -3);
|
||||
}
|
||||
|
||||
public Player spawnPlayer(float x, float y, float z)
|
||||
public PlayerEntity spawnPlayer(float x, float y, float z)
|
||||
{
|
||||
// Player model and stuff
|
||||
TexturedModel dirtModel = ModelLoader.loadGenericCube("block/cubes/soil/dirt.png");
|
||||
this.player = new Player(dirtModel, new Vector3f(x, y, z), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
this.player.setVisible(false);
|
||||
this.playerEntity = new PlayerEntity(dirtModel, new Vector3f(x, y, z), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
this.playerEntity.setVisible(false);
|
||||
// Generate world around player
|
||||
long time = System.currentTimeMillis();
|
||||
System.out.println("Generating world!");
|
||||
this.updateLoadedChunks(this.player.getChunkX(), this.player.getChunkY(), this.player.getChunkZ());
|
||||
this.updateLoadedChunks(this.playerEntity.getChunkX(), this.playerEntity.getChunkY(), this.playerEntity.getChunkZ());
|
||||
System.out.println("Generated world in " + (System.currentTimeMillis() - time) + " milliseconds");
|
||||
// return player
|
||||
return this.player;
|
||||
return this.playerEntity;
|
||||
}
|
||||
|
||||
public Chunk getChunk(int chunkX, int chunkY, int chunkZ)
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.*;
|
|||
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import com.github.halotroop.litecraft.types.entity.PlayerEntity;
|
||||
import com.github.hydos.ginger.engine.common.cameras.Camera;
|
||||
import com.github.hydos.ginger.engine.common.elements.GuiTexture;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.*;
|
||||
|
@ -18,20 +19,20 @@ public class GameData
|
|||
public List<RenderObject> entities;
|
||||
public List<Light> lights;
|
||||
public List<RenderObject> normalMapEntities;
|
||||
public Player player;
|
||||
public PlayerEntity playerEntity;
|
||||
public Camera camera;
|
||||
public Vector4f clippingPlane;
|
||||
public boolean handleGuis = true;
|
||||
public int tickSpeed = 20;
|
||||
|
||||
public GameData(Player player, Camera camera, int tickSpeed)
|
||||
public GameData(PlayerEntity playerEntity, Camera camera, int tickSpeed)
|
||||
{
|
||||
clippingPlane = new Vector4f(0, -1, 0, 100000);
|
||||
guis = new ArrayList<GuiTexture>();
|
||||
entities = new ArrayList<RenderObject>();
|
||||
lights = new ArrayList<Light>();
|
||||
normalMapEntities = new ArrayList<RenderObject>();
|
||||
this.player = player;
|
||||
this.playerEntity = playerEntity;
|
||||
this.camera = camera;
|
||||
this.tickSpeed = tickSpeed;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.github.hydos.ginger.engine.common.cameras;
|
|||
import org.joml.Vector3f;
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.Player;
|
||||
import com.github.halotroop.litecraft.types.entity.PlayerEntity;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
|
||||
public class Camera
|
||||
|
@ -13,15 +13,15 @@ public class Camera
|
|||
private Vector3f position = new Vector3f(0, 0, 0);
|
||||
private float pitch, yaw;
|
||||
private float roll;
|
||||
public Player player;
|
||||
public PlayerEntity playerEntity;
|
||||
|
||||
public Camera(Player player)
|
||||
{ this.player = player; }
|
||||
public Camera(PlayerEntity playerEntity)
|
||||
{ this.playerEntity = playerEntity; }
|
||||
|
||||
public Camera(Vector3f vector3f, Player player)
|
||||
public Camera(Vector3f vector3f, PlayerEntity playerEntity)
|
||||
{
|
||||
this.position = vector3f;
|
||||
this.player = player;
|
||||
this.playerEntity = playerEntity;
|
||||
}
|
||||
|
||||
private void calculateAngleAroundPlayer()
|
||||
|
@ -35,12 +35,12 @@ public class Camera
|
|||
|
||||
private void calculateCameraPosition(float horizDistance, float verticDistance)
|
||||
{
|
||||
float theta = player.getRotY() + angleAroundPlayer;
|
||||
float theta = playerEntity.getRotY() + angleAroundPlayer;
|
||||
float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta)));
|
||||
float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta)));
|
||||
position.x = player.getPosition().x - offsetX;
|
||||
position.z = player.getPosition().z - offsetZ;
|
||||
position.y = player.getPosition().y + verticDistance;
|
||||
position.x = playerEntity.getPosition().x - offsetX;
|
||||
position.z = playerEntity.getPosition().z - offsetZ;
|
||||
position.y = playerEntity.getPosition().y + verticDistance;
|
||||
}
|
||||
|
||||
private float calculateHorizontalDistance()
|
||||
|
@ -105,7 +105,7 @@ public class Camera
|
|||
float horizontalDistance = calculateHorizontalDistance();
|
||||
float verticalDistance = calculateVerticalDistance();
|
||||
calculateCameraPosition(horizontalDistance, verticalDistance);
|
||||
this.yaw = 180 - (player.getRotY() + angleAroundPlayer);
|
||||
this.yaw = 180 - (playerEntity.getRotY() + angleAroundPlayer);
|
||||
}
|
||||
|
||||
public void setPitch(float pitch)
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.github.hydos.ginger.engine.common.cameras;
|
|||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.Player;
|
||||
import com.github.halotroop.litecraft.types.entity.PlayerEntity;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
|
||||
public class FirstPersonCamera extends Camera
|
||||
|
@ -11,10 +11,10 @@ public class FirstPersonCamera extends Camera
|
|||
private float pitch, yaw;
|
||||
private float roll;
|
||||
|
||||
public FirstPersonCamera(Player player)
|
||||
public FirstPersonCamera(PlayerEntity playerEntity)
|
||||
{
|
||||
super(player);
|
||||
player.setVisible(false);
|
||||
super(playerEntity);
|
||||
playerEntity.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,11 +36,11 @@ public class FirstPersonCamera extends Camera
|
|||
@Override
|
||||
public void updateMovement()
|
||||
{
|
||||
position.x = player.getPosition().x;
|
||||
position.z = player.getPosition().z;
|
||||
position.y = player.getPosition().y;
|
||||
roll = player.getRotX();
|
||||
yaw = -player.getRotY() + 180 + Window.getNormalizedMouseCoordinates().x() * 70;
|
||||
pitch = player.getRotZ() + -Window.getNormalizedMouseCoordinates().y() * 70;
|
||||
position.x = playerEntity.getPosition().x;
|
||||
position.z = playerEntity.getPosition().z;
|
||||
position.y = playerEntity.getPosition().y;
|
||||
roll = playerEntity.getRotX();
|
||||
yaw = -playerEntity.getRotY() + 180 + Window.getNormalizedMouseCoordinates().x() * 70;
|
||||
pitch = playerEntity.getRotZ() + -Window.getNormalizedMouseCoordinates().y() * 70;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ import org.joml.Vector2f;
|
|||
import com.github.halotroop.litecraft.Litecraft;
|
||||
import com.github.halotroop.litecraft.logic.Timer;
|
||||
import com.github.halotroop.litecraft.logic.Timer.TickListener;
|
||||
import com.github.halotroop.litecraft.types.entity.PlayerEntity;
|
||||
import com.github.hydos.ginger.engine.common.api.GingerRegister;
|
||||
import com.github.hydos.ginger.engine.common.api.game.*;
|
||||
import com.github.hydos.ginger.engine.common.elements.buttons.TextureButton;
|
||||
import com.github.hydos.ginger.engine.common.elements.objects.Player;
|
||||
import com.github.hydos.ginger.engine.common.font.*;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.screen.Screen;
|
||||
|
@ -51,13 +51,13 @@ public class GingerGL
|
|||
registry.currentScreen = screen;
|
||||
}
|
||||
|
||||
public void setGingerPlayer(Player player)
|
||||
public void setGingerPlayer(PlayerEntity playerEntity)
|
||||
{
|
||||
registry.game.data.entities.remove(Litecraft.getInstance().player); // remove the old player
|
||||
registry.game.data.player = player; // set all the player variables
|
||||
Litecraft.getInstance().player = player;
|
||||
Litecraft.getInstance().getCamera().player = player;
|
||||
registry.game.data.entities.add(player); // add the new player
|
||||
registry.game.data.entities.remove(Litecraft.getInstance().playerEntity); // remove the old player
|
||||
registry.game.data.playerEntity = playerEntity; // set all the player variables
|
||||
Litecraft.getInstance().playerEntity = playerEntity;
|
||||
Litecraft.getInstance().getCamera().playerEntity = playerEntity;
|
||||
registry.game.data.entities.add(playerEntity); // add the new player
|
||||
}
|
||||
|
||||
public TextureButton registerButton(String resourceLocation, Vector2f position, Vector2f scale)
|
||||
|
|
Loading…
Reference in New Issue