Block selling to NPCs, trading and salvaging UUID locked items
[no changelog]
This commit is contained in:
@@ -18,6 +18,7 @@ data class IsSlotProtectedEvent(
|
||||
val actionType: SlotActionType,
|
||||
var isProtected: Boolean,
|
||||
val itemStackOverride: ItemStack?,
|
||||
var silent: Boolean = false,
|
||||
) : FirmamentEvent() {
|
||||
val itemStack get() = itemStackOverride ?: slot!!.stack
|
||||
|
||||
@@ -25,18 +26,25 @@ data class IsSlotProtectedEvent(
|
||||
isProtected = true
|
||||
}
|
||||
|
||||
fun protectSilent() {
|
||||
if (!isProtected) {
|
||||
silent = true
|
||||
}
|
||||
isProtected = true
|
||||
}
|
||||
|
||||
companion object : FirmamentEventBus<IsSlotProtectedEvent>() {
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun shouldBlockInteraction(slot: Slot?, action: SlotActionType, itemStackOverride: ItemStack? = null): Boolean {
|
||||
if (slot == null && itemStackOverride == null) return false
|
||||
val event = IsSlotProtectedEvent(slot, action, false, itemStackOverride)
|
||||
return publish(event).isProtected.also {
|
||||
if (it) {
|
||||
MC.player?.sendMessage(Text.translatable("firmament.protectitem").append(event.itemStack.name))
|
||||
CommonSoundEffects.playFailure()
|
||||
}
|
||||
publish(event)
|
||||
if (event.isProtected && !event.silent) {
|
||||
MC.player?.sendMessage(Text.translatable("firmament.protectitem").append(event.itemStack.name))
|
||||
CommonSoundEffects.playFailure()
|
||||
}
|
||||
return event.isProtected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user