fix NPC skin layers sometimes don't show

This commit is contained in:
JCThePants 2015-09-16 21:01:28 -07:00
parent f204fc1ecf
commit 82eab1e8f6
2 changed files with 42 additions and 16 deletions

View File

@ -235,6 +235,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
controllerMove = new PlayerControllerMove(this);
navigation = new PlayerNavigation(this, world);
NMS.setStepHeight(this, 1); // the default (0) breaks step climbing
setSkinFlags((byte)0xFF);
}
public boolean isNavigating() {
@ -278,6 +280,18 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
controllerJump.a();
}
@Override
public void setSkinFlags(byte flags) {
// set skin flag byte (DataWatcher API is lacking so
// catch the NPE as a sign that this is a MC 1.7 server without the
// skin flag)
try {
getDataWatcher().watch(10, flags);
} catch (NullPointerException e) {
getDataWatcher().a(10, flags);
}
}
@Override
public void setSkinName(String name) {
Preconditions.checkNotNull(name);
@ -333,15 +347,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private void updatePackets(boolean navigating) {
if (world.getWorld().getFullTime() % Setting.PACKET_UPDATE_DELAY.asInt() == 0) {
// set skin flag byte to all visible (DataWatcher API is lacking so
// catch the NPE as a sign that this is a MC 1.7 server without the
// skin flag)
try {
datawatcher.watch(10, Byte.valueOf((byte) 127));
} catch (NullPointerException e) {
datawatcher.a(10, Byte.valueOf((byte) 127));
}
Location current = getBukkitEntity().getLocation(packetLocationCache);
Packet<?>[] packets = new Packet[navigating ? 5 : 6];
if (!navigating) {
@ -422,6 +427,11 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
cserver.getEntityMetadata().setMetadata(this, metadataKey, newMetadataValue);
}
@Override
public void setSkinFlags(byte flags) {
((SkinnableEntity) this.entity).setSkinFlags(flags);
}
@Override
public void setSkinName(String name) {
((SkinnableEntity) this.entity).setSkinName(name);

View File

@ -9,11 +9,6 @@ import org.bukkit.entity.Player;
*/
public interface SkinnableEntity extends NPCHolder {
/**
* Get the entities skin packet tracker.
*/
SkinPacketTracker getSkinTracker();
/**
* Get the bukkit entity.
*/
@ -29,12 +24,33 @@ public interface SkinnableEntity extends NPCHolder {
*/
String getSkinName();
/**
* Get the entities skin packet tracker.
*/
SkinPacketTracker getSkinTracker();
/**
* Set the bit flags that represent the skin layer parts visibility.
*
* <p>
* Setting the skin flags automatically updates the NPC skin.
* </p>
*
* @param flags
* The bit flags.
*/
void setSkinFlags(byte flags);
/**
* Set the name of the player whose skin the NPC
* uses.
*
* <p>Setting the skin name automatically updates and
* respawn the NPC.</p>
* <p>
* Setting the skin name automatically updates and respawn the NPC.
* </p>
*
* @param name
* The skin name.
*/
void setSkinName(String name);
}