1
0
Fork 0

add camera system

This commit is contained in:
Sen 2025-08-06 19:07:15 +02:00
parent e0a031c5d0
commit a76c0c66e1
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
17 changed files with 464 additions and 207 deletions

View file

@ -217,6 +217,10 @@ public abstract class Command implements Executable {
return this.addParameter(new PlayerParser(name, defaulted, policy));
}
protected Command addPlayer(String name, char shortName, boolean defaulted, UserPolicy policy) {
return this.addParameter(shortName, new PlayerParser(name, defaulted, policy));
}
protected Command addPlayerList(String name, boolean defaulted, UserPolicy policy) {
return this.addParameter(new PlayerListParser(name, defaulted, policy));
}

View file

@ -283,6 +283,8 @@ public class CommandEnvironment {
this.registerExecutable(new CommandEpoch());
this.registerExecutable(new CommandTime());
this.registerExecutable(new CommandSeason());
this.registerExecutable(new CommandCamera());
this.registerExecutable(new CommandNocam());
this.registerExecutable(new CommandSet());
}

View file

@ -0,0 +1,33 @@
package server.command.commands;
import common.dimension.Dimension;
import common.entity.item.EntityCamera.CameraType;
import common.util.Vec3;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.UserPolicy;
import server.network.Player;
public class CommandCamera extends Command {
public CommandCamera() {
super("camera");
this.addVector("position", false, true);
this.addDimension("dim", true);
this.addYaw("yaw", true);
this.addPitch("pitch", true);
this.setParamsOptional();
this.addInt("radius", 'r', 0, 1024, 256);
this.addDouble("speed", 's', 0.1, 10.0, 1.0);
this.addEnum("type", 't', CameraType.FREE, CameraType.class, CameraType.values());
this.addFlag("fixed", 'f');
this.setParamsRequired();
this.addPlayer("player", 'p', true, UserPolicy.NON_ADMINS_OR_SELF);
}
public void exec(CommandEnvironment env, Executor exec, Vec3 position, Dimension dim, double yaw, double pitch, int radius, double speed, CameraType type, boolean fixed, Player player) {
player.setCamera(position.xCoord, position.yCoord, position.zCoord, (float)yaw, (float)pitch, radius, (float)speed, type, fixed);
}
}

View file

@ -0,0 +1,19 @@
package server.command.commands;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.UserPolicy;
import server.network.Player;
public class CommandNocam extends Command {
public CommandNocam() {
super("nocam");
this.addPlayer("player", true, UserPolicy.NON_ADMINS_OR_SELF);
}
public void exec(CommandEnvironment env, Executor exec, Player player) {
player.removeCamera();
}
}

View file

