Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public TraitManager(StackMob sm) {
public void registerTraits() throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
registerTrait(SheepColor.class);
registerTrait(SheepShear.class);
registerTrait(SnowmanShear.class);
registerTrait(HorseColor.class);
registerTrait(SlimeSize.class);
registerTrait(LlamaColor.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.antiperson.stackmob.entity.traits.trait;

import org.bukkit.entity.Snowman;
import uk.antiperson.stackmob.entity.traits.Trait;
import uk.antiperson.stackmob.entity.traits.TraitMetadata;

@TraitMetadata(path = "snowman-sheared")
public class SnowmanShear implements Trait<Snowman> {
@Override
public boolean checkTrait(Snowman first, Snowman nearby) {
return first.isDerp() == nearby.isDerp();
}

@Override
public void applyTrait(Snowman spawned, Snowman dead) {
spawned.setDerp(dead.isDerp());
}
}
33 changes: 18 additions & 15 deletions src/main/java/uk/antiperson/stackmob/listeners/ShearListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.loot.LootContext;
import uk.antiperson.stackmob.StackMob;
import uk.antiperson.stackmob.config.EntityConfig;
Expand All @@ -31,7 +30,7 @@ public ShearListener(StackMob sm) {
}

@EventHandler
public void onShearSheep(PlayerShearEntityEvent event) {
public void onShearEntity(PlayerShearEntityEvent event) {
if (event.isCancelled()) {
return;
}
Expand All @@ -48,7 +47,7 @@ public void onShearSheep(PlayerShearEntityEvent event) {
}

@EventHandler
public void onShearSheep(BlockShearEntityEvent event) {
public void onShearEntity(BlockShearEntityEvent event) {
if (event.isCancelled()) {
return;
}
Expand Down Expand Up @@ -78,7 +77,7 @@ private EquipmentSlot checkSlot(Player player, EquipmentSlot slot) {
}

private ItemStack shearLogic(LivingEntity entity, ItemStack item) {
if (!((entity instanceof Sheep) || (entity instanceof MushroomCow))) {
if (!(entity instanceof Shearable)) {
return null;
}
StackEntity stackEntity = sm.getEntityManager().getStackEntity(entity);
Expand All @@ -101,12 +100,11 @@ private ItemStack shearLogic(LivingEntity entity, ItemStack item) {
int damage = health - amount;
if (damage > 0) {
damageable.setDamage(damageable.getDamage() + amount);
item.setItemMeta((ItemMeta) damageable);
item.setItemMeta(damageable);
} else {
item = new ItemStack(Material.AIR);
}
if (entity instanceof Sheep) {
Sheep sheared = (Sheep) entity;
if (entity instanceof Sheep sheared) {
LootContext lootContext = new LootContext.Builder(sheared.getLocation()).lootedEntity(sheared).build();
Collection<ItemStack> loot = sheared.getLootTable().populateLoot(ThreadLocalRandom.current(), lootContext);
for (ItemStack itemStack : loot) {
Expand All @@ -116,15 +114,20 @@ private ItemStack shearLogic(LivingEntity entity, ItemStack item) {
}
}
return item;
} else if (entity instanceof MushroomCow mushroomCow) {
ItemStack mushrooms = new ItemStack(getMaterial(mushroomCow), 1);
Drops.dropItem(mushroomCow.getLocation(), mushrooms, (amount - 1) * 5, true);
// Spawn separate normal cow for the rest of the stack.
Entity cow = mushroomCow.getWorld().spawnEntity(mushroomCow.getLocation(), EntityType.COW);
StackEntity stackCow = sm.getEntityManager().registerStackedEntity((LivingEntity) cow);
stackCow.setSize(amount - 1);
return item;
} else if (entity instanceof Snowman snowman) {
ItemStack carvedPumpkin = new ItemStack(Material.CARVED_PUMPKIN, 1);
Drops.dropItem(snowman.getLocation(), carvedPumpkin, (amount - 1), true);
return item;
}
MushroomCow mushroomCow = (MushroomCow) entity;
ItemStack mushrooms = new ItemStack(getMaterial(mushroomCow), 1);
Drops.dropItem(mushroomCow.getLocation(), mushrooms, (amount - 1) * 5, true);
// Spawn separate normal cow for the rest of the stack.
Entity cow = mushroomCow.getWorld().spawnEntity(mushroomCow.getLocation(), EntityType.COW);
StackEntity stackCow = sm.getEntityManager().registerStackedEntity((LivingEntity) cow);
stackCow.setSize(amount - 1);
return item;
return null;
}

private Material getMaterial(MushroomCow mushroomCow) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ traits:
frog-variant: true
sheep-color: true
sheep-sheared: true
snowman-sheared: true
slime-size: true
horse-color: true
llama-color: true
Expand Down