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);
}
}
}
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;
}
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;
}
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;
}
Aggregations