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

@ -110,6 +110,7 @@ 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.EntityCart;
import common.entity.npc.Energy;
import common.entity.npc.EntityCpu;
@ -150,7 +151,9 @@ import common.network.PacketSplitter;
import common.network.NetHandler.ThreadQuickExitException;
import common.packet.CPacketAction;
import common.packet.CPacketCheat;
import common.packet.CPacketInput;
import common.packet.CPacketMessage;
import common.packet.CPacketPlayerPosLook;
import common.packet.HPacketHandshake;
import common.packet.CPacketAction.Action;
import common.properties.Property;
@ -847,7 +850,7 @@ public class Client implements IThreadListener {
else
{
if (Bind.PERSPECTIVE.isPressed())
if (Bind.PERSPECTIVE.isPressed() && this.viewEntity == this.player)
{
++this.thirdPersonView;
@ -864,35 +867,37 @@ public class Client implements IThreadListener {
}
boolean hadZoom = this.zooming;
this.zooming = Bind.ZOOM.isDown();
this.zooming = Bind.ZOOM.isDown() || this.viewEntity != this.player;
if(this.zooming && !hadZoom) {
this.zoomLevel = 2.0f;
this.zoomLevel = this.viewEntity != this.player ? 1.0f : 2.0f;
}
for (int l = 0; l < 9; ++l)
{
if (this.keyBindsHotbar[l].isPressed())
{
if(this.player.getSelectedIndex() != l)
this.controller.resetUseCooldown();
this.player.setSelectedIndex(l);
}
if(this.viewEntity == this.player) {
for (int l = 0; l < 9; ++l)
{
if (this.keyBindsHotbar[l].isPressed())
{
if(this.player.getSelectedIndex() != l)
this.controller.resetUseCooldown();
this.player.setSelectedIndex(l);
}
}
if (Bind.THROW.isPressed())
{
this.player.dropOneItem(this.ctrl());
}
else if(Bind.RENAME.isPressed()) {
ItemStack stack = this.player.getHeldItem();
if(stack != null)
this.show(new GuiRename(-1, stack, null));
}
this.primary |= Bind.PRIMARY.isPressed();
this.secondary |= Bind.SECONDARY.isPressed();
this.tertiary |= Bind.TERTIARY.isPressed();
this.quarternary |= Bind.QUARTERNARY.isPressed();
}
if (Bind.THROW.isPressed())
{
this.player.dropOneItem(this.ctrl());
}
else if(Bind.RENAME.isPressed()) {
ItemStack stack = this.player.getHeldItem();
if(stack != null)
this.show(new GuiRename(-1, stack, null));
}
this.primary |= Bind.PRIMARY.isPressed();
this.secondary |= Bind.SECONDARY.isPressed();
this.tertiary |= Bind.TERTIARY.isPressed();
this.quarternary |= Bind.QUARTERNARY.isPressed();
}
}
@ -932,7 +937,7 @@ public class Client implements IThreadListener {
if (this.open == null && this.player != null) {
if (this.player.isUsingItem())
{
if (!Bind.SECONDARY.isDown())
if (!Bind.SECONDARY.isDown() || this.viewEntity != this.player)
{
this.controller.stopUsing(this.player);
}
@ -960,12 +965,12 @@ public class Client implements IThreadListener {
}
}
if (Bind.SECONDARY.isDown() && this.rightClickTimer == 0 && !this.player.isUsingItem())
if (Bind.SECONDARY.isDown() && this.rightClickTimer == 0 && !this.player.isUsingItem() && this.viewEntity == this.player)
{
this.secondary();
}
this.sendClickBlockToController(this.open == null && Bind.PRIMARY.isDown());
this.sendClickBlockToController(this.open == null && Bind.PRIMARY.isDown() && this.viewEntity == this.player);
}
this.primary = this.secondary = this.tertiary = this.quarternary = false;
@ -1014,13 +1019,15 @@ public class Client implements IThreadListener {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
}
if(this.open == null) {
if(this.player != null)
if(this.player != null && this.viewEntity == this.player)
this.player.setAngles(this.deltaX, this.deltaY);
else if(this.player != null && this.viewEntity instanceof EntityCamera camera)
camera.setAnglesClamped(this.deltaX, this.deltaY);
this.deltaX = this.deltaY = 0.0f;
}
if(this.player != null)
this.soundManager.setListener(this.player, (float)this.tickFraction);
if(this.player != null && this.player.isEntityInsideOpaqueBlock())
if(this.player != null && (this.player.isEntityInsideOpaqueBlock() || this.viewEntity != this.player))
this.thirdPersonView = 0;
GL11.glPushMatrix();
GL11.glClear(16640);
@ -1384,7 +1391,7 @@ public class Client implements IThreadListener {
public void scroll(int dir) {
if(this.zooming)
this.zoomLevel = ExtMath.clampf(this.zoomLevel + (dir < 0 ? -0.25f : 0.25f), 2.0f, 16.0f);
this.zoomLevel = ExtMath.clampf(this.zoomLevel + (dir < 0 ? -0.25f : 0.25f), this.viewEntity != this.player ? 1.0f : 2.0f, 16.0f);
else if(this.player != null) {
this.player.setSelectedIndex(this.player.getSelectedIndex() - dir);
if(this.player.getSelectedIndex() < 0)
@ -1827,6 +1834,15 @@ public class Client implements IThreadListener {
this.moveStrafe = (float)((double)this.moveStrafe * 0.3D);
this.moveForward = (float)((double)this.moveForward * 0.3D);
}
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(!camera.fixed && this.sprint)
// this.viewEntity = this.player;
}
}
public String getLeft() {
@ -3110,7 +3126,7 @@ public class Client implements IThreadListener {
GlState.depthMask(false);
GL11.glPushMatrix();
GL11.glTranslatef((float)(this.fbX / 2), (float)(this.fbY / 2), 0.0F);
this.renderer.rotateCamera(this.viewEntity, partialTicks);
this.renderer.rotateCamera(this.viewEntity, partialTicks, true);
Renderer.drawOutlinedBoundingBox(new BoundingBox(0.0D, 0.0D, 0.0D, 24D, 1D, 1D), 255, 0, 0, 255);
Renderer.drawOutlinedBoundingBox(new BoundingBox(0.0D, 0.0D, 0.0D, 1D, 1D, 24D), 0, 0, 255, 255);
Renderer.drawOutlinedBoundingBox(new BoundingBox(0.0D, 0.0D, 0.0D, 1D, -20D, 1D), 0, 255, 0, 255);