Update explosive hammer
This commit is contained in:
parent
192b26e8ab
commit
aaecbf8ae5
@ -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 <V : Any> immutableList(a: V, vararg values: V): ImmutableList<V> {
|
||||
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))
|
||||
}
|
||||
|
@ -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<Attribute, AttributeModifier> {
|
||||
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)
|
||||
|
@ -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")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user