Bien sûr :
SoundBlock.java
| |
| public class SoundBlock extends BlockContainer{ |
| |
| public SoundBlock(int par1, Material par2Material) { |
| super(par1, par2Material); |
| } |
| |
| @Override |
| public TileEntity createNewTileEntity(World world) { |
| return new TileEntitySoundBlock(); |
| } |
| |
| @Override |
| public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ |
| |
| } |
| |
| @Override |
| public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack){ |
| |
| } |
| } |
SoundBlockDialog.java (Le GUI)
| |
| public class SoundBlockDialog extends JDialog { |
| |
| private JComboBox soundChooser; |
| private JCheckBox loopCheckBox; |
| private JSpinner delayChooser; |
| private JSlider volumeChooser; |
| private JLabel volumeLabel; |
| |
| private TileEntitySoundBlock tileEntity; |
| |
| |
| |
| |
| public SoundBlockDialog(TileEntitySoundBlock tile){ |
| tileEntity = tile; |
| setTitle("Edition des paramètres - Bloc sonore"); |
| setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
| setModal(true); |
| setResizable(false); |
| setBounds(100, 100, 316, 331); |
| getContentPane().setLayout(null); |
| |
| JLabel label1 = new JLabel("Son \u00E0 jouer :"); |
| label1.setBounds(10, 43, 290, 29); |
| getContentPane().add(label1); |
| |
| soundChooser = new JComboBox(); |
| for(String i : Registry.soundList){ |
| soundChooser.addItem(i.replace("wsmod:","")); |
| } |
| soundChooser.setBounds(10, 83, 217, 35); |
| getContentPane().add(soundChooser); |
| |
| loopCheckBox = new JCheckBox("Jouer le son en boucle"); |
| loopCheckBox.setBounds(10, 7, 290, 29); |
| getContentPane().add(loopCheckBox); |
| |
| JButton closeButton = new JButton("Fermer"); |
| closeButton.addActionListener(new CloseButtonListener()); |
| closeButton.setBounds(98, 249, 114, 35); |
| getContentPane().add(closeButton); |
| |
| delayChooser = new JSpinner(); |
| delayChooser.setModel(new SpinnerNumberModel(0, 0, 200, 5)); |
| delayChooser.setBounds(237, 129, 63, 29); |
| getContentPane().add(delayChooser); |
| |
| JLabel label2 = new JLabel("D\u00E9lai entre chaque r\u00E9p\u00E9tition (max 200) :"); |
| label2.setBounds(10, 129, 290, 29); |
| getContentPane().add(label2); |
| |
| volumeChooser = new JSlider(); |
| volumeChooser.addChangeListener(new VolumeChooserListener()); |
| volumeChooser.setValue(0); |
| volumeChooser.setPaintTicks(true); |
| volumeChooser.setMajorTickSpacing(10); |
| volumeChooser.setMinorTickSpacing(5); |
| |
| volumeChooser.setBounds(10, 209, 290, 29); |
| getContentPane().add(volumeChooser); |
| |
| volumeLabel = new JLabel("0%"); |
| volumeLabel.setHorizontalAlignment(SwingConstants.CENTER); |
| volumeLabel.setBounds(129, 169, 53, 29); |
| getContentPane().add(volumeLabel); |
| |
| JLabel label3 = new JLabel("Volume :"); |
| label3.setBounds(10, 169, 290, 29); |
| getContentPane().add(label3); |
| |
| loopCheckBox.setSelected(tileEntity.getIsLoop()); |
| soundChooser.setSelectedItem(tileEntity.getSound()); |
| delayChooser.setValue(tileEntity.getDelay()); |
| volumeChooser.setValue((int)(tileEntity.getVolume()*100)); |
| |
| JButton playButton = new JButton("Lire"); |
| playButton.addActionListener(new PlayButtonListener()); |
| playButton.setBounds(237, 83, 63, 35); |
| getContentPane().add(playButton); |
| |
| setVisible(true); |
| } |
| |
| class CloseButtonListener implements ActionListener{ |
| @Override |
| public void actionPerformed(ActionEvent e) { |
| tileEntity.setIsLoop(loopCheckBox.isSelected()); |
| tileEntity.setSound((String)soundChooser.getSelectedItem()); |
| tileEntity.setDelay((int)delayChooser.getValue()); |
| tileEntity.setVolume((float)volumeChooser.getValue()/100); |
| } |
| } |
| |
| class VolumeChooserListener implements ChangeListener{ |
| @Override |
| public void stateChanged(ChangeEvent e){ |
| volumeLabel.setText(volumeChooser.getValue() + "%"); |
| } |
| } |
| |
| class PlayButtonListener implements ActionListener{ |
| @Override |
| public void actionPerformed(ActionEvent e){ |
| |
| } |
| } |
| } |
| |
TileEntitySoundBlock.java
| |
| public class TileEntitySoundBlock extends TileEntity{ |
| |
| private boolean loop = false; |
| private String sound = "alarm.ogg"; |
| private float volume = 1.0F; |
| private int delay = 0; |
| |
| @Override |
| public void readFromNBT(NBTTagCompound nbtTag){ |
| super.readFromNBT(nbtTag); |
| nbtTag.setBoolean("Loop",this.loop); |
| nbtTag.setString("Sound",this.sound); |
| nbtTag.setFloat("Volume",this.volume); |
| nbtTag.setInteger("Delay",this.delay); |
| } |
| |
| @Override |
| public void writeToNBT(NBTTagCompound nbtTag){ |
| super.writeToNBT(nbtTag); |
| this.loop = nbtTag.getBoolean("Loop"); |
| this.sound = nbtTag.getString("Sound"); |
| this.volume = nbtTag.getFloat("Volume"); |
| this.delay = nbtTag.getInteger("Delay"); |
| } |
| |
| public void setVolume(float volume){ |
| this.volume = volume; |
| } |
| |
| public float getVolume(){ |
| return this.volume; |
| } |
| |
| public void setDelay(int delay){ |
| this.delay = delay; |
| } |
| public int getDelay(){ |
| return this.delay; |
| } |
| public void setSound(String sound){ |
| this.sound = sound; |
| } |
| |
| public String getSound(){ |
| return this.sound; |
| } |
| |
| public String getSoundToPlay(){ |
| return "wsmod:" + this.sound; |
| } |
| |
| public void setIsLoop(boolean loop){ |
| this.loop = loop; |
| } |
| |
| public boolean getIsLoop(){ |
| return this.loop; |
| } |
| } |
| |