Skip to content
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

Strange freeze upon using the origins:action_on_being_used power #353

Closed
LadyAelita opened this issue Aug 12, 2023 · 11 comments
Closed

Strange freeze upon using the origins:action_on_being_used power #353

LadyAelita opened this issue Aug 12, 2023 · 11 comments

Comments

@LadyAelita
Copy link

LadyAelita commented Aug 12, 2023

EDIT: Forgot to give these:
Origins version: 1.19.2-1.7.1.1
Forge version: 43.2.0


In my mod, I have an item, aelitas_dark_origins:sunscreen_bottle. It's just an extension of the basic Item class, but at the moment it doesn't actually override any methods, so, origins aside, it doesn't have any "on use" functionality that could get in the way.

I have the following power:

"apply_with_help": {
	"type": "origins:action_on_being_used",
	"item_condition": {
		"type": "origins:ingredient",
		"ingredient": {
			"item": "aelitas_dark_origins:sunscreen_bottle"
		}
	},
	"condition": {
		"type": "origins:resource",
		"resource": "*:*_stacks",
		"comparison": "<",
		"compare_to": 4
	},
	"bientity_condition": {
		"type": "origins:distance",
		"comparison": "<=",
		"compare_to": 3
	},
	"held_item_action": {
		"type": "origins:consume",
		"amount": 1
	},
	"bientity_action": {
		"type": "origins:and",
		"actions": [
			{
				"type": "origins:target_action",
				"action": {
					"type": "origins:change_resource",
					"resource": "*:*_stacks",
					"change": 2
				}
			},
			{
				"type": "origins:actor_action",
				"action": {
					"type": "origins:give",
					"stack": {
						"item": "minecraft:glass_bottle",
						"amount": 1
					}
				}
			}
		]
	},
	"action_result": "success"
}

The issue is - when a player (actor), holding a sunscreen_bottle, right-clicks another player (target) who has the above power:

  • the actor's client immediately freezes
  • the target can still move around, and on their end, the resource change seems to have been applied correctly (the bar updates)
  • the server console stops logging anything or responding to commands such as stop - the Java process running the server has to be terminated the hard way
  • the server's resource usage increases drastically, to the extent of making the whole host OS barely responsive
  • even if I don't kill the server, the target gets disconnected after a while, with the "Timed out" message
  • after killing the server and launching it again, the world save is not up to date, but instead from a few minutes prior to the problematic power usage - I'm assuming it restores a backup

The kicker is that it only happens sometimes. There are times that it works correctly and nothing bad happens. I haven't been able to find any notable differences between cases where it works and cases where it breaks.


For the record, here is the whole origins:multiple power. The self_apply subpower doesn't have the same issue (apologies for a rather naive implementation, but I haven't managed to find a cleaner way to do it within the Origins JSON API):

{
	"type": "origins:multiple",
	"name": "Sunscreen",
	"hidden": true,
	"stacks": {
		"type": "origins:resource",
		"min": 0,
		"max": 4,
		"start_value": 0,
		"hud_render": {
			"should_render": true,
			"sprite_location": "origins:textures/gui/community/huang/resource_bar_02.png",
			"bar_index": 20,
			"condition": {
				"type": "origins:resource",
				"resource": "*:*_stacks",
				"comparison": ">",
				"compare_to": 0
			}
		}
	},
	"expire_at_end_of_day": {
		"type": "origins:action_over_time",
		"interval": 20,
		"condition": {
			"type": "origins:daytime"
		},
		"falling_action": {
			"type": "origins:change_resource",
			"resource": "*:*_stacks",
			"operation": "set",
			"change": 0
		}
	},
	"self_apply": {
		"type": "origins:active_self",
		"key": {
			"key": "key.use"
		},
		"cooldown": 10,
		"condition": {
			"type": "origins:and",
			"conditions": [
				{
					"type": "origins:resource",
					"resource": "*:*_stacks",
					"comparison": "<",
					"compare_to": 4
				},
				{
					"type": "origins:or",
					"conditions": [
						{
							"type": "origins:equipped_item",
							"equipment_slot": "mainhand",
							"item_condition": {
								"type": "origins:ingredient",
								"ingredient": {
									"item": "aelitas_dark_origins:sunscreen_bottle"
								}
							}
						},
						{
							"type": "origins:equipped_item",
							"equipment_slot": "offhand",
							"item_condition": {
								"type": "origins:ingredient",
								"ingredient": {
									"item": "aelitas_dark_origins:sunscreen_bottle"
								}
							}
						}
					]
				}
			]
		},
		"entity_action": {
			"type": "origins:and",
			"actions": [
				{
					"type": "origins:if_else_list",
					"actions": [
						{
							"condition": {
								"type": "origins:equipped_item",
								"equipment_slot": "mainhand",
								"item_condition": {
									"type": "origins:ingredient",
									"ingredient": {
										"item": "aelitas_dark_origins:sunscreen_bottle"
									}
								}
							},
							"action": {
								"type": "origins:and",
								"actions": [
									{
										"type": "origins:swing_hand",
										"hand": "MAIN_HAND"
									},
									{
										"type": "origins:equipped_item_action",
										"equipment_slot": "mainhand",
										"action": {
											"type": "origins:consume",
											"amount": 1
										}
									},
									{
										"type": "origins:change_resource",
										"resource": "*:*_stacks",
										"change": 1
									}
								]
							}
						},
						{
							"condition": {
								"type": "origins:equipped_item",
								"equipment_slot": "offhand",
								"item_condition": {
									"type": "origins:ingredient",
									"ingredient": {
										"item": "aelitas_dark_origins:enchanted_blood"
									}
								}
							},
							"action": {
								"type": "origins:and",
								"actions": [
									{
										"type": "origins:swing_hand",
										"hand": "OFF_HAND"
									},
									{
										"type": "origins:equipped_item_action",
										"equipment_slot": "offhand",
										"action": {
											"type": "origins:consume",
											"amount": 1
										}
									},
									{
										"type": "origins:change_resource",
										"resource": "*:*_stacks",
										"change": 1
									}
								]
							}
						}
					]
				},
				{
					"type": "origins:play_sound",
					"sound": "minecraft:entity.witch.drink",
					"volume": 1.0,
					"pitch": 1.2
				},
				{
					"type": "origins:give",
					"stack": {
						"item": "minecraft:glass_bottle",
						"amount": 1
					}
				}
			]
		}
	},
	"apply_with_help": {
		"type": "origins:action_on_being_used",
		"item_condition": {
			"type": "origins:ingredient",
			"ingredient": {
				"item": "aelitas_dark_origins:sunscreen_bottle"
			}
		},
		"condition": {
			"type": "origins:resource",
			"resource": "*:*_stacks",
			"comparison": "<",
			"compare_to": 4
		},
		"bientity_condition": {
			"type": "origins:distance",
			"comparison": "<=",
			"compare_to": 3
		},
		"held_item_action": {
			"type": "origins:consume",
			"amount": 1
		},
		"bientity_action": {
			"type": "origins:and",
			"actions": [
				{
					"type": "origins:target_action",
					"action": {
						"type": "origins:change_resource",
						"resource": "*:*_stacks",
						"change": 2
					}
				},
				{
					"type": "origins:actor_action",
					"action": {
						"type": "origins:give",
						"stack": {
							"item": "minecraft:glass_bottle",
							"amount": 1
						}
					}
				}
			]
		},
		"action_result": "success"
	}
}
@MerchantPug
Copy link
Collaborator

