Search in sources :

Example 1 with SlimeEntity

use of net.minecraft.entity.monster.SlimeEntity in project Arclight by IzzelAliz.

the class SlimeEntityMixin method remove.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite(remap = false)
@Override
public void remove(boolean keepData) {
    int i = this.getSlimeSize();
    if (!this.world.isRemote && i > 1 && this.getHealth() <= 0.0f) {
        int j = 2 + this.rand.nextInt(3);
        SlimeSplitEvent event = new SlimeSplitEvent((Slime) this.getBukkitEntity(), j);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled() || event.getCount() <= 0) {
            super.remove(keepData);
            return;
        }
        j = event.getCount();
        List<LivingEntity> slimes = new ArrayList<>(j);
        for (int k = 0; k < j; ++k) {
            float f = (k % 2 - 0.5f) * i / 4.0f;
            float f2 = (k / 2 - 0.5f) * i / 4.0f;
            SlimeEntity entityslime = this.getType().create(this.world);
            if (this.hasCustomName()) {
                entityslime.setCustomName(this.getCustomName());
            }
            if (this.isNoDespawnRequired()) {
                entityslime.enablePersistence();
            }
            entityslime.setInvulnerable(this.isInvulnerable());
            entityslime.setSlimeSize(i / 2, true);
            entityslime.setLocationAndAngles(this.posX + f, this.posY + 0.5, this.posZ + f2, this.rand.nextFloat() * 360.0f, 0.0f);
            slimes.add(entityslime);
        }
        if (CraftEventFactory.callEntityTransformEvent((SlimeEntity) (Object) this, slimes, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) {
            return;
        }
        for (LivingEntity living : slimes) {
            ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SLIME_SPLIT);
            this.world.addEntity(living);
        }
    }
    super.remove(keepData);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) ArrayList(java.util.ArrayList) SlimeSplitEvent(org.bukkit.event.entity.SlimeSplitEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 ArrayList (java.util.ArrayList)1 LivingEntity (net.minecraft.entity.LivingEntity)1 SlimeEntity (net.minecraft.entity.monster.SlimeEntity)1 SlimeSplitEvent (org.bukkit.event.entity.SlimeSplitEvent)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1