Added methods and changed internals for flag watchers.

This commit is contained in:
Andrew 2013-07-09 16:08:47 +12:00
parent d181addde9
commit a2e789aac6
5 changed files with 147 additions and 76 deletions

@ -7,12 +7,6 @@ public class HorseWatcher extends AgeableWatcher {
public HorseWatcher(int entityId) { public HorseWatcher(int entityId) {
super(entityId); super(entityId);
setValue(16, 0); setValue(16, 0);
// Horse types (19) are
// Horse
// Donkey
// Mule
// Zombie
// Skeleton
setValue(19, (byte) 0); setValue(19, (byte) 0);
setValue(20, new Random().nextInt(7)); setValue(20, new Random().nextInt(7));
setValue(21, ""); setValue(21, "");
@ -27,14 +21,86 @@ public class HorseWatcher extends AgeableWatcher {
return (int) (Byte) getValue(19); return (int) (Byte) getValue(19);
} }
public boolean hasChest() {
return isTrue(8);
}
public boolean isBredable() {
return isTrue(16);
}
public boolean isGrazing() {
return isTrue(32);
}
public boolean isMouthOpen() {
return isTrue(128);
}
public boolean isRearing() {
return isTrue(64);
}
public boolean isSaddled() {
return isTrue(4);
}
public boolean isTamed() {
return isTrue(2);
}
private boolean isTrue(int i) {
return ((Integer) getValue(16) & i) != 0;
}
public void setCanBred(boolean bred) {
setFlag(16, bred);
}
public void setCarryingChest(boolean chest) {
setFlag(8, true);
}
public void setColoring(int color) { public void setColoring(int color) {
setValue(20, color); setValue(20, color);
sendData(20); sendData(20);
} }
private void setFlag(int i, boolean flag) {
if (isTrue(i) != flag) {
int j = (Integer) getValue(16);
if (flag) {
setValue(16, j | i);
} else {
setValue(16, j & ~i);
}
sendData(16);
}
}
public void setGrazing(boolean grazing) {
setFlag(32, grazing);
}
public void setHorseType(int type) { public void setHorseType(int type) {
setValue(19, (byte) type); setValue(19, (byte) type);
sendData(19); sendData(19);
} }
public void setMouthOpen(boolean mouthOpen) {
setFlag(128, mouthOpen);
}
public void setRearing(boolean rear) {
setFlag(64, true);
}
public void setSaddled(boolean saddled) {
setFlag(4, saddled);
}
public void setTamed(boolean tamed) {
setFlag(2, tamed);
}
} }

