From 0736259b11b698b1995a587344dd99144aa5df10 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 26 Oct 2022 21:07:41 +0700 Subject: [PATCH] Wearing tritanium leggings and boots disable sweet berry bush damage Fixes #164 --- .../dbotthepony/mc/otm/OverdriveThatMatters.java | 2 ++ .../dbotthepony/mc/otm/item/TritaniumArmorItem.kt | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 679eb93d3..de072a52c 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -34,6 +34,7 @@ import ru.dbotthepony.mc.otm.client.render.WidgetAtlasHolder; import ru.dbotthepony.mc.otm.compat.mekanism.QIOKt; import ru.dbotthepony.mc.otm.compat.mekanism.TooltipsKt; import ru.dbotthepony.mc.otm.core.ImpreciseFraction; +import ru.dbotthepony.mc.otm.item.ItemTritaniumArmor; import ru.dbotthepony.mc.otm.item.QuantumBatteryItem; import ru.dbotthepony.mc.otm.item.weapon.AbstractWeaponItem; import ru.dbotthepony.mc.otm.item.PortableCondensationDriveItem; @@ -149,6 +150,7 @@ public final class OverdriveThatMatters { EVENT_BUS.addListener(EventPriority.LOWEST, SynchronizedBlockEntity.Companion::postLevelTick); EVENT_BUS.addListener(EventPriority.NORMAL, EnderTeleporterFeature.Companion::onEntityDeath); + EVENT_BUS.addListener(EventPriority.HIGH, ItemTritaniumArmor.Companion::onHurt); MatteryPlayerNetworkChannel.INSTANCE.register(); MenuNetworkChannel.INSTANCE.register(); diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/TritaniumArmorItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/TritaniumArmorItem.kt index c8ba240d3..1b703eb9e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/TritaniumArmorItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/TritaniumArmorItem.kt @@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.item import net.minecraft.client.model.HumanoidModel import net.minecraft.sounds.SoundEvent import net.minecraft.sounds.SoundEvents +import net.minecraft.world.damagesource.DamageSource import net.minecraft.world.entity.Entity import net.minecraft.world.entity.EquipmentSlot import net.minecraft.world.entity.LivingEntity @@ -12,9 +13,12 @@ import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Rarity import net.minecraft.world.item.crafting.Ingredient import net.minecraftforge.client.extensions.common.IClientItemExtensions +import net.minecraftforge.event.entity.living.LivingAttackEvent +import net.minecraftforge.event.entity.living.LivingHurtEvent import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.client.model.TritaniumArmorModel import ru.dbotthepony.mc.otm.registry.MItemTags +import ru.dbotthepony.mc.otm.registry.MItems import java.util.function.Consumer private object TritaniumArmorMaterial : ArmorMaterial { @@ -76,5 +80,16 @@ class ItemTritaniumArmor(slot: EquipmentSlot) : ArmorItem(TritaniumArmorMaterial companion object { const val TEXTURE_LOCATION = "${OverdriveThatMatters.MOD_ID}:textures/models/armor/tritanium_armor.png" + + fun onHurt(event: LivingAttackEvent) { + if (event.source === DamageSource.SWEET_BERRY_BUSH || event.source.msgId == "sweetBerryBush") { + if ( + event.entity.getItemBySlot(EquipmentSlot.FEET).let { !it.isEmpty && it.item == MItems.TRITANIUM_BOOTS } && + event.entity.getItemBySlot(EquipmentSlot.LEGS).let { !it.isEmpty && it.item == MItems.TRITANIUM_PANTS } + ) { + event.isCanceled = true + } + } + } } }