use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.
the class NMSHandler method getVanillaNBTEntityID.
@Override
@Nullable
public String getVanillaNBTEntityID(final ItemStack item) {
net.minecraft.server.v1_11_R1.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("BlockEntityTag")) {
return null;
}
tag = tag.getCompound("BlockEntityTag");
if (tag.hasKey("EntityId")) {
return tag.getString("EntityId");
} else if (tag.hasKey("SpawnData") && tag.getCompound("SpawnData").hasKey("id")) {
return tag.getCompound("SpawnData").getString("id");
} else if (tag.hasKey("SpawnPotentials") && !tag.getList("SpawnPotentials", 8).isEmpty()) {
return tag.getList("SpawnPotentials", 8).get(0).getCompound("Entity").getString("id");
} else {
return null;
}
}
use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Mohist by MohistMC.
the class CraftItemStack method asNMSCopy.
public static net.minecraft.world.item.ItemStack asNMSCopy(ItemStack original) {
if (original instanceof CraftItemStack) {
CraftItemStack stack = (CraftItemStack) original;
return stack.handle == null ? net.minecraft.world.item.ItemStack.EMPTY : stack.handle.copy();
}
if (original == null || original.getType() == Material.AIR) {
return net.minecraft.world.item.ItemStack.EMPTY;
}
Item item = CraftMagicNumbers.getItem(original.getType(), original.getDurability());
if (item == null) {
return net.minecraft.world.item.ItemStack.EMPTY;
}
net.minecraft.world.item.ItemStack stack = new net.minecraft.world.item.ItemStack(item, original.getAmount());
if (original.hasItemMeta()) {
setItemMeta(stack, original.getItemMeta());
}
return stack;
}
use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Mohist by MohistMC.
the class CraftEventFactory method callPlayerInteractEvent.
public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, InteractionHand 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 == InteractionHand.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_18_R2.inventory.CraftItemStack in project Mohist by MohistMC.
the class CraftEventFactory method callBlockDamageAbortEvent.
public static BlockDamageAbortEvent callBlockDamageAbortEvent(ServerPlayer who, BlockPos pos, ItemStack itemstack) {
Player player = who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
Block blockClicked = CraftBlock.at(who.getLevel(), pos);
BlockDamageAbortEvent event = new BlockDamageAbortEvent(player, blockClicked, itemInHand);
player.getServer().getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Mohist by MohistMC.
the class CraftEventFactory method callPlayerHarvestBlockEvent.
/**
* Player Harvest Block Event
*/
public static PlayerHarvestBlockEvent callPlayerHarvestBlockEvent(Level world, BlockPos blockposition, net.minecraft.world.entity.player.Player who, List<ItemStack> itemsToHarvest) {
List<org.bukkit.inventory.ItemStack> bukkitItemsToHarvest = new ArrayList<>(itemsToHarvest.stream().map(CraftItemStack::asBukkitCopy).collect(Collectors.toList()));
Player player = (Player) who.getBukkitEntity();
PlayerHarvestBlockEvent playerHarvestBlockEvent = new PlayerHarvestBlockEvent(player, CraftBlock.at(world, blockposition), bukkitItemsToHarvest);
Bukkit.getPluginManager().callEvent(playerHarvestBlockEvent);
return playerHarvestBlockEvent;
}
Aggregations