Use onItemUseFirst
This commit is contained in:
parent
516de507e4
commit
82e410ad33
@ -47,7 +47,6 @@ import ru.dbotthepony.mc.otm.config.ServerConfig;
|
|||||||
import ru.dbotthepony.mc.otm.config.ToolsConfig;
|
import ru.dbotthepony.mc.otm.config.ToolsConfig;
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal;
|
import ru.dbotthepony.mc.otm.core.math.Decimal;
|
||||||
import ru.dbotthepony.mc.otm.item.ItemTritaniumArmor;
|
import ru.dbotthepony.mc.otm.item.ItemTritaniumArmor;
|
||||||
import ru.dbotthepony.mc.otm.item.PriorityUseItemKt;
|
|
||||||
import ru.dbotthepony.mc.otm.item.QuantumBatteryItem;
|
import ru.dbotthepony.mc.otm.item.QuantumBatteryItem;
|
||||||
import ru.dbotthepony.mc.otm.item.weapon.AbstractWeaponItem;
|
import ru.dbotthepony.mc.otm.item.weapon.AbstractWeaponItem;
|
||||||
import ru.dbotthepony.mc.otm.item.PortableCondensationDriveItem;
|
import ru.dbotthepony.mc.otm.item.PortableCondensationDriveItem;
|
||||||
@ -187,8 +186,6 @@ public final class OverdriveThatMatters {
|
|||||||
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryBlockEntity.Companion::playerDisconnected);
|
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryBlockEntity.Companion::playerDisconnected);
|
||||||
EVENT_BUS.addListener(EventPriority.LOWEST, MatteryBlockEntity.Companion::postLevelTick);
|
EVENT_BUS.addListener(EventPriority.LOWEST, MatteryBlockEntity.Companion::postLevelTick);
|
||||||
|
|
||||||
EVENT_BUS.addListener(EventPriority.NORMAL, PriorityUseItemKt::onItemRightClick);
|
|
||||||
|
|
||||||
EVENT_BUS.addListener(EventPriority.LOWEST, KillAsAndroidTrigger.INSTANCE::onKill);
|
EVENT_BUS.addListener(EventPriority.LOWEST, KillAsAndroidTrigger.INSTANCE::onKill);
|
||||||
|
|
||||||
EVENT_BUS.addListener(EventPriority.NORMAL, EnderTeleporterFeature.Companion::onEntityDeath);
|
EVENT_BUS.addListener(EventPriority.NORMAL, EnderTeleporterFeature.Companion::onEntityDeath);
|
||||||
|
@ -24,7 +24,6 @@ import net.minecraft.world.level.material.Fluids
|
|||||||
import net.minecraftforge.common.SoundActions
|
import net.minecraftforge.common.SoundActions
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
||||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent
|
|
||||||
import net.minecraftforge.fluids.FluidStack
|
import net.minecraftforge.fluids.FluidStack
|
||||||
import net.minecraftforge.fluids.capability.IFluidHandler
|
import net.minecraftforge.fluids.capability.IFluidHandler
|
||||||
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack
|
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack
|
||||||
@ -38,7 +37,7 @@ import ru.dbotthepony.mc.otm.core.immutableList
|
|||||||
import ru.dbotthepony.mc.otm.core.immutableMap
|
import ru.dbotthepony.mc.otm.core.immutableMap
|
||||||
import ru.dbotthepony.mc.otm.core.orNull
|
import ru.dbotthepony.mc.otm.core.orNull
|
||||||
|
|
||||||
class FluidCapsuleItem(val capacity: () -> Int) : Item(Properties().stacksTo(64)), PriorityUseItem {
|
class FluidCapsuleItem(val capacity: () -> Int) : Item(Properties().stacksTo(64)) {
|
||||||
private inner class Cap(itemStack: ItemStack) : FluidHandlerItemStack(itemStack, capacity.invoke()) {
|
private inner class Cap(itemStack: ItemStack) : FluidHandlerItemStack(itemStack, capacity.invoke()) {
|
||||||
override fun fill(resource: FluidStack, doFill: IFluidHandler.FluidAction): Int {
|
override fun fill(resource: FluidStack, doFill: IFluidHandler.FluidAction): Int {
|
||||||
this.capacity = this@FluidCapsuleItem.capacity.invoke()
|
this.capacity = this@FluidCapsuleItem.capacity.invoke()
|
||||||
@ -61,17 +60,17 @@ class FluidCapsuleItem(val capacity: () -> Int) : Item(Properties().stacksTo(64)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isPriorityConsumer(event: PlayerInteractEvent.RightClickBlock): Boolean {
|
// TODO: Так как использование предмета заблокировано за player.abilities.canBuild
|
||||||
return canInteract(event.itemStack, event.entity, Context(event.hitVec.blockPos, event.entity.level.getBlockState(event.hitVec.blockPos), event.hitVec.direction))
|
// капсулу нельзя использовать в режиме приключения
|
||||||
}
|
// почему же можно использовать вёдра на котлах?
|
||||||
|
// ИБО КОТЛЫ ЗАХАРДКОЖЕНЫ НА ВЗАИМОДЕЙСТВИЕ С ВЁДРАМИ
|
||||||
override fun useOn(pContext: UseOnContext): InteractionResult {
|
override fun onItemUseFirst(stack: ItemStack, pContext: UseOnContext): InteractionResult {
|
||||||
val context = Context(pContext.clickedPos, pContext.level.getBlockState(pContext.clickedPos), pContext.clickedFace)
|
val context = Context(pContext.clickedPos, pContext.level.getBlockState(pContext.clickedPos), pContext.clickedFace)
|
||||||
|
|
||||||
if (canInteract(pContext.itemInHand, pContext.player ?: return InteractionResult.FAIL, context))
|
if (canInteract(pContext.itemInHand, pContext.player ?: return InteractionResult.FAIL, context))
|
||||||
return interact(pContext.itemInHand, pContext.player!!, context)
|
return interact(pContext.itemInHand, pContext.player!!, context)
|
||||||
|
|
||||||
return InteractionResult.FAIL
|
return super.onItemUseFirst(stack, pContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(pStack: ItemStack): Component {
|
override fun getName(pStack: ItemStack): Component {
|
||||||
@ -140,7 +139,7 @@ class FluidCapsuleItem(val capacity: () -> Int) : Item(Properties().stacksTo(64)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return InteractionResult.sidedSuccess(player.level.isClientSide)
|
return InteractionResult.CONSUME
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package ru.dbotthepony.mc.otm.item
|
|
||||||
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent
|
|
||||||
import net.minecraftforge.eventbus.api.Event
|
|
||||||
|
|
||||||
interface PriorityUseItem {
|
|
||||||
fun isPriorityConsumer(event: PlayerInteractEvent.RightClickBlock): Boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun onItemRightClick(event: PlayerInteractEvent.RightClickBlock) {
|
|
||||||
val item = event.itemStack.item
|
|
||||||
|
|
||||||
if (!event.itemStack.isEmpty && item is PriorityUseItem) {
|
|
||||||
if (item.isPriorityConsumer(event)) {
|
|
||||||
event.useBlock = Event.Result.DENY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user