Search in sources :

Example 1 with LootGenerateEvent

use of org.bukkit.event.world.LootGenerateEvent in project Arclight by IzzelAliz.

the class LootTableMixin method fillInventory.

// @formatter:on
public void fillInventory(IInventory inv, LootContext context, boolean plugin) {
    List<ItemStack> list = this.generate(context);
    Random random = context.getRandom();
    LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, list, plugin);
    if (event.isCancelled()) {
        return;
    }
    list = event.getLoot().stream().map(CraftItemStack::asNMSCopy).collect(Collectors.toList());
    List<Integer> list1 = this.getEmptySlotsRandomized(inv, random);
    this.shuffleItems(list, list1.size(), random);
    for (ItemStack itemstack : list) {
        if (list1.isEmpty()) {
            LOGGER.warn("Tried to over-fill a container");
            return;
        }
        if (itemstack.isEmpty()) {
            inv.setInventorySlotContents(list1.remove(list1.size() - 1), ItemStack.EMPTY);
        } else {
            inv.setInventorySlotContents(list1.remove(list1.size() - 1), itemstack);
        }
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) Random(java.util.Random) LootGenerateEvent(org.bukkit.event.world.LootGenerateEvent) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 2 with LootGenerateEvent

use of org.bukkit.event.world.LootGenerateEvent in project Mohist by MohistMC.

the class CraftEventFactory method callLootGenerateEvent.

