Fix Speaker not playing sounds on break and replace for entire Lua session

This commit is contained in:
Restioson 2017-05-08 19:27:14 +02:00
parent 2899246dbc
commit dc96f2121a
3 changed files with 13 additions and 12 deletions

View File

@ -334,6 +334,7 @@ public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess worl
break;
}
case Speaker: {
state = state.withProperty( Properties.FACING, dir );
break;
}
case Monitor:

View File

@ -16,7 +16,7 @@
public class SpeakerPeripheral implements IPeripheral {
private final TileSpeaker m_speaker;
private TileSpeaker m_speaker;
private long m_clock;
private long m_lastPlayTime;
@ -27,12 +27,11 @@ public SpeakerPeripheral(TileSpeaker speaker)
m_lastPlayTime = 0;
}
protected void updateClock()
void updateClock()
{
m_clock++;
}
/* IPeripheral implementations */
@Override
@ -80,7 +79,6 @@ public String[] getMethodNames()
@Override
public Object[] callMethod(IComputerAccess computerAccess, ILuaContext context, int methodIndex, Object[] args) throws LuaException
{
switch (methodIndex)
{
// playsound
@ -96,7 +94,7 @@ public Object[] callMethod(IComputerAccess computerAccess, ILuaContext context,
default:
{
return null;
throw new LuaException("Method index out of range!");
}
}

View File

@ -6,6 +6,7 @@
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;
@ -18,20 +19,21 @@ public class TileSpeaker extends TilePeripheralBase
// Members
private SpeakerPeripheral m_peripheral;
@Override
public synchronized void update()
public TileSpeaker()
{
if (m_peripheral != null)
{
m_peripheral.updateClock();
}
super();
m_peripheral = new SpeakerPeripheral(this);
}
@Override
public synchronized void update() {
m_peripheral.updateClock();
}
// IPeripheralTile implementation
public IPeripheral getPeripheral(EnumFacing side)
{
m_peripheral = new SpeakerPeripheral(this);
return m_peripheral;
}