Search in sources :

Example 26 with Slot

use of net.minecraft.server.v1_16_R3.Slot in project MyPet by xXKeyleXx.

the class EntityMySkeleton method handlePlayerInteraction.

@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
        return EnumInteractionResult.CONSUME;
    }
    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
        if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
            boolean hadEquipment = false;
            for (EquipmentSlot slot : EquipmentSlot.values()) {
                ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
                if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) {
                    EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
                    entityitem.pickupDelay = 10;
                    entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
                    this.world.addEntity(entityitem);
                    getMyPet().setEquipment(slot, null);
                    hadEquipment = true;
                }
            }
            if (hadEquipment) {
                if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                    try {
                        itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
                    } catch (Error e) {
                        // TODO REMOVE
                        itemStack.damage(1, entityhuman, (entityhuman1) -> {
                            try {
                                ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
                            } catch (IllegalAccessException | InvocationTargetException ex) {
                                ex.printStackTrace();
                            }
                        });
                    }
                }
            }
            return EnumInteractionResult.CONSUME;
        } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
            EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.j(itemStack).getSlotFlag());
            ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
            if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
                entityitem.pickupDelay = 10;
                entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
                this.world.addEntity(entityitem);
            }
            getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
            if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                itemStack.subtract(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                }
            }
            return EnumInteractionResult.CONSUME;
        }
    }
    return EnumInteractionResult.PASS;
}
Also used : MyPet(de.Keyle.MyPet.api.entity.MyPet) Util(de.Keyle.MyPet.api.Util) Arrays(java.util.Arrays) PetState(de.Keyle.MyPet.api.entity.MyPet.PetState) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) MySkeleton(de.Keyle.MyPet.api.entity.types.MySkeleton) MyPetApi(de.Keyle.MyPet.MyPetApi) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) Pair(com.mojang.datafixers.util.Pair) InvocationTargetException(java.lang.reflect.InvocationTargetException) ENTITY_LIVING_broadcastItemBreak(de.Keyle.MyPet.compat.v1_16_R3.CompatManager.ENTITY_LIVING_broadcastItemBreak) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) Bukkit(org.bukkit.Bukkit) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

Example 27 with Slot

use of net.minecraft.server.v1_16_R3.Slot in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        ItemStack equipment = getEquipment(slot);
        ItemStack cache = equipmentCache.get(slot);
        if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
            itemChanged = true;
        }
        equipmentCache.put(slot, equipment);
    }
    if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
        return;
    updateCounter = 0;
    Location current = getBukkitEntity().getLocation(packetLocationCache);
    Packet<?>[] packets = new Packet[1];
    List<Pair<EnumItemSlot, ItemStack>> vals = Lists.newArrayList();
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        vals.add(new Pair<EnumItemSlot, ItemStack>(slot, getEquipment(slot)));
    }
    packets[0] = new PacketPlayOutEntityEquipment(getId(), vals);
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_16_R3.EnumItemSlot) Packet(net.minecraft.server.v1_16_R3.Packet) ItemStack(net.minecraft.server.v1_16_R3.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment) Location(org.bukkit.Location) Pair(com.mojang.datafixers.util.Pair)

Example 28 with Slot

use of net.minecraft.server.v1_16_R3.Slot in project X-Road by nordic-institute.

the class HardwareModuleWorker method listTokens.

