use of net.minecraft.server.v1_16_R2.Item in project MechanicsMain by WeaponMechanics.
the class NonNullList_1_12_R1 method set.
@Override
public ItemStack set(int index, ItemStack newItem) {
ItemStack oldItem = get(index);
Item item = (Item) ReflectionUtil.invokeField(itemField, newItem);
if (newItem.getCount() == 0 && item != null) {
newItem.setCount(1);
consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
newItem.setCount(0);
} else if (!ItemStack.matches(oldItem, newItem)) {
consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
}
return super.set(index, newItem);
}
use of net.minecraft.server.v1_16_R2.Item in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method updateEntityNameTagForPlayer.
@Override
public void updateEntityNameTagForPlayer(Player player, org.bukkit.entity.Entity entity, String customName, boolean customNameVisible) {
try {
List<Item<?>> dataWatchers = new ArrayList<>();
Optional<IChatBaseComponent> nameComponent = Optional.ofNullable(CraftChatMessage.fromStringOrNull(customName));
dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.f.a(2), nameComponent));
dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.i.a(3), customNameVisible));
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata();
field_PacketPlayOutEntityMetadata_a.set(packetPlayOutEntityMetadata, entity.getEntityId());
field_PacketPlayOutEntityMetadata_b.set(packetPlayOutEntityMetadata, dataWatchers);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.
the class NMSHandler method setSpawnersUnstackable.
@Override
public void setSpawnersUnstackable() {
try {
final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
maxStackSize.setAccessible(true);
maxStackSize.set(spawner, 1);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.
the class NMSHandler method setSpawnersUnstackable.
@Override
public void setSpawnersUnstackable() {
try {
final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
maxStackSize.setAccessible(true);
maxStackSize.set(spawner, 1);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.
the class NMSHandler method getSilkSpawnersNBTEntityID.
@Override
@Nullable
public String getSilkSpawnersNBTEntityID(final ItemStack item) {
net.minecraft.server.v1_16_R2.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
final NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("SilkSpawners")) {
return null;
}
return tag.getCompound("SilkSpawners").getString("entity");
}
Aggregations