Search in sources :

Example 11 with net.minecraft.server.v1_15_R1

use of net.minecraft.server.v1_15_R1 in project SilkSpawners by timbru31.

the class NMSHandler method getVanillaEggNBTEntityID.

@Override
public String getVanillaEggNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_15_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("EntityTag")) {
        final MinecraftKey vanillaKey = IRegistry.ITEM.getKey(itemStack.getItem());
        if (vanillaKey != null) {
            return vanillaKey.getKey().replace("minecraft:", "").replace("_spawn_egg", "");
        }
    } else {
        tag = tag.getCompound("EntityTag");
        if (tag.hasKey("id")) {
            return tag.getString("id").replace("minecraft:", "");
        }
    }
    return null;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound) MinecraftKey(net.minecraft.server.v1_15_R1.MinecraftKey)

Example 12 with net.minecraft.server.v1_15_R1

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

the class v1_15_R1 method openAnvilGUI.

@Override
public void openAnvilGUI(Player player, Object con, String title, ItemStack[] items) {
    ContainerAnvil container = (ContainerAnvil) con;
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = 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.setItem(i, item = (net.minecraft.server.v1_15_R1.ItemStack) asNMSItem(is));
        nmsItems[i] = item;
    }
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, "minecraft:anvil", 0, 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.checkReachable = false;
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftContainer) Container(net.minecraft.server.v1_15_R1.Container) ContainerAnvil(net.minecraft.server.v1_15_R1.ContainerAnvil) 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 13 with net.minecraft.server.v1_15_R1

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

the class v1_15_R1 method setBlock.

@Override
public void setBlock(Object chunk, int x, int y, int z, Object IblockData, int data) {
    net.minecraft.server.v1_15_R1.Chunk c = (net.minecraft.server.v1_15_R1.Chunk) chunk;
    ChunkSection sc = c.getSections()[y >> 4];
    if (sc == null) {
        c.getSections()[y >> 4] = sc = new ChunkSection(y >> 4 << 4);
    }
    BlockPosition pos = new BlockPosition(x, y, z);
    // REMOVE TILE ENTITY
    c.tileEntities.remove(pos);
    sc.getBlocks().b(x & 15, y & 15, z & 15, (IBlockData) IblockData);
    // ADD TILE ENTITY
    if (IblockData instanceof ITileEntity) {
        TileEntity ent = ((ITileEntity) IblockData).createTile(c);
        c.tileEntities.put(pos, ent);
        Object packet = ent.getUpdatePacket();
        Bukkit.getOnlinePlayers().forEach(player -> BukkitLoader.getPacketHandler().send(player, packet));
    }
}
Also used : ITileEntity(net.minecraft.server.v1_15_R1.ITileEntity) TileEntity(net.minecraft.server.v1_15_R1.TileEntity) ITileEntity(net.minecraft.server.v1_15_R1.ITileEntity) BlockPosition(net.minecraft.server.v1_15_R1.BlockPosition) Chunk(org.bukkit.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) ChunkSection(net.minecraft.server.v1_15_R1.ChunkSection)

Example 14 with net.minecraft.server.v1_15_R1

use of net.minecraft.server.v1_15_R1 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 15 with net.minecraft.server.v1_15_R1

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

the class EntityUtils method PSetHPChange.

public static void PSetHPChange(LivingEntity targetToDamage, Double hpchange, LivingEntity sourceEntityOfChange, boolean playHurtSound) {
    if (targetToDamage instanceof ArmorStand || sourceEntityOfChange instanceof ArmorStand)
        return;
    if (hpchange == 0)
        return;
    // This will check both their invulnerability from minecraft and godmode from essentials
    if (hpchange < 0 && EntityUtils.IsInvulnerable(targetToDamage))
        return;
    float cur_hp = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getHealth();
    float max_hp = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getMaxHealth();
    float hp = cur_hp + hpchange.floatValue();
    if (hp >= max_hp)
        cur_hp = max_hp;
    else
        cur_hp = hp;
    ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).setHealth(cur_hp);
    float soundVolume = 1.0F;
    if (hpchange < 0) {
        DamageSource damagesource = net.minecraft.server.v1_15_R1.DamageSource.mobAttack(((EntityLiving) ((CraftLivingEntity) sourceEntityOfChange).getHandle()));
        DamageCause damagecause = DamageCause.ENTITY_ATTACK;
        EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(sourceEntityOfChange, targetToDamage, damagecause, hpchange);
        ((CraftLivingEntity) targetToDamage).setLastDamage(hpchange.doubleValue());
        ((CraftLivingEntity) targetToDamage).setLastDamageCause(event);
        ((CraftLivingEntity) targetToDamage).setNoDamageTicks(20);
        ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtDuration = 10;
        ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtTicks = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtDuration;
        ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getCombatTracker().trackDamage(damagesource, cur_hp, hpchange.floatValue());
        if (((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getHealth() <= 0.0F) {
            targetToDamage.getWorld().playSound(targetToDamage.getLocation(), Sound.ENTITY_GENERIC_DEATH, soundVolume, GetSoundPitch(((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle())));
            ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).die(damagesource);
        } else {
            if (targetToDamage instanceof Player) {
                PacketPlayOutAnimation packet = new PacketPlayOutAnimation(((CraftPlayer) targetToDamage).getHandle(), 1);
                ((CraftPlayer) targetToDamage).getHandle().playerConnection.sendPacket(packet);
            }
            if (playHurtSound)
                targetToDamage.getWorld().playSound(targetToDamage.getLocation(), Sound.ENTITY_GENERIC_HURT, soundVolume, GetSoundPitch(((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle())));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) ArmorStand(org.bukkit.entity.ArmorStand) EntityLiving(net.minecraft.server.v1_15_R1.EntityLiving) DamageSource(net.minecraft.server.v1_15_R1.DamageSource) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CraftLivingEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PacketPlayOutAnimation(net.minecraft.server.v1_15_R1.PacketPlayOutAnimation)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)10 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)9 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)7 ItemStack (org.bukkit.inventory.ItemStack)7 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)5 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)5 CraftChunk (org.bukkit.craftbukkit.v1_15_R1.CraftChunk)5 Container (net.minecraft.server.v1_15_R1.Container)3 CraftWorld (org.bukkit.craftbukkit.v1_15_R1.CraftWorld)3 Player (org.bukkit.entity.Player)3 UUID (java.util.UUID)2 Nullable (javax.annotation.Nullable)2 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)2 ChunkSection (net.minecraft.server.v1_15_R1.ChunkSection)2 ContainerAnvil (net.minecraft.server.v1_15_R1.ContainerAnvil)2 EntityLiving (net.minecraft.server.v1_15_R1.EntityLiving)2 Chunk (org.bukkit.Chunk)2 Location (org.bukkit.Location)2 CraftEntity (org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity)2 CraftContainer (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftContainer)2