manual hammer priming
This commit is contained in:
parent
636afe639e
commit
0e83e08ec6
@ -9,7 +9,10 @@ import net.minecraft.network.chat.Component
|
|||||||
import net.minecraft.network.protocol.game.ClientboundExplodePacket
|
import net.minecraft.network.protocol.game.ClientboundExplodePacket
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.server.level.ServerPlayer
|
import net.minecraft.server.level.ServerPlayer
|
||||||
|
import net.minecraft.sounds.SoundEvents
|
||||||
|
import net.minecraft.sounds.SoundSource
|
||||||
import net.minecraft.world.InteractionHand
|
import net.minecraft.world.InteractionHand
|
||||||
|
import net.minecraft.world.InteractionResultHolder
|
||||||
import net.minecraft.world.damagesource.DamageSource
|
import net.minecraft.world.damagesource.DamageSource
|
||||||
import net.minecraft.world.entity.EquipmentSlot
|
import net.minecraft.world.entity.EquipmentSlot
|
||||||
import net.minecraft.world.entity.LivingEntity
|
import net.minecraft.world.entity.LivingEntity
|
||||||
@ -21,38 +24,24 @@ import net.minecraft.world.entity.player.Player
|
|||||||
import net.minecraft.world.item.Item
|
import net.minecraft.world.item.Item
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.item.TooltipFlag
|
import net.minecraft.world.item.TooltipFlag
|
||||||
|
import net.minecraft.world.item.UseAnim
|
||||||
import net.minecraft.world.level.Explosion
|
import net.minecraft.world.level.Explosion
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.phys.AABB
|
import net.minecraft.world.phys.AABB
|
||||||
import net.minecraft.world.phys.Vec3
|
import net.minecraft.world.phys.Vec3
|
||||||
import net.minecraftforge.common.MinecraftForge
|
import net.minecraftforge.common.MinecraftForge
|
||||||
|
import net.minecraftforge.common.Tags
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent
|
||||||
import net.minecraftforge.event.level.BlockEvent
|
import net.minecraftforge.event.level.BlockEvent
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
|
||||||
import ru.dbotthepony.mc.otm.config.ItemsConfig
|
|
||||||
import ru.dbotthepony.mc.otm.config.ToolsConfig
|
import ru.dbotthepony.mc.otm.config.ToolsConfig
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
import ru.dbotthepony.mc.otm.core.damageType
|
import ru.dbotthepony.mc.otm.core.math.*
|
||||||
import ru.dbotthepony.mc.otm.core.getExplosionResistance
|
|
||||||
import ru.dbotthepony.mc.otm.core.gracefulBlockBreak
|
|
||||||
import ru.dbotthepony.mc.otm.core.immutableMap
|
|
||||||
import ru.dbotthepony.mc.otm.core.immutableMultimap
|
|
||||||
import ru.dbotthepony.mc.otm.core.isExplosion
|
|
||||||
import ru.dbotthepony.mc.otm.core.math.component1
|
|
||||||
import ru.dbotthepony.mc.otm.core.math.component2
|
|
||||||
import ru.dbotthepony.mc.otm.core.math.component3
|
|
||||||
import ru.dbotthepony.mc.otm.core.math.plus
|
|
||||||
import ru.dbotthepony.mc.otm.core.math.times
|
|
||||||
import ru.dbotthepony.mc.otm.core.math.toDoubleVector
|
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||||
import ru.dbotthepony.mc.otm.core.position
|
|
||||||
import ru.dbotthepony.mc.otm.core.tagNotNull
|
|
||||||
import ru.dbotthepony.mc.otm.item.weapon.EnergySwordItem
|
|
||||||
import ru.dbotthepony.mc.otm.registry.MDamageTypes
|
import ru.dbotthepony.mc.otm.registry.MDamageTypes
|
||||||
import ru.dbotthepony.mc.otm.registry.MRegistry
|
|
||||||
import ru.dbotthepony.mc.otm.registry.MatteryDamageSource
|
import ru.dbotthepony.mc.otm.registry.MatteryDamageSource
|
||||||
import ru.dbotthepony.mc.otm.triggers.NailedEntityTrigger
|
import ru.dbotthepony.mc.otm.triggers.NailedEntityTrigger
|
||||||
|
import java.util.function.Predicate
|
||||||
|
|
||||||
class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1).fireResistant().durability(durability)) {
|
class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1).fireResistant().durability(durability)) {
|
||||||
override fun canBeHurtBy(pDamageSource: DamageSource): Boolean {
|
override fun canBeHurtBy(pDamageSource: DamageSource): Boolean {
|
||||||
@ -72,6 +61,11 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1)
|
|||||||
itemStack.tagNotNull["primed"] = false
|
itemStack.tagNotNull["primed"] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun canPrime(player: Player): Boolean {
|
||||||
|
return player.inventory.clearOrCountMatchingItems(GUNPOWDER_PREDICATE, 0, player.inventoryMenu.craftSlots) > 0 &&
|
||||||
|
player.inventory.clearOrCountMatchingItems(IRON_NUGGET_PREDICATE, 0, player.inventoryMenu.craftSlots) > 0
|
||||||
|
}
|
||||||
|
|
||||||
private val aabb = AABB(-0.1, -0.1, -0.1, 0.1, 0.1, 0.1)
|
private val aabb = AABB(-0.1, -0.1, -0.1, 0.1, 0.1, 0.1)
|
||||||
|
|
||||||
val attributes = immutableMultimap {
|
val attributes = immutableMultimap {
|
||||||
@ -228,7 +222,44 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getUseAnimation(stack: ItemStack): UseAnim {
|
||||||
|
return if (isPrimed(stack)) super.getUseAnimation(stack) else UseAnim.CROSSBOW
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getUseDuration(stack: ItemStack): Int {
|
||||||
|
return if (isPrimed(stack)) super.getUseDuration(stack) else 20
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun use(level: Level, player: Player, hand: InteractionHand): InteractionResultHolder<ItemStack> {
|
||||||
|
val stack = player.getItemInHand(hand)
|
||||||
|
|
||||||
|
if (stack.isEmpty || isPrimed(stack) || !canPrime(player))
|
||||||
|
return super.use(level, player, hand)
|
||||||
|
|
||||||
|
player.startUsingItem(hand)
|
||||||
|
return InteractionResultHolder.consume(stack)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun finishUsingItem(stack: ItemStack, level: Level, entity: LivingEntity): ItemStack {
|
||||||
|
|
||||||
|
if (entity is Player && canPrime(entity)) {
|
||||||
|
if (level is ServerLevel) {
|
||||||
|
entity.inventory.clearOrCountMatchingItems(GUNPOWDER_PREDICATE, 1, entity.inventoryMenu.craftSlots)
|
||||||
|
entity.inventory.clearOrCountMatchingItems(IRON_NUGGET_PREDICATE, 1, entity.inventoryMenu.craftSlots)
|
||||||
|
|
||||||
|
prime(stack)
|
||||||
|
}
|
||||||
|
|
||||||
|
level.playSound(entity, entity.blockPosition(), SoundEvents.CROSSBOW_LOADING_END, SoundSource.PLAYERS, 1.0F, 1.0F)
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.finishUsingItem(stack, level, entity)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
val GUNPOWDER_PREDICATE = Predicate { stack: ItemStack -> stack.`is`(Tags.Items.GUNPOWDER) }
|
||||||
|
val IRON_NUGGET_PREDICATE = Predicate { stack: ItemStack -> stack.`is`(Tags.Items.NUGGETS_IRON) }
|
||||||
|
|
||||||
fun onLeftClickBlock(event: PlayerInteractEvent.LeftClickBlock) {
|
fun onLeftClickBlock(event: PlayerInteractEvent.LeftClickBlock) {
|
||||||
val item = event.itemStack.item
|
val item = event.itemStack.item
|
||||||
|
|
||||||
|
@ -336,8 +336,16 @@ object MRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemProperties.register(MItems.EXPLOSIVE_HAMMER, ResourceLocation(OverdriveThatMatters.MOD_ID, "is_primed")) { stack, _, _, _ ->
|
ItemProperties.register(MItems.EXPLOSIVE_HAMMER, ResourceLocation(OverdriveThatMatters.MOD_ID, "is_primed")) { stack, level, entity, _ ->
|
||||||
if (MItems.EXPLOSIVE_HAMMER.isPrimed(stack)) 1f else 0f
|
if (MItems.EXPLOSIVE_HAMMER.isPrimed(stack)) {
|
||||||
|
1f
|
||||||
|
} else {
|
||||||
|
if ((entity?.useItemRemainingTicks ?: 0) <= 0) {
|
||||||
|
0f
|
||||||
|
} else {
|
||||||
|
(stack.useDuration - (entity?.useItemRemainingTicks ?: stack.useDuration)).toFloat() / stack.useDuration
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"overrides": [
|
"overrides": [
|
||||||
|
{ "predicate": { "overdrive_that_matters:is_primed": 0.01 }, "model": "overdrive_that_matters:item/explosive_hammer_charging" },
|
||||||
{ "predicate": { "overdrive_that_matters:is_primed": 1.0 }, "model": "overdrive_that_matters:item/explosive_hammer_primed" }
|
{ "predicate": { "overdrive_that_matters:is_primed": 1.0 }, "model": "overdrive_that_matters:item/explosive_hammer_primed" }
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"loader": "forge:separate_transforms",
|
||||||
|
"gui_light": "front",
|
||||||
|
"base":
|
||||||
|
{
|
||||||
|
"parent": "overdrive_that_matters:item/explosive_hammer_unprimed",
|
||||||
|
"display": {
|
||||||
|
"thirdperson_righthand": {
|
||||||
|
"rotation": [0, 45, 0],
|
||||||
|
"translation": [0, -10, 5]
|
||||||
|
},
|
||||||
|
"thirdperson_lefthand": {
|
||||||
|
"rotation": [0, 45, 0],
|
||||||
|
"translation": [0, -10, 5]
|
||||||
|
},
|
||||||
|
"firstperson_righthand": {
|
||||||
|
"rotation": [-65, 0, 75],
|
||||||
|
"translation": [5, -7.5, -10]
|
||||||
|
},
|
||||||
|
"firstperson_lefthand": {
|
||||||
|
"rotation": [-65, 0, 75],
|
||||||
|
"translation": [5, -7.5, -10]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"perspectives": {
|
||||||
|
"gui": {
|
||||||
|
"parent": "overdrive_that_matters:item/explosive_hammer_inventory"
|
||||||
|
},
|
||||||
|
"fixed": {
|
||||||
|
"parent": "overdrive_that_matters:item/explosive_hammer_inventory"
|
||||||
|
},
|
||||||
|
"ground": {
|
||||||
|
"parent": "overdrive_that_matters:item/explosive_hammer_inventory"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user