Use Forge's packet methods for sending SoundEvents

Doesn't fix #515 (arguably makes it worse in the sense that it's more
likely to throw). However it should provide better error reporting, and
make it more clear that it's not CC:T's fault.
This commit is contained in:
SquidDev 2020-08-22 15:31:48 +01:00
parent d5de39ebd4
commit 29fb0baa09
1 changed files with 2 additions and 4 deletions

View File

@ -13,10 +13,8 @@
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Objects;
/** /**
* Starts or stops a record on the client, depending on if {@link #soundEvent} is {@code null}. * Starts or stops a record on the client, depending on if {@link #soundEvent} is {@code null}.
@ -51,7 +49,7 @@ public PlayRecordClientMessage( PacketBuffer buf )
if( buf.readBoolean() ) if( buf.readBoolean() )
{ {
name = buf.readString( Short.MAX_VALUE ); name = buf.readString( Short.MAX_VALUE );
soundEvent = ForgeRegistries.SOUND_EVENTS.getValue( buf.readResourceLocation() ); soundEvent = buf.readRegistryIdSafe( SoundEvent.class );
} }
else else
{ {
@ -72,7 +70,7 @@ public void toBytes( @Nonnull PacketBuffer buf )
{ {
buf.writeBoolean( true ); buf.writeBoolean( true );
buf.writeString( name ); buf.writeString( name );
buf.writeResourceLocation( Objects.requireNonNull( soundEvent.getRegistryName(), "Sound is not registered" ) ); buf.writeRegistryId( soundEvent );
} }
} }