Search in sources :

Example 16 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project TheAPI by TheDevTec.

the class v1_15_R1 method openGUI.

@Override
public void openGUI(Player player, Object container, String legacy, int size, String title, ItemStack[] items) {
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = ((Container) container).windowId;
    net.minecraft.server.v1_15_R1.ItemStack[] nmsItems = new net.minecraft.server.v1_15_R1.ItemStack[items.length];
    for (int i = 0; i < items.length; ++i) {
        ItemStack is = items[i];
        if (is == null || is.getType() == Material.AIR)
            continue;
        net.minecraft.server.v1_15_R1.ItemStack item = null;
        ((Container) container).setItem(i, item = (net.minecraft.server.v1_15_R1.ItemStack) asNMSItem(is));
        nmsItems[i] = item;
    }
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, legacy, size, title));
    int i = 0;
    for (net.minecraft.server.v1_15_R1.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
    nmsPlayer.activeContainer.transferTo((Container) container, (CraftPlayer) player);
    nmsPlayer.activeContainer = (Container) container;
    ((Container) container).addSlotListener(nmsPlayer);
    ((Container) container).checkReachable = false;
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftContainer) Container(net.minecraft.server.v1_15_R1.Container) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)

Example 17 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.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() == 8)
        // 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) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack) DataWatcher(net.minecraft.server.v1_15_R1.DataWatcher) SneakyThrows(lombok.SneakyThrows)

Example 18 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project solinia3-core by mixxit.

the class ItemStackUtils method ConvertItemStackToJsonRegular.

public static String ConvertItemStackToJsonRegular(ItemStack itemStack) {
    // First we convert the item stack into an NMS itemstack
    net.minecraft.server.v1_15_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound compound = new NBTTagCompound();
    compound = nmsItemStack.save(compound);
    return compound.toString();
}
Also used : NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound)

Example 19 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project solinia3-core by mixxit.

the class ItemStackUtils method getWeaponDamageFromItemStack.

public static int getWeaponDamageFromItemStack(ItemStack itemStack, EnumItemSlot itemSlot) {
    double attackDamage = 1.0;
    UUID uuid = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF");
    net.minecraft.server.v1_15_R1.ItemStack craftItemStack = CraftItemStack.asNMSCopy(itemStack);
    net.minecraft.server.v1_15_R1.Item item = craftItemStack.getItem();
    if (item instanceof net.minecraft.server.v1_15_R1.ItemSword || item instanceof net.minecraft.server.v1_15_R1.ItemTool || item instanceof net.minecraft.server.v1_15_R1.ItemHoe) {
        Multimap<String, AttributeModifier> map = item.a(itemSlot);
        Collection<AttributeModifier> attributes = map.get(GenericAttributes.ATTACK_DAMAGE.getName());
        if (!attributes.isEmpty()) {
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.ADDITION)
                    attackDamage += am.getAmount();
            }
            double y = 1;
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_BASE)
                    y += am.getAmount();
            }
            attackDamage *= y;
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_TOTAL)
                    attackDamage *= (1 + am.getAmount());
            }
        }
    }
    Long rounded = Math.round(attackDamage);
    if (rounded > Integer.MAX_VALUE)
        rounded = (long) Integer.MAX_VALUE;
    int damage = Integer.valueOf(rounded.intValue());
    return damage;
}
Also used : AttributeModifier(net.minecraft.server.v1_15_R1.AttributeModifier) UUID(java.util.UUID)

Example 20 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project solinia3-core by mixxit.

the class SoliniaLivingEntity method getItemBonusesTuple.

public Tuple<Integer, Integer> getItemBonusesTuple(SpellEffectType spellEffectType, SpellResistType filterResistType) {
    List<ISoliniaItem> equippedItems = this.getEquippedSoliniaItems();
    int highest = 0;
    int highest2 = 0;
    // Check if item focus effect exists for the client.
    if (equippedItems.size() > 0) {
        ISoliniaItem TempItem = null;
        // item focus
        for (ISoliniaItem item : equippedItems) {
            TempItem = item;
            if (TempItem == null)
                continue;
            if (TempItem.getFocusEffectId() < 1) {
                continue;
            }
            ISoliniaSpell spell = null;
            try {
                spell = StateManager.getInstance().getConfigurationManager().getSpell(item.getFocusEffectId());
                if (spell == null)
                    continue;
                if (!filterResistType.equals(SpellResistType.RESIST_NONE))
                    if (spell.isEffectInSpell(SpellEffectType.LimitResist)) {
                        try {
                            // For spells like Pet Focus where the spell type has type limits (ie fire resist = fire pet)
                            int resistTypeId = spell.getSpellEffectBase(SpellEffectType.LimitResist);
                            if (SpellUtils.getSpellResistType(resistTypeId) != filterResistType)
                                continue;
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                if (!spell.isEffectInSpell(spellEffectType))
                    continue;
                Tuple<Integer, Integer> spellBonuses = ApplySpellsBonuses(spell.getId(), getBukkitLivingEntity(), getBukkitLivingEntity(), spell.getSpellEffect(spellEffectType), getMentorLevel(), 0, 0);
                if (spellBonuses.a() > highest) {
                    highest = spellBonuses.a();
                    highest2 = spellBonuses.b();
                }
            } catch (CoreStateInitException e) {
            }
        }
    }
    return new Tuple<Integer, Integer>(highest, highest2);
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Tuple(net.minecraft.server.v1_15_R1.Tuple)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)12 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)8 ChannelPromise (io.netty.channel.ChannelPromise)8 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)8 ItemStack (org.bukkit.inventory.ItemStack)7 ArrayList (java.util.ArrayList)5 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 Container (net.minecraft.server.v1_15_R1.Container)3 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)3 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)2 Field (java.lang.reflect.Field)2 Timestamp (java.sql.Timestamp)2 UUID (java.util.UUID)2 Nullable (javax.annotation.Nullable)2 ContainerAnvil (net.minecraft.server.v1_15_R1.ContainerAnvil)2 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)2 Item (net.minecraft.server.v1_15_R1.Item)2 ItemStack (net.minecraft.server.v1_15_R1.ItemStack)2