public static LootGenerateEvent callLootGenerateEvent(Container inventory, LootTable lootTable, LootContext lootInfo, List<ItemStack> loot, boolean plugin) {
    CraftWorld world = lootInfo.getLevel().getWorld();
    Entity entity = lootInfo.getParamOrNull(LootContextParams.THIS_ENTITY);
    NamespacedKey key = CraftNamespacedKey.fromMinecraft(world.getHandle().getServer().getLootTables().getKey(lootTable));
    CraftLootTable craftLootTable = new CraftLootTable(key, lootTable);
    List<org.bukkit.inventory.ItemStack> bukkitLoot = loot.stream().map(CraftItemStack::asCraftMirror).collect(Collectors.toCollection(ArrayList::new));
    InventoryHolder owner;
    try {
        owner = inventory.getOwner();
    } catch (AbstractMethodError error) {
        MohistMC.LOGGER.error("An error occurred while handling Mod inventory: " + error.getMessage());
        owner = null;
    }
    LootGenerateEvent event = new LootGenerateEvent(world, (entity != null ? entity.getBukkitEntity() : null), owner, craftLootTable, CraftLootTable.convertContext(lootInfo), bukkitLoot, plugin);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) CraftNamespacedKey(org.bukkit.craftbukkit.v1_18_R2.util.CraftNamespacedKey) NamespacedKey(org.bukkit.NamespacedKey) LootGenerateEvent(org.bukkit.event.world.LootGenerateEvent) ItemStack(net.minecraft.world.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 3 with LootGenerateEvent

use of org.bukkit.event.world.LootGenerateEvent in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callLootGenerateEvent.

public static LootGenerateEvent callLootGenerateEvent(IInventory inventory, LootTable lootTable, LootContext lootInfo, List<ItemStack> loot, boolean plugin) {
    CraftWorld world = lootInfo.getLevel().getWorldCB();
    Entity entity = lootInfo.getParamOrNull(LootParameters.THIS_ENTITY);
    NamespacedKey key = CraftNamespacedKey.fromMinecraft(world.getHandle().getServer().getLootTables().lootTableToKey.get(lootTable));
    CraftLootTable craftLootTable = new CraftLootTable(key, lootTable);
    List<org.bukkit.inventory.ItemStack> bukkitLoot = loot.stream().map(CraftItemStack::asCraftMirror).collect(Collectors.toCollection(ArrayList::new));
    LootGenerateEvent event = new LootGenerateEvent(world, (entity != null ? entity.getBukkitEntity() : null), InventoryHelper.getHolderOwner(inventory), craftLootTable, CraftLootTable.convertContext(lootInfo), bukkitLoot, plugin);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) AbstractRaiderEntity(net.minecraft.entity.monster.AbstractRaiderEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) LivingEntity(org.bukkit.entity.LivingEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) StriderEntity(net.minecraft.entity.passive.StriderEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SpellcastingIllagerEntity(net.minecraft.entity.monster.SpellcastingIllagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) MobEntity(net.minecraft.entity.MobEntity) HumanEntity(org.bukkit.entity.HumanEntity) Entity(net.minecraft.entity.Entity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftNamespacedKey(org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey) NamespacedKey(org.bukkit.NamespacedKey) CraftLootTable(org.bukkit.craftbukkit.v1_16_R3.CraftLootTable) LootGenerateEvent(org.bukkit.event.world.LootGenerateEvent) ItemStack(net.minecraft.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 4 with LootGenerateEvent

use of org.bukkit.event.world.LootGenerateEvent in project LoliServer by Loli-Server.

the class CraftEventFactory method callLootGenerateEvent.

public static LootGenerateEvent callLootGenerateEvent(IInventory inventory, LootTable lootTable, LootContext lootInfo, List<ItemStack> loot, boolean plugin) {
    CraftWorld world = lootInfo.getLevel().getWorld();
    Entity entity = lootInfo.getParamOrNull(LootParameters.THIS_ENTITY);
    // LoliServer
    NamespacedKey key = CraftNamespacedKey.fromMinecraft(world.getHandle().getServer().getLootTables().getKey(lootTable));
    CraftLootTable craftLootTable = new CraftLootTable(key, lootTable);
    List<org.bukkit.inventory.ItemStack> bukkitLoot = loot.stream().map(CraftItemStack::asCraftMirror).collect(Collectors.toCollection(ArrayList::new));
    LootGenerateEvent event = new LootGenerateEvent(world, (entity != null ? entity.getBukkitEntity() : null), InventoryOwner.get(inventory), craftLootTable, CraftLootTable.convertContext(lootInfo), bukkitLoot, plugin);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : StriderEntity(net.minecraft.entity.passive.StriderEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) LivingEntity(net.minecraft.entity.LivingEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) AbstractRaiderEntity(net.minecraft.entity.monster.AbstractRaiderEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) SpellcastingIllagerEntity(net.minecraft.entity.monster.SpellcastingIllagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) PiglinEntity(net.minecraft.entity.monster.piglin.PiglinEntity) MobEntity(net.minecraft.entity.MobEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) Entity(net.minecraft.entity.Entity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftNamespacedKey(org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey) NamespacedKey(org.bukkit.NamespacedKey) CraftLootTable(org.bukkit.craftbukkit.v1_16_R3.CraftLootTable) LootGenerateEvent(org.bukkit.event.world.LootGenerateEvent) ItemStack(net.minecraft.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Aggregations

LootGenerateEvent (org.bukkit.event.world.LootGenerateEvent)4 ItemStack (net.minecraft.item.ItemStack)3 NamespacedKey (org.bukkit.NamespacedKey)3 AreaEffectCloudEntity (net.minecraft.entity.AreaEffectCloudEntity)2 Entity (net.minecraft.entity.Entity)2 MobEntity (net.minecraft.entity.MobEntity)2 EnderDragonEntity (net.minecraft.entity.boss.dragon.EnderDragonEntity)2 ExperienceOrbEntity (net.minecraft.entity.item.ExperienceOrbEntity)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 VillagerEntity (net.minecraft.entity.merchant.villager.VillagerEntity)2 AbstractRaiderEntity (net.minecraft.entity.monster.AbstractRaiderEntity)2 GhastEntity (net.minecraft.entity.monster.GhastEntity)2 MonsterEntity (net.minecraft.entity.monster.MonsterEntity)2 SlimeEntity (net.minecraft.entity.monster.SlimeEntity)2 SpellcastingIllagerEntity (net.minecraft.entity.monster.SpellcastingIllagerEntity)2 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)2 GolemEntity (net.minecraft.entity.passive.GolemEntity)2 StriderEntity (net.minecraft.entity.passive.StriderEntity)2 WaterMobEntity (net.minecraft.entity.passive.WaterMobEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2