Skip to content

Commit

Permalink
Finalise affix implementation and close #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Beaucamps committed Feb 1, 2020
1 parent 63514b8 commit 68a046c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +41,9 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
}
Optional<ItemStack> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +36,8 @@ public ItemStack apply(ItemStack itemStack) {
}

private ItemStack setAttribute(ItemStack itemStack) {
List<DataContainer> containers = new ArrayList<>();
List<DataView> containers = itemStack.toContainer().getViewList(DataQuery.of("UnsafeData", "AttributeModifiers")).orElse(new ArrayList<>());

if (getAttributes().isEmpty()) {
return itemStack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
9 changes: 6 additions & 3 deletions src/main/java/com/onaple/itemizer/utils/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,9 +57,11 @@ public ItemBean registerItem(String id, ItemStack stack) {
}

private ItemStack applyAffix(ItemStack itemStack, ItemBean item) {
Optional<AffixFactory> optionalAffixFactory = probabilityFetcher.fetcher(item.getAffix().getTiers());
if (optionalAffixFactory.isPresent()) {
itemStack = optionalAffixFactory.get().apply(itemStack);
if (Objects.nonNull(item.getAffix())) {
Optional<AffixFactory> optionalAffixFactory = probabilityFetcher.fetcher(item.getAffix().getTiers());
if (optionalAffixFactory.isPresent()) {
itemStack = optionalAffixFactory.get().apply(itemStack);
}
}
return itemStack;
}
Expand Down
81 changes: 71 additions & 10 deletions src/main/resources/assets/itemizer/items.conf
Original file line number Diff line number Diff line change
@@ -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
}
]
]
4 changes: 2 additions & 2 deletions version.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 68a046c

Please sign in to comment.