diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index 1a01dc53..ef4f37f7 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -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); diff --git a/client/src/main/java/client/network/ClientPlayer.java b/client/src/main/java/client/network/ClientPlayer.java index 6428db0f..47b8acc7 100755 --- a/client/src/main/java/client/network/ClientPlayer.java +++ b/client/src/main/java/client/network/ClientPlayer.java @@ -39,6 +39,7 @@ import common.entity.DataWatcher; import common.entity.Entity; import common.entity.effect.EntityLightning; import common.entity.item.EntityBoat; +import common.entity.item.EntityCamera; import common.entity.item.EntityXp; import common.entity.npc.EntityNPC; import common.entity.npc.PlayerCharacter; @@ -693,7 +694,8 @@ public class ClientPlayer implements IClientPlayer } entityplayer.setPositionAndRotation(d0, d1, d2, f, f1); - this.connection.sendPacket(new CPacketPlayerPosLook(entityplayer.posX, entityplayer.getEntityBoundingBox().minY, entityplayer.posZ, entityplayer.rotYaw, entityplayer.rotPitch, false)); + if(this.gm.getRenderViewEntity() == entityplayer) + this.connection.sendPacket(new CPacketPlayerPosLook(entityplayer.posX, entityplayer.getEntityBoundingBox().minY, entityplayer.posZ, entityplayer.rotYaw, entityplayer.rotPitch, false)); if (!this.loaded) { @@ -1663,12 +1665,8 @@ public class ClientPlayer implements IClientPlayer public void handleCamera(SPacketCamera packetIn) { NetHandler.checkThread(packetIn, this, this.gm, this.world); - Entity entity = packetIn.getEntity(this.world); - - if (entity != null) - { - this.gm.setRenderViewEntity(entity); - } + EntityCamera camera = packetIn.getEntity(this.world); + this.gm.setRenderViewEntity(camera == null ? this.gm.player : camera); } diff --git a/client/src/main/java/client/renderer/BlockRenderer.java b/client/src/main/java/client/renderer/BlockRenderer.java deleted file mode 100755 index d016f419..00000000 --- a/client/src/main/java/client/renderer/BlockRenderer.java +++ /dev/null @@ -1,5 +0,0 @@ -package client.renderer; - -public class BlockRenderer -{ -} diff --git a/client/src/main/java/client/renderer/Renderer.java b/client/src/main/java/client/renderer/Renderer.java index c0ad0452..fe11a8e5 100755 --- a/client/src/main/java/client/renderer/Renderer.java +++ b/client/src/main/java/client/renderer/Renderer.java @@ -668,38 +668,26 @@ public class Renderer { if (!this.gm.debugCamEnable || this.gm.thirdPersonView == 0) { - GL11.glRotatef(entity.prevPitch + (entity.rotPitch - entity.prevPitch) * partialTicks, 1.0F, 0.0F, 0.0F); - - if (entity instanceof EntityAnimal) - { - EntityAnimal entityanimal = (EntityAnimal)entity; - GL11.glRotatef(entityanimal.prevHeadYaw + (entityanimal.headYaw - entityanimal.prevHeadYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); - } - else - { - GL11.glRotatef(entity.prevYaw + (entity.rotYaw - entity.prevYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); - } + this.rotateCamera(entity, partialTicks, false); } GL11.glTranslatef(0.0F, -f, 0.0F); - d0 = entity.prevX + (entity.posX - entity.prevX) * (double)partialTicks; - d1 = entity.prevY + (entity.posY - entity.prevY) * (double)partialTicks + (double)f; - d2 = entity.prevZ + (entity.posZ - entity.prevZ) * (double)partialTicks; } - - public void rotateCamera(Entity entity, float partialTicks) { - GL11.glRotatef(360.0f - (entity.prevPitch + (entity.rotPitch - entity.prevPitch) * partialTicks), 1.0F, 0.0F, 0.0F); - if (entity instanceof EntityAnimal) - { - EntityAnimal entityanimal = (EntityAnimal)entity; - GL11.glRotatef(entityanimal.prevHeadYaw + (entityanimal.headYaw - entityanimal.prevHeadYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); - } - else - { - GL11.glRotatef(entity.prevYaw + (entity.rotYaw - entity.prevYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); - } - } + public void rotateCamera(Entity entity, float partialTicks, boolean invert) { + if(invert) + GL11.glRotatef(360.0f - (entity.prevPitch + (entity.rotPitch - entity.prevPitch) * partialTicks), 1.0F, 0.0F, 0.0F); + else + GL11.glRotatef(entity.prevPitch + (entity.rotPitch - entity.prevPitch) * partialTicks, 1.0F, 0.0F, 0.0F); + + if(entity instanceof EntityAnimal) { + EntityAnimal entityanimal = (EntityAnimal)entity; + GL11.glRotatef(entityanimal.prevHeadYaw + (entityanimal.headYaw - entityanimal.prevHeadYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); + } + else { + GL11.glRotatef(entity.prevYaw + (entity.rotYaw - entity.prevYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F); + } + } private void setupCameraTransform(float partialTicks) { @@ -1208,7 +1196,7 @@ public class Renderer { this.setupFog(0, partialTicks); this.gm.getTextureManager().bindTexture(TextureMap.BLOCKS); ItemRenderer.disableStandardItemLighting(); - this.setupTerrain(entity, (double)partialTicks, this.frameCount++, this.gm.player.noclip); + this.setupTerrain(entity, (double)partialTicks, this.frameCount++, entity != this.gm.player || this.gm.player.noclip); this.updateChunks(finishTimeNano); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); @@ -1292,11 +1280,11 @@ public class Renderer { this.renderCloudsCheck(partialTicks); } -// if (this.renderHand) -// { - GL11.glClear(256); - this.renderHand(partialTicks); -// } + if (entity == this.gm.player) + { + GL11.glClear(256); + this.renderHand(partialTicks); + } } private void renderCloudsCheck(float partialTicks) diff --git a/client/src/main/java/client/renderer/entity/RenderHumanoid.java b/client/src/main/java/client/renderer/entity/RenderHumanoid.java index c201b658..ab8540eb 100755 --- a/client/src/main/java/client/renderer/entity/RenderHumanoid.java +++ b/client/src/main/java/client/renderer/entity/RenderHumanoid.java @@ -69,16 +69,13 @@ public class RenderHumanoid extends RenderNpc public void doRender(EntityNPC entity, double x, double y, double z, float partialTicks) { - if (entity != this.manager.gm.player || this.manager.livingPlayer == entity) - { - // if(entity.isBoss()) - // BossStatus.setBossStatus(entity); - double d0 = y; - if(/* this.canSneak() && */ entity.isSneakingVisually() && entity != this.manager.gm.player) - d0 = y - 0.125D; - this.setModelVisibilities(entity); - super.doRender(entity, x, d0, z, partialTicks); - } +// if(entity.isBoss()) +// BossStatus.setBossStatus(entity); + double d0 = y; + if(/* this.canSneak() && */ entity.isSneakingVisually()) + d0 = y - 0.125D; + this.setModelVisibilities(entity); + super.doRender(entity, x, d0, z, partialTicks); } protected void renderLayers(EntityNPC entity, float swing, float amount, float partial, float time, float dYaw, float dPitch, float scale) { diff --git a/common/src/main/java/common/entity/item/EntityCamera.java b/common/src/main/java/common/entity/item/EntityCamera.java new file mode 100644 index 00000000..f85cb9ff --- /dev/null +++ b/common/src/main/java/common/entity/item/EntityCamera.java @@ -0,0 +1,91 @@ +package common.entity.item; + +import common.entity.types.EntityWeatherEffect; +import common.util.ExtMath; +import common.world.World; + +public class EntityCamera extends EntityWeatherEffect { + public static enum CameraType { + STATIC, + ROTATABLE, + MOVEABLE, + PLANE, + FREE; + } + + public final double baseX; + public final double baseY; + public final double baseZ; + public final int radius; + public final float speed; + public final CameraType type; + public final boolean fixed; + + public EntityCamera(World worldIn, double x, double y, double z, float yaw, float pitch, int radius, float speed, CameraType type, boolean fixed) { + super(worldIn); + this.setSize(0.1F, 0.1F); + this.setPosition(x, y, z); + this.setRotation(type == CameraType.PLANE || type == CameraType.MOVEABLE ? 0.0f : yaw, pitch); + this.noClip = true; + this.baseX = this.prevX = x; + this.baseY = this.prevY = y; + this.baseZ = this.prevZ = z; + this.radius = radius; + this.speed = speed; + this.type = type; + this.fixed = fixed; + } + + public void onUpdate() { + this.lastTickPosX = this.posX; + this.lastTickPosY = this.posY; + this.lastTickPosZ = this.posZ; + this.prevX = this.posX; + this.prevY = this.posY; + this.prevZ = this.posZ; + this.prevPitch = this.rotPitch; + this.prevYaw = this.rotYaw; + this.setPositionClamped(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); +// this.motionX = this.motionY = this.motionZ = 0.0D; + } + + public float getEyeHeight() { + return 0.0F; + } + + public void setMovement(float strafe, float forward, boolean jumping, boolean sneaking) { + if(this.type != CameraType.MOVEABLE && this.type != CameraType.PLANE && this.type != CameraType.FREE) + return; + double x = strafe > 0.5f ? 1.0f : (strafe < -0.5f ? -1.0 : 0.0); + double y = this.type == CameraType.PLANE ? 0.0 : (jumping ? (sneaking ? 0.0 : 1.0) : (sneaking ? -1.0 : 0.0)); + double z = forward > 0.5f ? 1.0f : (forward < -0.5f ? -1.0 : 0.0); + if(this.type == CameraType.FREE) { + this.motionX = this.motionZ = 0.0; + this.moveFlying((float)x, (float)z, 1.0f); + this.setVelocity(this.motionX * this.speed, y * this.speed, this.motionZ * this.speed); + } + else { + this.setVelocity(x * (double)this.speed, y * (double)this.speed, z * (double)this.speed); + } + } + + public void setPositionClamped(double x, double y, double z) + { + if(this.type == CameraType.MOVEABLE || this.type == CameraType.PLANE || this.type == CameraType.FREE) + this.setPosition(ExtMath.clampd(x, this.baseX - (double)this.radius, this.baseX + (double)this.radius), + this.type == CameraType.PLANE ? this.baseY : ExtMath.clampd(y, this.baseY - (double)this.radius, this.baseY + (double)this.radius), + ExtMath.clampd(z, this.baseZ - (double)this.radius, this.baseZ + (double)this.radius)); + } + + public void setAnglesClamped(float yaw, float pitch) + { + if(this.type == CameraType.ROTATABLE || this.type == CameraType.FREE) + this.setAngles(yaw, pitch); + } + + public void setRotationClamped(float yaw, float pitch) + { + if(this.type == CameraType.ROTATABLE || this.type == CameraType.FREE) + this.setRotation(yaw, pitch); + } +} diff --git a/common/src/main/java/common/entity/npc/EntityHoveringNPC.java b/common/src/main/java/common/entity/npc/EntityHoveringNPC.java index a4b0887d..ad8d0e4b 100755 --- a/common/src/main/java/common/entity/npc/EntityHoveringNPC.java +++ b/common/src/main/java/common/entity/npc/EntityHoveringNPC.java @@ -91,7 +91,7 @@ public abstract class EntityHoveringNPC extends EntityNPC // return 1.0F; // } - public void onUpdateWalkingPlayer() + public void syncMovement() { boolean flag = this.isHovering(); @@ -109,12 +109,12 @@ public abstract class EntityHoveringNPC extends EntityNPC this.serverHoverState = flag; } - super.onUpdateWalkingPlayer(); + super.syncMovement(); } public void onLivingUpdate() { - if(this.client != null) { + if(this.client != null && this.client.isRenderViewEntity(this)) { if(this.client.isJumping() && this.client.isSprinting() && this.client.getMoveForward() == 0.0f && this.client.getMoveStrafe() == 0.0f) this.setHovering(true); if(this.isFlying() || (!this.client.isJumping() && this.client.isSneaking() && this.onGround)) diff --git a/common/src/main/java/common/entity/npc/EntityNPC.java b/common/src/main/java/common/entity/npc/EntityNPC.java index 7fc3f31d..9906e56d 100755 --- a/common/src/main/java/common/entity/npc/EntityNPC.java +++ b/common/src/main/java/common/entity/npc/EntityNPC.java @@ -1557,16 +1557,26 @@ public abstract class EntityNPC extends EntityLiving implements IInventory { // super.onUpdate(); this.updatePlayer(); - - if (this.isRiding()) - { - this.client.addToSendQueue(new CPacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround)); - this.client.addToSendQueue(new CPacketInput(this.moveStrafe, this.moveForward, this.client.isJumping(), this.client.isSneaking())); - } - else - { - this.onUpdateWalkingPlayer(); - } + + if(this.client.isRenderViewEntity(this)) { + if (this.isRiding()) + { + this.client.addToSendQueue(new CPacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround)); + this.client.addToSendQueue(new CPacketInput(this.moveStrafe, this.moveForward, this.client.isJumping(), this.client.isSneaking(), false)); + } + else + { + this.syncMovement(); + } + } + else if (this.vehicle == null) + { + this.client.addToSendQueue(new CPacketPlayer(this.onGround)); + } + else + { + this.client.addToSendQueue(new CPacketPlayerPosLook(this.motionX, -99999999.0D, this.motionZ, this.rotYaw, this.rotPitch, this.onGround)); + } } return; } @@ -1904,7 +1914,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory */ public boolean isSneaking() { - return this.client != null ? this.client.isSneaking() : super.isSneaking(); + return this.client != null && this.client.isRenderViewEntity(this) ? this.client.isSneaking() : super.isSneaking(); } public void updateEntityActionState() @@ -1917,15 +1927,23 @@ public abstract class EntityNPC extends EntityLiving implements IInventory this.headYaw = this.rotYaw; // super.updateEntityActionState(); - if (this.client != null && this.client.isRenderViewEntity(this)) + if (this.client != null) { - this.moveStrafe = this.client.getMoveStrafe(); - this.moveForward = this.client.getMoveForward(); - this.jumping = this.client.isJumping(); - this.prevRenderArmYaw = this.renderArmYaw; - this.prevRenderArmPitch = this.renderArmPitch; - this.renderArmPitch = (float)((double)this.renderArmPitch + (double)(this.rotPitch - this.renderArmPitch) * 0.5D); - this.renderArmYaw = (float)((double)this.renderArmYaw + (double)(this.rotYaw - this.renderArmYaw) * 0.5D); + if(this.client.isRenderViewEntity(this)) { + this.moveStrafe = this.client.getMoveStrafe(); + this.moveForward = this.client.getMoveForward(); + this.jumping = this.client.isJumping(); + this.prevRenderArmYaw = this.renderArmYaw; + this.prevRenderArmPitch = this.renderArmPitch; + this.renderArmPitch = (float)((double)this.renderArmPitch + (double)(this.rotPitch - this.renderArmPitch) * 0.5D); + this.renderArmYaw = (float)((double)this.renderArmYaw + (double)(this.rotYaw - this.renderArmYaw) * 0.5D); + } + else { + this.moveStrafe = 0.0f; + this.moveForward = 0.0f; + this.jumping = false; + this.setSprinting(false); + } } } @@ -2001,13 +2019,14 @@ public abstract class EntityNPC extends EntityLiving implements IInventory // --this.portalTimer; // } - boolean flag = this.client.isJumping(); - boolean flag1 = this.client.isSneaking(); + boolean jump = this.client.isJumping(); + boolean sneak = this.client.isSneaking(); float f = 0.8F; - boolean flag2 = this.client.getMoveForward() >= f; + boolean moving = this.client.getMoveForward() >= f; this.client.updatePlayerMoveState(); + boolean current = this.client.isRenderViewEntity(this); - if (this.isUsingItem() && !this.isRiding()) + if (current && this.isUsingItem() && !this.isRiding()) { this.client.setMoveStrafe(this.client.getMoveStrafe() * 0.2F); this.client.setMoveForward(this.client.getMoveForward() * 0.2F); @@ -2020,7 +2039,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D); boolean canSprint = true; // (float)this.getFoodStats().getFoodLevel() > 6.0F || this.allowFlying; - if (this.onGround && !flag1 && !flag2 && this.client.getMoveForward() >= f && !this.isSprinting() && canSprint && !this.isUsingItem() && !this.hasEffect(Effect.BLINDNESS)) + if (current && this.onGround && !sneak && !moving && this.client.getMoveForward() >= f && !this.isSprinting() && canSprint && !this.isUsingItem() && !this.hasEffect(Effect.BLINDNESS)) { if (this.sprintToggleTimer <= 0 && !this.client.isSprinting()) { @@ -2032,12 +2051,12 @@ public abstract class EntityNPC extends EntityLiving implements IInventory } } - if (!this.isSprinting() && this.client.getMoveForward() >= f && canSprint && !this.isUsingItem() && !this.hasEffect(Effect.BLINDNESS) && this.client.isSprinting()) + if (current && !this.isSprinting() && this.client.getMoveForward() >= f && canSprint && !this.isUsingItem() && !this.hasEffect(Effect.BLINDNESS) && this.client.isSprinting()) { this.setSprinting(true); } - if (this.isSprinting() && (this.client.getMoveForward() < f || this.collidedHorizontally || !canSprint)) + if (current && this.isSprinting() && (this.client.getMoveForward() < f || this.collidedHorizontally || !canSprint)) { this.setSprinting(false); } @@ -2052,7 +2071,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.START_FLYING)); } } - else if (!flag && this.client.isJumping()) + else if (current && !jump && this.client.isJumping()) { if (this.flyToggleTimer == 0) { @@ -2072,7 +2091,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory } // this.firstEffectUpdate = false; - if (this.isFlying() && this.client.isRenderViewEntity(this)) + if (current && this.isFlying()) { if (this.client.isSneaking()) { @@ -2087,7 +2106,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory } } - if (this.isRidingHorse()) + if (current && this.isRidingHorse()) { if (this.horseJumpPowerCounter < 0) { @@ -2099,17 +2118,17 @@ public abstract class EntityNPC extends EntityLiving implements IInventory } } - if (flag && !this.client.isJumping()) + if (jump && !this.client.isJumping()) { this.horseJumpPowerCounter = -10; this.sendHorseJump(); } - else if (!flag && this.client.isJumping()) + else if (!jump && this.client.isJumping()) { this.horseJumpPowerCounter = 0; this.horseJumpPower = 0.0F; } - else if (flag) + else if (jump) { ++this.horseJumpPowerCounter; @@ -2282,7 +2301,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory /** * called every tick when the player is on foot. Performs all the things that normally happen during movement. */ - public void onUpdateWalkingPlayer() + public void syncMovement() { boolean flag = this.isSprinting(); @@ -2316,56 +2335,53 @@ public abstract class EntityNPC extends EntityLiving implements IInventory this.serverSneakState = flag1; } - if (this.client.isRenderViewEntity(this)) - { - double d0 = this.posX - this.lastReportedPosX; - double d1 = this.getEntityBoundingBox().minY - this.lastReportedPosY; - double d2 = this.posZ - this.lastReportedPosZ; - double d3 = (double)(this.rotYaw - this.lastReportedYaw); - double d4 = (double)(this.rotPitch - this.lastReportedPitch); - boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20; - boolean flag3 = d3 != 0.0D || d4 != 0.0D; + double d0 = this.posX - this.lastReportedPosX; + double d1 = this.getEntityBoundingBox().minY - this.lastReportedPosY; + double d2 = this.posZ - this.lastReportedPosZ; + double d3 = (double)(this.rotYaw - this.lastReportedYaw); + double d4 = (double)(this.rotPitch - this.lastReportedPitch); + boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20; + boolean flag3 = d3 != 0.0D || d4 != 0.0D; - if (this.vehicle == null) + if (this.vehicle == null) + { + if (flag2 && flag3) { - if (flag2 && flag3) - { - this.client.addToSendQueue(new CPacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.rotYaw, this.rotPitch, this.onGround)); - } - else if (flag2) - { - this.client.addToSendQueue(new CPacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround)); - } - else if (flag3) - { - this.client.addToSendQueue(new CPacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround)); - } - else - { - this.client.addToSendQueue(new CPacketPlayer(this.onGround)); - } + this.client.addToSendQueue(new CPacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.rotYaw, this.rotPitch, this.onGround)); + } + else if (flag2) + { + this.client.addToSendQueue(new CPacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround)); + } + else if (flag3) + { + this.client.addToSendQueue(new CPacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround)); } else { - this.client.addToSendQueue(new CPacketPlayerPosLook(this.motionX, -99999999.0D, this.motionZ, this.rotYaw, this.rotPitch, this.onGround)); - flag2 = false; + this.client.addToSendQueue(new CPacketPlayer(this.onGround)); } + } + else + { + this.client.addToSendQueue(new CPacketPlayerPosLook(this.motionX, -99999999.0D, this.motionZ, this.rotYaw, this.rotPitch, this.onGround)); + flag2 = false; + } - ++this.positionUpdateTicks; + ++this.positionUpdateTicks; - if (flag2) - { - this.lastReportedPosX = this.posX; - this.lastReportedPosY = this.getEntityBoundingBox().minY; - this.lastReportedPosZ = this.posZ; - this.positionUpdateTicks = 0; - } + if (flag2) + { + this.lastReportedPosX = this.posX; + this.lastReportedPosY = this.getEntityBoundingBox().minY; + this.lastReportedPosZ = this.posZ; + this.positionUpdateTicks = 0; + } - if (flag3) - { - this.lastReportedYaw = this.rotYaw; - this.lastReportedPitch = this.rotPitch; - } + if (flag3) + { + this.lastReportedYaw = this.rotYaw; + this.lastReportedPitch = this.rotPitch; } } diff --git a/common/src/main/java/common/packet/CPacketInput.java b/common/src/main/java/common/packet/CPacketInput.java index 1bc90df0..6397e95a 100755 --- a/common/src/main/java/common/packet/CPacketInput.java +++ b/common/src/main/java/common/packet/CPacketInput.java @@ -12,17 +12,19 @@ public class CPacketInput implements Packet private float forwardSpeed; private boolean jumping; private boolean sneaking; + private boolean camera; public CPacketInput() { } - public CPacketInput(float strafeSpeed, float forwardSpeed, boolean jumping, boolean sneaking) + public CPacketInput(float strafeSpeed, float forwardSpeed, boolean jumping, boolean sneaking, boolean camera) { this.strafeSpeed = strafeSpeed; this.forwardSpeed = forwardSpeed; this.jumping = jumping; this.sneaking = sneaking; + this.camera = camera; } public void readPacketData(PacketBuffer buf) throws IOException @@ -32,6 +34,7 @@ public class CPacketInput implements Packet byte b0 = buf.readByte(); this.jumping = (b0 & 1) > 0; this.sneaking = (b0 & 2) > 0; + this.camera = (b0 & 4) > 0; } public void writePacketData(PacketBuffer buf) throws IOException @@ -50,6 +53,11 @@ public class CPacketInput implements Packet b0 = (byte)(b0 | 2); } + if (this.camera) + { + b0 = (byte)(b0 | 4); + } + buf.writeByte(b0); } @@ -77,4 +85,9 @@ public class CPacketInput implements Packet { return this.sneaking; } + + public boolean isCamera() + { + return this.camera; + } } diff --git a/common/src/main/java/common/packet/CPacketPlayer.java b/common/src/main/java/common/packet/CPacketPlayer.java index ccafdc3a..39a04f33 100755 --- a/common/src/main/java/common/packet/CPacketPlayer.java +++ b/common/src/main/java/common/packet/CPacketPlayer.java @@ -14,6 +14,7 @@ public class CPacketPlayer implements Packet protected float yaw; protected float pitch; protected boolean onGround; + protected boolean camera; protected boolean moving; protected boolean rotating; @@ -33,12 +34,14 @@ public class CPacketPlayer implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.onGround = buf.readUnsignedByte() != 0; + byte flags = buf.readByte(); + this.onGround = (flags & 1) != 0; + this.camera = (flags & 2) != 0; } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeByte(this.onGround ? 1 : 0); + buf.writeByte((this.onGround ? 1 : 0) | (this.camera ? 2 : 0)); } public double getPositionX() @@ -85,4 +88,9 @@ public class CPacketPlayer implements Packet { this.moving = isMoving; } + + public boolean isCamera() + { + return this.camera; + } } diff --git a/common/src/main/java/common/packet/CPacketPlayerPosLook.java b/common/src/main/java/common/packet/CPacketPlayerPosLook.java index 9b02b822..8ca36a47 100644 --- a/common/src/main/java/common/packet/CPacketPlayerPosLook.java +++ b/common/src/main/java/common/packet/CPacketPlayerPosLook.java @@ -23,6 +23,11 @@ public class CPacketPlayerPosLook extends CPacketPlayer this.rotating = true; this.moving = true; } + + public CPacketPlayerPosLook setCamera() { + this.camera = true; + return this; + } public void readPacketData(PacketBuffer buf) throws IOException { diff --git a/common/src/main/java/common/packet/SPacketCamera.java b/common/src/main/java/common/packet/SPacketCamera.java index d72765c2..862accf3 100755 --- a/common/src/main/java/common/packet/SPacketCamera.java +++ b/common/src/main/java/common/packet/SPacketCamera.java @@ -2,42 +2,78 @@ package common.packet; import java.io.IOException; -import common.entity.Entity; +import common.entity.item.EntityCamera; +import common.entity.item.EntityCamera.CameraType; import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; import common.world.World; -public class SPacketCamera implements Packet -{ - public int entityId; +public class SPacketCamera implements Packet { + private int radius; + private float speed; + private double posX; + private double posY; + private double posZ; + private float yaw; + private float pitch; + private CameraType type; + private boolean fixed; - public SPacketCamera() - { - } + public SPacketCamera() { + } - public SPacketCamera(Entity entityIn) - { - this.entityId = entityIn.getId(); - } - - public void readPacketData(PacketBuffer buf) throws IOException - { - this.entityId = buf.readVarInt(); - } - - public void writePacketData(PacketBuffer buf) throws IOException - { - buf.writeVarInt(this.entityId); - } - - public void processPacket(IClientPlayer handler) - { - handler.handleCamera(this); - } + public SPacketCamera(EntityCamera camera) { + if(camera == null) + return; + this.radius = camera.radius; + this.speed = camera.speed; + this.posX = camera.baseX; + this.posY = camera.baseY; + this.posZ = camera.baseZ; + this.yaw = camera.rotYaw; + this.pitch = camera.rotPitch; + this.type = camera.type; + this.fixed = camera.fixed; + } - public Entity getEntity(World worldIn) - { - return worldIn.getEntityByID(this.entityId); - } + public void readPacketData(PacketBuffer buf) throws IOException { + this.type = buf.readEnumOrNull(CameraType.class); + if(this.type != null) { + if(this.type == CameraType.MOVEABLE || this.type == CameraType.PLANE || this.type == CameraType.FREE) { + this.radius = buf.readVarInt(); + this.speed = buf.readFloat(); + } + this.posX = buf.readDouble(); + this.posY = buf.readDouble(); + this.posZ = buf.readDouble(); + this.yaw = buf.readFloat(); + this.pitch = buf.readFloat(); + this.fixed = buf.readBoolean(); + } + } + + public void writePacketData(PacketBuffer buf) throws IOException { + buf.writeEnumOrNull(this.type); + if(this.type != null) { + if(this.type == CameraType.MOVEABLE || this.type == CameraType.PLANE || this.type == CameraType.FREE) { + buf.writeVarInt(this.radius); + buf.writeFloat(this.speed); + } + buf.writeDouble(this.posX); + buf.writeDouble(this.posY); + buf.writeDouble(this.posZ); + buf.writeFloat(this.yaw); + buf.writeFloat(this.pitch); + buf.writeBoolean(this.fixed); + } + } + + public void processPacket(IClientPlayer handler) { + handler.handleCamera(this); + } + + public EntityCamera getEntity(World world) { + return this.type == null ? null : new EntityCamera(world, this.posX, this.posY, this.posZ, this.yaw, this.pitch, this.radius, this.speed, this.type, this.fixed); + } } diff --git a/server/src/main/java/server/command/Command.java b/server/src/main/java/server/command/Command.java index 14628c3d..42161e40 100644 --- a/server/src/main/java/server/command/Command.java +++ b/server/src/main/java/server/command/Command.java @@ -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)); } diff --git a/server/src/main/java/server/command/CommandEnvironment.java b/server/src/main/java/server/command/CommandEnvironment.java index 989b679e..efb13627 100644 --- a/server/src/main/java/server/command/CommandEnvironment.java +++ b/server/src/main/java/server/command/CommandEnvironment.java @@ -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()); } diff --git a/server/src/main/java/server/command/commands/CommandCamera.java b/server/src/main/java/server/command/commands/CommandCamera.java new file mode 100644 index 00000000..2e686d3d --- /dev/null +++ b/server/src/main/java/server/command/commands/CommandCamera.java @@ -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); + } +} diff --git a/server/src/main/java/server/command/commands/CommandNocam.java b/server/src/main/java/server/command/commands/CommandNocam.java new file mode 100644 index 00000000..635e282f --- /dev/null +++ b/server/src/main/java/server/command/commands/CommandNocam.java @@ -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(); + } +} diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index 0476ed29..fa50a8d4 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -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)