-
-
Notifications
You must be signed in to change notification settings - Fork 113
Some component stuff #2734
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
Open
heypr
wants to merge
8
commits into
DenizenScript:dev
Choose a base branch
from
heypr:new-stuff
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+335
−25
Open
Some component stuff #2734
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0e03c46
Components :o
heypr 3b843b5
Updated name + corrected registration
heypr 7041ca6
Addressed comments
heypr af3e6b8
Merge remote-tracking branch 'upstream/dev' into new-stuff
heypr 20a1c76
Merge remote-tracking branch 'upstream/dev' into new-stuff
heypr da0349d
Addressed comments.
heypr aeba5f6
Max durability tag for <=1.19
heypr 90ccdd2
Update ItemDurability.java
heypr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
18 changes: 7 additions & 11 deletions
18
paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperItemExtensions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,18 @@ | ||
| package com.denizenscript.denizen.paper.properties; | ||
|
|
||
| import com.denizenscript.denizen.nms.NMSHandler; | ||
| import com.denizenscript.denizen.nms.NMSVersion; | ||
| import com.denizenscript.denizen.objects.ItemTag; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
|
|
||
| public class PaperItemExtensions { | ||
|
|
||
| public static void register() { | ||
|
|
||
| // <--[tag] | ||
| // @attribute <ItemTag.rarity> | ||
| // @returns ElementTag | ||
| // @group paper | ||
| // @Plugin Paper | ||
| // @description | ||
| // Returns the rarity of an item, as "common", "uncommon", "rare", or "epic". | ||
| // --> | ||
| ItemTag.tagProcessor.registerTag(ElementTag.class, "rarity", (attribute, item) -> { | ||
| return new ElementTag(item.getItemStack().getRarity()); | ||
| }); | ||
| if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_19)) { | ||
| ItemTag.tagProcessor.registerTag(ElementTag.class, "rarity", (attribute, item) -> { | ||
| return new ElementTag(item.getItemStack().getRarity()); | ||
| }); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemFood.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package com.denizenscript.denizen.objects.properties.item; | ||
|
|
||
| import com.denizenscript.denizen.objects.ItemTag; | ||
| import com.denizenscript.denizencore.objects.Mechanism; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
| import com.denizenscript.denizencore.objects.core.MapTag; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
| import org.bukkit.inventory.meta.components.FoodComponent; | ||
|
|
||
| public class ItemFood extends ItemProperty<MapTag> { | ||
|
|
||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name food | ||
| // @input MapTag | ||
| // @description | ||
| // Controls the food properties of the item. | ||
| // A food item has the 'nutrition', 'saturation', and 'can_always_eat' properties. | ||
| // The 'nutrition' is the amount of hunger points the food restores. | ||
| // The 'saturation' is the amount of saturation points the food restores. | ||
| // The 'can_always_eat' is a boolean indicating if the food can be eaten even when the player is not hungry. | ||
| // @tag | ||
| // If the item does not have food properties, this will return null. | ||
| // @mechanism | ||
| // Provide no input to entirely remove the food component from the item. | ||
| // --> | ||
|
|
||
| public static boolean describes(ItemTag item) { | ||
| return item.getBukkitMaterial() != Material.AIR; | ||
| } | ||
|
|
||
| @Override | ||
| public MapTag getPropertyValue() { | ||
| if (getItemMeta().hasFood()) { | ||
| FoodComponent food = getItemMeta().getFood(); | ||
| MapTag map = new MapTag(); | ||
| map.putObject("nutrition", new ElementTag(food.getNutrition())); | ||
| map.putObject("saturation", new ElementTag(food.getSaturation())); | ||
| map.putObject("can_always_eat", new ElementTag(food.canAlwaysEat())); | ||
| return map; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(MapTag map, Mechanism mechanism) { | ||
| editMeta(ItemMeta.class, meta -> { | ||
| if (map == null) { | ||
| meta.setFood(null); | ||
| return; | ||
| } | ||
| FoodComponent food = meta.getFood(); | ||
| ElementTag nutrition = map.getElement("nutrition"); | ||
| if (nutrition != null) { | ||
| food.setNutrition(nutrition.asInt()); | ||
| } | ||
| ElementTag saturation = map.getElement("saturation"); | ||
| if (saturation != null) { | ||
| food.setSaturation(saturation.asFloat()); | ||
| } | ||
| ElementTag canAlwaysEat = map.getElement("can_always_eat"); | ||
| if (canAlwaysEat != null) { | ||
| food.setCanAlwaysEat(canAlwaysEat.asBoolean()); | ||
| } | ||
| meta.setFood(food); | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "food"; | ||
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("food", ItemFood.class, MapTag.class, false); | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
...in/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemMaxDurability.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package com.denizenscript.denizen.objects.properties.item; | ||
|
|
||
| import com.denizenscript.denizen.objects.ItemTag; | ||
| import com.denizenscript.denizencore.objects.Mechanism; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.inventory.meta.Damageable; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
|
|
||
| public class ItemMaxDurability extends ItemProperty<ElementTag> { | ||
|
|
||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name max_durability | ||
| // @input ElementTag | ||
| // @description | ||
| // Controls the maximum durability of an item, if it can have durability. | ||
| // If the item cannot have durability (e.g. is not a tool or armor), this will return null. | ||
| // @tag | ||
| // If the item does not have a max durability item component set, this will return the default max durability for the item type. | ||
| // --> | ||
|
Comment on lines
+20
to
+21
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is specific to the tag, and should be under |
||
|
|
||
| public static boolean describes(ItemTag item) { | ||
| return item.getBukkitMaterial() != Material.AIR | ||
| && item.getItemMeta() instanceof Damageable; | ||
| } | ||
|
|
||
| @Override | ||
| public ElementTag getPropertyValue() { | ||
| if (getItemMeta() instanceof Damageable damageable) { | ||
| if (damageable.hasMaxDamage()) { | ||
| return new ElementTag(damageable.getMaxDamage()); | ||
| } | ||
| else { | ||
| return new ElementTag(getItemStack().getType().getMaxDurability()); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(ElementTag element, Mechanism mechanism) { | ||
| editMeta(ItemMeta.class, meta -> { | ||
|
Comment on lines
+42
to
+43
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, needs to handle |
||
| if (meta instanceof Damageable damageable) { | ||
| if (element == null) { | ||
| damageable.setMaxDamage((int) getItemStack().getType().getMaxDurability()); | ||
| } | ||
| else if (mechanism.requireInteger()) { | ||
| damageable.setMaxDamage(element.asInt()); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "max_durability"; | ||
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("max_durability", ItemMaxDurability.class, ElementTag.class, false); | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemMaxStackSize.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.denizenscript.denizen.objects.properties.item; | ||
|
|
||
| import com.denizenscript.denizen.objects.ItemTag; | ||
| import com.denizenscript.denizencore.objects.Mechanism; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
|
|
||
| public class ItemMaxStackSize extends ItemProperty<ElementTag> { | ||
|
|
||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name max_stack_size | ||
| // @input ElementTag | ||
| // @description | ||
| // Controls the maximum stack size of the item. | ||
| // @mechanism | ||
| // Provide no input to reset the max stack size to the default for the item type. | ||
| // --> | ||
|
|
||
| public static boolean describes(ItemTag item) { | ||
| return item.getBukkitMaterial() != Material.AIR; | ||
| } | ||
|
|
||
| @Override | ||
| public ElementTag getPropertyValue() { | ||
| if (getItemMeta().hasMaxStackSize()) { | ||
| return new ElementTag(getItemMeta().getMaxStackSize()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(ElementTag element, Mechanism mechanism) { | ||
| editMeta(ItemMeta.class, meta -> { | ||
| if (element == null) { | ||
| meta.setMaxStackSize(getItemStack().getType().getMaxStackSize()); | ||
| } | ||
| else { | ||
| meta.setMaxStackSize(element.asInt()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "max_stack_size"; | ||
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("max_stack_size", ItemMaxStackSize.class, ElementTag.class, false); | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemModel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.denizenscript.denizen.objects.properties.item; | ||
|
|
||
| import com.denizenscript.denizen.objects.ItemTag; | ||
| import com.denizenscript.denizen.utilities.Utilities; | ||
| import com.denizenscript.denizencore.objects.Mechanism; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
|
|
||
| public class ItemModel extends ItemProperty<ElementTag> { | ||
|
|
||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name item_model | ||
| // @input ElementTag | ||
| // @description | ||
| // Controls the item model of the item in namespaced key format, if any. | ||
| // @mechanism | ||
| // Provide no input to remove the item model component from the item. | ||
| // --> | ||
|
|
||
| public static boolean describes(ItemTag item) { | ||
| return item.getBukkitMaterial() != Material.AIR; | ||
| } | ||
|
|
||
| @Override | ||
| public ElementTag getPropertyValue() { | ||
| if (getItemMeta().hasItemModel()) { | ||
| return new ElementTag(Utilities.namespacedKeyToString(getItemMeta().getItemModel())); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(ElementTag element, Mechanism mechanism) { | ||
| editMeta(ItemMeta.class, meta -> { | ||
| if (element == null) { | ||
| meta.setItemModel(null); | ||
| } | ||
| else { | ||
| meta.setItemModel(Utilities.parseNamespacedKey(element.toString())); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "item_model"; | ||
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("item_model", ItemModel.class, ElementTag.class, false); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessarily the case? with item components you should be able to give any item durability (also true for other properties here, the point of item components is that you can kinda give any item any component).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items can't be stackable and be damageable unfortunately.