@ -4,9 +4,6 @@ import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Ocelot.Type; import org.bukkit.entity.Ocelot.Type;
public class OcelotWatcher extends AgeableWatcher { public class OcelotWatcher extends AgeableWatcher {
private boolean isSitting;
private boolean isTamed;
private Type type = Ocelot.Type.WILD_OCELOT;
public OcelotWatcher(int entityId) { public OcelotWatcher(int entityId) {
super(entityId); super(entityId);
@ -20,7 +17,23 @@ public class OcelotWatcher extends AgeableWatcher {
} }
public Type getType() { public Type getType() {
return type; return Ocelot.Type.getType((Byte) getValue(18));
}
private boolean isTrue(int no) {
return ((Byte) getValue(16) & no) != 0;
}
private void setFlag(int no, boolean flag) {
if (isTrue(no) != flag) {
byte b0 = (Byte) getValue(16);
if (flag) {
setValue(16, (byte) (b0 | (no)));
} else {
setValue(16, (byte) (b0 & -(no + 1)));
}
sendData(16);
}
} }
public void setOwner(String newOwner) { public void setOwner(String newOwner) {
@ -28,29 +41,17 @@ public class OcelotWatcher extends AgeableWatcher {
} }
public void setSitting(boolean sitting) { public void setSitting(boolean sitting) {
if (isSitting != sitting) { setFlag(1, sitting);
isSitting = sitting;
updateStatus();
}
} }
public void setTamed(boolean tamed) { public void setTamed(boolean tamed) {
if (isTamed != tamed) { setFlag(4, tamed);
isTamed = tamed;
updateStatus();
}
} }
public void setType(Type newType) { public void setType(Type newType) {
if (type != newType) { if (getType() != newType) {
type = newType; setValue(18, (byte) newType.getId());
setValue(18, (byte) type.getId());
sendData(18); sendData(18);
} }
} }
private void updateStatus() {
setValue(16, (byte) ((isSitting ? 1 : 0) + (isTamed ? 4 : 0)));
sendData(16);
}
} }

@ -3,31 +3,37 @@ package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.AnimalColor; import me.libraryaddict.disguise.DisguiseTypes.AnimalColor;
public class SheepWatcher extends AgeableWatcher { public class SheepWatcher extends AgeableWatcher {
private AnimalColor color = AnimalColor.WHITE;
private boolean isSheared;
public SheepWatcher(int entityId) { public SheepWatcher(int entityId) {
super(entityId); super(entityId);
setValue(16, (byte) 0); setValue(16, (byte) 0);
} }
public AnimalColor getColor() {
return AnimalColor.values()[(Byte) getValue(16) & 15];
}
public boolean isSheared() { public boolean isSheared() {
return isSheared; return ((Byte) getValue(16) & 16) != 0;
} }
public void setColor(AnimalColor newColor) { public void setColor(AnimalColor color) {
if (color != newColor) { if (getColor() != color) {
setValue(16, (byte) (newColor.getId() + (isSheared ? 16 : 0))); byte b0 = (Byte) getValue(16);
setValue(16, (byte) (b0 & 240 | color.getId() & 15));
sendData(16); sendData(16);
} }
} }
public void setSheared(boolean sheared) { public void setSheared(boolean flag) {
if (sheared != isSheared) { if (isSheared() != flag) {
isSheared = sheared; byte b0 = (Byte) getValue(16);
setValue(16, (byte) (color.getId() + (isSheared ? 16 : 0))); if (flag) {
setValue(16, (byte) (b0 | 16));
} else {
setValue(16, (byte) (b0 & -17));
}
sendData(16); sendData(16);
} }
} }
} }

@ -5,18 +5,19 @@ import java.util.Random;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Villager.Profession;
public class VillagerWatcher extends AgeableWatcher { public class VillagerWatcher extends AgeableWatcher {
private Profession profession;
public VillagerWatcher(int entityId) { public VillagerWatcher(int entityId) {
super(entityId); super(entityId);
profession = Profession.values()[new Random().nextInt(Profession.values().length)]; setValue(16, Profession.values()[new Random().nextInt(Profession.values().length)].getId());
setValue(16, profession.getId()); }
public Profession getProfession() {
return Profession.values()[(Integer) getValue(16)];
} }
public void setProfession(Profession newProfession) { public void setProfession(Profession newProfession) {
if (profession != newProfession) { if (getProfession() != newProfession) {
profession = newProfession; setValue(16, newProfession.getId());
setValue(16, profession.getId());
sendData(16); sendData(16);
} }
} }

@ -3,10 +3,6 @@ package me.libraryaddict.disguise.DisguiseTypes.Watchers;
import me.libraryaddict.disguise.DisguiseTypes.AnimalColor; import me.libraryaddict.disguise.DisguiseTypes.AnimalColor;
public class WolfWatcher extends AgeableWatcher { public class WolfWatcher extends AgeableWatcher {
private AnimalColor collarColor = AnimalColor.RED;
private boolean isAgressive;
private boolean isSitting;
private boolean isTamed;
public WolfWatcher(int entityId) { public WolfWatcher(int entityId) {
super(entityId); super(entityId);
@ -14,11 +10,11 @@ public class WolfWatcher extends AgeableWatcher {
setValue(17, ""); setValue(17, "");
setValue(18, 8F); setValue(18, 8F);
setValue(19, (byte) 0); setValue(19, (byte) 0);
setValue(20, (byte) collarColor.getId()); setValue(20, (byte) 14);
} }
public AnimalColor getCollarColor() { public AnimalColor getCollarColor() {
return collarColor; return AnimalColor.values()[(Byte) getValue(20)];
} }
public float getHealth() { public float getHealth() {
@ -29,55 +25,56 @@ public class WolfWatcher extends AgeableWatcher {
return (String) getValue(17); return (String) getValue(17);
} }
public boolean isAgressive() { public boolean isAngry() {
return isAgressive; return isTrue(2);
} }
public boolean isSitting() { public boolean isSitting() {
return isSitting; return isTrue(1);
} }
public boolean isTamed() { public boolean isTamed() {
return isTamed; return isTrue(4);
} }
public void setAgressive(boolean aggressive) { private boolean isTrue(int no) {
if (isAgressive != aggressive) { return ((Byte) getValue(16) & no) != 0;
isAgressive = aggressive; }
updateStatus();
} public void setAngry(boolean angry) {
setFlag(2, angry);
} }
public void setCollarColor(AnimalColor newColor) { public void setCollarColor(AnimalColor newColor) {
if (newColor != collarColor) { if (newColor != getCollarColor()) {
collarColor = newColor;
setValue(20, (byte) newColor.getId()); setValue(20, (byte) newColor.getId());
sendData(20); sendData(20);
} }
} }
private void setFlag(int no, boolean flag) {
if (isTrue(no) != flag) {
byte b0 = (Byte) getValue(16);
if (flag) {
setValue(16, (byte) (b0 | (no)));
} else {
setValue(16, (byte) (b0 & -(no + 1)));
}
sendData(16);
}
}
public void setHealth(float newHealth) { public void setHealth(float newHealth) {
setValue(18, newHealth); setValue(18, newHealth);
sendData(18); sendData(18);
} }
public void setSitting(boolean sitting) { public void setSitting(boolean sitting) {
if (isSitting != sitting) { setFlag(1, sitting);
isSitting = sitting;
updateStatus();
}
} }
public void setTamed(boolean tamed) { public void setTamed(boolean tamed) {
if (isTamed != tamed) { setFlag(4, tamed);
isTamed = tamed;
updateStatus();
}
}
private void updateStatus() {
setValue(16, (byte) ((isTamed ? 4 : 0) + (isSitting ? 1 : 0) + (isAgressive ? 2 : 0)));
sendData(16);
} }
} }