本文整理汇总了Java中net.minecraft.item.ItemBlock.setTileEntityNBT方法的典型用法代码示例。如果您正苦于以下问题:Java ItemBlock.setTileEntityNBT方法的具体用法?Java ItemBlock.setTileEntityNBT怎么用?Java ItemBlock.setTileEntityNBT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemBlock
的用法示例。
在下文中一共展示了ItemBlock.setTileEntityNBT方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onItemUse
import net.minecraft.item.ItemBlock; //导入方法依赖的package包/类
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(fruitType.toString(), "cake")));
if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
facing = EnumFacing.UP;
else if (!block.isReplaceable(worldIn, pos))
pos = pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
if (!worldIn.setBlockState(pos, blockState, 11))
return EnumActionResult.FAIL;
else {
blockState = worldIn.getBlockState(pos);
if (blockState.getBlock() == cake) {
ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
}
SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
return EnumActionResult.SUCCESS;
}
}
else
return EnumActionResult.FAIL;
}
示例2: onItemUse
import net.minecraft.item.ItemBlock; //导入方法依赖的package包/类
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(vegetableType.toString(), "cake")));
if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
facing = EnumFacing.UP;
else if (!block.isReplaceable(worldIn, pos))
pos = pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
if (!worldIn.setBlockState(pos, blockState, 11))
return EnumActionResult.FAIL;
else {
blockState = worldIn.getBlockState(pos);
if (blockState.getBlock() == cake) {
ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
}
SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
return EnumActionResult.SUCCESS;
}
}
else
return EnumActionResult.FAIL;
}