Skip to content
Browse files

Don't increase exhaustion unless moving, set pitch and yaw instead of…

… incrementing
  • Loading branch information...
1 parent 2978545 commit 1bb940cf714f86bafab31402e494269ade4d9fbe @zml2008 zml2008 committed Apr 16, 2012
View
44 src/main/java/org/spout/vanilla/controller/VanillaActionController.java
@@ -1,9 +1,9 @@
/*
- * This file is part of Vanilla (http://www.spout.org/).
+ * This file is part of vanilla (http://www.spout.org/).
*
- * Vanilla is licensed under the SpoutDev License Version 1.
+ * vanilla is licensed under the SpoutDev License Version 1.
*
- * Vanilla is free software: you can redistribute it and/or modify
+ * vanilla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
@@ -12,7 +12,7 @@
* software, incorporating those changes, under the terms of the MIT license,
* as described in the SpoutDev License Version 1.
*
- * Vanilla is distributed in the hope that it will be useful,
+ * vanilla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
@@ -81,12 +81,12 @@ public boolean needsVelocityUpdate() {
public boolean needsPositionUpdate() {
return positionTicks++ % 60 == 0;
}
-
+
protected VanillaActionController(VanillaControllerType type) {
super(type);
this.type = type;
}
-
+
@Override
public void onDeath() {
//Don't count disconnects/unknown exceptions as dead (!Yes that's a difference!)
@@ -116,35 +116,35 @@ public void setMaxSpeed(float maxSpeed) {
public Vector3 getVelocity() {
return velocity;
}
-
+
public Vector3 getPreviousPosition() {
return this.oldPosition;
}
-
+
public Vector3 getPreviousRotation() {
return this.oldRotation;
}
-
+
public int getClientPosX() {
return this.clientX;
}
-
+
public int getClientPosY() {
return this.clientY;
}
-
+
public int getClientPosZ() {
return this.clientZ;
}
-
+
public int getClientYaw() {
return this.clientYaw;
}
-
+
public int getClientPitch() {
return this.clientPitch;
}
-
+
//FIXME: MOVE TO MATHHELPER!
public static byte wrapByte(int value) {
value %= 256;
@@ -153,15 +153,15 @@ public static byte wrapByte(int value) {
}
return (byte) value;
}
-
+
public void updateClientPosition() {
this.clientX = MathHelper.floor(this.getParent().getPosition().getX() * 32.0);
this.clientY = MathHelper.floor(this.getParent().getPosition().getY() * 32.0);
this.clientZ = MathHelper.floor(this.getParent().getPosition().getZ() * 32.0);
this.clientYaw = wrapByte(MathHelper.floor(this.getParent().getYaw() / 360f * 256f));
this.clientPitch = wrapByte(MathHelper.floor(this.getParent().getPitch() / 360f * 256f));
}
-
+
public void setClientPosition(int x, int y, int z, int yaw, int pitch) {
this.clientX = x;
this.clientY = y;
@@ -196,41 +196,41 @@ public void onAttached() {
this.oldRotation = getParent().getRotation().getAxisAngles();
this.updateClientPosition();
}
-
+
@Override
public void onCollide(Block block) {
this.setVelocity(Vector3.ZERO);
}
-
+
@Override
public void onCollide(Entity entity) {
//push entities apart
//TODO: Ignore if this entity is a passenger?
Vector2 diff = entity.getPosition().subtract(this.getParent().getPosition()).toVector2();
float distance = diff.length();
- if (distance > 0.1f) {
+ if (distance > 0.1f) {
double factor = Math.min(1f / distance, 1f) / distance * 0.05;
diff = diff.multiply(factor);
this.setVelocity(this.getVelocity().add(diff.toVector3()));
}
}
@Override
- public void onTick(float dt) {
+ public void onTick(float dt) {
//Check controller health, send messages to the client based on current state.
if (getParent().getHealth() <= 0) {
broadcastPacket(new EntityStatusMessage(getParent().getId(), EntityStatusMessage.ENTITY_DEAD));
getParent().kill();
}
-
+
this.oldPosition = getParent().getPosition();
this.oldRotation = getParent().getRotation().getAxisAngles();
//HACK: Store Position for later purposes
if(getParent().getPosition() != null && getParent().getPosition() != Point.invalid) {
lastKnownPosition = getParent().getPosition();
}
-
+
super.onTick(dt);
}
View
40 src/main/java/org/spout/vanilla/controller/living/player/VanillaPlayer.java
@@ -63,6 +63,7 @@
protected ItemStack itemOnCursor;
protected String tabListName;
protected GameMode gameMode;
+ private int distanceMoved;
public VanillaPlayer(Player p, GameMode gameMode) {
super(VanillaControllerTypes.PLAYER);
@@ -71,7 +72,7 @@ public VanillaPlayer(Player p, GameMode gameMode) {
this.gameMode = gameMode;
p.getEntity().setInventorySize(45);
}
-
+
public VanillaPlayer(Player p) {
this(p, GameMode.SURVIVAL);
}
@@ -132,17 +133,21 @@ public void onTick(float dt) {
creativeTick(dt);
}
}
-
+
private void survivalTick(float dt) {
- exhaustion += 0.1;
+ if ((distanceMoved += getPreviousPosition().distanceSquared(getParent().getPosition())) >= 1) {
+ exhaustion += 0.01;
+ distanceMoved = 0;
+ }
+
if (sprinting) {
exhaustion += 0.1;
}
// TODO: Check for swimming, jumping, sprint jumping, block breaking, attacking, receiving damage for exhaustion level.
if (poisoned) {
- exhaustion += 15.0;
+ exhaustion += 15.0 / 30 * dt;
}
// Track hunger
@@ -159,32 +164,37 @@ private void updateHealth() {
health = (short) parent.getHealth();
if (exhaustion > 4.0) {
- exhaustion = 0;
+ exhaustion -= 4.0;
if (foodSaturation > 0) {
foodSaturation = Math.max(foodSaturation - 0.1f, 0);
} else {
hunger = (short) Math.max(hunger - 1, 0);
}
}
- if (hunger <= 0) {
+ boolean changed = false;
+ if (hunger <= 0 && health > 0) {
health = (short) Math.max(health - 1, 0);
parent.setHealth(health, new HealthChangeReason(HealthChangeReason.Type.STARVE));
- } else if (hunger >= 18) {
+ changed = true;
+ } else if (hunger >= 18 && health < 20) {
health = (short) Math.min(health + 1, 20);
parent.setHealth(health, new HealthChangeReason(HealthChangeReason.Type.REGENERATION));
+ changed = true;
}
- System.out.println("Performing health/hunger update...");
- System.out.println("Food saturation: " + foodSaturation);
- System.out.println("Hunger: " + hunger);
- System.out.println("Health: " + health);
- System.out.println("Exhaustion: " + exhaustion);
- sendPacket(owner, new PlayerHealthMessage(health, hunger, foodSaturation));
+ if (changed) {
+ System.out.println("Performing health/hunger update...");
+ System.out.println("Food saturation: " + foodSaturation);
+ System.out.println("Hunger: " + hunger);
+ System.out.println("Health: " + health);
+ System.out.println("Exhaustion: " + exhaustion);
+ sendPacket(owner, new PlayerHealthMessage(health, hunger, foodSaturation));
@windy1
Spout member
windy1 added a note Apr 17, 2012

We can lose this line actually, we would be sending it twice :3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
}
-
+
private void creativeTick(float dt) {
-
+
}
/**
View
4 src/main/java/org/spout/vanilla/protocol/handler/GroundMessageHandler.java
@@ -36,10 +36,10 @@
public class GroundMessageHandler extends MessageHandler<GroundMessage> {
@Override
public void handleServer(Session session, Player player, GroundMessage message) {
- if (player.getEntity().getController() == null) {
+ if (player == null || player.getEntity() == null || player.getEntity().getController() == null) {
return;
}
- if (!(player.getEntity().getController() instanceof PlayerController)) {
+ if (!(player.getEntity().getController() instanceof VanillaPlayer)) {
return;
}
VanillaPlayer vplayer = (VanillaPlayer) player.getEntity().getController();
View
4 src/main/java/org/spout/vanilla/protocol/handler/PositionRotationMessageHandler.java
@@ -56,8 +56,8 @@ public void handleServer(Session session, Player player, PositionRotationMessage
Point p = new Point(entity.getWorld(), (float) x, (float) y, (float) z);
entity.setPosition(p);
- entity.yaw(rot);
- entity.pitch(pitch);
+ entity.setYaw(rot);
+ entity.setPitch(pitch);
}
@Override

0 comments on commit 1bb940c

Please sign in to comment.
Something went wrong with that request. Please try again.