1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2026-01-28 14:31:17 +00:00

Use custom packet to play records, instead of using block events

Breaking a disk drive was not stopping the record being played as the
block event never reached the client. Instead, we send a custom packet
which starts/stops music at a given location.

We also remove all the plumbing for eventReceived/sendBlockEvent from
the generic block/tile classes, as they are no longer used.

Closes #443
This commit is contained in:
SquidDev
2017-09-12 15:46:46 +01:00
parent 1fdfcdb5f2
commit afec3743f3
8 changed files with 46 additions and 77 deletions

View File

@@ -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 )
{
@@ -384,6 +372,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
{
case ComputerCraftPacket.ComputerChanged:
case ComputerCraftPacket.ComputerDeleted:
case ComputerCraftPacket.PlayRecord:
{
// Packet from Server to Client
IThreadListener listener = Minecraft.getMinecraft();
@@ -435,6 +424,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 );
}
}
}
}