当前位置: 首页>>代码示例>>Java>>正文


Java World.getTileEntity方法代码示例

本文整理汇总了Java中org.spongepowered.api.world.World.getTileEntity方法的典型用法代码示例。如果您正苦于以下问题:Java World.getTileEntity方法的具体用法?Java World.getTileEntity怎么用?Java World.getTileEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.world.World的用法示例。


在下文中一共展示了World.getTileEntity方法的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());
		
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:23,代码来源:RollbackManager.java

示例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());
		
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:32,代码来源:RollbackManager.java


注:本文中的org.spongepowered.api.world.World.getTileEntity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。