Skip to content

Determination format modernization Part.2 #2689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

MrMaleficus
Copy link
Contributor

Updating the determination format for the following ScriptEvents :

  • FurnaceStartsSmeltingScriptEvent
  • RedstoneScriptEvent
  • EntityHealsScriptEvent
  • PlayerCraftsItemScriptEvent
  • PlayerItemTakesDamageScriptEvent

@@ -34,6 +34,9 @@ public class RedstoneScriptEvent extends BukkitScriptEvent implements Listener {

public RedstoneScriptEvent() {
registerCouldMatcher("redstone recalculated");
this.<RedstoneScriptEvent, ElementTag>registerDetermination(null, ElementTag.class, (evt, context, current) -> {
evt.event.setNewCurrent(current.asInt());
Copy link
Member

Choose a reason for hiding this comment

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

these rewrites are removing the error checks that the prior impl had

return switch (name) {
case "location" -> location;
case "item" -> item;
case "recipe_id" -> new ElementTag(Utilities.namespacedKeyToString(event.getRecipe().getKey()), true);
Copy link
Member

Choose a reason for hiding this comment

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

this is a functionality change

@MrMaleficus
Copy link
Contributor Author

Updated

@@ -44,6 +45,11 @@ public class FurnaceStartsSmeltingScriptEvent extends BukkitScriptEvent implemen

public FurnaceStartsSmeltingScriptEvent() {
registerCouldMatcher("furnace starts smelting <item>");
this.<FurnaceStartsSmeltingScriptEvent, DurationTag>registerDetermination(null, DurationTag.class, (evt, context, time) -> {
if (time.asElement().isInt()) {
Copy link
Member

Choose a reason for hiding this comment

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

this still has no error handling that was previously available. Go test a bad determination on an old build vs your version and compare the results

Copy link
Member

Choose a reason for hiding this comment

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

... go test a good determination too, this is registered as a DurationTag, so asElement.isInt is always false

@@ -34,6 +34,11 @@ public class RedstoneScriptEvent extends BukkitScriptEvent implements Listener {

public RedstoneScriptEvent() {
registerCouldMatcher("redstone recalculated");
this.<RedstoneScriptEvent, ElementTag>registerDetermination(null, ElementTag.class, (evt, context, current) -> {
if (current.asElement().isInt()) {
Copy link
Member

Choose a reason for hiding this comment

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

It should already be an element?

@@ -50,6 +50,9 @@ public class PlayerCraftsItemScriptEvent extends BukkitScriptEvent implements Li
// -->

public PlayerCraftsItemScriptEvent() {
this.<PlayerCraftsItemScriptEvent, ItemTag>registerDetermination(null, ItemTag.class, (evt, context, result_item) -> {
Copy link
Member

Choose a reason for hiding this comment

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

Java naming standards - this would be resultItem

Comment on lines -64 to +67
if (!couldMatchItem(path.eventArgLowerAt(2))) {
return false;
}
return true;
return couldMatchItem(path.eventArgLowerAt(2));
Copy link
Member

Choose a reason for hiding this comment

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

That syntax was intentional - either way if anything just update it to registerCouldMatcher, no point changing around code that needs to be removed anyway

@@ -47,6 +47,11 @@ public class PlayerItemTakesDamageScriptEvent extends BukkitScriptEvent implemen

public PlayerItemTakesDamageScriptEvent() {
registerCouldMatcher("player <item> takes damage");
this.<PlayerItemTakesDamageScriptEvent, ElementTag>registerDetermination(null, ElementTag.class, (evt, context, amount) -> {
if (amount.asElement().isInt()) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here, this is already an element

@tal5 tal5 marked this pull request as draft May 15, 2025 14:16
@tal5
Copy link
Member

tal5 commented May 15, 2025

Marking this as a draft for now, feel free to mark as ready to review once comments are addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants