Initial commit

Added support for entity capture and spawning with eggs
Added README
Added spigot docker build tools
Added some comments
This commit is contained in:
2025-11-20 00:08:35 -05:00
commit 641631a0dd
8 changed files with 197 additions and 0 deletions

15
.gitignore vendored Normal file
View File

@@ -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

3
.gitmodules vendored Normal file
View File

@@ -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

6
README.md Normal file
View File

@@ -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.

14
install.sh Executable file
View File

@@ -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

57
pom.xml Normal file
View File

@@ -0,0 +1,57 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aaaaahhhhhhh.bananapuncher714</groupId>
<artifactId>mob-capture</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.21.10-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.bananapuncher714</groupId>
<artifactId>nbteditor</artifactId>
<version>7.19.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<relocations>
<relocation>
<pattern>io.github.bananapuncher714.nbteditor</pattern>
<shadedPattern>com.aaaaahhhhhhh.bananapuncher714.mobcapture.nbteditor</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -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 );
}
}
}
}

View File

@@ -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