Skip to content

Commit

Permalink
feat(despoil-loot): damage durability of held despoil sickle when dro…
Browse files Browse the repository at this point in the history
…pping loot
  • Loading branch information
Elenterius committed Jun 16, 2023
1 parent 8c25845 commit 798bcd7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private void addItemTranslations() {
addItem(ModItems.VOLATILE_FLUID, "Volatile Fluid", "Combustible extract, needs further processing to be more dangerous.");
addItem(ModItems.BILE, "Bile", "Organic base material which is often used in bio-alchemy.");

addItem(ModItems.DESPOIL_SICKLE, "[PH] Flesh Plunderer", "A very brittle yet highly specialized tool for pillaging special loot from dying mobs.\nWhen last hitting mobs the tool receives less damage.");
addItem(ModItems.DESPOIL_SICKLE, "[PH] Flesh Plunderer", "A very brittle yet highly specialized tool for pillaging special loot from dying mobs.\n\nWhen held in any Hand the tool guarantees Despoil Loot to drop while receiving additional durability damage.");
addItem(ModItems.VIAL, "Organic Vial", "A small organic container with very high alchemical resistance, perfect for holding reactive substances.\nThe vial dissolves on use.");
addItem(ModItems.LIVING_FLESH, "Living Flesh", "It's alive!\nBut it looks too dumb to be the brain of a mob. You should turn it into a construct.");
addItem(ModItems.PRIMORDIAL_CORE, "Primordial Core", "[WIP] A ominous artifact made of flesh. It makes you feel uneasy...");
Expand Down
2 changes: 1 addition & 1 deletion src/generated/resources/assets/biomancy/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"item.biomancy.bile": "Bile",
"item.biomancy.bile.tooltip": "Organic base material which is often used in bio-alchemy.",
"item.biomancy.despoil_sickle": "[PH] Flesh Plunderer",
"item.biomancy.despoil_sickle.tooltip": "A very brittle yet highly specialized tool for pillaging special loot from dying mobs.\nWhen last hitting mobs the tool receives less damage.",
"item.biomancy.despoil_sickle.tooltip": "A very brittle yet highly specialized tool for pillaging special loot from dying mobs.\n\nWhen held in any Hand the tool guarantees Despoil Loot to drop while receiving additional durability damage.",
"item.biomancy.vial": "Organic Vial",
"item.biomancy.vial.tooltip": "A small organic container with very high alchemical resistance, perfect for holding reactive substances.\nThe vial dissolves on use.",
"item.biomancy.living_flesh": "Living Flesh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public int getEnchantmentLevel(ItemStack stack, Enchantment enchantment) {

@Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
int itemDamage = target.isDeadOrDying() ? 1 : 5;
stack.hurtAndBreak(itemDamage, attacker, a -> a.broadcastBreakEvent(EquipmentSlot.MAINHAND));
stack.hurtAndBreak(5, attacker, a -> a.broadcastBreakEvent(EquipmentSlot.MAINHAND));
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.warden.Warden;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -96,10 +97,19 @@ protected static int getDespoilLevel(ItemStack stack) {
return stack.getEnchantmentLevel(ModEnchantments.DESPOIL.get());
}

protected static boolean isHolding(LootContext lootContext, Item item) {
protected static boolean hurtAndBreak(LootContext lootContext, Item item, int amount) {
Entity killer = lootContext.getParamOrNull(LootContextParams.KILLER_ENTITY);

if (killer instanceof LivingEntity livingEntity) {
return livingEntity.isHolding(item);
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
if (equipmentSlot.getType() == EquipmentSlot.Type.HAND) {
ItemStack stack = livingEntity.getItemBySlot(equipmentSlot);
if (stack.is(item)) {
stack.hurtAndBreak(amount, livingEntity, user -> user.broadcastBreakEvent(equipmentSlot));
return true;
}
}
}
}

return false;
Expand Down Expand Up @@ -145,7 +155,7 @@ protected ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generate
DynamicLootTable lootTable = buildLootTable(victim);
if (lootTable.isEmpty()) return generatedLoot;

if (!isHolding(context, ModItems.DESPOIL_SICKLE.get())) {
if (!hurtAndBreak(context, ModItems.DESPOIL_SICKLE.get(), 1)) {
lootTable.add(EMPTY, 15); //only the despoil sickle has a 100% guarantee to drop despoil loot
}

Expand Down

0 comments on commit 798bcd7

Please sign in to comment.