Fixed Wolves, Endermen, and Ocelots
All mob and misc disguises work now
This commit is contained in:
parent
e95df4a2df
commit
27baf53073
@ -124,8 +124,7 @@ public class FlagWatcher {
|
||||
}
|
||||
}
|
||||
// Here we check for if there is a health packet that says they died.
|
||||
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null
|
||||
&& getDisguise().getEntity() instanceof Player) {
|
||||
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) {
|
||||
for (WrappedWatchableObject watch : newList) {
|
||||
// Its a health packet
|
||||
if (watch.getIndex() == 6) {
|
||||
@ -261,6 +260,9 @@ public class FlagWatcher {
|
||||
}
|
||||
Object value = entityValues.get(data);
|
||||
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) {
|
||||
if (disguise.getType() != DisguiseType.WOLF &&
|
||||
disguise.getType() != DisguiseType.OCELOT &&
|
||||
disguise.getType() != DisguiseType.ENDERMAN)
|
||||
value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
|
||||
}
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(data, value));
|
||||
@ -341,6 +343,7 @@ public class FlagWatcher {
|
||||
|
||||
/**
|
||||
* Don't use this, use setItemInMainHand instead
|
||||
*
|
||||
* @param itemstack
|
||||
*/
|
||||
@Deprecated
|
||||
|
@ -1,6 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EndermanWatcher extends LivingWatcher {
|
||||
@ -11,12 +14,29 @@ public class EndermanWatcher extends LivingWatcher {
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInMainHand() {
|
||||
return new ItemStack((int) getValue(11, 1), 1, (short) 0);
|
||||
Optional<Integer> value = (Optional<Integer>) getValue(11, Optional.of(1));
|
||||
if (value.isPresent()) {
|
||||
Pair<Integer, Integer> pair = ReflectionManager.getFromCombinedId(value.get());
|
||||
int id = pair.getLeft();
|
||||
int data = pair.getRight();
|
||||
return new ItemStack(id, 1, (short) data);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(ItemStack itemstack) {
|
||||
setValue(11, itemstack.getTypeId());
|
||||
setItemInMainHand(itemstack.getTypeId(), itemstack.getDurability());
|
||||
}
|
||||
|
||||
public void setItemInMainHand(int typeId) {
|
||||
setItemInMainHand(typeId, 0);
|
||||
}
|
||||
|
||||
public void setItemInMainHand(int typeId, int data) {
|
||||
int combined = ReflectionManager.getCombinedId(typeId, data);
|
||||
setValue(11, Optional.of(combined));
|
||||
}
|
||||
|
||||
public boolean isAggressive() {
|
||||
|
@ -25,8 +25,9 @@ public enum DisguiseSound {
|
||||
ELDER_GUARDIAN("entity.guardian.elder.hit", null, "entity.guardian.elder.death", "entity.guardian.elder.death"),
|
||||
ENDER_DRAGON("entity.enderdragon.hit", null, "entity.enderdragon.end", "entity.enderdragon.growl", "damage.fallsmall",
|
||||
"entity.enderdragon.wings", "damage.fallbig"),
|
||||
ENDERMAN("entity.endermen.hit", "step.grass", "entity.endermen.death", "entity.endermen.idle", "entity.endermen.scream",
|
||||
"entity.endermen.portal", "entity.endermen.stare"),
|
||||
//TODO: Fix enderman sounds
|
||||
// ENDERMAN("entity.endermen.hit", "step.grass", "entity.endermen.death", "entity.endermen.idle", "entity.endermen.scream",
|
||||
// "entity.endermen.portal", "entity.endermen.stare"),
|
||||
ENDERMITE("entity.silverfish.hit", "entity.silverfish.step", "entity.silverfish.kill", "entity.silverfish.ambient"),
|
||||
GHAST("entity.ghast.scream", null, "entity.ghast.death", "entity.ghast.moan", "damage.fallsmall", "entity.ghast.fireball",
|
||||
"damage.fallbig", "entity.ghast.affectionate_scream", "entity.ghast.charge"),
|
||||
|
@ -284,7 +284,7 @@ public class PacketsManager {
|
||||
int objectId = disguise.getType().getObjectId();
|
||||
int data = ((MiscDisguise) disguise).getData();
|
||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
||||
data = ((MiscDisguise) disguise).getId() + (data << 12);
|
||||
data = ReflectionManager.getCombinedId(((MiscDisguise) disguise).getId(), data);
|
||||
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) {
|
||||
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id
|
||||
data = disguisedEntity.getEntityId();
|
||||
@ -326,9 +326,9 @@ public class PacketsManager {
|
||||
private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) {
|
||||
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
||||
try {
|
||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ?
|
||||
flagWatcher.convert(watcher.getWatchableObjects()) : flagWatcher.getWatchableObjects();
|
||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert(watcher.getWatchableObjects()) : flagWatcher.getWatchableObjects();
|
||||
for (WrappedWatchableObject watchableObject : list) {
|
||||
if (watchableObject == null) continue;
|
||||
if (watchableObject.getValue() == null) continue;
|
||||
if (Registry.get(watchableObject.getValue().getClass()) == null) continue;
|
||||
WrappedDataWatcherObject obj = new WrappedDataWatcherObject(watchableObject.getIndex(), Registry.get(watchableObject.getValue().getClass()));
|
||||
@ -1281,7 +1281,9 @@ public class PacketsManager {
|
||||
|
||||
// Else if the packet is sending entity metadata
|
||||
else if (sentPacket.getType() == Server.ENTITY_METADATA) {
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled() && (disguise.getType() != DisguiseType.WOLF &&
|
||||
disguise.getType() != DisguiseType.OCELOT &&
|
||||
disguise.getType() != DisguiseType.ENDERMAN)) {
|
||||
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||
packets[0].getWatchableCollectionModifier().read(0));
|
||||
packets[0] = new PacketContainer(sentPacket.getType());
|
||||
@ -1394,7 +1396,9 @@ public class PacketsManager {
|
||||
if (heldItem != null && heldItem.getType() != Material.AIR) {
|
||||
// Convert the datawatcher
|
||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled() && (disguise.getType() != DisguiseType.WOLF &&
|
||||
disguise.getType() != DisguiseType.OCELOT &&
|
||||
disguise.getType() != DisguiseType.ENDERMAN)) {
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(0,
|
||||
WrappedDataWatcher.getEntityWatcher(entity).getByte(0)));
|
||||
list.add(watch);
|
||||
|
@ -6,6 +6,8 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -667,4 +669,14 @@ public class ReflectionManager {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getCombinedId(int id, int data) {
|
||||
return id + (data << 12);
|
||||
}
|
||||
|
||||
public static Pair<Integer, Integer> getFromCombinedId(int combinedId) {
|
||||
int j = combinedId & 4095;
|
||||
int k = combinedId >> 12 & 15;
|
||||
return new ImmutablePair<>(j, k);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user