Fixed falling block disguise, fixed velocity when flying
This commit is contained in:
@@ -18,6 +18,7 @@ import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||
import me.libraryaddict.disguise.utilities.packetlisteners.*;
|
||||
@@ -432,7 +433,9 @@ public class PacketsManager {
|
||||
int data = ((MiscDisguise) disguise).getData();
|
||||
|
||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
||||
data = ReflectionManager.getCombinedId(((MiscDisguise) disguise).getId(), data);
|
||||
ItemStack block = ((FallingBlockWatcher) disguise.getWatcher()).getBlock();
|
||||
|
||||
data = ReflectionManager.getCombinedIdByItemStack(block);
|
||||
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) {
|
||||
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners
|
||||
// entity id
|
||||
@@ -448,6 +451,16 @@ public class PacketsManager {
|
||||
.createPacket(nmsEntity, objectId, data);
|
||||
packets.addPacket(spawnEntity);
|
||||
|
||||
// If it's not the same type, then highly likely they have different velocity settings which we'd want to
|
||||
// cancel
|
||||
if (DisguiseType.getType(disguisedEntity) != disguise.getType()) {
|
||||
StructureModifier<Integer> ints = spawnEntity.getIntegers();
|
||||
|
||||
ints.write(1, 0);
|
||||
ints.write(2, 0);
|
||||
ints.write(3, 0);
|
||||
}
|
||||
|
||||
spawnEntity.getModifier().write(8, pitch);
|
||||
spawnEntity.getModifier().write(9, yaw);
|
||||
|
||||
@@ -1089,7 +1102,8 @@ public class PacketsManager {
|
||||
|
||||
// If the entity is sending velocity and its a falling block
|
||||
else if (sentPacket.getType() == Server.ENTITY_VELOCITY) {
|
||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
||||
// If the disguise is a misc and the disguised is not the same type
|
||||
if (disguise.getType().isMisc() && DisguiseType.getType(entity) != disguise.getType()) {
|
||||
packets.clear();
|
||||
}
|
||||
}
|
||||
|
@@ -833,33 +833,13 @@ public class ReflectionManager {
|
||||
return ((Double) value).floatValue();
|
||||
} else if (value instanceof NbtWrapper) {
|
||||
return ((NbtWrapper) value).getHandle();
|
||||
} else if (value instanceof Particle) {
|
||||
return getParticleType((Particle) value);
|
||||
} else if (value instanceof WrappedParticle) {
|
||||
return ((WrappedParticle) value).getHandle();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Object getParticleType(Particle particle) {
|
||||
try {
|
||||
Class craftParticle = getCraftClass("CraftParticle");
|
||||
Field mcKeyField = craftParticle.getDeclaredField("minecraftKey");
|
||||
mcKeyField.setAccessible(true);
|
||||
Object mcKey = mcKeyField.get(Enum.valueOf(craftParticle, particle.name()));
|
||||
|
||||
Class typesClass = getNmsClass("IRegistry");
|
||||
|
||||
Object registry = typesClass.getField("PARTICLE_TYPE").get(null);
|
||||
|
||||
return registry.getClass().getMethod("get", mcKey.getClass()).invoke(registry, mcKey);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getMinecraftVersion() {
|
||||
String version = Bukkit.getVersion();
|
||||
version = version.substring(version.lastIndexOf(" ") + 1, version.length() - 1);
|
||||
@@ -979,10 +959,6 @@ public class ReflectionManager {
|
||||
return new WrappedWatchableObject(watcherItem);
|
||||
}
|
||||
|
||||
public static int getCombinedId(int id, int data) {
|
||||
return id + (data << 12);
|
||||
}
|
||||
|
||||
public static int getCombinedIdByItemStack(ItemStack itemStack) {
|
||||
try {
|
||||
Object nmsItem = getNmsItem(itemStack);
|
||||
@@ -991,7 +967,9 @@ public class ReflectionManager {
|
||||
|
||||
Object nmsBlock = getNmsMethod(blockClass, "asBlock", getNmsClass("Item")).invoke(null, item);
|
||||
|
||||
return (int) getNmsMethod(blockClass, "getBlockData").invoke(nmsBlock);
|
||||
Object iBlockData = getNmsMethod(blockClass, "getBlockData").invoke(nmsBlock);
|
||||
|
||||
return (int) getNmsMethod("Block", "getCombinedId", getNmsClass("IBlockData")).invoke(null, iBlockData);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
Reference in New Issue
Block a user