Skip to content

Commit

Permalink
Fix player speed attribute resetting all the time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim H committed Nov 18, 2013
1 parent 67784f0 commit a9feadc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import de.kumpelblase2.remoteentities.EntityManager;
import de.kumpelblase2.remoteentities.RemoteEntities;
import de.kumpelblase2.remoteentities.api.DespawnReason;
import de.kumpelblase2.remoteentities.api.RemoteEntityType;
import de.kumpelblase2.remoteentities.api.events.RemoteEntitySpawnEvent;
import de.kumpelblase2.remoteentities.nms.CustomPlayerAbilities;

public class RemotePlayer extends RemoteAttackingBaseEntity<Player>
{
Expand Down Expand Up @@ -68,7 +70,7 @@ public void spawn(Location inLocation)
if(this.m_speed != -1)
this.setSpeed(this.m_speed);
else
this.setSpeed(0.7d);
this.setSpeed(1d);

if(this.m_speedModifier != null)
{
Expand All @@ -77,6 +79,13 @@ public void spawn(Location inLocation)
}
}

@Override
public void setSpeed(double inSpeed)
{
super.setSpeed(inSpeed);
((CustomPlayerAbilities)((RemotePlayerEntity)this.m_entity).abilities).setWalkSpeed((float)inSpeed);
}

@Override
public String getNativeEntityName()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.kumpelblase2.remoteentities.nms;

import net.minecraft.server.v1_6_R3.NBTTagCompound;
import net.minecraft.server.v1_6_R3.PlayerAbilities;

public class CustomPlayerAbilities extends PlayerAbilities
{
protected float flySpeed = 0.05F;
protected float walkSpeed = 0.1F;

public CustomPlayerAbilities() {}

public void a(NBTTagCompound nbttagcompound) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();

nbttagcompound1.setBoolean("invulnerable", this.isInvulnerable);
nbttagcompound1.setBoolean("flying", this.isFlying);
nbttagcompound1.setBoolean("mayfly", this.canFly);
nbttagcompound1.setBoolean("instabuild", this.canInstantlyBuild);
nbttagcompound1.setBoolean("mayBuild", this.mayBuild);
nbttagcompound1.setFloat("flySpeed", this.flySpeed);
nbttagcompound1.setFloat("walkSpeed", this.walkSpeed);
nbttagcompound.set("abilities", nbttagcompound1);
}

public void b(NBTTagCompound nbttagcompound) {
if (nbttagcompound.hasKey("abilities")) {
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("abilities");

this.isInvulnerable = nbttagcompound1.getBoolean("invulnerable");
this.isFlying = nbttagcompound1.getBoolean("flying");
this.canFly = nbttagcompound1.getBoolean("mayfly");
this.canInstantlyBuild = nbttagcompound1.getBoolean("instabuild");
if (nbttagcompound1.hasKey("flySpeed")) {
this.flySpeed = nbttagcompound1.getFloat("flySpeed");
this.walkSpeed = nbttagcompound1.getFloat("walkSpeed");
}

if (nbttagcompound1.hasKey("mayBuild")) {
this.mayBuild = nbttagcompound1.getBoolean("mayBuild");
}
}
}

public float a() {
return this.flySpeed;
}

public float b() {
return this.walkSpeed;
}

public void setFlySpeed(float inSpeed)
{
this.flySpeed = inSpeed;
}

public void setWalkSpeed(float inSpeed)
{
this.walkSpeed = inSpeed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class PlayerSenses extends EntitySenses
// --- Taken from minecraft/EntitySenses.java
// --- Modified to work with an entity living
EntityLiving entity;
List seenEntities = new ArrayList();
List unseenEntities = new ArrayList();
List<Entity> seenEntities = new ArrayList<Entity>();
List<Entity> unseenEntities = new ArrayList<Entity>();

public PlayerSenses(EntityLiving inEntity) {
super(NMSUtil.getTempInsentientEntity());
Expand Down

0 comments on commit a9feadc

Please sign in to comment.