1
0
Fork 0

fix and improve camera system

This commit is contained in:
Sen 2025-08-07 02:17:59 +02:00
parent a76c0c66e1
commit 72dc4a1305
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
15 changed files with 180 additions and 108 deletions

View file

@ -111,9 +111,10 @@ import common.effect.StatusEffect;
import common.entity.Entity;
import common.entity.animal.EntityHorse;
import common.entity.item.EntityCamera;
import common.entity.item.EntityCamera.CameraType;
import common.entity.item.EntityCart;
import common.entity.npc.Energy;
import common.entity.npc.EntityCpu;
import common.entity.npc.EntityCameraHolder;
import common.entity.npc.EntityNPC;
import common.entity.npc.EntityWaterNPC;
import common.entity.npc.PlayerCharacter;
@ -431,6 +432,7 @@ public class Client implements IThreadListener {
public boolean charEditor;
public boolean fullscreen;
public boolean interrupted;
public boolean freecam;
private int leftClickCounter;
private int rightClickTimer;
@ -717,7 +719,7 @@ public class Client implements IThreadListener {
this.dimensionName = "debug";
Space.INSTANCE.setDisplay("Debug-Welt");
this.controller = new PlayerController(this, player);
this.loadWorld(Space.INSTANCE, EntityRegistry.getEntityID(EntityCpu.class));
this.loadWorld(Space.INSTANCE, EntityRegistry.getEntityID(EntityCameraHolder.class));
this.player.setId(0);
this.show(null);
this.player.flying = true;
@ -737,6 +739,7 @@ public class Client implements IThreadListener {
this.debugWorld = false;
this.charEditor = false;
this.viewEntity = null;
this.freecam = false;
this.connection = null;
this.world = null;
this.resetWorld();
@ -1644,6 +1647,7 @@ public class Client implements IThreadListener {
{
this.resetWorld();
this.viewEntity = null;
this.freecam = false;
this.connection = null;
this.soundManager.stopSounds();
this.world = new WorldClient(dim);
@ -1691,6 +1695,7 @@ public class Client implements IThreadListener {
this.player = this.controller.createPlayerEntity(this.world, type);
this.player.getDataWatcher().updateWatchedObjectsFromList(entityplayersp.getDataWatcher().getAllWatched());
this.viewEntity = this.player;
this.freecam = false;
this.player.preparePlayerToSpawn();
this.spawnEntity(this.player);
this.player.rotYaw = -180.0F;
@ -1750,6 +1755,7 @@ public class Client implements IThreadListener {
public void setRenderViewEntity(Entity viewingEntity)
{
this.viewEntity = viewingEntity;
this.freecam = false;
}
public void schedule(Runnable task) {
@ -1838,8 +1844,12 @@ public class Client implements IThreadListener {
if(this.viewEntity instanceof EntityCamera camera) {
camera.onUpdate();
camera.setMovement(this.moveStrafe, this.moveForward, this.jump, this.sneak);
this.getNetHandler().addToSendQueue(new CPacketInput(this.moveStrafe, this.moveForward, this.jump, this.sneak, true));
this.getNetHandler().addToSendQueue(new CPacketPlayerPosLook(camera.posX, camera.posY, camera.posZ, camera.rotYaw, camera.rotPitch, this.sprint).setCamera());
if(!this.freecam) {
this.getNetHandler().addToSendQueue(new CPacketInput(this.moveStrafe, this.moveForward, this.jump, this.sneak, true));
this.getNetHandler().addToSendQueue(new CPacketPlayerPosLook(camera.posX, camera.posY, camera.posZ, camera.rotYaw, camera.rotPitch, this.sprint).setCamera());
if(this.player != null)
this.player.setPositionAndRotation(camera.posX, camera.posY, camera.posZ, camera.rotYaw, camera.rotPitch);
}
// if(!camera.fixed && this.sprint)
// this.viewEntity = this.player;
}
@ -2723,6 +2733,16 @@ public class Client implements IThreadListener {
}
}
});
if(Util.DEVMODE)
this.registerDebug(Keysym.SPACE, "Kamera umschalten", new DebugRunner() {
public void execute(Keysym key) {
if(Client.this.world != null && Client.this.player != null) {
Client.this.viewEntity = Client.this.viewEntity == Client.this.player ? new EntityCamera(Client.this.world,
Client.this.player.posX, Client.this.player.posY, Client.this.player.posZ, Client.this.player.rotYaw, Client.this.player.rotPitch, 256, 2.5f, CameraType.FREE, false) : Client.this.player;
Client.this.freecam = Client.this.viewEntity != Client.this.player;
}
}
});
if(Util.DEVMODE)
this.registerDebug(Keysym.AE, "Programm sofort beenden und server beenden", new DebugRunner() {
public void execute(Keysym key) {