Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
fix: food replacement replacing improperly
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 18, 2024
1 parent 002fe78 commit 65b71d8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerItemConsumeEvent
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
import kotlin.random.Random

class FoodConsumptionListener : Listener {
Expand All @@ -17,13 +18,17 @@ class FoodConsumptionListener : Listener {
val gearyFood = entity?.get<Food>() ?: return

if (player.gameMode != GameMode.CREATIVE) {
replacement = gearyFood.replacement?.toItemStack()
item.subtract()
player.inventory.getItem(hand).subtract()
gearyFood.replacement?.toItemStack()?.let { replacement ->
if (player.inventory.firstEmpty() != -1) player.inventory.addItem(replacement)
else player.world.dropItemNaturally(player.location, replacement)
}

if (gearyFood.effectList.isNotEmpty() && Random.nextDouble(0.0, 1.0) <= gearyFood.effectChance)
player.addPotionEffects(gearyFood.effectList)
}

isCancelled = true
player.foodLevel += minOf(gearyFood.hunger, 20)
player.saturation += minOf(gearyFood.saturation, 20.0).toFloat()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,47 @@ package com.mineinabyss.looty.features.holdsentity

import com.mineinabyss.geary.papermc.tracking.entities.helpers.spawnFromPrefab
import com.mineinabyss.geary.papermc.tracking.items.inventory.toGeary
import com.mineinabyss.idofront.messaging.broadcast
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.Action
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.player.PlayerBucketEmptyEvent
import org.bukkit.event.player.PlayerBucketEntityEvent
import org.bukkit.event.player.PlayerBucketFillEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.EquipmentSlot

class SpawnHeldPrefabSystem : Listener {
@EventHandler(ignoreCancelled = true) // Fires after the onPickupMob thus it places it aswell
fun PlayerInteractEvent.onEmptyMobzyBucket() {
if (action != Action.RIGHT_CLICK_BLOCK || hand != EquipmentSlot.HAND) return
val heldEntity = player.inventory.toGeary()?.itemInMainHand?.get<HoldsEntity>() ?: return
val block = clickedBlock?.getRelative(blockFace) ?: return

block.location.toCenterLocation().spawnFromPrefab(heldEntity.prefabKey)
player.inventory.setItemInMainHand(heldEntity.emptiedItem?.toItemStack())
isCancelled = true // Cancel vanilla behaviour
}
// @EventHandler(ignoreCancelled = true) // Fires after the onPickupMob thus it places it aswell
// fun PlayerInteractEvent.onEmptyMobzyBucket() {
// if (action != Action.RIGHT_CLICK_BLOCK || hand != EquipmentSlot.HAND) return
// val heldEntity = player.inventory.toGeary()?.itemInMainHand?.get<HoldsEntity>() ?: return
// val block = clickedBlock?.getRelative(blockFace) ?: return
//
// block.location.toCenterLocation().spawnFromPrefab(heldEntity.prefabKey)
// player.inventory.setItemInMainHand(heldEntity.emptiedItem?.toItemStack())
// isCancelled = true // Cancel vanilla behaviour
// }
//
// @EventHandler(ignoreCancelled = true)
// fun PlayerBucketEntityEvent.onBucketMob() {
// broadcast("PlayerBucketEntityEvent")
// val heldEntity = player.inventory.toGeary()?.itemInMainHand?.get<HoldsEntity>() ?: return
// if (player.inventory.toGeary()?.itemInMainHand?.has<HoldsEntity>() == true) {
// isCancelled = true
// } else {
// }
// }
//
// @EventHandler(ignoreCancelled = true)
// fun PlayerBucketFillEvent.onBucketMob() {
// broadcast("PlayerBucketFillEvent")
// val heldEntity = player.inventory.toGeary()?.itemInMainHand?.get<HoldsEntity>() ?: return
// }
//
// @EventHandler(ignoreCancelled = true)
// fun PlayerBucketEmptyEvent.onBucketMob() {
// broadcast("PlayerBucketEmptyEvent")
// }
}

0 comments on commit 65b71d8

Please sign in to comment.