Skip to content

Commit

Permalink
Fix server crashes with alarms (GregTechCEu#2411)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruberu authored Mar 10, 2024
1 parent fd65290 commit 77ed2e0
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
return ModularUI.builder(GuiTextures.BACKGROUND, 240, 86)
.widget(new LabelWidget(10, 5, getMetaFullName()))
.widget(new SelectorWidget(10, 20, 220, 20,
getSounds().stream().map((event) -> event.getSoundName().toString())
getSounds().stream().map(this::getNameOfSound)
.collect(Collectors.toList()),
0x555555, () -> this.selectedSound.getSoundName().toString(), true).setOnChanged((v) -> {
GregTechAPI.soundManager.stopTileSound(getPos());
0x555555, () -> getNameOfSound(this.selectedSound), true).setOnChanged((v) -> {
if (this.getWorld().isRemote)
GregTechAPI.soundManager.stopTileSound(getPos());
SoundEvent newSound = SoundEvent.REGISTRY.getObject(new ResourceLocation(v));
if (this.selectedSound != newSound) {
this.selectedSound = SoundEvent.REGISTRY.getObject(new ResourceLocation(v));
this.writeCustomData(GregtechDataCodes.UPDATE_SOUND,
(writer) -> writer.writeResourceLocation(this.selectedSound.getSoundName()));
(writer) -> writer
.writeResourceLocation(getResourceLocationOfSound(this.selectedSound)));
}
}))
.widget(new ImageWidget(10, 54, 220, 20, GuiTextures.DISPLAY))
Expand Down Expand Up @@ -168,14 +170,14 @@ public void receiveInitialSyncData(PacketBuffer buf) {
public void writeInitialSyncData(PacketBuffer buf) {
super.writeInitialSyncData(buf);
buf.writeBoolean(this.isActive);
buf.writeResourceLocation(this.selectedSound.getSoundName());
buf.writeResourceLocation(getResourceLocationOfSound(this.selectedSound));
buf.writeInt(this.radius);
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound data) {
data.setBoolean("isActive", this.isActive);
data.setString("selectedSound", this.selectedSound.getSoundName().toString());
data.setString("selectedSound", getNameOfSound(this.selectedSound));
data.setInteger("radius", this.radius);
return super.writeToNBT(data);
}
Expand All @@ -187,4 +189,12 @@ public void readFromNBT(NBTTagCompound data) {
this.radius = data.getInteger("radius");
super.readFromNBT(data);
}

public String getNameOfSound(SoundEvent sound) {
return getResourceLocationOfSound(sound).toString();
}

public ResourceLocation getResourceLocationOfSound(SoundEvent sound) {
return SoundEvent.REGISTRY.getNameForObject(sound);
}
}

0 comments on commit 77ed2e0

Please sign in to comment.