Skip to content

Commit

Permalink
Merge pull request #8 from GallowsDove/master
Browse files Browse the repository at this point in the history
Added missing 1.16 mobs
  • Loading branch information
ybw0014 committed Jul 29, 2022
2 parents c21b00a + 1b2297f commit df36d23
Show file tree
Hide file tree
Showing 14 changed files with 495 additions and 42 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand All @@ -116,7 +116,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.1.0</version>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
/**
* This is a simple Adapter that allows conversion between a {@link LivingEntity} and
* a {@link JsonObject}.
*
*
* It also requires the implementation of {@link PersistentDataType}.
*
*
* @author TheBusyBiscuit
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import io.github.thebusybiscuit.mobcapturer.items.MobCannon;
import io.github.thebusybiscuit.mobcapturer.items.MobEgg;
import io.github.thebusybiscuit.mobcapturer.items.MobPellet;
import io.github.thebusybiscuit.mobcapturer.mobs.AnimalsAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.BeeAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.CatAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.ChestedHorseAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.CreeperAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.EndermiteAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.FoxAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.HoglinAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.HorseAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.IronGolemAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.LlamaAdapter;
Expand All @@ -67,6 +67,8 @@
import io.github.thebusybiscuit.mobcapturer.mobs.ParrotAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.PhantomAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.PigAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.PiglinAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.PiglinBruteAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.PufferFishAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.RabbitAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.RaiderAdapter;
Expand All @@ -76,18 +78,27 @@
import io.github.thebusybiscuit.mobcapturer.mobs.SlimeAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.SnowmanAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.StandardMobAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.StriderAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.TropicalFishAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.UndeadHorseAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.VexAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.WolfAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.ZoglinAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.ZombieAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.ZombieVillagerAdapter;
import io.github.thebusybiscuit.mobcapturer.mobs.ZombifiedPiglinAdapter;

import io.github.thebusybiscuit.mobcapturer.items.MobCannon;
import io.github.thebusybiscuit.mobcapturer.items.MobEgg;
import io.github.thebusybiscuit.mobcapturer.items.MobPellet;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.api.researches.Research;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config;
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.libraries.dough.skins.PlayerHead;
Expand Down Expand Up @@ -122,12 +133,12 @@ public void onEnable() {
SlimefunItemStack cannon = new SlimefunItemStack("MOB_CANNON", Material.BLAZE_ROD, "&6Mob Capturing Cannon", "", "&eRight Click &7to shoot a &fMob Caging Pellet");
SlimefunItemStack pellet = new SlimefunItemStack("MOB_CAPTURING_PELLET", "983b30e9d135b05190eea2c3ac61e2ab55a2d81e1a58dbb26983a14082664", "&fMob Capturing Pellet", "", "&7These Pellets are used as", "&7Ammunition for your &6Mob Capturing Cannon");

MobPellet mobPellet = new MobPellet(itemGroup, pellet, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] { new ItemStack(Material.STRING), new ItemStack(Material.IRON_NUGGET), new ItemStack(Material.STRING), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.EGG), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.STRING), new ItemStack(Material.IRON_NUGGET), new ItemStack(Material.STRING) });
MobPellet mobPellet = new MobPellet(itemGroup, pellet, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[]{new ItemStack(Material.STRING), new ItemStack(Material.IRON_NUGGET), new ItemStack(Material.STRING), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.EGG), SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.STRING), new ItemStack(Material.IRON_NUGGET), new ItemStack(Material.STRING)});

research.addItems(mobPellet);
mobPellet.register(this);

MobCannon mobCannon = new MobCannon(this, itemGroup, cannon, mobPellet, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] { null, SlimefunItems.STEEL_INGOT, SlimefunItems.HOOK, SlimefunItems.STEEL_INGOT, SlimefunItems.POWER_CRYSTAL, SlimefunItems.STEEL_INGOT, SlimefunItems.ADVANCED_CIRCUIT_BOARD, SlimefunItems.STEEL_INGOT, null });
MobCannon mobCannon = new MobCannon(this, itemGroup, cannon, mobPellet, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[]{null, SlimefunItems.STEEL_INGOT, SlimefunItems.HOOK, SlimefunItems.STEEL_INGOT, SlimefunItems.POWER_CRYSTAL, SlimefunItems.STEEL_INGOT, SlimefunItems.ADVANCED_CIRCUIT_BOARD, SlimefunItems.STEEL_INGOT, null});

research.addItems(mobCannon);
mobCannon.register(this);
Expand All @@ -144,6 +155,8 @@ public void onEnable() {
register("Turtle", EntityType.TURTLE, new AnimalsAdapter<>(Turtle.class), "15a45e24cadc18f305291af45a22fc8b3607a675baa31ed583d3a56b15223c5c");
register("Polar Bear", EntityType.POLAR_BEAR, new AnimalsAdapter<>(PolarBear.class), "291abcab7a20b28195c0f1786db28c7670c2979243de71703b04e9d93f59aa8d");
register("Panda", EntityType.PANDA, new PandaAdapter(), "1ab24611bb37ce3971fdbf01ba3f11bd2e4c72f5d40b6d8d8d536d69e695cd0c");
register("Fox", EntityType.FOX, new FoxAdapter(), "db8c11abae08927c8ae413d22f2f556c954c7d8a4edf0aa3f4b86597fb7b1cec");
register("Bee", EntityType.BEE, new BeeAdapter(), "208e55d3b4a865f4888174c02592a631d0a10475fa2686b490d465860fe8cf91");

// Mobs
register("Slime", EntityType.SLIME, new SlimeAdapter<>(Slime.class), "9330af17f8512ed3b49e78bca7ef2d83f2dc1e598a8cb542ecc3b6becee9f57");
Expand All @@ -170,6 +183,14 @@ public void onEnable() {
register("Blaze", EntityType.BLAZE, new StandardMobAdapter<>(Blaze.class), "533acae6e075a578ccfc7dc2d5a15dbccfa8f59c609f9703889ef54c742c56");
register("Magma Cube", EntityType.MAGMA_CUBE, new SlimeAdapter<>(MagmaCube.class), "1185657c38acdd8f95e1d2cd1115bb0f11139ad2b3ce442267e69706d916e");
register("Ghast", EntityType.GHAST, new StandardMobAdapter<>(Ghast.class), "c442c228f099fdfc1c6b46dfc80b252d81f7fb1739deb16ee7a597c17f7c9");
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) {
register("Piglin", EntityType.PIGLIN, new PiglinAdapter(), "f2f621045771323d916c26bfb5ebec5738dbff8301246fe1481e9f9d25326f3b");
register("Piglin Brute", EntityType.PIGLIN_BRUTE, new PiglinBruteAdapter(), "b13a4d678041dff776fffd96486e90f1b5e115af33647454caf401fd3fd00d5e");
register("Zombified Piglin", EntityType.ZOMBIFIED_PIGLIN, new ZombifiedPiglinAdapter(), "4db2e40571acefdcb7f15f94e1f174c3b9c299921f14da052628a0ba18e0c323");
register("Hoglin", EntityType.HOGLIN, new HoglinAdapter(), "a6eddc5a25d4ff8f9f3490d673613093e65b866d369a26f8ee8b93983c692be3");
register("Zoglin", EntityType.ZOGLIN, new ZoglinAdapter(), "31a6d71f3587ad1888d757fea265614ab7d0204daade131954fb675e92585227");
register("Strider", EntityType.STRIDER, new StriderAdapter(), "34f2759b413a8a645504fb5074dae1dddcc8af150b7fe06cc5832667e776b6f7");
}

// Ender things
register("Shulker", EntityType.SHULKER, new ShulkerAdapter(), "d04252216231b3f744c9ff4ace7084ae9f4164f8b384c65410848a19617af4d");
Expand Down Expand Up @@ -220,7 +241,7 @@ public void onEnable() {
public <T extends LivingEntity> void register(String name, EntityType type, MobAdapter<T> adapter, String eggTexture) {
SlimefunItemStack itemstack = new SlimefunItemStack("MOB_EGG_" + type.toString(), eggTexture, "&aMob Egg &7(" + name + ")", "", "&7Right Click this Item on a Block", "&7to release your captured Mob");

MobEgg<T> egg = new MobEgg<>(itemGroup, itemstack, dataKey, inventoryKey, adapter, recipeType, new ItemStack[] { null, null, null, null, new CustomItemStack(PlayerHead.getItemStack(PlayerSkin.fromHashCode(eggTexture)), ChatColor.WHITE + name), null, null, null, null });
MobEgg<T> egg = new MobEgg<>(itemGroup, itemstack, dataKey, inventoryKey, adapter, recipeType, new ItemStack[]{null, null, null, null, new CustomItemStack(PlayerHead.getItemStack(PlayerSkin.fromHashCode(eggTexture)), ChatColor.WHITE + name), null, null, null, null});

egg.register(this);

Expand All @@ -240,7 +261,7 @@ public JavaPlugin getJavaPlugin() {
return this;
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public Optional<ItemStack> capture(LivingEntity entity) {
MobEgg egg = adapters.get(entity.getType());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package io.github.thebusybiscuit.mobcapturer;

import java.util.Optional;

import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.projectiles.ProjectileSource;

import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction;
import java.util.Optional;

public class PelletListener implements Listener {

Expand All @@ -23,14 +28,23 @@ public PelletListener(MobCapturer plugin) {
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH)
public void onProjectileHit(EntityDamageByEntityEvent e) {
if (e.getDamager() instanceof Snowball && e.getEntity() instanceof LivingEntity && e.getDamager().hasMetadata("mob_capturing_cannon")) {
Optional<ItemStack> optional = plugin.capture((LivingEntity) e.getEntity());
Snowball pellet = (Snowball) e.getDamager();
ProjectileSource shooter = pellet.getShooter();

if (optional.isPresent()) {
e.getDamager().removeMetadata("mob_capturing_cannon", plugin);
e.getEntity().remove();
e.getEntity().getWorld().dropItemNaturally(((LivingEntity) e.getEntity()).getEyeLocation(), optional.get());
if (shooter instanceof Player && canCapture((Player) shooter, e.getEntity().getLocation())) {
Optional<ItemStack> optional = plugin.capture((LivingEntity) e.getEntity());

if (optional.isPresent()) {
e.getDamager().removeMetadata("mob_capturing_cannon", plugin);
e.getEntity().remove();
e.getEntity().getWorld().dropItemNaturally(((LivingEntity) e.getEntity()).getEyeLocation(), optional.get());
}
}
}
}

protected boolean canCapture(Player p, Location l) {
return Slimefun.getProtectionManager().hasPermission(p, l, Interaction.ATTACK_ENTITY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import java.util.Map;
import java.util.Optional;


import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
Expand All @@ -26,8 +29,10 @@
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.ItemUtils;
import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction;

public class MobEgg<T extends LivingEntity> extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable {

Expand Down Expand Up @@ -78,37 +83,44 @@ public ItemUseHandler getItemHandler() {

if (block.isPresent()) {
Block b = block.get();
T entity = b.getWorld().spawn(b.getRelative(e.getClickedFace()).getLocation(), adapter.getEntityClass());

PersistentDataContainer container = e.getItem().getItemMeta().getPersistentDataContainer();
JsonObject json = container.get(dataKey, adapter);
ItemUtils.consumeItem(e.getItem(), false);
if (canPlaceMob(e.getPlayer(), b.getRelative(e.getClickedFace()).getLocation())) {
T entity = b.getWorld().spawn(b.getRelative(e.getClickedFace()).getLocation(), adapter.getEntityClass());

PersistentDataContainer container = e.getItem().getItemMeta().getPersistentDataContainer();
JsonObject json = container.get(dataKey, adapter);
ItemUtils.consumeItem(e.getItem(), false);

if (json != null) {
adapter.apply(entity, json);
if (json != null) {
adapter.apply(entity, json);

if (adapter instanceof InventoryAdapter) {
Map<String, ItemStack> inventory = new HashMap<>();
if (adapter instanceof InventoryAdapter) {
Map<String, ItemStack> inventory = new HashMap<>();

try (Reader reader = new StringReader(container.get(inventoryKey, PersistentDataType.STRING))) {
FileConfiguration yaml = YamlConfiguration.loadConfiguration(reader);
try (Reader reader = new StringReader(container.get(inventoryKey, PersistentDataType.STRING))) {
FileConfiguration yaml = YamlConfiguration.loadConfiguration(reader);

for (String key : yaml.getKeys(true)) {
Object obj = yaml.get(key);
for (String key : yaml.getKeys(true)) {
Object obj = yaml.get(key);

if (obj instanceof ItemStack) {
inventory.put(key, (ItemStack) obj);
if (obj instanceof ItemStack) {
inventory.put(key, (ItemStack) obj);
}
}
} catch (IOException x) {
x.printStackTrace();
}
} catch (IOException x) {
x.printStackTrace();
}

((InventoryAdapter<T>) adapter).applyInventory(entity, inventory);
((InventoryAdapter<T>) adapter).applyInventory(entity, inventory);
}
}
}
}
};
}

protected boolean canPlaceMob(Player p, Location l) {
return Slimefun.getProtectionManager().hasPermission(p, l, Interaction.PLACE_BLOCK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.thebusybiscuit.mobcapturer.mobs;

import org.bukkit.entity.Bee;

import com.google.gson.JsonObject;

public class BeeAdapter extends AnimalsAdapter<Bee> {

public BeeAdapter() {
super(Bee.class);
}

@Override
public void apply(Bee entity, JsonObject json) {
super.apply(entity, json);

entity.setAnger(json.get("anger").getAsInt());
entity.setCannotEnterHiveTicks(json.get("cannotEnterHiveTicks").getAsInt());
entity.setHasNectar(json.get("nectar").getAsBoolean());
entity.setHasStung(json.get("stung").getAsBoolean());
}

@Override
public JsonObject saveData(Bee entity) {
JsonObject json = super.saveData(entity);

json.addProperty("anger", entity.getAnger());
json.addProperty("cannotEnterHiveTicks", entity.getCannotEnterHiveTicks());
json.addProperty("nectar", entity.hasNectar());
json.addProperty("stung", entity.hasStung());

return json;
}

}
Loading

0 comments on commit df36d23

Please sign in to comment.