-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acdd650
commit b6dc6d7
Showing
4 changed files
with
45 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
src/main/kotlin/pers/cierra_runis/survired/pickup/PickuoRightClickEventListener.kt
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/pers/cierra_runis/survired/pickup/SurviRedPickupEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} | ||
} |