1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-06 16:33:00 +00:00

Merge pull request #451 from SquidDev-CC/ComputerCraft/hotfix/disk-drive-stop

Use custom packet to play records, instead of using block events
This commit is contained in:
SquidDev
2017-11-14 21:30:52 +00:00
8 changed files with 46 additions and 77 deletions

View File

@@ -337,22 +337,6 @@ public abstract class BlockGeneric extends Block implements
return 0;
}
@Override
@Deprecated
public boolean eventReceived( IBlockState state, World world, BlockPos pos, int eventID, int eventParameter )
{
if( world.isRemote )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric )
{
TileGeneric generic = (TileGeneric)tile;
generic.onBlockEvent( eventID, eventParameter );
}
}
return true;
}
@Nonnull
@Override
public final TileEntity createTileEntity( @Nonnull World world, @Nonnull IBlockState state )

View File

@@ -175,20 +175,6 @@ public abstract class TileGeneric extends TileEntity
{
}
public final void sendBlockEvent( int eventID )
{
sendBlockEvent( eventID, 0 );
}
public final void sendBlockEvent( int eventID, int eventParameter )
{
getWorld().addBlockEvent( getPos(), getWorld().getBlockState( getPos() ).getBlock(), eventID, eventParameter );
}
public void onBlockEvent( int eventID, int eventParameter )
{
}
@Override
public boolean shouldRefresh( World world, BlockPos pos, @Nonnull IBlockState oldState, @Nonnull IBlockState newState )
{

View File

@@ -32,6 +32,7 @@ public class ComputerCraftPacket
public static final byte ComputerChanged = 7;
public static final byte ComputerTerminalChanged = 8;
public static final byte ComputerDeleted = 9;
public static final byte PlayRecord = 10;
// Packet class
public byte m_packetType;

View File

@@ -46,11 +46,6 @@ import static net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABI
public class TileDiskDrive extends TilePeripheralBase
implements IInventory, ITickable
{
// Statics
private static final int BLOCKEVENT_PLAY_RECORD = 0;
private static final int BLOCKEVENT_STOP_RECORD = 1;
private static class MountInfo
{
public String mountPath;
@@ -90,7 +85,7 @@ public class TileDiskDrive extends TilePeripheralBase
{
if( m_recordPlaying )
{
sendBlockEvent( BLOCKEVENT_STOP_RECORD );
stopRecord();
}
}
}
@@ -188,7 +183,7 @@ public class TileDiskDrive extends TilePeripheralBase
// Music
synchronized( this )
{
if( m_recordPlaying != m_recordQueued || m_restartRecord )
if( !world.isRemote && m_recordPlaying != m_recordQueued || m_restartRecord )
{
m_restartRecord = false;
if( m_recordQueued )
@@ -198,7 +193,7 @@ public class TileDiskDrive extends TilePeripheralBase
if( record != null )
{
m_recordPlaying = true;
sendBlockEvent( BLOCKEVENT_PLAY_RECORD );
playRecord();
}
else
{
@@ -207,7 +202,7 @@ public class TileDiskDrive extends TilePeripheralBase
}
else
{
sendBlockEvent( BLOCKEVENT_STOP_RECORD );
stopRecord();
m_recordPlaying = false;
}
}
@@ -306,7 +301,7 @@ public class TileDiskDrive extends TilePeripheralBase
// Stop music
if( m_recordPlaying )
{
sendBlockEvent( BLOCKEVENT_STOP_RECORD );
stopRecord();
m_recordPlaying = false;
m_recordQueued = false;
}
@@ -658,25 +653,6 @@ public class TileDiskDrive extends TilePeripheralBase
}
}
@Override
public void onBlockEvent( int eventID, int eventParameter )
{
super.onBlockEvent( eventID, eventParameter );
switch( eventID )
{
case BLOCKEVENT_PLAY_RECORD:
{
playRecord();
break;
}
case BLOCKEVENT_STOP_RECORD:
{
stopRecord();
break;
}
}
}
@Override
public boolean shouldRefresh( World world, BlockPos pos, @Nonnull IBlockState oldState, @Nonnull IBlockState newState )
{

View File

@@ -149,7 +149,22 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
}
@Override
public abstract void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos );
public void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos )
{
ComputerCraftPacket packet = new ComputerCraftPacket();
packet.m_packetType = ComputerCraftPacket.PlayRecord;
if( record != null )
{
packet.m_dataInt = new int[] { pos.getX(), pos.getY(), pos.getZ(), SoundEvent.REGISTRY.getIDForObject( record ) };
packet.m_dataString = new String[] { recordInfo };
}
else
{
packet.m_dataInt = new int[] { pos.getX(), pos.getY(), pos.getZ() };
}
ComputerCraft.sendToAllPlayers( packet );
}
@Override
public abstract Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive );