Skip to content

Commit

Permalink
Add config to allow max tool level damage
Browse files Browse the repository at this point in the history
Signed-off-by: Savage <[email protected]>
  • Loading branch information
devsavage committed May 14, 2020
1 parent 60c92e7 commit 1ce5b70
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ModConfiguration
}

public static final ForgeConfigSpec.IntValue MAX_SOUL_TOOL_LEVEL;
public static final ForgeConfigSpec.BooleanValue SHOULD_DAMAGE_MAX_TOOL;

static {
final ForgeConfigSpec.Builder common = new ForgeConfigSpec.Builder();
Expand All @@ -48,6 +49,9 @@ public class ModConfiguration
.comment("This number handles the Soul Matter Tool max tool level. When the tool reaches this number, it will have max abilities.")
.translation("configGui.soulmatter.max_soul_tool_level")
.defineInRange("maxSoulToolLevel", 3, 2, 8);
SHOULD_DAMAGE_MAX_TOOL = common.comment("Damage Soul Matter Tools that have reached max level")
.translation("configGui.soulmatter.should_damage_max_tool_level")
.define("shouldDamageMaxTool", false);

common.pop();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.google.common.collect.ImmutableSet;
import io.savagedev.soulmatter.handlers.SoulToolLevelHandler;
import io.savagedev.soulmatter.init.ModConfiguration;
import io.savagedev.soulmatter.init.ModItems;
import io.savagedev.soulmatter.init.ModToolTier;
import io.savagedev.soulmatter.util.LogHelper;
Expand Down Expand Up @@ -90,9 +91,15 @@ public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity atta
event.sendBreakAnimation(attacker.getActiveHand());
});
} else {
stack.damageItem(0, attacker, (event) -> {
event.sendBreakAnimation(attacker.getActiveHand());
});
if(ModConfiguration.SHOULD_DAMAGE_MAX_TOOL.get()) {
stack.damageItem(1, attacker, (event) -> {
event.sendBreakAnimation(attacker.getActiveHand());
});
} else {
stack.damageItem(0, attacker, (event) -> {
event.sendBreakAnimation(attacker.getActiveHand());
});
}
}

return true;
Expand All @@ -112,19 +119,31 @@ public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state
event.sendBreakAnimation(entityLiving.getActiveHand());
});
} else {
stack.damageItem(0, entityLiving, (event) -> {
event.sendBreakAnimation(entityLiving.getActiveHand());
});
if(ModConfiguration.SHOULD_DAMAGE_MAX_TOOL.get()) {
stack.damageItem(1, entityLiving, (event) -> {
event.sendBreakAnimation(entityLiving.getActiveHand());
});
} else {
stack.damageItem(0, entityLiving, (event) -> {
event.sendBreakAnimation(entityLiving.getActiveHand());
});
}
}
} else {
if(!SoulToolLevelHandler.isMaxToolLevel(stack)) {
stack.damageItem(1, entityLiving, (event) -> {
event.sendBreakAnimation(entityLiving.getActiveHand());
});
} else {
stack.damageItem(0, entityLiving, (event) -> {
event.sendBreakAnimation(entityLiving.getActiveHand());
});
if(ModConfiguration.SHOULD_DAMAGE_MAX_TOOL.get()) {
stack.damageItem(1, entityLiving, (event) -> {
event.sendBreakAnimation(entityLiving.getActiveHand());
});
} else {
stack.damageItem(0, entityLiving, (event) -> {
event.sendBreakAnimation(entityLiving.getActiveHand());
});
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import io.savagedev.soulmatter.handlers.SoulToolLevelHandler;
import io.savagedev.soulmatter.init.ModConfiguration;
import io.savagedev.soulmatter.init.ModItems;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -93,16 +94,22 @@ public ActionResultType onItemUse(ItemUseContext context) {
if (!world.isRemote) {
world.setBlockState(blockpos, blockstate, 11);
if (playerentity != null) {
if(SoulToolLevelHandler.hasLevelTags(context.getItem()) && !SoulToolLevelHandler.isMaxToolLevel(context.getItem())) {
if(!SoulToolLevelHandler.isMaxToolLevel(context.getItem())) {
SoulToolLevelHandler.addXp(context.getItem(), playerentity, MathHelper.nextInt(new Random(), 2, 8));

context.getItem().damageItem(1, playerentity, (hand) -> {
hand.sendBreakAnimation(context.getHand());
});
} else {
context.getItem().damageItem(0, playerentity, (hand) -> {
hand.sendBreakAnimation(context.getHand());
});
if(ModConfiguration.SHOULD_DAMAGE_MAX_TOOL.get()) {
context.getItem().damageItem(1, context.getPlayer(), (event) -> {
event.sendBreakAnimation(context.getPlayer().getActiveHand());
});
} else {
context.getItem().damageItem(0, context.getPlayer(), (event) -> {
event.sendBreakAnimation(context.getPlayer().getActiveHand());
});
}
}

}
Expand Down

0 comments on commit 1ce5b70

Please sign in to comment.