本文整理汇总了Java中cn.nukkit.entity.item.EntityPainting.spawnToAll方法的典型用法代码示例。如果您正苦于以下问题:Java EntityPainting.spawnToAll方法的具体用法?Java EntityPainting.spawnToAll怎么用?Java EntityPainting.spawnToAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.entity.item.EntityPainting
的用法示例。
在下文中一共展示了EntityPainting.spawnToAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivate
import cn.nukkit.entity.item.EntityPainting; //导入方法依赖的package包/类
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4);
if (chunk == null) {
return false;
}
if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) {
int[] direction = {2, 0, 1, 3};
int[] right = {4, 5, 3, 2};
List<EntityPainting.Motive> validMotives = new ArrayList<>();
for (EntityPainting.Motive motive : EntityPainting.motives) {
boolean valid = true;
for (int x = 0; x < motive.width && valid; x++) {
for (int z = 0; z < motive.height && valid; z++) {
if (target.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isTransparent() ||
target.up(z).isTransparent() ||
block.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isSolid() ||
block.up(z).isSolid()) {
valid = false;
}
}
}
if (valid) {
validMotives.add(motive);
}
}
CompoundTag nbt = new CompoundTag()
.putByte("Direction", direction[face.getIndex() - 2])
.putString("Motive", validMotives.get(ThreadLocalRandom.current().nextInt(validMotives.size())).title)
.putList(new ListTag<DoubleTag>("Pos")
.add(new DoubleTag("0", target.x))
.add(new DoubleTag("1", target.y))
.add(new DoubleTag("2", target.z)))
.putList(new ListTag<DoubleTag>("Motion")
.add(new DoubleTag("0", 0))
.add(new DoubleTag("1", 0))
.add(new DoubleTag("2", 0)))
.putList(new ListTag<FloatTag>("Rotation")
.add(new FloatTag("0", direction[face.getIndex() - 2] * 90))
.add(new FloatTag("1", 0)));
EntityPainting entity = new EntityPainting(chunk, nbt);
if (player.isSurvival()) {
Item item = player.getInventory().getItemInHand();
item.setCount(item.getCount() - 1);
player.getInventory().setItemInHand(item);
}
entity.spawnToAll();
return true;
}
return false;
}
示例2: onActivate
import cn.nukkit.entity.item.EntityPainting; //导入方法依赖的package包/类
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, int face, double fx, double fy, double fz) {
FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4);
if (chunk == null) {
return false;
}
if (!target.isTransparent() && face > 1 && !block.isSolid()) {
int[] direction = {2, 0, 1, 3};
int[] right = {4, 5, 3, 2};
List<EntityPainting.Motive> validMotives = new ArrayList<>();
for (EntityPainting.Motive motive : EntityPainting.motives) {
boolean valid = true;
for (int x = 0; x < motive.width && valid; x++) {
for (int z = 0; z < motive.height && valid; z++) {
if (target.getSide(right[face - 2], x).isTransparent() ||
target.getSide(Vector3.SIDE_UP, z).isTransparent() ||
block.getSide(right[face - 2], x).isSolid() ||
block.getSide(Vector3.SIDE_UP, z).isSolid()) {
valid = false;
}
}
}
if (valid) {
validMotives.add(motive);
}
}
CompoundTag nbt = new CompoundTag()
.putByte("Direction", direction[face - 2])
.putString("Motive", validMotives.get(ThreadLocalRandom.current().nextInt(validMotives.size())).title)
.putList(new ListTag<DoubleTag>("Pos")
.add(new DoubleTag("0", target.x))
.add(new DoubleTag("1", target.y))
.add(new DoubleTag("2", target.z)))
.putList(new ListTag<DoubleTag>("Motion")
.add(new DoubleTag("0", 0))
.add(new DoubleTag("1", 0))
.add(new DoubleTag("2", 0)))
.putList(new ListTag<FloatTag>("Rotation")
.add(new FloatTag("0", direction[face - 2] * 90))
.add(new FloatTag("1", 0)));
EntityPainting entity = new EntityPainting(chunk, nbt);
if (player.isSurvival()) {
Item item = player.getInventory().getItemInHand();
item.setCount(item.getCount() - 1);
player.getInventory().setItemInHand(item);
}
entity.spawnToAll();
return true;
}
return false;
}