1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-17 21:55:12 +00:00

Added speaker as turtle peripheral

This commit is contained in:
Restioson
2017-05-10 16:46:18 +02:00
parent 3bf15a3798
commit a3b0e4e993
6 changed files with 203 additions and 12 deletions

View File

@@ -13,6 +13,8 @@ import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class SpeakerPeripheral implements IPeripheral {
@@ -20,18 +22,33 @@ public class SpeakerPeripheral implements IPeripheral {
private long m_clock;
private long m_lastPlayTime;
public SpeakerPeripheral(TileSpeaker speaker)
public SpeakerPeripheral()
{
m_speaker = speaker;
m_clock = 0;
m_lastPlayTime = 0;
}
void updateClock()
public SpeakerPeripheral(TileSpeaker speaker)
{
this();
m_speaker = speaker;
}
public void updateClock()
{
m_clock++;
}
public World getWorld()
{
return m_speaker.getWorld();
}
public BlockPos getPos()
{
return m_speaker.getPos();
}
/* IPeripheral implementations */
@Override
@@ -197,7 +214,7 @@ public class SpeakerPeripheral implements IPeripheral {
if (SoundEvent.REGISTRY.containsKey(resourceName))
{
m_speaker.getWorld().playSound(null, m_speaker.getPos(), new SoundEvent(resourceName), SoundCategory.RECORDS, volume, pitch);
getWorld().playSound(null, getPos(), new SoundEvent(resourceName), SoundCategory.RECORDS, volume, pitch);
m_lastPlayTime = m_clock;
return new Object[]{true}; // Success, return true
}

View File

@@ -6,18 +6,17 @@
package dan200.computercraft.shared.peripheral.speaker;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
import net.minecraft.util.EnumFacing;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
import net.minecraft.util.EnumFacing;
public class TileSpeaker extends TilePeripheralBase
{
// Statics
public static final int MIN_TICKS_BETWEEN_SOUNDS = 1;
static final int MIN_TICKS_BETWEEN_SOUNDS = 1;
// Members
private SpeakerPeripheral m_peripheral;
private SpeakerPeripheral m_peripheral; // TODO what happens when multiple computers wrap one peripheral?
public TileSpeaker()
{