本文整理汇总了Java中org.spongepowered.api.world.World.setBlock方法的典型用法代码示例。如果您正苦于以下问题:Java World.setBlock方法的具体用法?Java World.setBlock怎么用?Java World.setBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.world.World
的用法示例。
在下文中一共展示了World.setBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performRemoval
import org.spongepowered.api.world.World; //导入方法依赖的package包/类
private void performRemoval(LookupLine line) {
World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
if (w == null) return;
if (line.getTarget() instanceof ItemType) {
Optional<TileEntity> te = w.getTileEntity(line.getPos());
if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
TileEntityCarrier c = (TileEntityCarrier) te.get();
Inventory i = c.getInventory();
Inventory slot = i.query(new SlotIndex(line.getSlot()));
slot.set(ItemStack.of(ItemTypes.NONE, 0));
}
} else if (line.getTarget() instanceof BlockType) {
BlockState block = BlockState.builder().blockType(BlockTypes.AIR).build();
w.setBlock(line.getPos(), block, Cause.source(container).build());
}
}
示例2: performAddition
import org.spongepowered.api.world.World; //导入方法依赖的package包/类
private void performAddition(LookupLine line) {
//TODO: Debug this function, blocks are not being added
World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
if (w == null) return;
if (line.getTarget() instanceof ItemType) {
Optional<TileEntity> te = w.getTileEntity(line.getPos());
if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
TileEntityCarrier c = (TileEntityCarrier) te.get();
Inventory i = c.getInventory();
ItemType type = (ItemType) line.getTarget();
ItemStack stack = ItemStack.builder()
.fromContainer(line.getDataAsView())
.itemType(type)
.quantity(line.getCount())
.build();
Inventory slot = i.query(new SlotIndex(line.getSlot()));
slot.set(stack);
}
} else if (line.getTarget() instanceof BlockType) {
BlockState block = BlockState.builder().build(line.getDataAsView()).orElse(null);
if (block != null)
w.setBlock(line.getPos(), block, Cause.source(container).build());
}
}