public void setRotation(Rotation rotation) throws IllegalArgumentException { switch (rotation) { case CLOCKWISE: getHandle().setItemRotation(0); break; case COUNTER_CLOCKWISE: getHandle().setItemRotation(1); break; case FLIPPED: getHandle().setItemRotation(2); break; case NONE: getHandle().setItemRotation(3); break; } }
Rotation toBukkitRotation(int value) { // Translate NMS rotation integer to Bukkit API switch (value) { case 0: return Rotation.NONE; case 1: return Rotation.CLOCKWISE_45; case 2: return Rotation.CLOCKWISE; case 3: return Rotation.CLOCKWISE_135; case 4: return Rotation.FLIPPED; case 5: return Rotation.FLIPPED_45; case 6: return Rotation.COUNTER_CLOCKWISE; case 7: return Rotation.COUNTER_CLOCKWISE_45; default: throw new AssertionError("Unknown rotation " + value + " for " + getHandle()); } }
static int toInteger(Rotation rotation) { // Translate Bukkit API rotation to NMS integer switch (rotation) { case NONE: return 0; case CLOCKWISE_45: return 1; case CLOCKWISE: return 2; case CLOCKWISE_135: return 3; case FLIPPED: return 4; case FLIPPED_45: return 5; case COUNTER_CLOCKWISE: return 6; case COUNTER_CLOCKWISE_45: return 7; default: throw new IllegalArgumentException(rotation + " is not applicable to an ItemFrame"); } }
Rotation toBukkitRotation(int value) { // Translate NMS rotation integer to Bukkit API switch (value) { case 0: return Rotation.NONE; case 1: return Rotation.CLOCKWISE; case 2: return Rotation.FLIPPED; case 3: return Rotation.COUNTER_CLOCKWISE; default: throw new AssertionError("Unknown rotation " + value + " for " + getHandle()); } }
static int toInteger(Rotation rotation) { // Translate Bukkit API rotation to NMS integer switch (rotation) { case NONE: return 0; case CLOCKWISE: return 1; case FLIPPED: return 2; case COUNTER_CLOCKWISE: return 3; default: throw new IllegalArgumentException(rotation + " is not applicable to an ItemFrame"); } }
@EventHandler public void onEntityInteractEntity(PlayerInteractEntityEvent event) { if (event.getRightClicked().getType() == EntityType.ITEM_FRAME) { event.setCancelled(true); ItemFrame frame = (ItemFrame) event.getRightClicked(); frame.setRotation(Rotation.NONE); } }
@Override public void onLoad() { add(Rotation.NONE, "None", "0", "360", "North", "Up"); add(Rotation.CLOCKWISE_45, "Clockwise 45", "45", "-315", "North East", "Up Right"); add(Rotation.CLOCKWISE, "Clockwise", "90", "-270", "East", "Right"); add(Rotation.CLOCKWISE_135, "Clockwise 135", "135", "-225", "South East", "Down Right"); add(Rotation.FLIPPED, "Flipped", "180", "-180", "South", "Down"); add(Rotation.FLIPPED_45, "Flipped 45", "225", "-135", "South West", "Down Left"); add(Rotation.COUNTER_CLOCKWISE, "Counter Clockwise", "270", "-90", "West", "Left"); add(Rotation.COUNTER_CLOCKWISE_45, "Counter Clockwise 45", "315", "-45", "North West", "Up Left"); }
@Override @Nullable protected Rotation[] get(Event e) { if (entity != null) { if (entity.getSingle(e) instanceof ItemFrame) { return new Rotation[]{((ItemFrame)entity.getSingle(e)).getRotation()}; } } return null; }
@Override public void change(Event e, Object[] delta, Changer.ChangeMode mode){ if (mode == ChangeMode.SET) { if (entity != null) { if (entity.getSingle(e) instanceof ItemFrame) { ((ItemFrame)entity.getSingle(e)).setRotation((Rotation)delta[0]); } } } }
@Override public Class<?>[] acceptChange(final Changer.ChangeMode mode) { if (mode == ChangeMode.SET) { return CollectionUtils.array(Rotation.class); } return null; }
public static void attachItemFrame(Block block, ItemStack map, BlockFace face) { ItemFrame frame = block.getWorld().spawn(block.getRelative(face).getLocation(), ItemFrame.class); Block frameBlock = block.getRelative(face); frameBlock.setType(Material.AIR); frame.teleport(frameBlock.getLocation()); frame.setFacingDirection(face, true); frame.setItem(map); frame.setRotation(Rotation.NONE); }
public Rotation getRotation() { if (getHandle().getItemRotation() == 0) { return Rotation.NONE; } else if (getHandle().getItemRotation() == 1) { return Rotation.CLOCKWISE; } else if (getHandle().getItemRotation() == 2) { return Rotation.FLIPPED; } else { return Rotation.COUNTER_CLOCKWISE; } }
private ItemFrame[][] find(Location pos1, Location pos2, BlockFace facing) { try { Location distance = pos2.clone().subtract(pos1).add(1, 1, 1); int width = Math.max(distance.getBlockX(), distance.getBlockZ()); ItemFrame[][] frames = new ItemFrame[width][distance.getBlockY()]; World world = pos1.getWorld(); this.reverse = (facing == BlockFace.NORTH || facing == BlockFace.EAST); int v = 0; for (double y = pos1.getY(); y <= pos2.getY(); y++, v++) { int h = 0; for (double z = pos1.getZ(); z <= pos2.getZ(); z++) { for (double x = pos1.getX(); x <= pos2.getX(); x++, h++) { Location pos = new Location(world, x, y, z); Collection<Entity> entities = world.getNearbyEntities(pos, 0.1, 0.1, 0.1); boolean contains = false; for (Entity ent : entities) { if (ent instanceof ItemFrame && ((ItemFrame) ent).getFacing() == facing) { ItemFrame itemFrame = (ItemFrame) ent; itemFrame.setRotation(Rotation.NONE); contains = true; frames[reverse ? width - 1 - h : h][v] = (ItemFrame) ent; break; } } if (!contains) return null; } } } return frames; } catch (Throwable e) { e.printStackTrace(); } return null; }
public static EntityData loadItemFrame(Vector location, ItemStack item, BlockFace direction, Rotation rotation) { EntityData data = new EntityData(EntityType.ITEM_FRAME); data.facing = direction; data.relativeLocation = location.clone(); data.rotation = rotation; data.item = item; return data; }
@Override public void execute(BlockPlacer blockPlacer, BlockLoger loger) { Chunk chunk = m_location.getChunk(); if (!chunk.isLoaded()) { if (!chunk.load()) { return; } } World w = m_location.getWorld(); Block block = w.getBlockAt(m_location); Material material = block.getType(); if (!isSolid(material)) { m_oldMaterial = material; block.setType(Material.BARRIER); } else { m_oldMaterial = null; } m_frame = (ItemFrame) w.spawn(block.getRelative(m_rotation).getLocation(), ItemFrame.class); m_frame.setFacingDirection(m_rotation, true); m_frame.setRotation(Rotation.NONE); m_mapView = Bukkit.createMap(w); m_mapHelper.storeMap(m_mapView, m_img); m_mapHelper.drawImage(m_mapView, m_img); m_frame.setItem(new ItemStack(Material.MAP, 1, m_mapView.getId())); }