mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 03:30:29 +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:
commit
09da119f27
@ -533,6 +533,11 @@ public class ComputerCraft
|
||||
networkEventChannel.sendToServer( encode( packet ) );
|
||||
}
|
||||
|
||||
public static void sendToAllAround( ComputerCraftPacket packet, NetworkRegistry.TargetPoint point )
|
||||
{
|
||||
networkEventChannel.sendToAllAround( encode( packet ), point );
|
||||
}
|
||||
|
||||
public static void handlePacket( ComputerCraftPacket packet, EntityPlayer player )
|
||||
{
|
||||
proxy.handlePacket( packet, player );
|
||||
|
@ -51,7 +51,6 @@ import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
@ -314,17 +313,6 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos )
|
||||
{
|
||||
Minecraft mc = FMLClientHandler.instance().getClient();
|
||||
world.playRecord( pos, record );
|
||||
if( record != null )
|
||||
{
|
||||
mc.ingameGUI.setRecordPlayingMessage( recordInfo );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive )
|
||||
{
|
||||
@ -385,6 +373,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
case ComputerCraftPacket.ComputerChanged:
|
||||
case ComputerCraftPacket.ComputerTerminalChanged:
|
||||
case ComputerCraftPacket.ComputerDeleted:
|
||||
case ComputerCraftPacket.PlayRecord:
|
||||
{
|
||||
// Packet from Server to Client
|
||||
IThreadListener listener = Minecraft.getMinecraft();
|
||||
@ -437,6 +426,22 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ComputerCraftPacket.PlayRecord:
|
||||
{
|
||||
BlockPos pos = new BlockPos( packet.m_dataInt[ 0 ], packet.m_dataInt[ 1 ], packet.m_dataInt[ 2 ] );
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if( packet.m_dataInt.length > 3 )
|
||||
{
|
||||
SoundEvent sound = SoundEvent.REGISTRY.getObjectById( packet.m_dataInt[ 3 ] );
|
||||
mc.world.playRecord( pos, sound );
|
||||
mc.ingameGUI.setRecordPlayingMessage( packet.m_dataString[ 0 ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.world.playRecord( pos, null );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,9 @@
|
||||
|
||||
package dan200.computercraft.server.proxy;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.network.ComputerCraftPacket;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
|
||||
@ -65,11 +67,6 @@ public class ComputerCraftProxyServer extends ComputerCraftProxyCommon
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive )
|
||||
{
|
||||
|
@ -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 )
|
||||
|
@ -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 )
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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 )
|
||||
{
|
||||
|
@ -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 );
|
||||
|
Loading…
Reference in New Issue
Block a user