Looking into this now.

@MerchantPug
Copy link
Collaborator

MerchantPug commented Aug 31, 2023

I'm unable to reproduce this with just vanilla items and Origins Forge and its dependencies alone.

@LadyAelita
Copy link
Author

I'll look into creating a repo with a minimal reproduction, then.

LadyAelita added a commit to LadyAelita/dark-origins-public that referenced this issue Sep 5, 2023
LadyAelita added a commit to LadyAelita/dark-origins-public that referenced this issue Sep 5, 2023
LadyAelita added a commit to LadyAelita/dark-origins-public that referenced this issue Sep 5, 2023
@LadyAelita
Copy link
Author

Done, what remains is pretty much just a datapack packaged as a mod. The Java part of the mod is empty.

https://github.com/LadyAelita/dark-origins-public/tree/sunscreen-bug-min-repro

I've made the aelitas_dark_origins:vampire/sunscreen_apply_with_help power use minecraft:iron_ingot instead of the modded item, and it still suffers from the described bug.

@MerchantPug
Copy link
Collaborator

I'll take a look a little later.

@LadyAelita
Copy link
Author

I've recently found a fix for it for the purposes of my mod, by replacing the following part:

"bientity_action": {
	"type": "origins:and",
	"actions": [
		{
			"type": "origins:target_action",
			"action": {
				"type": "origins:change_resource",
				"resource": "*:*_stacks",
				"change": 2
			}
		},
		{
			"type": "origins:actor_action",
			"action": {
				"type": "origins:give",
				"stack": {
					"item": "minecraft:glass_bottle",
					"amount": 1
				}
			}
		}
	]
},

with:

"bientity_action": {
	"type": "origins:target_action",
	"action": {
		"type": "origins:change_resource",
		"resource": "*:*_stacks",
		"change": 2
	}
},
"result_stack": {
	"item": "minecraft:glass_bottle",
	"amount": 1
},

@LaviStardust
Copy link

I am able to reproduce this with the 1.18.2 version of Origins (Forge), but not the 1.19.2 version. Regardless of what actions or conditions I use (or even none), the freeze you described happens consistently.
I have not been able to reproduce this in the Fabric versions, though.

@LaviStardust
Copy link

Nevermind, I was also able to replicate this issue in 1.19.2 Forge, but the massive lag-then-crash only happens on the second time Action On Being Used is triggered.
I am still not able to replicate it in the Fabric versions.

@LaviStardust
Copy link

At least on my end, I have pinpointed the issue to origins:consume.
origins:action_on_being_used works just fine if you have one item in your hand and it gets consumed, but if you have more than one item in your hand, instead of consuming one and leaving you with one, it freezes as described by OP.

@MerchantPug
Copy link
Collaborator

I'll be looking into this now on 1.20.1, I might backport the bugfixes too, but I'm a little unsure when I'll get to that.

@MerchantPug
Copy link
Collaborator

MerchantPug commented Mar 12, 2024

I think it was a recursion error with setting the stack to what was already in the hand, so I've modified this by making it so it will only manually set the stack in the hand if there is a result stack.

@MerchantPug MerchantPug self-assigned this Mar 12, 2024
MerchantPug added a commit to EdwinMindcraft/apoli that referenced this issue Mar 12, 2024
MerchantPug added a commit to EdwinMindcraft/origins-forge that referenced this issue Mar 12, 2024
MerchantPug added a commit to EdwinMindcraft/apoli that referenced this issue Mar 13, 2024
MerchantPug added a commit to EdwinMindcraft/origins-forge that referenced this issue Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants