Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #49 from Toad-Dev/fabric-fix-48
Browse files Browse the repository at this point in the history
Fix crash while playing a music disk in a drive on server.
  • Loading branch information
Merith-TK authored Jun 4, 2021
2 parents 7c0664b + 80c2fc6 commit 2fc2cf2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dan200.computercraft.fabric.mixin;

import net.minecraft.item.MusicDiscItem;
import net.minecraft.sound.SoundEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(MusicDiscItem.class)
public interface MusicDiscItemAccessor {
@Accessor
SoundEvent getSound();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import dan200.computercraft.api.media.IMedia;

import dan200.computercraft.fabric.mixin.MusicDiscItemAccessor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.MusicDiscItem;
Expand Down Expand Up @@ -42,6 +43,10 @@ public String getAudioTitle(@Nonnull ItemStack stack) {

@Override
public SoundEvent getAudio(@Nonnull ItemStack stack) {
return ((MusicDiscItem) stack.getItem()).getSound();
Item item = stack.getItem();
if (!(item instanceof MusicDiscItem)) {
return null;
}
return ((MusicDiscItemAccessor) item).getSound();
}
}
3 changes: 2 additions & 1 deletion src/main/resources/computercraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"SignBlockEntityAccess",
"SoundEventAccess",
"WorldSavePathAccess",
"MixinServerPlayerInteractionManager"
"MixinServerPlayerInteractionManager",
"MusicDiscItemAccessor"
],
"client": [
"AffineTransformationAccess",
Expand Down

0 comments on commit 2fc2cf2

Please sign in to comment.