Skip to content

Commit

Permalink
Add tag/mech jukebox_is_playing/play to match last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 13, 2021
1 parent cbacdd6 commit de42c49
Showing 1 changed file with 50 additions and 1 deletion.
Expand Up @@ -3316,6 +3316,23 @@ else if (material.hasModernData() && material.getModernData().data instanceof or

return new ItemTag(((Jukebox) state).getRecord());
});

// <--[tag]
// @attribute <LocationTag.jukebox_is_playing>
// @returns ElementTag
// @mechanism LocationTag.jukebox_play
// @description
// Returns whether the jukebox is currently playing a song.
// -->
registerTag("jukebox_is_playing", (attribute, object) -> {
BlockState state = object.getBlockStateForTag(attribute);
if (!(state instanceof Jukebox)) {
attribute.echoError("'jukebox_is_playing' tag is only valid for jukebox blocks.");
return null;
}

return new ElementTag(((Jukebox) state).isPlaying());
});
}

public static ObjectTagProcessor<LocationTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down Expand Up @@ -3864,7 +3881,8 @@ else if (state instanceof Dropper) {
// @name jukebox_record
// @input ItemTag
// @description
// Sets the record item played by a jukebox. Give no input to disable all songs.
// Sets the record item played by a jukebox. Give no input to set the jukebox to empty.
// See also <@link mechanism LocationTag.jukebox_play>.
// @tags
// <LocationTag.jukebox_record>
// -->
Expand All @@ -3884,6 +3902,37 @@ else if (state instanceof Dropper) {
}
}

// <--[mechanism]
// @object LocationTag
// @name jukebox_play
// @input ElementTag(Boolean)
// @description
// If 'true', starts playing the record inside. If 'false', stops playing any song.
// See also <@link mechanism LocationTag.jukebox_record>.
// @tags
// <LocationTag.jukebox_is_playing>
// -->
if (mechanism.matches("jukebox_play") && mechanism.requireBoolean()) {
BlockState state = getBlockState();
if (state instanceof Jukebox) {
if (mechanism.getValue().asBoolean()) {
Material mat = ((Jukebox) state).getRecord().getType();
if (mat == Material.AIR) {
Debug.echoError("'jukebox_play' cannot play nothing.");
return;
}
((Jukebox) state).setPlaying(mat);
}
else {
((Jukebox) state).stopPlaying();
}
state.update();
}
else {
Debug.echoError("'jukebox_play' mechanism can only be called on a jukebox block.");
}
}

CoreUtilities.autoPropertyMechanism(this, mechanism);
}
}

0 comments on commit de42c49

Please sign in to comment.