Skip to content

Commit

Permalink
🌍Add New Feature Pickup
Browse files Browse the repository at this point in the history
  • Loading branch information
Cierra-Runis committed Nov 5, 2024
1 parent acdd650 commit b6dc6d7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
<img src=".github/icon.png" alt='SurviRed'/>

[Figma](https://www.figma.com/design/B4xgnDzzLQ11tZtaSKujFo/SurviRed?m=auto&t=UQ0XIsjsgI5N8PWV-1)

[Villager Pickup](https://github.com/Living-Lemming/Villager-Pickup-Mod)
15 changes: 7 additions & 8 deletions src/main/kotlin/pers/cierra_runis/survired/SurviRed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package pers.cierra_runis.survired

import net.fabricmc.api.ModInitializer
import org.slf4j.LoggerFactory
import pers.cierra_runis.survired.pickup.SurviRedPickupEventListener

object SurviRed : ModInitializer {
private val logger = LoggerFactory.getLogger("survired")

override fun onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
logger.info("Hello Fabric world!")
}
private val logger = LoggerFactory.getLogger(this.javaClass)
override fun onInitialize() {
logger.info("Loading...")
SurviRedPickupEventListener.registerRightClickEvent()
logger.info("Loaded!")
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package pers.cierra_runis.survired.pickup

import net.fabricmc.fabric.api.event.player.UseEntityCallback
import net.minecraft.entity.Entity
import net.minecraft.item.ItemStack
import net.minecraft.item.SpawnEggItem
import net.minecraft.nbt.NbtCompound
import net.minecraft.util.ActionResult
import org.slf4j.LoggerFactory

object SurviRedPickupEventListener {
private val logger = LoggerFactory.getLogger(this.javaClass)

fun registerRightClickEvent() {
UseEntityCallback.EVENT.register(UseEntityCallback { playerEntity, world, hand, entity, entityHitResult ->
if (!playerEntity.isSneaking) return@UseEntityCallback ActionResult.PASS

val spawnEgg = SpawnEggItem.forEntity(entity.type) ?: return@UseEntityCallback ActionResult.FAIL

val entityNbt = entity.writeNbt(NbtCompound())
for (key in arrayOf("Pos", "Motion", "Rotation", "UUID")) entityNbt.remove(key)

val stack = ItemStack(spawnEgg).apply {
NbtCompound().apply {
put("EntityTag", entityNbt)
}
}

if (playerEntity.inventory.emptySlot != -1) playerEntity.giveItemStack(stack)
else playerEntity.dropItem(stack, true)

entity.remove(Entity.RemovalReason.DISCARDED)
return@UseEntityCallback ActionResult.SUCCESS
})
}
}

0 comments on commit b6dc6d7

Please sign in to comment.