use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.
the class GlowItemFrame method setItemInFrame.
public void setItemInFrame(ItemStack is) {
if (is == null) {
is = new ItemStack(Material.AIR, 1);
}
is.setAmount(1);
itemInFrame = is.getType();
metadata.set(MetadataIndex.ITEM_FRAME_ITEM, is);
metadata.set(MetadataIndex.ITEM_FRAME_ROTATION, 0);
}
use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.
the class BasicCraftingTest method can_craft_wood_from_logs.
@Test
public void can_craft_wood_from_logs() {
/*
* Used to "prove" the CraftingManager's recipe system loads and properly finds a simple matching recipe for some inputs.
* Sometimes needed to rule out other issues.
*/
ItemStack[] items = new ItemStack[4];
items[0] = new ItemStack(Material.LOG, 1, (short) 0);
Recipe recipe = cm.getCraftingRecipe(items);
assertThat("Crafting manager did not get recipe", recipe, IsNull.notNullValue());
assertThat("Crafting manager got wrong material", Material.WOOD, is(recipe.getResult().getType()));
assertThat("Crafting manager got wrong amount", 4, is(recipe.getResult().getAmount()));
}
use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.
the class ItemItemFrame method rightClickBlock.
@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
GlowItemFrame entity = new GlowItemFrame(player, target.getLocation().getBlock().getRelative(face).getLocation(), face);
List<Message> spawnMessage = entity.createSpawnMessage();
entity.getWorld().getRawPlayers().stream().filter(p -> p.canSeeEntity(entity)).forEach(p -> p.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
}
use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.
the class BlockType method rightClickBlock.
@Override
public final void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
GlowBlock target = against.getRelative(face);
// prevent building above the height limit
if (target.getLocation().getY() >= target.getWorld().getMaxHeight()) {
player.sendMessage(ChatColor.RED + "The height limit for this world is " + target.getWorld().getMaxHeight() + " blocks");
return;
}
// check whether the block clicked against should absorb the placement
BlockType againstType = ItemTable.instance().getBlock(against.getTypeId());
if (againstType != null) {
if (againstType.canAbsorb(against, face, holding)) {
target = against;
} else if (!target.isEmpty()) {
// air can always be overridden
BlockType targetType = ItemTable.instance().getBlock(target.getTypeId());
if (targetType != null && !targetType.canOverride(target, face, holding)) {
return;
}
}
}
if (getMaterial().isSolid()) {
BlockBoundingBox box = new BlockBoundingBox(target);
List<Entity> entities = target.getWorld().getEntityManager().getEntitiesInside(box, null);
for (Entity e : entities) {
if (e instanceof LivingEntity) {
return;
}
}
}
// call canBuild event
boolean canBuild = canPlaceAt(target, face);
BlockCanBuildEvent canBuildEvent = new BlockCanBuildEvent(target, getId(), canBuild);
if (!EventFactory.callEvent(canBuildEvent).isBuildable()) {
//revert(player, target);
return;
}
// grab states and update block
GlowBlockState oldState = target.getState(), newState = target.getState();
ItemType itemType = ItemTable.instance().getItem(holding.getType());
if (itemType.getPlaceAs() == null) {
placeBlock(player, newState, face, holding, clickedLoc);
} else {
placeBlock(player, newState, face, new ItemStack(itemType.getPlaceAs().getMaterial(), holding.getAmount(), holding.getDurability()), clickedLoc);
}
newState.update(true);
// call blockPlace event
BlockPlaceEvent event = new BlockPlaceEvent(target, oldState, against, holding, player, canBuild);
EventFactory.callEvent(event);
if (event.isCancelled() || !event.canBuild()) {
oldState.update(true);
return;
}
// play the placement sound, except for the current player (handled by the client)
SoundUtil.playSoundAtLocationExcept(target.getLocation(), getPlaceSound().getSound(), (getPlaceSound().getVolume() + 1F) / 2F, getPlaceSound().getPitch() * 0.8F, player);
// do any after-place actions
afterPlace(player, target, holding, oldState);
// deduct from stack if not in creative mode
if (player.getGameMode() != GameMode.CREATIVE) {
holding.setAmount(holding.getAmount() - 1);
}
}
use of org.bukkit.inventory.ItemStack in project Prism-Bukkit by prism.
the class PrismPlayerEvents method onCraftItem.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCraftItem(final CraftItemEvent event) {
final Player player = (Player) event.getWhoClicked();
if (!Prism.getIgnore().event("craft-item", player))
return;
final ItemStack item = event.getRecipe().getResult();
RecordingQueue.addToQueue(ActionFactory.createItemStack("craft-item", item, 1, -1, null, player.getLocation(), player.getName()));
}
Aggregations