Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4507,6 +4507,65 @@ else if (material.hasModernData() && material.getModernData() instanceof org.buk
}
return new ElementTag(chiseledBookshelf.getSlot(input.toVector()) + 1);
});

// <--[tag]
// @attribute <LocationTag.crafter_disabled_slots>
// @returns ListTag
// @mechanism LocationTag.crafter_disabled_slots
// @group world
// @description
// Returns which slots in a crafter are disabled.
// The slots are arranged from left to right, top to bottom.
// -->
tagProcessor.registerTag(ListTag.class, "crafter_disabled_slots", (attribute, object) -> {
if (!(object.getBlockStateForTag(attribute) instanceof Crafter crafter)) {
attribute.echoError("The 'LocationTag.crafter_disabled_slots' tag can only be called on a crafter block.");
return null;
}
ListTag slots = new ListTag();
for (int i = 0; i <= 8; i++) {
if (crafter.isSlotDisabled(i)) {
slots.addObject(new ElementTag(i + 1));
}
}
return slots;
});

// <--[mechanism]
// @object LocationTag
// @name crafter_disabled_slots
// @input ListTag
// @description
// Sets which slots in a crafter are disabled.
// The slots are arranged from left to right, top to bottom.
// Provide no input to enable all slots.
// @tags
// <LocationTag.crafter_disabled_slots>
// @example
// # Disables the slots in the top left and middle right
// - adjustblock <[location]> crafter_disabled_slots:1|6
// -->
tagProcessor.registerMechanism("crafter_disabled_slots", false, ListTag.class, (object, mechanism, input) -> {
if (!(object.getBlockState() instanceof Crafter crafter)) {
mechanism.echoError("The 'LocationTag.crafter_disabled_slots' mechanism can only be called on a crafter block.");
return;
}
for (int i = 0; i <= 8; i++) {
crafter.setSlotDisabled(i, false);
}
for (String slot : input) {
ElementTag element = new ElementTag(slot);
if (element.isInt()) {
int value = element.asInt();
if (value > 0 && value <= 9) {
crafter.setSlotDisabled(value - 1, true);
continue;
}
}
mechanism.echoError("'" + slot + "' is not a valid slot for the 'crafter_disabled_slots' mechanism.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being here is a slightly confusing flow imo, as you have to look at the nested continue above and all - I'd just go with early returning on the int check &/ range check above.

}
crafter.update();
});
}

// <--[mechanism]
Expand Down