use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project WLib by WizardlyBump17.
the class PacketListener method entityEquipment.
@SuppressWarnings("unchecked")
@SneakyThrows
private void entityEquipment(PacketPlayOutEntityEquipment handle) {
final Field field = handle.getClass().getDeclaredField("c");
field.setAccessible(true);
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> items = (List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>>) field.get(handle);
for (Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> item : items) {
final CraftItemStack stack = CraftItemStack.asCraftMirror(item.getSecond()).clone();
if (!isValidItem(stack))
continue;
final Field second = item.getClass().getDeclaredField("second");
second.setAccessible(true);
second.set(item, CraftItemStack.asNMSCopy(fixItem(stack)));
}
}
use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.
the class CraftEventFactory method callPlayerInteractEvent.
public static PlayerInteractEvent callPlayerInteractEvent(PlayerEntity who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, Hand hand) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
CraftWorld craftWorld = (CraftWorld) player.getWorld();
CraftServer craftServer = (CraftServer) player.getServer();
Block blockClicked = null;
if (position != null) {
blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
} else {
switch(action) {
case LEFT_CLICK_BLOCK:
action = Action.LEFT_CLICK_AIR;
break;
case RIGHT_CLICK_BLOCK:
action = Action.RIGHT_CLICK_AIR;
break;
}
}
BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
itemInHand = null;
}
PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
if (cancelledBlock) {
event.setUseInteractedBlock(Event.Result.DENY);
}
craftServer.getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.
the class CraftEventFactory method callEntityBreedEvent.
public static EntityBreedEvent callEntityBreedEvent(net.minecraft.entity.LivingEntity child, net.minecraft.entity.LivingEntity mother, net.minecraft.entity.LivingEntity father, net.minecraft.entity.LivingEntity breeder, ItemStack bredWith, int experience) {
org.bukkit.entity.LivingEntity breederEntity = (LivingEntity) (breeder == null ? null : breeder.getBukkitEntity());
CraftItemStack bredWithStack = bredWith == null ? null : CraftItemStack.asCraftMirror(bredWith).clone();
EntityBreedEvent event = new EntityBreedEvent((LivingEntity) child.getBukkitEntity(), (LivingEntity) mother.getBukkitEntity(), (LivingEntity) father.getBukkitEntity(), breederEntity, bredWithStack, experience);
child.level.getServerCB().getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.
the class CraftEventFactory method getPlayerBucketEvent.
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, World world, PlayerEntity who, BlockPos changed, BlockPos clicked, Direction clickedFace, ItemStack itemstack, net.minecraft.item.Item item) {
Player player = (Player) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem());
CraftServer craftServer = (CraftServer) player.getServer();
Block block = CraftBlock.at(world, changed);
Block blockClicked = CraftBlock.at(world, clicked);
BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);
PlayerEvent event;
if (isFilling) {
event = new PlayerBucketFillEvent(player, block, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketFillEvent) event).setCancelled(!canBuild(world, player, changed.getX(), changed.getZ()));
} else {
event = new PlayerBucketEmptyEvent(player, block, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(world, player, changed.getX(), changed.getZ()));
}
craftServer.getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.
the class CraftEventFactory method callEntityShootBowEvent.
/**
* EntityShootBowEvent
*/
public static EntityShootBowEvent callEntityShootBowEvent(net.minecraft.entity.LivingEntity who, ItemStack bow, ItemStack consumableItem, Entity entityArrow, Hand hand, float force, boolean consumeItem) {
LivingEntity shooter = (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;
}
Aggregations