All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.event.block.TurtleEggHatchEvent Maven / Gradle / Ivy

Go to download

A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.

There is a newer version: 1.6.0.1-PN
Show newest version
package cn.nukkit.event.block;

import cn.nukkit.block.Block;
import cn.nukkit.block.BlockAir;
import cn.nukkit.block.BlockTurtleEgg;
import cn.nukkit.event.Cancellable;
import cn.nukkit.event.HandlerList;

public class TurtleEggHatchEvent extends BlockEvent implements Cancellable {

    private static final HandlerList handlers = new HandlerList();

    private int eggsHatching;
    private Block newState;
    private boolean recalculateOnFailure = true;

    public TurtleEggHatchEvent(BlockTurtleEgg turtleEgg, int eggsHatching, Block newState) {
        super(turtleEgg);
        this.eggsHatching = eggsHatching;
        this.newState = newState;
    }

    public void recalculateNewState() {
        BlockTurtleEgg turtleEgg = getBlock();
        int eggCount = turtleEgg.getEggCount();
        int eggsHatching = this.eggsHatching;
        if (eggCount <= eggsHatching) {
            newState = new BlockAir();
        } else {
            turtleEgg = turtleEgg.clone();
            turtleEgg.setEggCount(eggCount - eggsHatching);
            newState = turtleEgg;
        }
    }

    public Block getNewState() {
        return newState;
    }

    public void setNewState(Block newState) {
        this.newState = newState;
    }

    @Override
    public BlockTurtleEgg getBlock() {
        return (BlockTurtleEgg) super.getBlock();
    }

    public int getEggsHatching() {
        return eggsHatching;
    }

    public void setEggsHatching(int eggsHatching) {
        this.eggsHatching = eggsHatching;
    }

    public boolean isRecalculateOnFailure() {
        return recalculateOnFailure;
    }

    public void setRecalculateOnFailure(boolean recalculateOnFailure) {
        this.recalculateOnFailure = recalculateOnFailure;
    }

    public static HandlerList getHandlers() {
        return handlers;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy