Skip to content

Commit

Permalink
feat: enderman capturing (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 authored Sep 20, 2023
1 parent 3e337a3 commit 085b1a8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.thebusybiscuit.mobcapturer.adapters.mobs;

import com.google.gson.JsonObject;

import io.github.thebusybiscuit.mobcapturer.adapters.MobAdapter;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Enderman;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import java.util.List;

public class EndermanAdapter implements MobAdapter<Enderman> {

@Nonnull
@Override
public List<String> getLore(@Nonnull JsonObject json) {
List<String> lore = MobAdapter.super.getLore(json);

lore.add(ChatColor.GRAY + "Carrying block: " + ChatColor.WHITE + json.has("carriedBlock"));

return lore;
}

@Override
@ParametersAreNonnullByDefault
public void apply(Enderman entity, JsonObject json) {
MobAdapter.super.apply(entity, json);

if (json.has("carriedBlock")) {
BlockData blockData = Bukkit.getServer().createBlockData(json.get("carriedBlock").getAsString());
entity.setCarriedBlock(blockData);
}
}

@Nonnull
@Override
public JsonObject saveData(@Nonnull Enderman entity) {
JsonObject json = MobAdapter.super.saveData(entity);

BlockData blockData = entity.getCarriedBlock();
if (blockData != null) {
json.addProperty("carriedBlock", blockData.getAsString());
}

return json;
}

@Nonnull
@Override
public Class<Enderman> getEntityClass() {
return Enderman.class;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.mobcapturer.MobCapturer;
Expand All @@ -41,9 +42,9 @@ public PelletListener(@Nonnull MobCapturer plugin) {
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onProjectileHit(@Nonnull EntityDamageByEntityEvent e) {
if (e.getDamager() instanceof Snowball pellet
&& e.getEntity() instanceof LivingEntity entity
public void onProjectileHit(@Nonnull ProjectileHitEvent e) {
if (e.getEntity() instanceof Snowball pellet
&& e.getHitEntity() instanceof LivingEntity entity
&& pellet.hasMetadata(Keys.MOB_CAPTURING_PELLET)
&& pellet.getShooter() instanceof Player player
&& canCapture(player, entity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import io.github.thebusybiscuit.mobcapturer.adapters.mobs.CatAdapter;
import io.github.thebusybiscuit.mobcapturer.adapters.mobs.ChestedHorseAdapter;
import io.github.thebusybiscuit.mobcapturer.adapters.mobs.CreeperAdapter;
import io.github.thebusybiscuit.mobcapturer.adapters.mobs.EndermanAdapter;
import io.github.thebusybiscuit.mobcapturer.adapters.mobs.EndermiteAdapter;
import io.github.thebusybiscuit.mobcapturer.adapters.mobs.FoxAdapter;
import io.github.thebusybiscuit.mobcapturer.adapters.mobs.FrogAdapter;
Expand Down Expand Up @@ -255,6 +256,8 @@ private static void setupMobEggs() {
//</editor-fold>

//<editor-fold desc="Ender things">
// https://minecraft-heads.com/custom-heads/decoration/953-spawn-egg-enderman
registerMob(EntityType.ENDERMAN, new EndermanAdapter(), "37c0d010dd0e512ffea108d7c5fe69d576c31ec266c884b51ec0b28cc457");
// https://minecraft-heads.com/custom-heads/decoration/23585-spawn-egg-shulker
registerMob(EntityType.SHULKER, new ShulkerAdapter(), "d04252216231b3f744c9ff4ace7084ae9f4164f8b384c65410848a19617af4d");
// https://minecraft-heads.com/custom-heads/decoration/954-spawn-egg-endermite
Expand Down

0 comments on commit 085b1a8

Please sign in to comment.