@ -19,6 +19,8 @@ import common.effect.Effect;
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.EntityItem;
import common.entity.item.EntityXp;
import common.entity.npc.Alignment;
@ -83,6 +85,7 @@ import common.packet.SPacketTabComplete;
import common.packet.SPacketAnimation;
import common.packet.SPacketBlockBreakAnim;
import common.packet.SPacketBlockChange;
import common.packet.SPacketCamera;
import common.packet.SPacketCharacterList;
import common.packet.SPacketChunkData;
import common.packet.SPacketDestroyEntities;
@ -214,6 +217,7 @@ public class Player extends User implements Executor, IPlayer
private Executor forcedExec;
private Position deathPos;
private Position teleportPos;
private EntityCamera camera;
public Player(Server server, NetConnection connection, String user)
{
@ -265,6 +269,8 @@ public class Player extends User implements Executor, IPlayer
}
if(this.itemUseCooldown > 0)
--this.itemUseCooldown;
if(this.camera != null)
this.camera.onUpdate();
}
public boolean isOnline() {
@ -351,7 +357,19 @@ public class Player extends User implements Executor, IPlayer
public void setCamera(double x, double y, double z, float yaw, float pitch, int radius, float speed, CameraType type, boolean fixed) {
this.camera = new EntityCamera(this.entity.worldObj, x, y, z, yaw, pitch, radius, speed, type, fixed);
this.sendPacket(new SPacketCamera(this.camera));
}
public void removeCamera() {
if(this.camera != null) {
this.camera = null;
this.sendPacket(new SPacketCamera(null));
}
}
@ -427,21 +445,25 @@ public class Player extends User implements Executor, IPlayer
}
}
public void setEntityActionState(float p_110430_1_, float p_110430_2_, boolean p_110430_3_, boolean sneaking)
private void setEntityActionState(float strafe, float forward, boolean jumping, boolean sneaking, boolean camera)
{
if (this.entity.vehicle != null)
if(camera) {
if(this.camera != null)
this.camera.setMovement(strafe, forward, jumping, sneaking);
}
else if (this.entity.vehicle != null)
{
if (p_110430_1_ >= -1.0F && p_110430_1_ <= 1.0F)
if (strafe >= -1.0F && strafe <= 1.0F)
{
this.entity.moveStrafe = p_110430_1_;
this.entity.moveStrafe = strafe;
}
if (p_110430_2_ >= -1.0F && p_110430_2_ <= 1.0F)
if (forward >= -1.0F && forward <= 1.0F)
{
this.entity.moveForward = p_110430_2_;
this.entity.moveForward = forward;
}
this.entity.setJumping(p_110430_3_);
this.entity.setJumping(jumping);
this.entity.setSneaking(sneaking);
}
}
@ -638,6 +660,7 @@ public class Player extends User implements Executor, IPlayer
public void teleport(double x, double y, double z, float yaw, float pitch, Dimension dimension) {
this.teleportPos = this.entity.getPos();
this.removeCamera();
x = ExtMath.clampd(x, -World.MAX_SIZE + 1, World.MAX_SIZE - 1);
z = ExtMath.clampd(z, -World.MAX_SIZE + 1, World.MAX_SIZE - 1);
// this.setLastTeleport(this.getLocation());
@ -2009,6 +2032,15 @@ public class Player extends User implements Executor, IPlayer
{
WorldServer worldserver = this.getEntityWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
// this.updated = true;
if(packetIn.isCamera()) {
if(this.camera != null) {
this.camera.setPositionClamped(packetIn.getPositionX(), packetIn.getPositionY(), packetIn.getPositionZ());
this.camera.setRotationClamped(packetIn.getYaw(), packetIn.getPitch());
if(!this.camera.fixed && packetIn.isOnGround())
this.removeCamera();
}
return;
}
double d0 = this.entity.posX;
double d1 = this.entity.posY;
@ -2452,6 +2484,7 @@ public class Player extends User implements Executor, IPlayer
int last = this.selected;
this.selected = -1;
this.teleportPos = this.deathPos = null;
this.removeCamera();
this.sendPacket(!this.characters.isEmpty() && last >= 0 ? new SPacketCharacterList(this.selected, last, this.getCharacterInfo(tag)) : new SPacketCharacterList(this.selected));
break;
}
@ -2467,6 +2500,7 @@ public class Player extends User implements Executor, IPlayer
Position pos = this.server.getRandomSpawnPosition(origin);
this.entity.teleport(pos);
this.teleportPos = this.deathPos = null;
this.removeCamera();
this.sendPacket(new SPacketCharacterList(this.selected, this.selected, new PlayerCharacter(this.entity.getCustomNameTag(), this.entity.getDescription(), this.entity.getAlignment(), this.entity.worldObj.dimension.getDisplay(), this.entity.getPosition(), EntityRegistry.getEntityName(EntityRegistry.getEntityString(this.entity)), this.entity.experienceLevel, world.dimension == Space.INSTANCE ? null : world.dimension.getDisplay())));
// if(this.local)
// this.server.setDone();
@ -2481,6 +2515,7 @@ public class Player extends User implements Executor, IPlayer
this.server.swapPlayer(this, this.characters.get(index), null);
this.selected = index;
this.teleportPos = this.deathPos = null;
this.removeCamera();
this.sendPacket(new SPacketCharacterList(this.selected));
break;
}
@ -2495,6 +2530,7 @@ public class Player extends User implements Executor, IPlayer
int last = this.selected;
this.selected = index;
this.teleportPos = this.deathPos = null;
this.removeCamera();
this.sendPacket(!this.characters.isEmpty() && last >= 0 ? new SPacketCharacterList(this.selected, last, this.getCharacterInfo(etag)) : new SPacketCharacterList(this.selected));
break;
}
@ -2825,7 +2861,7 @@ public class Player extends User implements Executor, IPlayer
NetHandler.checkThread(packetIn, this, this.server);
if(this.charEditor)
return;
this.setEntityActionState(packetIn.getStrafeSpeed(), packetIn.getForwardSpeed(), packetIn.isJumping(), packetIn.isSneaking());
this.setEntityActionState(packetIn.getStrafeSpeed(), packetIn.getForwardSpeed(), packetIn.isJumping(), packetIn.isSneaking(), packetIn.isCamera());
}
public void processClick(CPacketClick packetIn)