diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt index cb8641ab3..0529123c4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt @@ -31,6 +31,7 @@ import net.minecraft.tags.TagKey import net.minecraft.world.entity.Entity import net.minecraft.world.item.Item import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.component.ItemAttributeModifiers import net.minecraft.world.item.crafting.CraftingInput import net.minecraft.world.item.crafting.RecipeInput import net.minecraft.world.level.BlockGetter @@ -200,6 +201,12 @@ fun immutableList(a: V, vararg values: V): ImmutableList { return builder.build() } +inline fun itemAttributes(builder: ItemAttributeModifiers.Builder.() -> Unit): ItemAttributeModifiers { + val value = ItemAttributeModifiers.builder() + builder(value) + return value.build() +} + fun FriendlyByteBuf.writeItemType(value: Item) { writeInt(BuiltInRegistries.ITEM.getId(value)) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/tool/ExplosiveHammerItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/tool/ExplosiveHammerItem.kt index 3a3ec4e4e..8fcdb6015 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/tool/ExplosiveHammerItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/tool/ExplosiveHammerItem.kt @@ -5,6 +5,7 @@ import com.google.common.collect.Multimap import it.unimi.dsi.fastutil.objects.ObjectArraySet import net.minecraft.ChatFormatting import net.minecraft.core.BlockPos +import net.minecraft.core.particles.ParticleTypes import net.minecraft.network.chat.Component import net.minecraft.network.protocol.game.ClientboundExplodePacket import net.minecraft.server.level.ServerLevel @@ -15,6 +16,7 @@ import net.minecraft.world.InteractionHand import net.minecraft.world.InteractionResultHolder import net.minecraft.world.damagesource.DamageSource import net.minecraft.world.entity.EquipmentSlot +import net.minecraft.world.entity.EquipmentSlotGroup import net.minecraft.world.entity.LivingEntity import net.minecraft.world.entity.ai.attributes.Attribute import net.minecraft.world.entity.ai.attributes.AttributeModifier @@ -31,9 +33,12 @@ import net.minecraft.world.level.Level import net.minecraft.world.phys.AABB import net.minecraft.world.phys.Vec3 import net.neoforged.neoforge.common.CommonHooks +import net.neoforged.neoforge.common.NeoForge import net.neoforged.neoforge.common.Tags import net.neoforged.neoforge.event.EventHooks import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent +import net.neoforged.neoforge.event.level.BlockEvent +import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.config.ToolsConfig import ru.dbotthepony.mc.otm.core.* @@ -70,9 +75,9 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1) private val aabb = AABB(-0.1, -0.1, -0.1, 0.1, 0.1, 0.1) - val attributes = immutableMultimap { - put(Attributes.ATTACK_DAMAGE, AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", 3.0, AttributeModifier.Operation.ADDITION)) - put(Attributes.ATTACK_SPEED, AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", -3.4, AttributeModifier.Operation.ADDITION)) + private val attributes = itemAttributes { + add(Attributes.ATTACK_DAMAGE, AttributeModifier(BASE_ATTACK_DAMAGE_ID, 3.0, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) + add(Attributes.ATTACK_SPEED, AttributeModifier(BASE_ATTACK_SPEED_ID, -3.4, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) } override fun hasCraftingRemainingItem(itemStack: ItemStack): Boolean = true @@ -82,11 +87,11 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1) if (player.level().isClientSide) return itemStack.copy() if (!isPrimed(itemStack)) { - itemStack.hurtAndBreak(1, player) {} + itemStack.hurtAndBreak(1, player.level() as ServerLevel, player) {} } else { val level = player.level() as ServerLevel - itemStack.hurtAndBreak(level.random.nextInt(1, 20), player) {} + itemStack.hurtAndBreak(level.random.nextInt(1, 20), player.level() as ServerLevel, player) {} unprime(itemStack) val (ex, ey, ez) = Vector.atCenterOf(player.blockPosition()) @@ -101,7 +106,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1) MatteryBlockEntity.watchingPlayers(player.position(), level) .filter { it.position.distanceTo(player.position()) <= 64.0 } .forEach { - it.connection.send(ClientboundExplodePacket(ex, ey, ez, 1f, exp.toBlow, exp.hitPlayers[it])) + it.connection.send(ClientboundExplodePacket(ex, ey, ez, 1f, exp.toBlow, exp.hitPlayers[it], Explosion.BlockInteraction.DESTROY, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE)) } if (!player.isCreative) { @@ -139,14 +144,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1) return itemStack.copy() } - override fun getAttributeModifiers( - slot: EquipmentSlot, - itemStack: ItemStack - ): Multimap { - if (slot != EquipmentSlot.MAINHAND) { - return ImmutableMultimap.of() - } - + override fun getDefaultAttributeModifiers(stack: ItemStack): ItemAttributeModifiers { return attributes } @@ -190,7 +188,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1) if (resist <= canTravel) { canTravel -= resist val cond = ToolsConfig.ExplosiveHammer.DAMAGE_BLOCKS && - (attacker !is Player || level.mayInteract(attacker, blockPos) && !MinecraftForge.EVENT_BUS.post(BlockEvent.BreakEvent(level, blockPos, block, attacker))) + (attacker !is Player || level.mayInteract(attacker, blockPos) && !NeoForge.EVENT_BUS.post(BlockEvent.BreakEvent(level, blockPos, block, attacker)).isCanceled) if (cond) { level.gracefulBlockBreak(blockPos, block) @@ -227,7 +225,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1) MatteryBlockEntity.watchingPlayers(pos, level) .filter { it.position.distanceTo(pos) <= 64.0 } .forEach { - it.connection.send(ClientboundExplodePacket(ex, ey, ez, 1f, exp.toBlow, exp.hitPlayers[it])) + it.connection.send(ClientboundExplodePacket(ex, ey, ez, 1f, exp.toBlow, exp.hitPlayers[it], Explosion.BlockInteraction.DESTROY, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE)) } if (attacker !is Player || !attacker.isCreative) { @@ -318,7 +316,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1) prime(stack) } - level.playSound(entity, entity.blockPosition(), SoundEvents.CROSSBOW_LOADING_END, SoundSource.PLAYERS, 1.0F, 1.0F) + level.playSound(entity, entity.blockPosition(), SoundEvents.CROSSBOW_LOADING_END.value(), SoundSource.PLAYERS, 1.0F, 1.0F) } return super.finishUsingItem(stack, level, entity) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/EnergySwordItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/EnergySwordItem.kt index 6e7a3cf54..e9726af8f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/EnergySwordItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/EnergySwordItem.kt @@ -46,14 +46,14 @@ class EnergySwordItem : MatteryItem(Properties().stacksTo(1).rarity(Rarity.RARE) init { var builder = ItemAttributeModifiers.builder() - builder.add(Attributes.ATTACK_DAMAGE, AttributeModifier(MODIFIER_ID, 11.0, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) - builder.add(Attributes.ATTACK_SPEED, AttributeModifier(MODIFIER_ID, -2.4, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) + builder.add(Attributes.ATTACK_DAMAGE, AttributeModifier(BASE_ATTACK_DAMAGE_ID, 11.0, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) + builder.add(Attributes.ATTACK_SPEED, AttributeModifier(BASE_ATTACK_SPEED_ID, -2.4, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) chargedAttributes = builder.build() builder = ItemAttributeModifiers.builder() - builder.add(Attributes.ATTACK_DAMAGE, AttributeModifier(MODIFIER_ID, 3.5, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) - builder.add(Attributes.ATTACK_SPEED, AttributeModifier(MODIFIER_ID, -2.4, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) + builder.add(Attributes.ATTACK_DAMAGE, AttributeModifier(BASE_ATTACK_DAMAGE_ID, 3.5, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) + builder.add(Attributes.ATTACK_SPEED, AttributeModifier(BASE_ATTACK_SPEED_ID, -2.4, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND) dischargedAttributes = builder.build() } @@ -199,8 +199,6 @@ class EnergySwordItem : MatteryItem(Properties().stacksTo(1).rarity(Rarity.RARE) private var _PLANT_POWER_COST: DecimalConfigValue by WriteOnce() private var _PLANT_POWER_COST_VARIANCE: DecimalConfigValue by WriteOnce() - private val MODIFIER_ID = ResourceLocation(OverdriveThatMatters.MOD_ID, "energy_sword") - fun registerConfig(builder: ModConfigSpec.Builder) { builder.comment("Energy sword values").push("EnergySword")