cn.nukkit.dispenser.DefaultDispenseBehavior Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.dispenser;
import cn.nukkit.block.BlockDispenser;
import cn.nukkit.item.Item;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.BlockFace.Axis;
import cn.nukkit.math.Vector3;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author CreeperFace
*/
public class DefaultDispenseBehavior implements DispenseBehavior {
public boolean success = true;
@Override
public Item dispense(BlockDispenser block, BlockFace face, Item item) {
Vector3 dispensePos = block.getDispensePosition();
if (face.getAxis() == Axis.Y) {
dispensePos.y -= 0.125;
} else {
dispensePos.y -= 0.15625;
}
Random rand = ThreadLocalRandom.current();
Vector3 motion = new Vector3();
double offset = rand.nextDouble() * 0.1 + 0.2;
motion.x = face.getXOffset() * offset;
motion.y = 0.20000000298023224;
motion.z = face.getZOffset() * offset;
motion.x += rand.nextGaussian() * 0.007499999832361937 * 6;
motion.y += rand.nextGaussian() * 0.007499999832361937 * 6;
motion.z += rand.nextGaussian() * 0.007499999832361937 * 6;
Item clone = item.clone();
clone.count = 1;
block.level.dropItem(dispensePos, clone, motion);
return null;
}
private int getParticleMetadataForFace(BlockFace face) {
return face.getXOffset() + 1 + (face.getZOffset() + 1) * 3;
}
}