Search in sources :

Example 76 with Item

use of net.minecraft.server.v1_12_R1.Item in project SilkSpawners by timbru31.

the class NMSHandler method getVanillaNBTEntityID.

@Override
public String getVanillaNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_12_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("BlockEntityTag")) {
        return null;
    }
    tag = tag.getCompound("BlockEntityTag");
    if (tag.hasKey("EntityId")) {
        return tag.getString("EntityId");
    } else if (tag.hasKey("SpawnData") && tag.getCompound("SpawnData").hasKey("id")) {
        return tag.getCompound("SpawnData").getString("id");
    } else if (tag.hasKey("SpawnPotentials") && !tag.getList("SpawnPotentials", 8).isEmpty()) {
        return tag.getList("SpawnPotentials", 8).get(0).getCompound("Entity").getString("id");
    } else {
        return null;
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 77 with Item

use of net.minecraft.server.v1_12_R1.Item in project SilkSpawners by timbru31.

the class NMSHandler method setNBTEntityID.

@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
    if (item == null || StringUtils.isBlank(entity)) {
        Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
        return null;
    }
    net.minecraft.server.v1_12_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag.getCompound("BlockEntityTag").setString("EntityId", entity);
    if (!tag.hasKey("SpawnData")) {
        tag.set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("SpawnData").setString("id", entity);
    if (!tag.getCompound("BlockEntityTag").hasKey("SpawnData")) {
        tag.getCompound("BlockEntityTag").set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("BlockEntityTag").getCompound("SpawnData").setString("id", entity);
    if (!tag.getCompound("BlockEntityTag").hasKey("SpawnPotentials")) {
        tag.getCompound("BlockEntityTag").set("SpawnPotentials", new NBTTagCompound());
    }
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    String prefixedEntity;
    if (!entity.startsWith("minecraft:")) {
        prefixedEntity = "minecraft:" + entity;
    } else {
        prefixedEntity = entity;
    }
    tag.getCompound("EntityTag").setString("id", prefixedEntity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 78 with Item

use of net.minecraft.server.v1_12_R1.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();
    }
}
Also used : Item(net.minecraft.server.v1_16_R2.Item) Field(java.lang.reflect.Field) MinecraftKey(net.minecraft.server.v1_16_R2.MinecraftKey)

Example 79 with Item

use of net.minecraft.server.v1_12_R1.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();
    }
}
Also used : Item(net.minecraft.server.v1_16_R3.Item) Field(java.lang.reflect.Field) MinecraftKey(net.minecraft.server.v1_16_R3.MinecraftKey)

Example 80 with Item

use of net.minecraft.server.v1_12_R1.Item in project WLib by WizardlyBump17.

the class PacketListener method entityMetadata.

@SuppressWarnings("unchecked")
@SneakyThrows
private void entityMetadata(World world, PacketContainer packet, PacketPlayOutEntityMetadata handle) {
    final Entity entity = packet.getEntityModifier(world).read(0);
    if (!(entity instanceof org.bukkit.entity.Item))
        return;
    final ItemStack itemStack = ((org.bukkit.entity.Item) entity).getItemStack().clone();
    if (isInvalid(itemStack))
        return;
    final Field field = handle.getClass().getDeclaredField("b");
    field.setAccessible(true);
    List<DataWatcher.Item<?>> items = new ArrayList<>((List<DataWatcher.Item<?>>) field.get(handle));
    final DataWatcher.Item<?> item;
    int index;
    if (items.size() == 7)
        // new item
        item = items.get(index = 6).d();
    else
        // item merge
        item = items.get(index = 0).d();
    final Field itemField = item.getClass().getDeclaredField("b");
    itemField.setAccessible(true);
    itemField.set(item, CraftItemStack.asNMSCopy(fixItem(itemStack)));
    items.set(index, item);
    field.set(handle, items);
}
Also used : Entity(org.bukkit.entity.Entity) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) DataWatcher(net.minecraft.server.v1_12_R1.DataWatcher) SneakyThrows(lombok.SneakyThrows)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)30 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)27 ItemStack (org.bukkit.inventory.ItemStack)25 Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 ItemMeta (org.bukkit.inventory.meta.ItemMeta)12 ArrayList (java.util.ArrayList)10 Player (org.bukkit.entity.Player)9 Field (java.lang.reflect.Field)7 PreparedStatement (java.sql.PreparedStatement)7 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)7 Test (org.junit.Test)7 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 Item (net.minecraft.server.v1_12_R1.Item)5 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)5 Location (org.bukkit.Location)5 OfflinePlayer (org.bukkit.OfflinePlayer)5