From 68a046c85fa62704f87e52686726bcd6727f775d Mon Sep 17 00:00:00 2001 From: Hugo Beaucamps Date: Sat, 1 Feb 2020 10:35:50 +0100 Subject: [PATCH] Finalise affix implementation and close #18 --- .../itemizer/commands/RegisterCommand.java | 4 + .../itemizer/data/beans/affix/AffixTier.java | 4 +- .../data/serializers/AffixNameAdapter.java | 2 +- .../onaple/itemizer/utils/ItemBuilder.java | 9 ++- src/main/resources/assets/itemizer/items.conf | 81 ++++++++++++++++--- version.properties | 4 +- 6 files changed, 87 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/onaple/itemizer/commands/RegisterCommand.java b/src/main/java/com/onaple/itemizer/commands/RegisterCommand.java index c0073fa..ee96351 100644 --- a/src/main/java/com/onaple/itemizer/commands/RegisterCommand.java +++ b/src/main/java/com/onaple/itemizer/commands/RegisterCommand.java @@ -2,6 +2,7 @@ import com.onaple.itemizer.Itemizer; +import com.onaple.itemizer.ItemizerKeys; import com.onaple.itemizer.data.beans.ItemBean; import com.onaple.itemizer.utils.ItemBuilder; import org.spongepowered.api.command.CommandException; @@ -40,6 +41,9 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm } Optional itemStackOptional = ((Player) src).getItemInHand(HandTypes.MAIN_HAND); if(itemStackOptional.isPresent()){ + if(itemStackOptional.get().get(ItemizerKeys.ITEM_ID).isPresent()) { + throw new CommandException(Text.of("Item already registered")); + } ItemBean itemRegistered = builder.registerItem(itemId, itemStackOptional.get()); ItemStack buildItemStack = builder.buildItemStack(itemRegistered); ((Player) src).setItemInHand(HandTypes.MAIN_HAND,buildItemStack); diff --git a/src/main/java/com/onaple/itemizer/data/beans/affix/AffixTier.java b/src/main/java/com/onaple/itemizer/data/beans/affix/AffixTier.java index 120ddd7..1f4439e 100644 --- a/src/main/java/com/onaple/itemizer/data/beans/affix/AffixTier.java +++ b/src/main/java/com/onaple/itemizer/data/beans/affix/AffixTier.java @@ -10,6 +10,7 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.spongepowered.api.data.DataContainer; import org.spongepowered.api.data.DataQuery; +import org.spongepowered.api.data.DataView; import org.spongepowered.api.data.key.Keys; import org.spongepowered.api.entity.Item; import org.spongepowered.api.item.inventory.ItemStack; @@ -35,7 +36,8 @@ public ItemStack apply(ItemStack itemStack) { } private ItemStack setAttribute(ItemStack itemStack) { - List containers = new ArrayList<>(); + List containers = itemStack.toContainer().getViewList(DataQuery.of("UnsafeData", "AttributeModifiers")).orElse(new ArrayList<>()); + if (getAttributes().isEmpty()) { return itemStack; } diff --git a/src/main/java/com/onaple/itemizer/data/serializers/AffixNameAdapter.java b/src/main/java/com/onaple/itemizer/data/serializers/AffixNameAdapter.java index 6719558..d411c2a 100644 --- a/src/main/java/com/onaple/itemizer/data/serializers/AffixNameAdapter.java +++ b/src/main/java/com/onaple/itemizer/data/serializers/AffixNameAdapter.java @@ -26,6 +26,6 @@ public AffixBean deserialize(@NonNull TypeToken type, @NonNull ConfigurationN @Override public void serialize(@NonNull TypeToken type, @Nullable AffixBean obj, @NonNull ConfigurationNode value) throws ObjectMappingException { - + value.setValue(obj.getGroupName()); } } diff --git a/src/main/java/com/onaple/itemizer/utils/ItemBuilder.java b/src/main/java/com/onaple/itemizer/utils/ItemBuilder.java index 67d8b16..41321dd 100755 --- a/src/main/java/com/onaple/itemizer/utils/ItemBuilder.java +++ b/src/main/java/com/onaple/itemizer/utils/ItemBuilder.java @@ -11,6 +11,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import java.util.Comparator; +import java.util.Objects; import java.util.Optional; import java.util.Random; import java.util.Set; @@ -56,9 +57,11 @@ public ItemBean registerItem(String id, ItemStack stack) { } private ItemStack applyAffix(ItemStack itemStack, ItemBean item) { - Optional optionalAffixFactory = probabilityFetcher.fetcher(item.getAffix().getTiers()); - if (optionalAffixFactory.isPresent()) { - itemStack = optionalAffixFactory.get().apply(itemStack); + if (Objects.nonNull(item.getAffix())) { + Optional optionalAffixFactory = probabilityFetcher.fetcher(item.getAffix().getTiers()); + if (optionalAffixFactory.isPresent()) { + itemStack = optionalAffixFactory.get().apply(itemStack); + } } return itemStack; } diff --git a/src/main/resources/assets/itemizer/items.conf b/src/main/resources/assets/itemizer/items.conf index 78fbe6b..6f53ad4 100755 --- a/src/main/resources/assets/itemizer/items.conf +++ b/src/main/resources/assets/itemizer/items.conf @@ -1,33 +1,94 @@ items=[ { - id="1" + id="training_stick" item { ContentVersion=2 Count=1 - ItemType="minecraft:coal" + Data=[ + { + ContentVersion=2 + ManipulatorData { + "." { + id="training_stick" + } + ContentVersion=1 + } + ManipulatorId="itemizer:item.id" + } + ] + ItemType="minecraft:stick" UnsafeDamage=0 UnsafeData { - RepairCost=0 + AttributeModifiers=[ + { + Amount=2 + AttributeName="generic.maxHealth" + Name="generic.maxHealth" + Operation=0 + Slot=mainhand + UUIDLeast=123 + UUIDMost=857 + } + ] display { - Name="Tin ore" + Lore=[ + "Used by recrue in their practice" + ] + Name="Training Stick" } - id="1" } } thirdParties=[] }, { - id="king_sword" + id="barbarian_axe" item { ContentVersion=2 Count=1 - ItemType="minecraft:golden_sword" + Data=[ + { + ContentVersion=2 + ManipulatorData { + "." { + id="barbarian_axe" + } + ContentVersion=1 + } + ManipulatorId="itemizer:item.id" + } + ] + ItemType="minecraft:iron_axe" UnsafeDamage=0 UnsafeData { - id="king_sword" + AttributeModifiers=[ + { + Amount=5 + AttributeName="generic.attackDamage" + Name="generic.attackDamage" + Operation=0 + Slot=mainhand + UUIDLeast=160005 + UUIDMost=13658 + }, + { + Amount=-0.1 + AttributeName="generic.attackSpeed" + Name="generic.attackSpeed" + Operation=1 + Slot=mainhand + UUIDLeast=169991 + UUIDMost=15894 + } + ] + display { + Lore=[ + "Nobody have whet this blade yet", + "however it still can sharp your finger" + ] + Name="Barbarian Axe" + } } } thirdParties=[] - affix=flatDamageBoost } -] \ No newline at end of file +] diff --git a/version.properties b/version.properties index 03f227e..3c07b9d 100644 --- a/version.properties +++ b/version.properties @@ -1,7 +1,7 @@ -#Wed Jan 29 23:25:17 CET 2020 +#Sat Feb 01 10:15:08 CET 2020 MAJOR=3 MINOR=0 PATCH=0 PRE_RELEASE= -BUILD=501 +BUILD=504 CODE=0