commit 641631a0dd10ec5b176cc10d926b26537793b4c9 Author: BananaPuncher714 Date: Thu Nov 20 00:08:35 2025 -0500 Initial commit Added support for entity capture and spawning with eggs Added README Added spigot docker build tools Added some comments diff --git a/.git-submodules/spigot-docker-build-tools b/.git-submodules/spigot-docker-build-tools new file mode 160000 index 0000000..36cdba1 --- /dev/null +++ b/.git-submodules/spigot-docker-build-tools @@ -0,0 +1 @@ +Subproject commit 36cdba14f3c7a602cccbbfaae88dcb5280472030 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1372fdc --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Eclipse project files +.classpath +.project +.settings/ +target/ + +# Generated javadocs +doc/ + +# Dependency reduced pom +dependency-reduced-pom.xml + +# Jetbrains Intellij IDEA +.idea/ +*.iml \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a6a85b3 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule ".git-submodules/spigot-docker-build-tools"] + path = .git-submodules/spigot-docker-build-tools + url = https://git.048596.world/banana/spigot-docker-build-tools.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..3cbc641 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Mob Capture + +This plugin serves as a basic example on how to use NBTEditor to manipulate entity data, such as +storing it in an item, and retrieving and applying it to an existing entity. It also highlights +the ability to work with entirely vanilla mechanics, such as spawn eggs, which can be extended to +work with more complex things, like spawners. \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..456cd81 --- /dev/null +++ b/install.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +export REV="1.21.10" +export M2_DIRECTORY="$M2_REPOSITORY" +export BUILD_DIRECTORY="$ARTIFACT_DIRECTORY" +export JAVA_VERSION="21" + +REPOSITORY_DIR=$(dirname "$0") + +cd "$REPOSITORY_DIR" + +git submodule update --init --recursive --remote + +./.git-submodules/spigot-docker-build-tools/run.sh mvn clean package \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..00e2c69 --- /dev/null +++ b/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + com.aaaaahhhhhhh.bananapuncher714 + mob-capture + 0.0.1-SNAPSHOT + + + + org.spigotmc + spigot + 1.21.10-R0.1-SNAPSHOT + provided + + + io.github.bananapuncher714 + nbteditor + 7.19.11 + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + + io.github.bananapuncher714.nbteditor + com.aaaaahhhhhhh.bananapuncher714.mobcapture.nbteditor + + + + + + package + + shade + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mobcapture/MobCapture.java b/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mobcapture/MobCapture.java new file mode 100644 index 0000000..cc0149e --- /dev/null +++ b/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mobcapture/MobCapture.java @@ -0,0 +1,95 @@ +package com.aaaaahhhhhhh.bananapuncher714.mobcapture; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Egg; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; + +import io.github.bananapuncher714.nbteditor.NBTEditor; +import io.github.bananapuncher714.nbteditor.NBTEditor.NBTCompound; + +public class MobCapture extends JavaPlugin implements Listener { + private Map< EntityType, Material > eggTypes = new HashMap< EntityType, Material >(); + + @Override + public void onEnable() { + for ( EntityType type : EntityType.values() ) { + String name = type.name(); + Material material = Material.getMaterial( name + "_SPAWN_EGG" ); + if ( material != null ) { + eggTypes.put( type, material ); + } + } + + Bukkit.getPluginManager().registerEvents( this, this ); + } + + @EventHandler + private void onEvent( ProjectileHitEvent event ) { + final Entity entity = event.getHitEntity(); + if ( entity != null && event.getEntity() instanceof Egg ) { + final Material type = eggTypes.get( entity.getType() ); + if ( type != null ) { + ItemStack egg = new ItemStack( type ); + + // Get the entity data + final NBTCompound compound = NBTEditor.getNBTCompound( entity ); + + // Delete the components that we don't want to persist + compound.set( NBTEditor.DELETE, "UUID" ); + compound.set( NBTEditor.DELETE, "Pos" ); + compound.set( NBTEditor.DELETE, "Motion" ); + + // We can use [ NBTEditor.ITEMSTACK_COMPONENTS, "minecraft:entity_data" ] here as the key + // since "minecraft:entity_data" is a default component on spawn eggs, but if you want to + // store the data in a custom component, you will need to use a different key such as + // [ NBTEditor.CUSTOM_DATA, "custom_entity_data" ]. + egg = NBTEditor.set( egg, compound, NBTEditor.ITEMSTACK_COMPONENTS, "minecraft:entity_data" ); + + Location location = entity.getLocation(); + entity.remove(); + + location.getWorld().dropItemNaturally( location, egg ); + location.getWorld().createExplosion( location, 0f, false, false ); + + event.setCancelled( true ); + } + } + } + + @EventHandler + private void onApply( PlayerInteractEntityEvent event ) { + final Entity entity = event.getRightClicked(); + final Material type = eggTypes.get( entity.getType() ); + final ItemStack item = event.getPlayer().getEquipment().getItem( event.getHand() ); + + if ( item != null && item.getType() == type ) { + if ( NBTEditor.contains( item, NBTEditor.ITEMSTACK_COMPONENTS, "minecraft:entity_data" ) ) { + // Get the corresponding entity data info from the item that the player + // is holding, and apply it to the entity that was clicked on + final NBTCompound compound = NBTEditor.getNBTCompound( item, NBTEditor.ITEMSTACK_COMPONENTS, "minecraft:entity_data" ); + final NBTCompound entityCompound = NBTEditor.getNBTCompound( entity ); + + // Set the UUID, position and motion to the clicked entity's data + compound.set( NBTEditor.getNBTCompound( entityCompound, "UUID" ), "UUID" ); + compound.set( NBTEditor.getNBTCompound( entityCompound, "Pos" ), "Pos" ); + compound.set( NBTEditor.getNBTCompound( entityCompound, "Motion" ), "Motion" ); + + NBTEditor.set( entity, compound ); + + event.setCancelled( true ); + } + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..0d2d1f1 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: MobCapture +main: com.aaaaahhhhhhh.bananapuncher714.mobcapture.MobCapture +version: 0.0.1 +description: Capture mobs +author: BananaPuncher714 +api-version: 1.13 \ No newline at end of file