parent
e2e256cf97
commit
45084e8fe0
@ -2,6 +2,10 @@ package ru.dbotthepony.mc.otm.item
|
||||
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.entity.SlotAccess
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.inventory.ClickAction
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.TooltipFlag
|
||||
@ -73,6 +77,71 @@ class MatterDustItem : Item(Properties().stacksTo(64)), IMatterItem {
|
||||
return matter(stack) >= ItemsConfig.MATTER_DUST_CAPACITY
|
||||
}
|
||||
|
||||
override fun overrideStackedOnOther(
|
||||
pStack: ItemStack,
|
||||
pSlot: Slot,
|
||||
pAction: ClickAction,
|
||||
pPlayer: Player
|
||||
): Boolean {
|
||||
if (pStack.isEmpty || pStack.count > 1)
|
||||
return super.overrideStackedOnOther(pStack, pSlot, pAction, pPlayer)
|
||||
|
||||
if (pAction == ClickAction.SECONDARY && pSlot.allowModification(pPlayer)) {
|
||||
val matterHalf = getMatterValue(pStack)?.matter?.div(2) ?: return true
|
||||
|
||||
if (!pSlot.hasItem()) {
|
||||
val halfStack = pStack.copyWithCount(1)
|
||||
|
||||
matter(halfStack, -addMatterValue(pStack, -matterHalf, pPlayer.level.isClientSide()))
|
||||
|
||||
pSlot.set(halfStack)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return super.overrideStackedOnOther(pStack, pSlot, pAction, pPlayer)
|
||||
}
|
||||
|
||||
override fun overrideOtherStackedOnMe(
|
||||
pStack: ItemStack,
|
||||
pOther: ItemStack,
|
||||
pSlot: Slot,
|
||||
pAction: ClickAction,
|
||||
pPlayer: Player,
|
||||
pAccess: SlotAccess
|
||||
): Boolean {
|
||||
if (pStack.isEmpty || pStack.count > 1)
|
||||
return super.overrideStackedOnOther(pStack, pSlot, pAction, pPlayer)
|
||||
|
||||
if (pAction == ClickAction.SECONDARY && pSlot.allowModification(pPlayer)) {
|
||||
val matterHalf = getMatterValue(pStack)?.matter?.div(2) ?: return true
|
||||
|
||||
if (pOther.isEmpty) {
|
||||
val halfStack = pStack.copyWithCount(1)
|
||||
|
||||
matter(halfStack, -addMatterValue(pStack, -matterHalf, pPlayer.level.isClientSide()))
|
||||
|
||||
pAccess.set(halfStack)
|
||||
|
||||
return true
|
||||
} else if (pOther.item is MatterDustItem && pOther.count == 1) {
|
||||
val matterOther = getMatterValue(pOther)?.matter ?: return true
|
||||
val diff = addMatterValue(pStack, matterOther, pPlayer.level.isClientSide())
|
||||
|
||||
if (matterOther - diff <= Decimal.ZERO) {
|
||||
pOther.shrink(1)
|
||||
} else {
|
||||
matter(pStack, matterOther - diff)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return super.overrideOtherStackedOnMe(pStack, pOther, pSlot, pAction, pPlayer, pAccess)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val DESC = TranslatableComponent("item.overdrive_that_matters.matter_dust.desc").withStyle(ChatFormatting.DARK_GRAY)
|
||||
private val DESC2 = TranslatableComponent("item.overdrive_that_matters.matter_dust.desc2").withStyle(ChatFormatting.GRAY)
|
||||
|
Loading…
Reference in New Issue
Block a user