/** * Shortcut for {@link #setObject(int, Object, boolean)} */ public void setObject(int index, Object value) { setObject(index, value, false); }
/** * Shortcut for {@link #setObject(WrappedDataWatcherObject, Object, boolean)} */ public void setObject(WrappedDataWatcherObject object, Object value) { setObject(object, value, false); }
/** * Alias for {@link #setObject(int, WrappedWatchableObject, boolean)} */ public void setObject(int index, WrappedWatchableObject value) { setObject(index, value.getRawValue(), false); }
/** * Alias for {@link #setObject(int, Serializer, Object, boolean)} */ public void setObject(int index, Serializer serializer, Object value) { setObject(new WrappedDataWatcherObject(index, serializer), value, false); }
/** * Sets the DataWatcher Item at a given index to a new value. * * @param index Index of the object to set * @param serializer Serializer from {@link Registry#get(Class)} * @param value New value * @param update Whether or not to inform the client * * @see {@link #setObject(WrappedDataWatcherObject, Object)} */ public void setObject(int index, Serializer serializer, Object value, boolean update) { setObject(new WrappedDataWatcherObject(index, serializer), value, update); }
/** * Sets the DataWatcher Item at a given index to a new value. * * @param index Index of the object to set * @param value New value * @param update Whether or not to inform the client * * @see {@link #setObject(int, Object, boolean)} */ public void setObject(int index, WrappedWatchableObject value, boolean update) { setObject(index, value.getRawValue(), update); }
/** * Sets the DataWatcher Item associated with a given watcher object to a new value. * * @param object Associated watcher object * @param value Wrapped value * @param update Whether or not to inform the client * * @see #setObject(WrappedDataWatcherObject, Object) */ public void setObject(WrappedDataWatcherObject object, WrappedWatchableObject value, boolean update) { setObject(object, value.getRawValue(), update); }
/** * Shortcut for {@link #setObject(WrappedDataWatcherObject, WrappedWatchableObject, boolean)} */ public void setObject(WrappedDataWatcherObject object, WrappedWatchableObject value) { setObject(object, value.getRawValue(), false); }
/** * Constructs a new DataWatcher using a fake egg entity and a given * list of watchable objects. * * @param objects The list of objects */ public WrappedDataWatcher(List<WrappedWatchableObject> objects) { this(); if (MinecraftReflection.watcherObjectExists()) { for (WrappedWatchableObject object : objects) { setObject(object.getWatcherObject(), object); } } else { for (WrappedWatchableObject object : objects) { setObject(object.getIndex(), object); } } }
/** * Sets the DataWatcher Item at a given index to a new value. In 1.9 and up, * you cannot register objects without a watcher object. * * @param index Index of the object to set * @param value New value * @param update Whether or not to inform the client * * @see {@link #setObject(WrappedDataWatcherObject, Object, boolean)} * @throws IllegalArgumentException in 1.9 and up if there isn't already an * object at this index */ public void setObject(int index, Object value, boolean update) { if (MinecraftReflection.watcherObjectExists() && !hasIndex(index)) { throw new IllegalArgumentException("You cannot register objects without a watcher object!"); } setObject(WrappedDataWatcherObject.fromIndex(index), value, update); }
/** * Clone the content of the current DataWatcher. * * @return A cloned data watcher. */ public WrappedDataWatcher deepClone() { WrappedDataWatcher clone = new WrappedDataWatcher(getEntity()); if (MinecraftReflection.watcherObjectExists()) { for (WrappedWatchableObject wrapper : this) { clone.setObject(wrapper.getWatcherObject(), wrapper); } } else { for (WrappedWatchableObject wrapper : this) { clone.setObject(wrapper.getIndex(), wrapper); } } return clone; }
WrappedDataWatcher dataWatcher = new WrappedDataWatcher(); dataWatcher.setObject(new WrappedDataWatcherObject(0, byteSerializer), (byte) 0x20); // Entity status: invisible dataWatcher.setObject(new WrappedDataWatcherObject(customNameWatcherIndex, chatComponentSerializer), Optional.of(WrappedChatComponent.fromText(customName).getHandle())); } else { dataWatcher.setObject(new WrappedDataWatcherObject(customNameWatcherIndex, stringSerializer), customName); dataWatcher.setObject(new WrappedDataWatcherObject(3, booleanSerializer), true); // Custom name visible dataWatcher.setObject(new WrappedDataWatcherObject(5, booleanSerializer), true); // No gravity dataWatcher.setObject(new WrappedDataWatcherObject(11, byteSerializer), (byte) (0x01 | 0x08 | 0x10)); // Armor stand data: small, no base plate, marker
/** * Create a new datawatcher but with the 'correct' values */ public static WrappedDataWatcher createSanitizedDataWatcher(WrappedDataWatcher entityWatcher, FlagWatcher disguiseWatcher) { WrappedDataWatcher newWatcher = new WrappedDataWatcher(); try { List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? disguiseWatcher.convert(entityWatcher.getWatchableObjects()) : disguiseWatcher.getWatchableObjects(); for (WrappedWatchableObject watchableObject : list) { if (watchableObject == null) continue; if (watchableObject.getValue() == null) continue; WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager .createDataWatcherObject(watchableObject.getIndex(), watchableObject.getValue()); newWatcher.setObject(obj, watchableObject.getValue()); } } catch (Exception ex) { ex.printStackTrace(); } return newWatcher; }
dataWatcher.setObject(new WrappedDataWatcherObject(itemstackMetadataWatcherIndex, itemSerializer), itemStackObject); dataWatcher.setObject(new WrappedDataWatcherObject(1, intSerializer), 300); dataWatcher.setObject(new WrappedDataWatcherObject(0, byteSerializer), (byte) 0); } else { dataWatcher.setObject(itemstackMetadataWatcherIndex, itemLine.getNmsItem().getRawItemStack()); dataWatcher.setObject(1, 300); dataWatcher.setObject(0, (byte) 0);
newWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(), WrappedDataWatcher.Registry.get(Byte.class)), (byte) 32);