@Override
protected List<TokenType> listTokens() throws Exception {
    log.trace("Listing tokens on module '{}'", module.getType());
    Slot[] slots = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
    if (slots.length == 0) {
        log.warn("Did not get any slots from module '{}'. Reinitializing module.", module.getType());
        // Error code doesn't really matter as long as it's PKCS11Exception
        throw new PKCS11Exception(PKCS11Constants.CKR_GENERAL_ERROR);
    }
    log.info("Module '{}' got {} slots", module.getType(), slots.length);
    for (int i = 0; i < slots.length; i++) {
        log.debug("Module '{}' Slot {} ID: {} (0x{})", module.getType(), i, slots[i].getSlotID(), Functions.toHexString(slots[i].getSlotID()));
    }
    // HSM slot ids defined in module data
    Set<Long> slotIds = module.getSlotIds();
    log.debug("Slot configuration for module '{}' defined as {}", module.getType(), slotIds.toString());
    Map<String, TokenType> tokens = new HashMap<>();
    for (int slotIndex = 0; slotIndex < slots.length; slotIndex++) {
        if (slotIds.isEmpty() || slotIds.contains(slots[slotIndex].getSlotID())) {
            TokenType token = createToken(slots, slotIndex);
            TokenType previous = tokens.putIfAbsent(token.getId(), token);
            if (previous == null) {
                log.info("Module '{}' slot #{} has token with ID '{}': {}", module.getType(), slotIndex, token.getId(), token);
            } else {
                log.info("Module '{}' slot #{} has token with ID '{}' but token with that ID is " + " already registered", module.getType(), slotIndex, token.getId());
            }
        }
    }
    return new ArrayList<>(tokens.values());
}
Also used : PKCS11Exception(iaik.pkcs.pkcs11.wrapper.PKCS11Exception) HardwareTokenType(ee.ria.xroad.signer.tokenmanager.token.HardwareTokenType) TokenType(ee.ria.xroad.signer.tokenmanager.token.TokenType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Slot(iaik.pkcs.pkcs11.Slot)

Example 29 with Slot

use of net.minecraft.server.v1_16_R3.Slot in project DragonsOnline by UniverseCraft.

the class PlayerNPC116R3 method setEquipment.

public void setEquipment(EquipmentSlot slot, org.bukkit.inventory.ItemStack item) {
    PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
    this.setField(packet, "a", handle.getId());
    this.setField(packet, "b", CraftEquipmentSlot.getNMS(slot));
    this.setField(packet, "c", CraftItemStack.asNMSCopy(item));
    this.sendPacket(packet);
}
Also used : PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment)

Example 30 with Slot

use of net.minecraft.server.v1_16_R3.Slot in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_16_R3 method serialize.

private static void serialize(Inventory inventory, NBTTagCompound tagCompound) {
    NBTTagList itemsList = new NBTTagList();
    org.bukkit.inventory.ItemStack[] items = inventory.getContents();
    for (int i = 0; i < items.length; ++i) {
        if (items[i] != null) {
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            nbtTagCompound.setByte("Slot", (byte) i);
            CraftItemStack.asNMSCopy(items[i]).save(nbtTagCompound);
            itemsList.add(nbtTagCompound);
        }
    }
    tagCompound.setInt("Size", inventory.getSize());
    tagCompound.set("Items", itemsList);
}
Also used : NBTTagList(net.minecraft.server.v1_16_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_16_R3.ItemStack)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)19 Pair (com.mojang.datafixers.util.Pair)18 MyPetApi (de.Keyle.MyPet.MyPetApi)17 Util (de.Keyle.MyPet.api.Util)17 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)17 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)17 MyPet (de.Keyle.MyPet.api.entity.MyPet)17 EntityMyPet (de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet)17 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 Arrays (java.util.Arrays)17 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)17 Bukkit (org.bukkit.Bukkit)17 ENTITY_LIVING_broadcastItemBreak (de.Keyle.MyPet.compat.v1_16_R3.CompatManager.ENTITY_LIVING_broadcastItemBreak)14 Configuration (de.Keyle.MyPet.api.Configuration)9 PetState (de.Keyle.MyPet.api.entity.MyPet.PetState)6 CompatManager (de.Keyle.MyPet.compat.v1_16_R3.CompatManager)3 ItemStack (net.minecraft.server.v1_16_R3.ItemStack)3 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)3 FailedNbt (com.ruinscraft.panilla.api.exception.FailedNbt)2 INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)2