Silly mojang and their silly bugs. Fixed right clicking not always working

This commit is contained in:
libraryaddict 2014-01-19 11:32:02 +13:00
parent 9879a38871
commit 1cea2e2163
2 changed files with 28 additions and 4 deletions

@ -4,7 +4,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -68,12 +67,10 @@ public class FlagWatcher {
} }
public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) { public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) {
Iterator<WrappedWatchableObject> itel = list.iterator();
List<WrappedWatchableObject> newList = new ArrayList<WrappedWatchableObject>(); List<WrappedWatchableObject> newList = new ArrayList<WrappedWatchableObject>();
HashSet<Integer> sentValues = new HashSet<Integer>(); HashSet<Integer> sentValues = new HashSet<Integer>();
boolean sendAllCustom = false; boolean sendAllCustom = false;
while (itel.hasNext()) { for (WrappedWatchableObject watch : list) {
WrappedWatchableObject watch = itel.next();
int dataType = watch.getIndex(); int dataType = watch.getIndex();
sentValues.add(dataType); sentValues.add(dataType);
// Its sending the air metadata. This is the least commonly sent metadata which all entitys still share. // Its sending the air metadata. This is the least commonly sent metadata which all entitys still share.

@ -1208,6 +1208,33 @@ public class PacketsManager {
packets[0].getModifier().write(2, packets[0].getModifier().write(2,
(itemstack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemstack))); (itemstack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemstack)));
} }
if (disguise.getWatcher().isRightClicking() && slot == 4) {
ItemStack heldItem = packets[0].getItemModifier().read(0);
if (heldItem != null && heldItem.getType() != Material.AIR) {
// Convert the datawatcher
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(entity);
List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>();
for (WrappedWatchableObject value : dataWatcher.getWatchableObjects()) {
if (value.getIndex() == 0) {
list.add(value);
}
}
list = disguise.getWatcher().convert(list);
// Construct the packets to return
PacketContainer packetBlock = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packetBlock.getModifier().write(0, entity.getEntityId());
packetBlock.getWatchableCollectionModifier().write(0, list);
PacketContainer packetUnblock = packetBlock.deepClone();
// Make a packet to send the 'unblock'
for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) {
watcher.setValue((byte) ((Byte) watcher.getValue() & ~(1 << 4)));
}
// Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler delay.
packets = new PacketContainer[] { packetUnblock, packets[0], packetBlock };
// Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset
// it.
}
}
} }
else if (sentPacket.getType() == PacketType.Play.Server.BED) { else if (sentPacket.getType() == PacketType.Play.Server.BED) {