use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack 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;
}
use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project LoliServer by Loli-Server.
the class CraftEventFactory method callEntityShootBowEvent.
/**
* EntityShootBowEvent
*/
public static EntityShootBowEvent callEntityShootBowEvent(LivingEntity who, ItemStack bow, ItemStack consumableItem, Entity entityArrow, Hand hand, float force, boolean consumeItem) {
org.bukkit.entity.LivingEntity shooter = (org.bukkit.entity.LivingEntity) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(bow);
CraftItemStack itemConsumable = CraftItemStack.asCraftMirror(consumableItem);
org.bukkit.entity.Entity arrow = entityArrow.getBukkitEntity();
EquipmentSlot handSlot = (hand == Hand.MAIN_HAND) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
itemInHand = null;
}
EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, itemConsumable, arrow, handSlot, force, consumeItem);
Bukkit.getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project MyPet by MyPetORG.
the class CustomInventory method addItem.
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
if (itemAdd == null) {
return 0;
}
itemAdd = itemAdd.clone();
for (int i = 0; i < this.getSize(); i++) {
CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
continue;
}
while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
craftItem.setAmount(craftItem.getAmount() + 1);
itemAdd.setAmount(itemAdd.getAmount() - 1);
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
if (itemAdd.getAmount() > 0) {
for (int i = 0; i < this.getSize(); i++) {
if (getItem(i) == null) {
if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
itemAdd.setAmount(0);
break;
} else {
CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
itemStack.setAmount(itemStack.getMaxStackSize());
setItem(i, CraftItemStack.asNMSCopy(itemStack));
itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
}
return itemAdd.getAmount();
}
use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project MyPet by MyPetORG.
the class CustomInventory method addItem.
@Override
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
if (itemAdd == null) {
return 0;
}
itemAdd = itemAdd.clone();
for (int i = 0; i < this.getSize(); i++) {
CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
continue;
}
while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
craftItem.setAmount(craftItem.getAmount() + 1);
itemAdd.setAmount(itemAdd.getAmount() - 1);
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
if (itemAdd.getAmount() > 0) {
for (int i = 0; i < this.getSize(); i++) {
if (getItem(i) == ItemStack.b) {
if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
itemAdd.setAmount(0);
break;
} else {
CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
itemStack.setAmount(itemStack.getMaxStackSize());
setItem(i, CraftItemStack.asNMSCopy(itemStack));
itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
}
return itemAdd.getAmount();
}
use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Essentials by drtshock.
the class v1_8_R2SpawnerProvider method getEntityType.
@Override
public EntityType getEntityType(ItemStack is) {
net.minecraft.server.v1_8_R2.ItemStack itemStack;
CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("BlockEntityTag")) {
throw new IllegalArgumentException();
}
String name = tag.getCompound("BlockEntityTag").getString("EntityId");
return EntityType.fromName(name);
}
Aggregations