Skip to content

Commit

Permalink
fixed fishing net item not placing fish back in the water
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Khar committed Jan 18, 2024
1 parent 8cd2e86 commit 6622f88
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/kotlin/dev/hybridlabs/aquatic/item/FishingNetItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import net.minecraft.entity.LivingEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.item.ItemUsageContext
import net.minecraft.nbt.NbtCompound
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.world.World
import java.util.*

class FishingNetItem(settings: Settings?): Item(settings) {
Expand All @@ -26,6 +28,28 @@ class FishingNetItem(settings: Settings?): Item(settings) {
return super.useOnEntity(stack, user, entity, hand)
}

override fun useOnBlock(context: ItemUsageContext): ActionResult {
val world: World = context.world

if (!world.isClient) {
val nbtCopy = context.stack.nbt?.copy() ?: return super.useOnBlock(context)

val optionalEntity = getEntityFromNBT(nbtCopy)
//val blockEntity = context.world.getBlockEntity(context.blockPos)

if (optionalEntity.isPresent) {
val entity = optionalEntity.get().create(context.world) ?: return ActionResult.FAIL
entity.readNbt(context.stack.nbt?.getCompound(ENTITY_KEY))
context.stack.nbt?.remove(ENTITY_KEY)

entity.setPosition(context.hitPos)
world.spawnEntity(entity)
return ActionResult.SUCCESS
}
}
return super.useOnBlock(context)
}

override fun getTooltipData(stack: ItemStack): Optional<TooltipData> {
return super.getTooltipData(stack)
}
Expand Down

0 comments on commit 6622f88

Please sign in to comment.