当前位置: 首页>>代码示例>>Java>>正文


Java NoteBlock类代码示例

本文整理汇总了Java中org.bukkit.block.NoteBlock的典型用法代码示例。如果您正苦于以下问题:Java NoteBlock类的具体用法?Java NoteBlock怎么用?Java NoteBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NoteBlock类属于org.bukkit.block包,在下文中一共展示了NoteBlock类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isInteractiveBlock

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
/**
 * checks if this block would give a reaction if you click on it without
 * shifting, e.g. opening a chest or switching a lever
 */
public static boolean isInteractiveBlock(Block b) {
	if (b == null || b.getState() == null) {
		return false;
	}
	if (b.getType() == Material.WORKBENCH || b.getType() == Material.ENCHANTMENT_TABLE || b.getType() == Material.ANVIL || b.getType() == Material.BREWING_STAND || b.getState() instanceof InventoryHolder || b.getState() instanceof NoteBlock) {
		return true;
	}
	if (b.getState().getData() instanceof Button || b.getState().getData() instanceof Lever || b.getState().getData() instanceof Door || b.getState().getData() instanceof TrapDoor || b.getState().getData() instanceof Gate || b.getState().getData() instanceof Comparator) {
		if (b.getType() != Material.IRON_DOOR && b.getType() != Material.IRON_DOOR_BLOCK && b.getType() != Material.IRON_TRAPDOOR) {
			return true;
		}
	}
	return false;
}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:19,代码来源:HitboxUtils.java

示例2: setInputs

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
@Override
public void setInputs(CommandSender initiator, String[] args) {
	//
	final Player player = (Player) initiator;
	final int ticksMax = (args.length > 1) ? Integer.parseInt(args[1]) : 20;

	final Location base = player.getLocation().clone();

	final int channels = this.trainingValues.length;

	for (int i = 0; i < channels; i++) {
		base.clone().add(i, 0, 0).getBlock().setType(Material.NOTE_BLOCK);
	}
	new BukkitRunnable() {
		int tick = 0;

		@SuppressWarnings("deprecation")
		@Override
		public void run() {
			tick++;
			int row = 0;
			for (Neuron n : ai.getOutputNeurons()) {
				if (n.isTriggered()) {
					((NoteBlock) base.clone().add(row, 0, 0).getBlock()
							.getState()).setRawNote((byte) n.getID());
					((NoteBlock) base.clone().add(row, 0, 0).getBlock()
							.getState()).play();
					row++;

				}
			}

			if (tick > ticksMax)
				cancel();
		}
	}.runTaskTimer(Main.getMainClass(), 30, 9);

}
 
开发者ID:ZombieStriker,项目名称:NeuralNetworkAPI,代码行数:39,代码来源:MusicBot.java

