Clean up misc disguise constructor a little

This commit is contained in:
Andrew 2013-11-08 04:37:36 +13:00
parent 01f7d2b911
commit 9d06e1e55e
3 changed files with 39 additions and 20 deletions

View File

@ -199,7 +199,7 @@ public class PacketsManager {
mods.write(2, loc.getBlockY()); mods.write(2, loc.getBlockY());
mods.write(3, loc.getBlockZ()); mods.write(3, loc.getBlockZ());
mods.write(4, ((int) loc.getYaw()) % 4); mods.write(4, ((int) loc.getYaw()) % 4);
int id = ((MiscDisguise) disguise).getId(); int id = ((MiscDisguise) disguise).getData();
if (id == -1) if (id == -1)
id = new Random().nextInt(EnumArt.values().length); id = new Random().nextInt(EnumArt.values().length);
mods.write(5, EnumArt.values()[id % EnumArt.values().length].B); mods.write(5, EnumArt.values()[id % EnumArt.values().length].B);
@ -275,17 +275,21 @@ public class PacketsManager {
int id = disguise.getType().getEntityId(); int id = disguise.getType().getEntityId();
int data = 0; int data = 0;
if (((MiscDisguise) disguise).getId() >= 0) if (((MiscDisguise) disguise).getId() >= 0) {
if (((MiscDisguise) disguise).getData() >= 0) if (((MiscDisguise) disguise).getData() >= 0)
data = (((MiscDisguise) disguise).getId() | ((MiscDisguise) disguise).getData() << 16); data = (((MiscDisguise) disguise).getId() | ((MiscDisguise) disguise).getData() << 16);
else else
data = ((MiscDisguise) disguise).getId(); data = ((MiscDisguise) disguise).getId();
}
// This won't actually work. // This won't actually work.
// But if someone constructing the disguise uses it properly. It will work. // But if someone constructing the disguise uses it properly. It will work.
if (disguise.getType() == DisguiseType.FISHING_HOOK) if (disguise.getType() == DisguiseType.FISHING_HOOK)
data = disguise.getEntity().getEntityId(); data = disguise.getEntity().getEntityId();
else if (disguise.getType() == DisguiseType.ITEM_FRAME) else if (disguise.getType() == DisguiseType.ITEM_FRAME) {
data = (int) Math.abs(loc.getYaw() % 4); data = (int) loc.getYaw();
if (data < 0)
data = -data;
}
spawnPackets[0] = new PacketContainer(Packets.Server.VEHICLE_SPAWN); spawnPackets[0] = new PacketContainer(Packets.Server.VEHICLE_SPAWN);
StructureModifier<Object> mods = spawnPackets[0].getModifier(); StructureModifier<Object> mods = spawnPackets[0].getModifier();
mods.write(0, disguisedEntity.getEntityId()); mods.write(0, disguisedEntity.getEntityId());

View File

@ -133,11 +133,11 @@ public enum DisguiseType {
} }
private int defaultData; private int defaultData;
private int defaultId; private int defaultId;
private int entityId; private int entityId;
private EntityType entityType; private EntityType entityType;
private Class watcherClass; private Class watcherClass;
private DisguiseType(EntityType newType, int... obj) { private DisguiseType(EntityType newType, int... obj) {
entityType = newType; entityType = newType;
for (int i = 0; i < obj.length; i++) { for (int i = 0; i < obj.length; i++) {

View File

@ -15,15 +15,40 @@ public class MiscDisguise extends Disguise {
} }
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int id, int data) { public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int id, int data) {
if (id == -1) switch (disguiseType) {
id = disguiseType.getDefaultId(); // The only disguises which should use a custom data.
case FISHING_HOOK:
case ARROW:
case SPLASH_POTION:
case SMALL_FIREBALL:
case FIREBALL:
case WITHER_SKULL:
case PAINTING:
case FALLING_BLOCK:
break;
default:
data = -1;
break;
}
if (disguiseType == DisguiseType.FALLING_BLOCK && id != -1) {
this.id = id;
} else {
this.id = disguiseType.getDefaultId();
}
if (data == -1) if (data == -1)
data = disguiseType.getDefaultData(); data = disguiseType.getDefaultData();
this.id = id;
this.data = data; this.data = data;
createDisguise(disguiseType, replaceSounds); createDisguise(disguiseType, replaceSounds);
} }
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int addictionalData) {
this(disguiseType, replaceSounds, -1, addictionalData);
}
public int getId() {
return id;
}
public MiscDisguise(DisguiseType disguiseType, int id, int data) { public MiscDisguise(DisguiseType disguiseType, int id, int data) {
this(disguiseType, true, id, data); this(disguiseType, true, id, data);
} }
@ -40,13 +65,7 @@ public class MiscDisguise extends Disguise {
@Deprecated @Deprecated
public MiscDisguise(EntityType entityType, boolean replaceSounds, int id, int data) { public MiscDisguise(EntityType entityType, boolean replaceSounds, int id, int data) {
if (id == -1) this(DisguiseType.getType(entityType), replaceSounds, id, data);
id = DisguiseType.getType(entityType).getDefaultId();
if (data == -1)
data = DisguiseType.getType(entityType).getDefaultData();
this.id = id;
this.data = data;
createDisguise(DisguiseType.getType(entityType), replaceSounds);
} }
@Deprecated @Deprecated
@ -56,7 +75,7 @@ public class MiscDisguise extends Disguise {
@Override @Override
public MiscDisguise clone() { public MiscDisguise clone() {
MiscDisguise disguise = new MiscDisguise(getType(), replaceSounds(), getId(), getData()); MiscDisguise disguise = new MiscDisguise(getType(), replaceSounds(), getData());
disguise.setViewSelfDisguise(viewSelfDisguise()); disguise.setViewSelfDisguise(viewSelfDisguise());
disguise.setHearSelfDisguise(canHearSelfDisguise()); disguise.setHearSelfDisguise(canHearSelfDisguise());
disguise.setHideArmorFromSelf(isHidingArmorFromSelf()); disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
@ -70,8 +89,4 @@ public class MiscDisguise extends Disguise {
return data; return data;
} }
public int getId() {
return id;
}
} }