Block selling to NPCs, trading and salvaging UUID locked items

[no changelog]
This commit is contained in:
nea
2023-10-04 16:41:04 +02:00
parent d0cc95b1e9
commit 64523821d8
3 changed files with 74 additions and 16 deletions

View File

@@ -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
}
}
}