示例3: execute

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
@Override
protected void execute(Event event) {
    Block block = blockExpression.getSingle(event);
    NoteBlock noteBlock = (NoteBlock) block.getState();
    if (instrumentExpression == null) {
        noteBlock.play();
    } else {
        Logging.debug(this, "Instrument: " + instrumentExpression.getSingle(event));
        Logging.debug(this, "Note: " + (noteExpression == null ? noteBlock.getNote() : noteExpression.getSingle(event)));
        noteBlock.play(instrumentExpression.getSingle(event), (noteExpression == null ? noteBlock.getNote() : noteExpression.getSingle(event)));
    }
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:13,代码来源:EffPlayNoteBlock.java

示例4: serializeState

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static Optional<String> serializeState(BlockState state) {
    YamlConfiguration yaml = new YamlConfiguration();

    // http://minecraft.gamepedia.com/Block_entity was used as a reference for this method

    if (state instanceof InventoryHolder) {
        yaml.set(INVENTORY_KEY, InventoryHelper.serializeInventory(((InventoryHolder) state).getInventory()));
    }

    if (state instanceof Sign) {
        yaml.set(SIGN_LINES_KEY, Arrays.asList(((Sign) state).getLines()));
    } else if (Support.BANNER && state instanceof Banner) {
        yaml.set(BANNER_BASE_COLOR_KEY, ((Banner) state).getBaseColor().name());
        ConfigurationSection patternSection = yaml.createSection(BANNER_PATTERNS_KEY);
        List<Pattern> patterns = ((Banner) state).getPatterns();
        for (int i = 0; i < patterns.size(); i++) {
            ConfigurationSection subSection = patternSection.createSection("" + i);
            subSection.set(BANNER_PATTERN_COLOR_KEY, patterns.get(i).getColor().name());
            subSection.set(BANNER_PATTERN_TYPE_KEY, patterns.get(i).getPattern().name());
        }
    } else if (state instanceof CreatureSpawner) {
        yaml.set(SPAWNER_TYPE_KEY, ((CreatureSpawner) state).getSpawnedType().name());
        yaml.set(SPAWNER_DELAY_KEY, ((CreatureSpawner) state).getDelay());
    } else if (state instanceof NoteBlock) {
        yaml.set(NOTE_OCTAVE_KEY, ((NoteBlock) state).getNote().getOctave());
        yaml.set(NOTE_TONE_KEY, ((NoteBlock) state).getNote().getTone().name());
    } else if (state instanceof Jukebox) {
        if (((Jukebox) state).isPlaying()) {
            yaml.set(JUKEBOX_DISC_KEY, ((Jukebox) state).getPlaying());
        }
    } else if (state instanceof Skull) {
        yaml.set(SKULL_OWNER_KEY, ((Skull) state).getOwner());
        yaml.set(SKULL_ROTATION_KEY, ((Skull) state).getRotation().name());
    } else if (state instanceof CommandBlock) {
        yaml.set(COMMAND_NAME_KEY, ((CommandBlock) state).getName());
        yaml.set(COMMAND_CMD_KEY, ((CommandBlock) state).getCommand());
    } else if (state instanceof FlowerPot) {
        yaml.set(FLOWER_TYPE_KEY, ((FlowerPot) state).getContents().getItemType().name());
        yaml.set(FLOWER_DATA_KEY, ((FlowerPot) state).getContents().getData());
    }

    if (yaml.getKeys(false).size() > 0) {
        return Optional.of(yaml.saveToString());
    }
    return Optional.absent();
}
 
开发者ID:caseif,项目名称:Steel,代码行数:48,代码来源:BlockStateSerializer.java

示例5: setOldBlock

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public void setOldBlock(BlockState state)
{
    super.setOldBlock(state);
    this.note = ((NoteBlock)state).getNote().getId();
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:8,代码来源:UseNoteblock.java

示例6: change

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
@Override
public void change(Block block, Note note, Changer.ChangeMode changeMode) {
    MundoUtil.cast(block.getState(), NoteBlock.class).ifPresent(noteBlock -> noteBlock.setNote(note));
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:5,代码来源:ExprNoteOfBlock.java

示例7: convert

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
@Override
public Note convert(Block block) {
    return MundoUtil.cast(block.getState(), NoteBlock.class).map(NoteBlock::getNote).orElse(null);
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:5,代码来源:ExprNoteOfBlock.java

示例8: onBlockBreak

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event)
{
    if (event.getBlock().getType() == AIR)
    {
        return; // breaking air !? -> no logging
    }
    if (!this.isActive(PlayerBlockBreak.class, event.getBlock().getWorld()))
    {
        return;
    }
    BlockState blockState = event.getBlock().getState();
    PlayerBlockBreak action;
    if (blockState instanceof NoteBlock)
    {
        action = this.newAction(PlayerNoteBlockBreak.class);
        ((PlayerNoteBlockBreak)action).setNote(((NoteBlock)blockState).getNote());
    }
    else if (blockState instanceof Sign)
    {
        action = this.newAction(PlayerSignBreak.class);
        ((PlayerSignBreak)action).setLines(((Sign)blockState).getLines());
    }
    else if (blockState instanceof Jukebox && ((Jukebox)blockState).getPlaying() != null)
    {
        action = this.newAction(PlayerJukeboxBreak.class);
        ((PlayerJukeboxBreak)action).setDisc(((Jukebox)blockState).getPlaying());
    }
    else if (blockState instanceof InventoryHolder)
    {
        action = this.newAction(PlayerContainerBreak.class, event.getBlock().getWorld());
        if (action == null)
        {
            action = this.newAction(PlayerBlockBreak.class);
        }
        else
        {
            ((PlayerContainerBreak)action).setContents(((InventoryHolder)blockState).getInventory().getContents());
        }
        // TODO item drops
        // itemDrop.logDropsFromChest((InventoryHolder)blockState,location,event.getPlayer());
    }
    else
    {
        action = this.newAction(PlayerBlockBreak.class);
        blockState = adjustBlockForDoubleBlocks(blockState); // WOOD_DOOR IRON_DOOR OR BED_BLOCK
    }
    action.setPlayer(event.getPlayer());
    action.setLocation(event.getBlock().getLocation());
    action.setOldBlock(blockState);
    action.setNewBlock(AIR);
    this.logAction(action);

    if (blockState.getType() == OBSIDIAN) // portal?
    {
        // TODO better & complete
        Block block = blockState.getBlock();
        for (BlockFace face : BLOCK_FACES)
        {
            if (block.getRelative(face).getType() == PORTAL)
            {
                Block portal = block.getRelative(face);
                PlayerBlockBreak pAction = this.newAction(PlayerBlockBreak.class);
                pAction.setPlayer(event.getPlayer());
                pAction.setLocation(portal.getLocation());
                pAction.setOldBlock(portal.getState());
                pAction.setNewBlock(AIR);
                pAction.reference = this.reference(action);
                this.logAction(pAction);
                break;
            }
        }
    }
    // TODO attached & falling
    ListenerBlock.logAttachedBlocks(this, module.getCore().getEventManager(), event.getBlock(), action);
    ListenerBlock.logFallingBlocks(this, module.getCore().getEventManager(), event.getBlock(), action);
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:78,代码来源:ListenerPlayerBlock.java

示例9: SerializableBlockEntity

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param blockState  The {@link org.bukkit.block.BlockState} that needs to be serialized.
 */
public SerializableBlockEntity(BlockState blockState) {
    PreCon.notNull(blockState);

    _location = blockState.getLocation();
    _material = blockState.getType();
    _data = blockState.getRawData();

    if (blockState instanceof InventoryHolder) {
        _contents = ((InventoryHolder) blockState).getInventory().getContents();
    }

    if (blockState instanceof CommandBlock) {
        CommandBlock commandBlock = (CommandBlock)blockState;
        _commandName = commandBlock.getName();
        _command = commandBlock.getCommand();
    }

    if (blockState instanceof CreatureSpawner) {
        CreatureSpawner spawner = (CreatureSpawner)blockState;
        _creatureTypeName = spawner.getCreatureTypeName();
        _creatureDelay = spawner.getDelay();
    }

    if (blockState instanceof NoteBlock) {
        NoteBlock noteBlock = (NoteBlock)blockState;

        _noteTone = noteBlock.getNote().getTone();
        _noteOctave = noteBlock.getNote().getOctave();
        _noteSharped = noteBlock.getNote().isSharped();
    }

    if (blockState instanceof Sign) {
        Sign sign = (Sign)blockState;

        _signLines = sign.getLines().clone();
    }

    if (blockState instanceof Skull) {
        Skull skull =  (Skull)blockState;

        _skullType = skull.getSkullType();
        _skullRotation = skull.getRotation();
        _skullOwner = skull.getOwner();
    }
}
 
开发者ID:JCThePants,项目名称:NucleusFramework,代码行数:51,代码来源:SerializableBlockEntity.java

示例10: applyTile

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
private void applyTile(BlockState blockState) {

        boolean requiresUpdate = false;

        // InventoryHolder
        if (blockState instanceof InventoryHolder && _contents != null) {
            InventoryHolder holder = (InventoryHolder)blockState;

            Inventory inventory = holder.getInventory();

            inventory.setContents(_contents);

            requiresUpdate = true;
        }

        // CommandBlock
        if (blockState instanceof CommandBlock) {
            CommandBlock commandBlock = (CommandBlock)blockState;

            if (_commandName != null)
                commandBlock.setName(_commandName);

            if (_command != null)
                commandBlock.setCommand(_command);

            requiresUpdate = true;
        }

        // CreatureSpawner
        if (blockState instanceof CreatureSpawner) {
            CreatureSpawner spawner = (CreatureSpawner)blockState;

            if (_creatureTypeName != null) {
                spawner.setCreatureTypeByName(_creatureTypeName);
                spawner.setDelay(_creatureDelay);
            }

            requiresUpdate = true;
        }

        if (blockState instanceof NoteBlock && _noteTone != null) {
            NoteBlock noteBlock = (NoteBlock)blockState;

            Note note = new Note(_noteOctave, _noteTone, _noteSharped);
            noteBlock.setNote(note);

            requiresUpdate = true;
        }

        if (blockState instanceof Sign && _signLines != null) {
            Sign sign = (Sign)blockState;

            for (int i=0; i < 4; i++)
                sign.setLine(i, _signLines[i]);

            requiresUpdate = true;
        }

        if (blockState instanceof Skull && _skullType != null) {
            Skull skull =  (Skull)blockState;

            skull.setSkullType(_skullType);
            skull.setRotation(_skullRotation);
            skull.setOwner(_skullOwner);

            requiresUpdate = true;
        }

        if (requiresUpdate) {
            blockState.update(true);
        }
    }
 
开发者ID:JCThePants,项目名称:NucleusFramework,代码行数:73,代码来源:SerializableBlockEntity.java

示例11: CHMIDINotePlayer

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
public CHMIDINotePlayer(NoteBlock noteBlock) {
	this.noteBlock = noteBlock;
}
 
开发者ID:Hekta,项目名称:CHMIDI,代码行数:4,代码来源:CHMIDINotePlayer.java

示例12: exec

import org.bukkit.block.NoteBlock; //导入依赖的package包/类
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
	MCLocation location = ObjectGenerator.GetGenerator().location(args[1], null, t);
	BlockState blockState = ((Location) location.getHandle()).getBlock().getState();
	if (!(blockState instanceof NoteBlock)) {
		throw new ConfigRuntimeException("The block at the specified location is not a note block", ExceptionType.RangeException, t);
	}
	NoteBlock noteBlock = (NoteBlock) blockState;
	File midiFile = new File(t.file().getParentFile(), args[0].val());
	if (!Security.CheckSecurity(midiFile.getAbsolutePath())) {
		throw new ConfigRuntimeException("You do not have permission to access the file '" + midiFile.getAbsolutePath() + "'", ExceptionType.SecurityException, t);
	}

	//id
	String id;
	if ((args.length == 2) || (args[2] instanceof CNull)) {
		id = String.valueOf(System.nanoTime());
		while (CHMIDISequencerManager.sequencerExists(id)) {
			id = String.valueOf(System.nanoTime());
		}
	} else {
		if (CHMIDISequencerManager.sequencerExists(args[2].val())) {
			throw new ConfigRuntimeException("A sequence with the given id ('" + args[2].val() + "') already exists.", ExceptionType.PluginInternalException, t);
		} else {
			id = args[2].val();
		}
	}
	//create
	final CHMIDISequencer sequencer = new CHMIDISequencer(id, midiFile, new CHMIDINotePlayer(noteBlock), t);
	//playNow
	final boolean startNow;
	if (args.length == 4) {
		startNow = Static.getBoolean(args[3]);
	} else {
		startNow = true;
	}

	CHMIDISequencerManager.addSequencer(sequencer, t);
	queue = new RunnableQueue("MethodScript-CHMIDI-" + id);
	queue.invokeLater(environment.getEnv(GlobalEnv.class).GetDaemonManager(), new Runnable() {
		public void run() {
			try {
				sequencer.open();
				if (startNow) {
					sequencer.start();
				}
				while (sequencer.getMIDISequencer().isRunning() || sequencer.isPaused()) {
					Thread.sleep(500);
				}
			} catch (Exception exception) {
			} finally {
				CHMIDISequencerManager.deleteSequencer(sequencer, Target.UNKNOWN);
			}
		}
	});

	return new CString(id, t);
}
 
开发者ID:Hekta,项目名称:CHMIDI,代码行数:58,代码来源:MIDIFunctions.java


注:本文中的org.bukkit.block.NoteBlock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。